Skip to content

Commit 3ac81ad

Browse files
committed
250804.1
1 parent c781abe commit 3ac81ad

File tree

5 files changed

+105
-29
lines changed

5 files changed

+105
-29
lines changed
Binary file not shown.

easycoder/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
from .ec_timestamp import *
1212
from .ec_value import *
1313

14-
__version__ = "250729.1"
14+
__version__ = "250804.1"

easycoder/ec_keyboard.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
QVBoxLayout,
77
QHBoxLayout,
88
QPushButton,
9+
QLineEdit,
10+
QPlainTextEdit,
911
QWidget,
1012
QStackedWidget,
1113
QSpacerItem,
@@ -126,10 +128,16 @@ def backspace(self):
126128
self.field.setText(current_text[:-1])
127129

128130
def setContent(self, text):
129-
self.field.setText(text)
131+
if isinstance(self.field, QLineEdit):
132+
self.field.setText(text)
133+
elif isinstance(self.field, QPlainTextEdit):
134+
self.field.setPlainText(text)
130135

131136
def getContent(self):
132-
return self.field.text()
137+
if isinstance(self.field, QLineEdit):
138+
return self.field.text()
139+
elif isinstance(self.field, QPlainTextEdit):
140+
return self.field.toPlainText()
133141

134142
class KeyboardButton(QPushButton):
135143
def __init__(self, width, height, onClick, text=None, icon=None):

easycoder/ec_pyside.py

Lines changed: 94 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
QLabel,
1717
QLCDNumber,
1818
QLineEdit,
19+
QPlainTextEdit,
1920
QListWidget,
2021
QMainWindow,
2122
QProgressBar,
@@ -52,7 +53,20 @@ def closeEvent(self):
5253
print('window closed')
5354

5455
def isWidget(self, keyword):
55-
return keyword in ['layout', 'groupbox', 'label', 'pushbutton', 'checkbox', 'lineinput', 'listbox', 'combobox']
56+
return keyword in [
57+
'layout',
58+
'groupbox',
59+
'label',
60+
'pushbutton',
61+
'checkbox',
62+
'lineinput',
63+
'multiline',
64+
'listbox',
65+
'combobox'
66+
]
67+
68+
def dialogTypes(self):
69+
return ['confirm', 'lineedit', 'multiline']
5670

5771
class ECDialog(QDialog):
5872
def __init__(self, parent, record):
@@ -334,6 +348,23 @@ def k_createLineEdit(self, command):
334348
self.add(command)
335349
return True
336350

351+
def k_createMultiLineEdit(self, command):
352+
cols = self.compileConstant(30)
353+
rows = self.compileConstant(5)
354+
while True:
355+
next = self.peek()
356+
if next == 'cols':
357+
self.nextToken()
358+
cols = self.nextValue()
359+
elif next == 'rows':
360+
self.nextToken()
361+
rows = self.nextValue()
362+
else: break;
363+
command['cols'] = cols
364+
command['rows'] = rows
365+
self.add(command)
366+
return True
367+
337368
def k_createListWidget(self, command):
338369
self.add(command)
339370
return True
@@ -351,7 +382,9 @@ def k_createDialog(self, command):
351382
while True:
352383
if self.peek() == 'type':
353384
self.nextToken()
354-
command['type'] = self.nextToken()
385+
dialogType = self.nextToken()
386+
if dialogType in self.dialogTypes(): command['type'] = dialogType
387+
else: return False
355388
elif self.peek() == 'title':
356389
self.nextToken()
357390
command['title'] = self.nextValue()
@@ -406,6 +439,7 @@ def k_create(self, command):
406439
elif keyword == 'pushbutton': return self.k_createPushbutton(command)
407440
elif keyword == 'checkbox': return self.k_createCheckBox(command)
408441
elif keyword == 'lineinput': return self.k_createLineEdit(command)
442+
elif keyword == 'multiline': return self.k_createMultiLineEdit(command)
409443
elif keyword == 'listbox': return self.k_createListWidget(command)
410444
elif keyword == 'combobox': return self.k_createComboBox(command)
411445
elif keyword == 'dialog': return self.k_createDialog(command)
@@ -486,6 +520,16 @@ def r_createLineEdit(self, command, record):
486520
record['widget'] = lineinput
487521
return self.nextPC()
488522

523+
def r_createMultiLineEdit(self, command, record):
524+
textinput = QPlainTextEdit()
525+
fontMetrics = textinput.fontMetrics()
526+
charWidth = fontMetrics.horizontalAdvance('x')
527+
charHeight = fontMetrics.height()
528+
textinput.setFixedWidth(charWidth * self.getRuntimeValue(command['cols']))
529+
textinput.setFixedHeight(charHeight * self.getRuntimeValue(command['rows']))
530+
record['widget'] = textinput
531+
return self.nextPC()
532+
489533
def r_createListWidget(self, command, record):
490534
record['widget'] = QListWidget()
491535
return self.nextPC()
@@ -504,18 +548,22 @@ def r_createDialog(self, command, record):
504548
dialogType = command['type'].lower()
505549
dialog.dialogType = dialogType
506550
prompt = self.getRuntimeValue(command['prompt'])
507-
if dialogType in ['confirm', 'lineedit']:
508-
if dialogType == 'confirm':
509-
mainLayout.addWidget(QLabel(prompt))
510-
elif dialogType == 'lineedit':
511-
mainLayout.addWidget(QLabel(prompt))
512-
dialog.lineEdit = QLineEdit(dialog)
513-
dialog.value = self.getRuntimeValue(command['value'])
514-
dialog.lineEdit.setText(dialog.value)
515-
mainLayout.addWidget(dialog.lineEdit)
516-
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, dialog)
517-
buttonBox.accepted.connect(dialog.accept)
518-
buttonBox.rejected.connect(dialog.reject)
551+
if dialogType == 'confirm':
552+
mainLayout.addWidget(QLabel(prompt))
553+
elif dialogType == 'lineedit':
554+
mainLayout.addWidget(QLabel(prompt))
555+
dialog.lineEdit = QLineEdit(dialog)
556+
dialog.value = self.getRuntimeValue(command['value'])
557+
dialog.lineEdit.setText(dialog.value)
558+
mainLayout.addWidget(dialog.lineEdit)
559+
elif dialogType == 'multiline':
560+
mainLayout.addWidget(QLabel(prompt))
561+
dialog.textEdit = QPlainTextEdit(self)
562+
dialog.textEdit.setText(dialog.value)
563+
mainLayout.addWidget(dialog.textEdit)
564+
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
565+
buttonBox.accepted.connect(self.accept)
566+
buttonBox.rejected.connect(self.reject)
519567
mainLayout.addWidget(buttonBox, alignment=Qt.AlignHCenter)
520568
record['dialog'] = dialog
521569
return self.nextPC()
@@ -540,6 +588,7 @@ def r_create(self, command):
540588
elif keyword == 'pushbutton': return self.r_createPushbutton(command, record)
541589
elif keyword == 'checkbox': return self.r_createCheckBox(command, record)
542590
elif keyword == 'lineinput': return self.r_createLineEdit(command, record)
591+
elif keyword == 'multiline': return self.r_createMultiLineEdit(command, record)
543592
elif keyword == 'listbox': return self.r_createListWidget(command, record)
544593
elif keyword == 'combobox': return self.r_createComboBox(command, record)
545594
elif keyword == 'dialog': return self.r_createDialog(command, record)
@@ -634,6 +683,13 @@ def k_messagebox(self, command):
634683
def r_messagebox(self, command):
635684
return self.nextPC()
636685

686+
# Declare a multiline input variable
687+
def k_multiline(self, command):
688+
return self.compileVariable(command, 'gui')
689+
690+
def r_multiline(self, command):
691+
return self.nextPC()
692+
637693
# on click {pushbutton}
638694
# on select {combobox}/{listbox}
639695
# on tick
@@ -794,8 +850,8 @@ def r_select(self, command):
794850
# set [the] width/height [of] {widget} [to] {value}
795851
# set [the] layout of {window} to {layout}
796852
# set [the] spacing of {layout} to {value}
797-
# set [the] text [of] {label}/{button}/{lineinput} [to] {text}
798-
# set [the] color [of] {label}/{button}/{lineinput} [to] {color}
853+
# set [the] text [of] {label}/{button}/{lineinput}/{multiline} [to] {text}
854+
# set [the] color [of] {label}/{button}/{lineinput}/{multiline} [to] {color}
799855
# set [the] state [of] {checkbox} [to] {color}
800856
# set {listbox} to {list}
801857
# set blocked true/false
@@ -839,7 +895,7 @@ def k_set(self, command):
839895
self.skip('of')
840896
if self.nextIsSymbol():
841897
record = self.getSymbolRecord()
842-
if record['keyword'] in ['label', 'pushbutton', 'lineinput']:
898+
if record['keyword'] in ['label', 'pushbutton', 'lineinput', 'multiline']:
843899
command['name'] = record['name']
844900
self.skip('to')
845901
command['value'] = self.nextValue()
@@ -870,7 +926,7 @@ def k_set(self, command):
870926
self.skip('of')
871927
if self.nextIsSymbol():
872928
record = self.getSymbolRecord()
873-
if record['keyword'] in ['label', 'pushbutton', 'lineinput']:
929+
if record['keyword'] in ['label', 'pushbutton', 'lineinput', 'multiline']:
874930
command['name'] = record['name']
875931
self.skip('to')
876932
command['value'] = self.nextValue()
@@ -911,7 +967,10 @@ def r_set(self, command):
911967
record = self.getVariable(command['name'])
912968
widget = self.getVariable(command['name'])['widget']
913969
text = self.getRuntimeValue(command['value'])
914-
widget.setText(text)
970+
if isinstance(widget, QLineEdit):
971+
widget.setText(text)
972+
elif isinstance(widget, QPlainTextEdit):
973+
widget.setPlainText(text)
915974
if record['keyword'] == 'pushbutton':
916975
widget.setAccessibleName(text)
917976
elif what == 'state':
@@ -996,13 +1055,16 @@ def r_show(self, command):
9961055
elif 'dialog' in command:
9971056
record = self.getVariable(command['dialog'])
9981057
dialog = record['dialog']
999-
if dialog.dialogType in ['confirm', 'lineedit']:
1000-
if dialog.dialogType == 'confirm':
1001-
record['result'] = True if dialog.exec() == QDialog.Accepted else False
1002-
elif dialog.dialogType == 'lineedit':
1003-
if dialog.exec() == QDialog.Accepted:
1004-
record['result'] = dialog.lineEdit.text()
1005-
else: record['result'] = dialog.value
1058+
if dialog.dialogType == 'confirm':
1059+
record['result'] = True if dialog.exec() == QDialog.Accepted else False
1060+
elif dialog.dialogType == 'lineedit':
1061+
if dialog.exec() == QDialog.Accepted:
1062+
record['result'] = dialog.lineEdit.text()
1063+
else: record['result'] = dialog.value
1064+
elif dialog.dialogType == 'multiline':
1065+
if dialog.exec() == QDialog.Accepted:
1066+
record['result'] = dialog.textEdit.toPlainText()
1067+
else: record['result'] = dialog.value
10061068
return self.nextPC()
10071069

10081070
# Start the graphics
@@ -1101,6 +1163,12 @@ def v_symbol(self, symbolRecord):
11011163
v['type'] = 'text'
11021164
v['content'] = lineinput.displayText()
11031165
return v
1166+
elif keyword == 'multiline':
1167+
multiline = symbolRecord['widget']
1168+
v = {}
1169+
v['type'] = 'text'
1170+
v['content'] = multiline.toPlainText()
1171+
return v
11041172
elif keyword == 'combobox':
11051173
combobox = symbolRecord['widget']
11061174
v = {}

0 commit comments

Comments
 (0)