Skip to content

Commit df0028b

Browse files
committed
250810.2
1 parent 5646f7c commit df0028b

File tree

4 files changed

+75
-19
lines changed

4 files changed

+75
-19
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__ = "250810.1"
14+
__version__ = "250810.2"

easycoder/ec_pyside.py

Lines changed: 74 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def closeEvent(self):
5454
def isWidget(self, keyword):
5555
return keyword in [
5656
'layout',
57-
'groupbox',
57+
'group',
5858
'label',
5959
'pushbutton',
6060
'checkbox',
@@ -115,11 +115,12 @@ def mousePressEvent(self, event):
115115
# (3) add stretch {widget} to {layout}
116116
# (4) add stretch to {layout}
117117
# (5) add spacer {size} to {layout}
118+
# (6) add {widget} at {col} {row} in {grid layout}
118119
def k_add(self, command):
119120
def addToLayout():
120121
if self.nextIsSymbol():
121122
record = self.getSymbolRecord()
122-
if record['keyword'] in ['layout', 'groupbox', 'element']:
123+
if record['keyword'] in ['layout', 'group', 'element']:
123124
command['layout'] = record['name']
124125
self.add(command)
125126
return True
@@ -155,12 +156,20 @@ def addToLayout():
155156
record = self.getSymbolRecord()
156157
if record['extra'] == 'gui':
157158
if self.isWidget(record['keyword']):
159+
command['widget'] = record['name']
158160
if self.peek() == 'to':
159161
# (2)
160162
record = self.getSymbolRecord()
161-
command['widget'] = record['name']
162163
self.nextToken()
163164
return addToLayout()
165+
elif self.peek() == 'at':
166+
# (6)
167+
self.nextToken()
168+
command['row'] = self.nextValue()
169+
command['col'] = self.nextValue()
170+
self.skip('in')
171+
return addToLayout()
172+
164173
else: return False
165174
# (1)
166175
value = self.getValue()
@@ -180,6 +189,12 @@ def r_add(self, command):
180189
widget = self.getVariable(command['widget'])
181190
if widget['keyword'] in ['listbox', 'combobox']:
182191
widget['widget'].addItem(value)
192+
elif 'row' in command and 'col' in command:
193+
layout = self.getVariable(command['layout'])['widget']
194+
widget = self.getVariable(command['widget'])['widget']
195+
row = self.getRuntimeValue(command['row'])
196+
col = self.getRuntimeValue(command['col'])
197+
layout.addWidget(widget, row, col)
183198
else:
184199
layoutRecord = self.getVariable(command['layout'])
185200
widget = command['widget']
@@ -194,11 +209,11 @@ def r_add(self, command):
194209
layout = layoutRecord['widget']
195210
stretch = 'stretch' in command
196211
if widgetRecord['keyword'] == 'layout':
197-
if layoutRecord['keyword'] == 'groupbox':
212+
if layoutRecord['keyword'] == 'group':
198213
if widgetRecord['keyword'] == 'layout':
199214
layout.setLayout(widget)
200215
else:
201-
RuntimeError(self.program, 'Can only add a layout to a groupbox')
216+
RuntimeError(self.program, 'Can only add a layout to a group')
202217
else:
203218
if stretch: layout.addLayout(widget, stretch=1)
204219
else: layout.addLayout(widget)
@@ -363,7 +378,7 @@ def k_createCheckBox(self, command):
363378
if self.peek() == 'text':
364379
self.nextToken()
365380
text = self.nextValue()
366-
else: text = ''
381+
else: text = self.compileConstant('')
367382
command['text'] = text
368383
self.add(command)
369384
return True
@@ -471,7 +486,7 @@ def k_create(self, command):
471486
keyword = record['keyword']
472487
if keyword == 'window': return self.k_createWindow(command)
473488
elif keyword == 'layout': return self.k_createLayout(command)
474-
elif keyword == 'groupbox': return self.k_createGroupBox(command)
489+
elif keyword == 'group': return self.k_createGroupBox(command)
475490
elif keyword == 'label': return self.k_createLabel(command)
476491
elif keyword == 'pushbutton': return self.k_createPushbutton(command)
477492
elif keyword == 'checkbox': return self.k_createCheckBox(command)
@@ -499,19 +514,19 @@ def r_createWindow(self, command, record):
499514
return self.nextPC()
500515

501516
def r_createLayout(self, command, record):
502-
type = command['type']
503-
if type == 'QHBoxLayout': layout = QHBoxLayout()
504-
elif type == 'QGridLayout': layout = QGridLayout()
505-
elif type == 'QStackedLayout': layout = QStackedLayout()
517+
layoutType = command['type']
518+
if layoutType == 'QHBoxLayout': layout = QHBoxLayout()
519+
elif layoutType == 'QGridLayout': layout = QGridLayout()
520+
elif layoutType == 'QStackedLayout': layout = QStackedLayout()
506521
else: layout = QVBoxLayout()
507-
layout.setContentsMargins(5,0,5,0)
522+
layout.setContentsMargins(5,5,5,5)
508523
record['widget'] = layout
509524
return self.nextPC()
510525

511526
def r_createGroupBox(self, command, record):
512-
groupbox = QGroupBox(self.getRuntimeValue(command['title']))
513-
groupbox.setAlignment(Qt.AlignLeft)
514-
record['widget'] = groupbox
527+
group = QGroupBox(self.getRuntimeValue(command['title']))
528+
group.setAlignment(Qt.AlignLeft)
529+
record['widget'] = group
515530
return self.nextPC()
516531

517532
def r_createLabel(self, command, record):
@@ -548,6 +563,7 @@ def r_createPushbutton(self, command, record):
548563

549564
def r_createCheckBox(self, command, record):
550565
checkbox = QCheckBox(self.getRuntimeValue(command['text']))
566+
checkbox.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred)
551567
record['widget'] = checkbox
552568
return self.nextPC()
553569

@@ -625,7 +641,7 @@ def r_create(self, command):
625641
keyword = record['keyword']
626642
if keyword == 'window': return self.r_createWindow(command, record)
627643
elif keyword == 'layout': return self.r_createLayout(command, record)
628-
elif keyword == 'groupbox': return self.r_createGroupBox(command, record)
644+
elif keyword == 'group': return self.r_createGroupBox(command, record)
629645
elif keyword == 'label': return self.r_createLabel(command, record)
630646
elif keyword == 'pushbutton': return self.r_createPushbutton(command, record)
631647
elif keyword == 'checkbox': return self.r_createCheckBox(command, record)
@@ -669,10 +685,10 @@ def r_enable(self, command):
669685
return self.nextPC()
670686

671687
# Create a group box
672-
def k_groupbox(self, command):
688+
def k_group(self, command):
673689
return self.compileVariable(command, 'gui')
674690

675-
def r_groupbox(self, command):
691+
def r_group(self, command):
676692
return self.nextPC()
677693

678694
# Initialize the graphics environment
@@ -953,6 +969,29 @@ def k_set(self, command):
953969
command['value'] = self.nextValue()
954970
self.add(command)
955971
return True
972+
elif token == 'alignment':
973+
self.skip('of')
974+
if self.nextIsSymbol():
975+
record = self.getSymbolRecord()
976+
if record['extra'] == 'gui':
977+
command['name'] = record['name']
978+
self.skip('to')
979+
flags = []
980+
while self.peek() in ['left', 'hcenter', 'right', 'top', 'vcenter', 'bottom', 'center']:
981+
flags.append(self.nextToken())
982+
command['value'] = flags
983+
self.add(command)
984+
return True
985+
elif token == 'style':
986+
self.skip('of')
987+
if self.nextIsSymbol():
988+
record = self.getSymbolRecord()
989+
if record['keyword'] == 'label':
990+
command['name'] = record['name']
991+
self.skip('to')
992+
command['value'] = self.nextValue()
993+
self.add(command)
994+
return True
956995
elif token == 'color':
957996
self.skip('of')
958997
if self.nextIsSymbol():
@@ -1021,6 +1060,23 @@ def r_set(self, command):
10211060
widget = self.getVariable(command['name'])['widget']
10221061
state = self.getRuntimeValue(command['value'])
10231062
widget.setChecked(state)
1063+
elif what == 'alignment':
1064+
widget = self.getVariable(command['name'])['widget']
1065+
flags = command['value']
1066+
alignment = 0
1067+
for flag in flags:
1068+
if flag == 'left': alignment |= Qt.AlignLeft
1069+
elif flag == 'hcenter': alignment |= Qt.AlignHCenter
1070+
elif flag == 'right': alignment |= Qt.AlignRight
1071+
elif flag == 'top': alignment |= Qt.AlignTop
1072+
elif flag == 'vcenter': alignment |= Qt.AlignVCenter
1073+
elif flag == 'bottom': alignment |= Qt.AlignBottom
1074+
elif flag == 'center': alignment |= Qt.AlignCenter
1075+
widget.setAlignment(alignment)
1076+
elif what == 'style':
1077+
widget = self.getVariable(command['name'])['widget']
1078+
styles = self.getRuntimeValue(command['value'])
1079+
widget.setStyleSheet(styles)
10241080
elif what == 'color':
10251081
widget = self.getVariable(command['name'])['widget']
10261082
color = self.getRuntimeValue(command['value'])

0 commit comments

Comments
 (0)