Skip to content

Commit 22b7571

Browse files
committed
refactor def
1 parent 91b3b89 commit 22b7571

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

Source/GUI/Qt.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -320,27 +320,6 @@
320320
,"CMD:Settings:Display:Scroll Speed:<0 to 65,535>"
321321
,"CMD:Settings:Display:Invert:<True/False>"]
322322

323-
def movable_widget(layout:QBoxLayout, widget:QWidget, padding: list[int],
324-
AlignmentX:Qt.AlignmentFlag=Qt.AlignmentFlag.AlignCenter,
325-
AlignmentY:Qt.AlignmentFlag=Qt.AlignmentFlag.AlignCenter):
326-
327-
if not isinstance(padding, list):
328-
raise TypeError("Input must be a list.")
329-
330-
LayoutV = QVBoxLayout()
331-
LayoutV.addSpacing(padding[2])
332-
LayoutV.addWidget(widget, alignment=AlignmentX | AlignmentY)
333-
LayoutV.addSpacing(padding[3])
334-
335-
LayoutH = QHBoxLayout()
336-
LayoutH.addSpacing(padding[0])
337-
LayoutH.addLayout(LayoutV)
338-
LayoutH.addSpacing(padding[1])
339-
340-
layout.addLayout(LayoutH)
341-
342-
return LayoutH
343-
344323
class SerialThread(QThread):
345324
message_received = Signal(str)
346325

@@ -420,7 +399,28 @@ def toggle_auto_scroll(self, state):
420399
#print(f"[Toggle Handler] State: {state} ({type(state)}), Qt.Checked: {Qt.Checked}")
421400
self.auto_scroll_enabled = state == Qt.CheckState.Checked.value
422401
#print(f"[Toggle Handler] Enabled: {self.auto_scroll_enabled}")
402+
403+
def add_movable_widget(self,layout:QBoxLayout, widget:QWidget, padding: list[int],
404+
AlignmentX:Qt.AlignmentFlag=Qt.AlignmentFlag.AlignCenter,
405+
AlignmentY:Qt.AlignmentFlag=Qt.AlignmentFlag.AlignCenter):
406+
407+
if not isinstance(padding, list):
408+
raise TypeError("Input must be a list.")
409+
410+
LayoutV = QVBoxLayout()
411+
LayoutV.addSpacing(padding[2])
412+
LayoutV.addWidget(widget, alignment=AlignmentX | AlignmentY)
413+
LayoutV.addSpacing(padding[3])
414+
415+
LayoutH = QHBoxLayout()
416+
LayoutH.addSpacing(padding[0])
417+
LayoutH.addLayout(LayoutV)
418+
LayoutH.addSpacing(padding[1])
419+
420+
layout.addLayout(LayoutH)
423421

422+
return LayoutH
423+
424424
def create_control_panel(self):
425425
# create a horizontal layout that will hold all items in a single row for connecting to HamMessenger
426426
control_row = QHBoxLayout()
@@ -429,14 +429,14 @@ def create_control_panel(self):
429429
port_combo_qbox = QHBoxLayout()
430430
# create and add port label
431431
label = QLabel("Port:")
432-
movable_widget(port_combo_qbox, label, [50,0,0,0], Qt.AlignmentFlag.AlignRight)
432+
self.add_movable_widget(port_combo_qbox, label, [50,0,0,0], Qt.AlignmentFlag.AlignRight)
433433
# create and add port combobox
434434
self.port_combo = QComboBox()
435-
movable_widget(port_combo_qbox, self.port_combo, [0,0,0,0], Qt.AlignmentFlag.AlignLeft)
435+
self.add_movable_widget(port_combo_qbox, self.port_combo, [0,0,0,0], Qt.AlignmentFlag.AlignLeft)
436436
# create and add refresh button
437437
button = QPushButton("Refresh")
438438
button.clicked.connect(self.populate_serial_ports)
439-
movable_widget(port_combo_qbox, button, [0,0,0,2], Qt.AlignmentFlag.AlignLeft)
439+
self.add_movable_widget(port_combo_qbox, button, [0,0,0,2], Qt.AlignmentFlag.AlignLeft)
440440
# set spacing between all widgets in port layout
441441
port_combo_qbox.setSpacing(0)
442442
# add the port layout to the control row
@@ -450,12 +450,12 @@ def create_control_panel(self):
450450
baud_combo_qbox = QHBoxLayout()
451451
# create the baud label and add it to the port horizontal layout
452452
baud_label = QLabel("Baud:")
453-
movable_widget(baud_combo_qbox, baud_label, [8,0,0,0], Qt.AlignmentFlag.AlignRight)
453+
self.add_movable_widget(baud_combo_qbox, baud_label, [8,0,0,0], Qt.AlignmentFlag.AlignRight)
454454
# create the combobox
455455
self.baud_combo = QComboBox()
456456
self.baud_combo.addItems(["9600", "19200", "38400", "57600", "115200"])
457457
self.baud_combo.setCurrentText("115200")
458-
movable_widget(baud_combo_qbox, self.baud_combo, [0,0,0,0], Qt.AlignmentFlag.AlignLeft)
458+
self.add_movable_widget(baud_combo_qbox, self.baud_combo, [0,0,0,0], Qt.AlignmentFlag.AlignLeft)
459459
# set the spacing of all items in the port horizontal layout to 0 so they are all clos
460460
baud_combo_qbox.setSpacing(0)
461461
# finally, add the port horizontal layout to the control row horizontal layout
@@ -470,10 +470,10 @@ def create_control_panel(self):
470470
# create the connect button and add it to the connection horizontal layout
471471
self.connect_button = QPushButton("Connect")
472472
self.connect_button.clicked.connect(self.toggle_connection)
473-
movable_widget(conn_combo_qbox, self.connect_button, [0,0,0,2.5], Qt.AlignmentFlag.AlignRight)
473+
self.add_movable_widget(conn_combo_qbox, self.connect_button, [0,0,0,2.5], Qt.AlignmentFlag.AlignRight)
474474
# create the baud label and add it to the port horizontal layout
475475
self.status_label = QLabel("Not connected")
476-
movable_widget(conn_combo_qbox, self.status_label, [10,0,0,0], Qt.AlignmentFlag.AlignLeft)
476+
self.add_movable_widget(conn_combo_qbox, self.status_label, [10,0,0,0], Qt.AlignmentFlag.AlignLeft)
477477
# set the spacing of all items in the port horizontal layout to 0 so they are all close
478478
conn_combo_qbox.setSpacing(0)
479479
# finally, add the port horizontal layout to the control row horizontal layout
@@ -493,7 +493,7 @@ def create_command_panel(self):
493493
cmd_combo_qbox = QHBoxLayout()
494494
# create the command label and add it to the command horizontal layout
495495
cmd_label = QLabel("Command:")
496-
movable_widget(cmd_combo_qbox, cmd_label, [20,0,0,0], Qt.AlignmentFlag.AlignRight)
496+
self.add_movable_widget(cmd_combo_qbox, cmd_label, [20,0,0,0], Qt.AlignmentFlag.AlignRight)
497497
# create the command combobox and add it to the command horizontal layout
498498
self.command_input = QComboBox()
499499
self.command_input.setEditable(True)
@@ -502,7 +502,7 @@ def create_command_panel(self):
502502
self.command_input.lineEdit().returnPressed.connect(self.send_serial_command)
503503
self.command_input.setFont(self.mono_font)
504504
self.command_input.setMinimumWidth(800)
505-
movable_widget(cmd_combo_qbox, self.command_input, [0,0,0,0], Qt.AlignmentFlag.AlignLeft)
505+
self.add_movable_widget(cmd_combo_qbox, self.command_input, [0,0,0,0], Qt.AlignmentFlag.AlignLeft)
506506
# set the spacing of all items in the command horizontal layout to 0 so they are all close
507507
cmd_combo_qbox.setSpacing(0)
508508
# finally, add the command horizontal layout to the command row horizontal layout
@@ -516,7 +516,7 @@ def create_command_panel(self):
516516
self.send_button = QPushButton("Send")
517517
self.send_button.clicked.connect(self.send_serial_command)
518518
#self.send_button.setMaximumWidth(100)
519-
movable_widget(cmd_row, self.send_button, [8,0,0,0], Qt.AlignmentFlag.AlignLeft)
519+
self.add_movable_widget(cmd_row, self.send_button, [8,0,0,0], Qt.AlignmentFlag.AlignLeft)
520520

521521
#
522522
cmd_row.setSpacing(0)
@@ -607,26 +607,26 @@ def create_tabs(self):
607607
message_send_qbox.addStretch()
608608
#
609609
label = QLabel("To:")
610-
movable_widget(message_send_qbox, label, [0,5,0,0], Qt.AlignmentFlag.AlignRight, Qt.AlignmentFlag.AlignTop)
610+
self.add_movable_widget(message_send_qbox, label, [0,5,0,0], Qt.AlignmentFlag.AlignRight, Qt.AlignmentFlag.AlignTop)
611611
#
612612
self.message_to = QLineEdit()
613613
self.message_to.setMaximumWidth(80)
614614
self.message_to.setFont(self.mono_font)
615615
self.message_to.setMaxLength(9) # 2x3 callsing with a dash and 2 digit ssid is 9 chars
616-
movable_widget(message_send_qbox, self.message_to, [0,30,0,0], Qt.AlignmentFlag.AlignLeft)
616+
self.add_movable_widget(message_send_qbox, self.message_to, [0,30,0,0], Qt.AlignmentFlag.AlignLeft)
617617
#
618618
label = QLabel("Message:")
619-
movable_widget(message_send_qbox, label, [0,5,0,0], Qt.AlignmentFlag.AlignRight, Qt.AlignmentFlag.AlignTop)
619+
self.add_movable_widget(message_send_qbox, label, [0,5,0,0], Qt.AlignmentFlag.AlignRight, Qt.AlignmentFlag.AlignTop)
620620
#
621621
self.message_msg = QLineEdit()
622622
self.message_msg.setMinimumWidth(400)
623623
self.message_msg.setFont(self.mono_font)
624624
self.message_to.setMaxLength(99) # max message length for HamMessenger is 99 chars for now
625-
movable_widget(message_send_qbox, self.message_msg, [0,30,0,0], Qt.AlignmentFlag.AlignLeft)
625+
self.add_movable_widget(message_send_qbox, self.message_msg, [0,30,0,0], Qt.AlignmentFlag.AlignLeft)
626626
#
627627
button = QPushButton("Send")
628628
button.clicked.connect(self.send_message)
629-
movable_widget(message_send_qbox, button, [0,0,0,3], Qt.AlignmentFlag.AlignLeft)
629+
self.add_movable_widget(message_send_qbox, button, [0,0,0,3], Qt.AlignmentFlag.AlignLeft)
630630
#
631631
message_send_qbox.setSpacing(0)
632632
message_send_qbox.addStretch()
@@ -704,7 +704,7 @@ def send_message(self):
704704
}
705705
self.msg_entries.append(msg_entry)
706706
self.render_msg_entry(msg_entry)
707-
707+
708708
self.message_msg.clear()
709709
self.message_msg.setFocus()
710710

0 commit comments

Comments
 (0)