namespacedialog.py
Go to the documentation of this file.
1 '''
2  Copyright (C) 1997-2017 JDERobot Developers Team
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Library General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, see <http://www.gnu.org/licenses/>.
16 
17  Authors : Okan Asik (asik.okan@gmail.com)
18  Pushkal Katara (katarapushkal@gmail.com)
19 
20  '''
21 
22 from PyQt5.QtCore import pyqtSignal
23 from PyQt5.QtWidgets import QDialog, QLineEdit, QVBoxLayout, QHBoxLayout, QPushButton, \
24  QWidget, QApplication, QLabel, QComboBox, QRadioButton, \
25  QFormLayout, QTabWidget, QPlainTextEdit, QInputDialog, QFileDialog, QMessageBox
26 from PyQt5.QtGui import QFontDatabase, QColor, QFontMetrics
27 from PyQt5.Qsci import QsciScintilla, QsciLexerPython, QsciLexerCPP
28 
29 class NamespaceDialog(QDialog):
30  namespaceChanged = pyqtSignal()
31 
32  def __init__(self, name, namespace):
33  super(QDialog, self).__init__()
34  self.setWindowTitle(name)
35  self.resize(800,600)
36 
37  self.namespace = namespace
38 
39  mainLayout = QVBoxLayout()
40 
41  self.pythonButton = QRadioButton('Python')
42  self.pythonButton.setChecked(True)
43  self.pythonButton.clicked.connect(self.pythonClicked)
44  self.cppButton = QRadioButton('C++')
45  self.cppButton.clicked.connect(self.cppClicked)
46 
47  hLayout0 = QHBoxLayout()
48  hLayout0.addWidget(self.pythonButton)
49  hLayout0.addWidget(self.cppButton)
50  container0 = QWidget()
51  container0.setLayout(hLayout0)
52  mainLayout.addWidget(container0)
53 
54  self.language = 'python'
55 
56  self.tabWidget = QTabWidget()
57 
58  self.functionTab = FunctionsTab(self.namespace.getFunctions())
59  self.functionTab.functionsChanged.connect(self.functionsChanged)
60  self.tabWidget.addTab(self.functionTab, 'Functions')
61 
62  self.variableTab = VariablesTab(self.namespace.getVariables())
63  self.variableTab.variablesChanged.connect(self.variablesChanged)
64  self.tabWidget.addTab(self.variableTab, 'Variables')
65 
66  mainLayout.addWidget(self.tabWidget)
67 
68  self.setLayout(mainLayout)
69 
70  def functionsChanged(self, functions):
71  self.namespace.setFunctions(functions)
72  self.namespaceChanged.emit()
73 
74  def variablesChanged(self, variables):
75  self.namespace.setVariables(variables)
76  self.namespaceChanged.emit()
77 
78  def setNamespace(self, namespace):
79  self.namespace = namespace
80 
81  def getNamespace(self):
82  return self.namespace
83 
84  def pythonClicked(self):
85  #TODO
86  pass
87 
88  def cppClicked(self):
89  #TODO
90  pass
91 
92 class FunctionsTab(QDialog):
93  functionsChanged = pyqtSignal('QString')
94 
95  def __init__(self, functions):
96  super(QDialog, self).__init__()
97 
98  self.codeDialog = CodeDialog(functions)
99 
100  verticalLayout = QVBoxLayout()
101  verticalLayout.addWidget(self.codeDialog)
102  self.setLayout(verticalLayout)
103 
104  self.codeDialog.codeChanged.connect(self.changeFunctions)
105 
106  def changeFunctions(self, functions):
107  self.functionsChanged.emit(functions)
108 
109 
110 class VariablesTab(QDialog):
111  variablesChanged = pyqtSignal('QString')
112 
113  def __init__(self, variables):
114  super(QDialog, self).__init__()
115 
116  self.codeDialog = CodeDialog(variables)
117 
118  verticalLayout = QVBoxLayout()
119  verticalLayout.addWidget(self.codeDialog)
120  self.setLayout(verticalLayout)
121 
122  self.codeDialog.codeChanged.connect(self.changeVariables)
123 
124  def changeVariables(self, variables):
125  self.variablesChanged.emit(variables)
126 
127 class CodeDialog(QDialog):
128  codeChanged = pyqtSignal('QString')
129 
130  def __init__(self, code):
131  super(QDialog, self).__init__()
132 
133  self.codeEdit = QsciScintilla()
134  self.codeEdit.setText(code)
135  fixedWidthFont = QFontDatabase.systemFont(QFontDatabase.FixedFont)
136  self.codeEdit.setFont(fixedWidthFont)
137  fontmetrics = QFontMetrics(fixedWidthFont)
138  self.codeEdit.setMarginWidth(0, fontmetrics.width("000"))
139  self.codeEdit.setMarginLineNumbers(0, True)
140  self.codeEdit.setMarginsBackgroundColor(QColor("#cccccc"))
141 
142  self.codeEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch)
143  self.codeEdit.setCaretLineVisible(True)
144  self.codeEdit.setCaretLineBackgroundColor(QColor("#ffe4e4"))
145  lexer = QsciLexerPython()
146  lexer.setDefaultFont(fixedWidthFont)
147  self.codeEdit.setLexer(lexer)
148  self.codeEdit.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
149  self.codeEdit.setUtf8(True)
150 
151  self.codeEdit.setTabWidth(4)
152  self.codeEdit.setIndentationsUseTabs(True)
153  self.codeEdit.setIndentationGuides(True)
154  self.codeEdit.setTabIndents(True)
155  self.codeEdit.setAutoIndent(True)
156 
157  verticalLayout = QVBoxLayout()
158  verticalLayout.addWidget(self.codeEdit)
159  self.setLayout(verticalLayout)
160 
161  self.codeEdit.textChanged.connect(self.changeCode)
162 
163  def changeCode(self):
164  self.codeChanged.emit(self.codeEdit.text())


visualstates
Author(s):
autogenerated on Thu Apr 1 2021 02:42:20