Skip to content

Commit 631826b

Browse files
committed
250809.1
1 parent fdcb1a7 commit 631826b

File tree

9 files changed

+79
-55
lines changed

9 files changed

+79
-55
lines changed
47.6 KB
Binary file not shown.
2.66 MB
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__ = "250807.2"
14+
__version__ = "250809.1"

easycoder/ec_keyboard.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import os
32
from .ec_handler import Handler
43
from PySide6.QtWidgets import (
@@ -14,7 +13,7 @@
1413
QSizePolicy,
1514
QGraphicsDropShadowEffect
1615
)
17-
from PySide6.QtGui import QFont, QIcon, QPixmap, QPainter, QColor
16+
from PySide6.QtGui import QFont, QIcon, QPixmap, QPainter
1817
from PySide6.QtCore import Qt, QTimer, Signal, QRect
1918

2019
class Keyboard(Handler):
@@ -65,22 +64,23 @@ def mouseReleaseEvent(self, event):
6564
self._drag_active = False
6665
super().mouseReleaseEvent(event)
6766

68-
def __init__(self, program, keyboardType, receiver, caller = None, parent=None):
67+
def __init__(self, program, keyboardType, receiverLayout, receivers, caller = None, parent=None):
6968
super().__init__(program.compiler)
7069

7170
self.program = program
7271
self.keyboardType = keyboardType
73-
self.receiver = receiver
72+
self.receivers = receivers
73+
self.selectedReceiver = receivers[0]
7474

7575
dialog = QDialog(caller)
7676
self.dialog = dialog
7777

7878
# dialog.setWindowTitle('')
7979
dialog.setWindowFlags(Qt.FramelessWindowHint)
8080
dialog.setModal(True)
81-
dialog.setFixedSize(500, 250)
81+
dialog.setFixedWidth(500)
8282
dialog.setStyleSheet('background-color: white;border:1px solid black;')
83-
self.originalText = receiver.getContent()
83+
self.originalText = self.selectedReceiver.getContent()
8484

8585
# Add drop shadow
8686
shadow = QGraphicsDropShadowEffect(dialog)
@@ -95,7 +95,8 @@ def __init__(self, program, keyboardType, receiver, caller = None, parent=None):
9595
border = self.Border()
9696
border.iconClicked.connect(self.reject)
9797
layout.addWidget(border)
98-
layout.addWidget(VirtualKeyboard(keyboardType, 42, receiver, dialog.accept))
98+
layout.addLayout(receiverLayout)
99+
layout.addWidget(VirtualKeyboard(keyboardType, 42, self.selectedReceiver, dialog.accept))
99100

100101
# Position at bottom of parent window
101102
dialog.show() # Ensure geometry is calculated
@@ -108,7 +109,7 @@ def __init__(self, program, keyboardType, receiver, caller = None, parent=None):
108109
dialog.exec()
109110

110111
def reject(self):
111-
self.receiver.setContent(self.originalText)
112+
self.selectedReceiver.setContent(self.originalText)
112113
self.dialog.reject()
113114

114115
class TextReceiver():

easycoder/ec_program.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __init__(self, argv):
4848
self.externalControl = False
4949
self.ticker = 0
5050
self.running = True
51-
self.start()
51+
# self.start()
5252

5353
# This is called at 10msec intervals by the GUI code
5454
def flushCB(self):

easycoder/ec_pyside.py

Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import sys
22
from .ec_handler import Handler
33
from .ec_classes import RuntimeError
4-
from .ec_keyboard import Keyboard, TextReceiver
5-
from PySide6.QtCore import Qt, QTimer
4+
from PySide6.QtCore import Qt, QTimer, Signal
65
from PySide6.QtGui import QPixmap
76
from PySide6.QtWidgets import (
87
QApplication,
@@ -80,6 +79,38 @@ def showEvent(self, event):
8079
def afterShown(self):
8180
if 'action' in self.record: self.record['action']()
8281

82+
class ClickableLineEdit(QLineEdit):
83+
clicked = Signal()
84+
85+
def __init__(self):
86+
super().__init__()
87+
self.program = None
88+
89+
def setCallback(self, program, pc):
90+
self.program = program
91+
self.pc = pc
92+
93+
def mousePressEvent(self, event):
94+
self.clicked.emit()
95+
super().mousePressEvent(event)
96+
if self.program != None: self.program.run(self.pc)
97+
98+
class ClickablePlainTextEdit(QPlainTextEdit):
99+
clicked = Signal()
100+
101+
def __init__(self):
102+
super().__init__()
103+
self.program = None
104+
105+
def setCallback(self, program, pc):
106+
self.program = program
107+
self.pc = pc
108+
109+
def mousePressEvent(self, event):
110+
self.clicked.emit()
111+
super().mousePressEvent(event)
112+
if self.program != None: self.program.run(self.pc)
113+
83114
#############################################################################
84115
# Keyword handlers
85116

@@ -297,21 +328,23 @@ def k_createGroupBox(self, command):
297328

298329
def k_createLabel(self, command):
299330
text = self.compileConstant('')
331+
size = self.compileConstant(20)
300332
while True:
301333
token = self.peek()
302334
if token == 'text':
303335
self.nextToken()
304336
text = self.nextValue()
305337
elif token == 'size':
306338
self.nextToken()
307-
command['size'] = self.nextValue()
339+
size = self.nextValue()
308340
elif token == 'align':
309341
self.nextToken()
310342
token = self.nextToken()
311343
if token in ['left', 'right', 'center', 'centre', 'justify']:
312344
command['align'] = token
313345
else: break
314346
command['text'] = text
347+
command['size'] = size
315348
self.add(command)
316349
return True
317350

@@ -340,11 +373,19 @@ def k_createCheckBox(self, command):
340373
return True
341374

342375
def k_createLineEdit(self, command):
343-
if self.peek() == 'size':
344-
self.nextToken()
345-
size = self.nextValue()
346-
else: size = self.compileConstant(10)
376+
text = self.compileConstant('')
377+
size = self.compileConstant(40)
378+
while True:
379+
token = self.peek()
380+
if token == 'text':
381+
self.nextToken()
382+
text = self.nextValue()
383+
elif token == 'size':
384+
self.nextToken()
385+
size = self.nextValue()
386+
else: break;
347387
command['size'] = size
388+
command['text'] = text
348389
self.add(command)
349390
return True
350391

@@ -479,6 +520,10 @@ def r_createGroupBox(self, command, record):
479520

480521
def r_createLabel(self, command, record):
481522
label = QLabel(str(self.getRuntimeValue(command['text'])))
523+
label.setStyleSheet("""
524+
background-color: transparent;
525+
border: none;
526+
""")
482527
if 'size' in command:
483528
fm = label.fontMetrics()
484529
c = label.contentsMargins()
@@ -500,7 +545,7 @@ def r_createPushbutton(self, command, record):
500545
if 'size' in command:
501546
fm = pushbutton.fontMetrics()
502547
c = pushbutton.contentsMargins()
503-
w = fm.horizontalAdvance('m') * self.getRuntimeValue(command['size']) +c.left()+c.right()
548+
w = fm.horizontalAdvance('m') * self.getRuntimeValue(command['size']) + c.left()+c.right()
504549
pushbutton.setMaximumWidth(w)
505550
record['widget'] = pushbutton
506551
return self.nextPC()
@@ -511,7 +556,8 @@ def r_createCheckBox(self, command, record):
511556
return self.nextPC()
512557

513558
def r_createLineEdit(self, command, record):
514-
lineinput = QLineEdit()
559+
lineinput = self.ClickableLineEdit()
560+
lineinput.setText(self.getRuntimeValue(command['text']))
515561
fm = lineinput.fontMetrics()
516562
m = lineinput.textMargins()
517563
c = lineinput.contentsMargins()
@@ -521,7 +567,7 @@ def r_createLineEdit(self, command, record):
521567
return self.nextPC()
522568

523569
def r_createMultiLineEdit(self, command, record):
524-
textinput = QPlainTextEdit()
570+
textinput = self.ClickablePlainTextEdit()
525571
fontMetrics = textinput.fontMetrics()
526572
charWidth = fontMetrics.horizontalAdvance('x')
527573
charHeight = fontMetrics.height()
@@ -552,13 +598,13 @@ def r_createDialog(self, command, record):
552598
mainLayout.addWidget(QLabel(prompt))
553599
elif dialogType == 'lineedit':
554600
mainLayout.addWidget(QLabel(prompt))
555-
dialog.lineEdit = QLineEdit(dialog)
601+
dialog.lineEdit = self.ClickableLineEdit(dialog)
556602
dialog.value = self.getRuntimeValue(command['value'])
557603
dialog.lineEdit.setText(dialog.value)
558604
mainLayout.addWidget(dialog.lineEdit)
559605
elif dialogType == 'multiline':
560606
mainLayout.addWidget(QLabel(prompt))
561-
dialog.textEdit = QPlainTextEdit(self)
607+
dialog.textEdit = self.ClickablePlainTextEdit(self)
562608
dialog.textEdit.setText(dialog.value)
563609
mainLayout.addWidget(dialog.textEdit)
564610
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
@@ -690,7 +736,7 @@ def k_multiline(self, command):
690736
def r_multiline(self, command):
691737
return self.nextPC()
692738

693-
# on click {pushbutton}
739+
# on click {pushbutton}/{lineinput}/{multiline}
694740
# on select {combobox}/{listbox}
695741
# on tick
696742
def k_on(self, command):
@@ -723,7 +769,7 @@ def setupOn():
723769
if token == 'click':
724770
if self.nextIsSymbol():
725771
record = self.getSymbolRecord()
726-
if record['keyword'] == 'pushbutton':
772+
if record['keyword'] in ['pushbutton', 'lineinput', 'multiline']:
727773
command['name'] = record['name']
728774
setupOn()
729775
return True
@@ -770,6 +816,8 @@ def r_on(self, command):
770816
keyword = record['keyword']
771817
if keyword == 'pushbutton':
772818
widget.clicked.connect(lambda: self.run(command['goto']))
819+
if keyword in ['lineinput', 'multiline']:
820+
widget.setCallback(self.program, command['goto'])
773821
elif keyword == 'combobox':
774822
widget.currentIndexChanged.connect(lambda: self.run(command['goto']))
775823
elif keyword == 'listbox':
@@ -895,7 +943,7 @@ def k_set(self, command):
895943
self.skip('of')
896944
if self.nextIsSymbol():
897945
record = self.getSymbolRecord()
898-
if record['keyword'] in ['label', 'pushbutton', 'lineinput', 'multiline']:
946+
if record['keyword'] in ['label', 'pushbutton', 'lineinput', 'multiline', 'element']:
899947
command['name'] = record['name']
900948
self.skip('to')
901949
command['value'] = self.nextValue()
@@ -968,7 +1016,8 @@ def r_set(self, command):
9681016
widget = self.getVariable(command['name'])['widget']
9691017
text = self.getRuntimeValue(command['value'])
9701018
keyword = record['keyword']
971-
if keyword in ['label', 'pushbutton', 'lineinput']:
1019+
setText = getattr(widget, "setText", None)
1020+
if callable(setText):
9721021
widget.setText(text)
9731022
elif keyword == 'multiline':
9741023
widget.setPlainText(text)

scripts/findxr.ecs

Lines changed: 0 additions & 26 deletions
This file was deleted.

testrc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
import os
44
from easycoder import Program
55

6-
os.chdir('../../rbr/')
7-
Program('rbrconf.ecs')
6+
os.chdir('../../rbr/roombyroom/Controller/ui')
7+
Program('rbrconf.ecs').start()

testui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
from easycoder import Program
55

66
os.chdir('../../rbr/roombyroom/Controller/ui')
7-
Program('rbr_ui.ecs')
7+
Program('rbr_ui.ecs').start()

0 commit comments

Comments
 (0)