Skip to content

Commit 9d79f17

Browse files
committed
Using deleteLater when possible and setting parents
1 parent 0e5edcb commit 9d79f17

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

ffb_ui.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,13 @@ def updateButtonSources(self,types):
259259
for b in self.buttonconfbuttons:
260260
self.remove_callbacks(b[1])
261261
b[0].setParent(None)
262-
del b
262+
b.deleteLater()
263+
#del b
263264
self.buttonconfbuttons.clear() # Clear buttons
264265
for b in self.buttonbtns.buttons():
265266
self.buttonbtns.removeButton(b)
266-
del b
267+
#del b
268+
b.deleteLater()
267269
#add buttons
268270
row = 0
269271
for c in self.btnClasses:
@@ -306,11 +308,13 @@ def updateAnalogSources(self,types):
306308
for b in self.axisconfbuttons:
307309
self.remove_callbacks(b[1])
308310
b[0].setParent(None)
309-
del b
311+
#del b
312+
b.deleteLater()
310313
self.axisconfbuttons.clear()
311314
for b in self.axisbtns.buttons():
312315
self.axisbtns.removeButton(b)
313-
del b
316+
#del b
317+
b.deleteLater()
314318
#add buttons
315319
row = 0
316320
for c in self.axisClasses:

main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def del_tab(self, widget : PyQt6.QtWidgets.QWidget):
395395
self.tabWidget_main.removeTab(self.tabWidget_main.indexOf(widget))
396396
base_ui.CommunicationHandler.remove_callbacks(widget)
397397
widget.deleteLater()
398-
#del widget
398+
del widget
399399

400400
def select_tab(self, idx):
401401
"""Select a specific tab from the idx parameter."""
@@ -453,7 +453,7 @@ def update_tabs_cb(active):
453453
for name, classe in self.active_classes.items()
454454
if name not in new_active_classes
455455
]
456-
# print(newActiveClasses)
456+
#print(new_active_classes)
457457

458458
for classe, name in delete_classes:
459459
self.del_tab(classe)

tmc4671_ui.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class TMC4671Ui(WidgetUI,CommunicationHandler):
2525
STATES = ["uninitialized","waitPower","Shutdown","Running","EncoderInit","EncoderFinished","HardError","OverTemp","IndexSearch","FullCalibration","ExternalEncoderInit","PI Autotune"]
2626

2727
def __init__(self, main=None, unique=0):
28-
self.axis = 0
29-
self.init_done = False
3028
WidgetUI.__init__(self, main,'tmc4671_ui.ui')
3129
CommunicationHandler.__init__(self)
30+
self.axis = 0
31+
self.init_done = False
3232
self.main = main #type: main.MainUi
3333

3434
self.axis = unique
@@ -58,23 +58,23 @@ def __init__(self, main=None, unique=0):
5858
self.chart = QChart()
5959
self.chart.setBackgroundRoundness(5)
6060
self.chart.setMargins(QMargins(0,0,0,0))
61-
self.chartXaxis = QValueAxis()
61+
self.chartXaxis = QValueAxis(self.chart)
6262
# use Application.instance().palette().dark().color() but with 50% opacity
6363
self.chartXaxis.setGridLineColor(QColor(QApplication.instance().palette().dark().color().red(),QApplication.instance().palette().dark().color().green(),QApplication.instance().palette().dark().color().blue(),128))
6464

6565

6666
self.chart.addAxis(self.chartXaxis,Qt.AlignmentFlag.AlignBottom)
6767

68-
self.chartYaxis_Amps = QValueAxis()
69-
self.chartYaxis_Temps = QValueAxis()
68+
self.chartYaxis_Amps = QValueAxis(self.chart)
69+
self.chartYaxis_Temps = QValueAxis(self.chart)
7070
# use Application.instance().palette().dark().color() but with 25% opacity
7171
self.chartYaxis_Amps.setGridLineColor(QColor(QApplication.instance().palette().dark().color().red(),QApplication.instance().palette().dark().color().green(),QApplication.instance().palette().dark().color().blue(),64))
7272
self.chartYaxis_Temps.setGridLineColor(QColor(QApplication.instance().palette().dark().color().red(),QApplication.instance().palette().dark().color().green(),QApplication.instance().palette().dark().color().blue(),64))
7373
self.chart.setBackgroundBrush(QApplication.instance().palette().window())
7474

7575
self.chart.addAxis(self.chartYaxis_Amps,Qt.AlignmentFlag.AlignLeft)
7676

77-
self.lines_Amps = QLineSeries()
77+
self.lines_Amps = QLineSeries(self.chart)
7878
self.lines_Amps.setName("Torque A")
7979
self.lines_Amps.setUseOpenGL(True)
8080

@@ -83,7 +83,7 @@ def __init__(self, main=None, unique=0):
8383
self.lines_Amps.attachAxis(self.chartYaxis_Amps)
8484
self.lines_Amps.attachAxis(self.chartXaxis)
8585

86-
self.lines_Flux = QLineSeries()
86+
self.lines_Flux = QLineSeries(self.chart)
8787
self.lines_Flux.setName("Flux A")
8888
self.lines_Flux.setOpacity(0.5)
8989
self.lines_Flux.setUseOpenGL(True)
@@ -94,7 +94,7 @@ def __init__(self, main=None, unique=0):
9494
self.lines_Flux.attachAxis(self.chartYaxis_Amps)
9595
self.lines_Flux.attachAxis(self.chartXaxis)
9696

97-
self.lines_Temps = QLineSeries()
97+
self.lines_Temps = QLineSeries(self.chart)
9898
self.lines_Temps.setName("Temp °C")
9999
self.lines_Temps.setColor(QColor("orange"))
100100
self.lines_Temps.setOpacity(0.5)
@@ -406,7 +406,7 @@ def advancedPidChanged(self,state):
406406
self.checkBox_I_Precision.setChecked(False)
407407

408408
def showVersionSelectorPopup(self):
409-
selectorPopup = OptionsDialog(TMC_HW_Version_Selector(self.tr("TMC Version"),self,self.axis),self.main)
409+
selectorPopup = OptionsDialog(TMC_HW_Version_Selector(self.tr("TMC Version"),self,self.axis),self)
410410
selectorPopup.exec()
411411
self.send_command("tmc","tmcHwType",self.axis,'!')
412412
self.send_command("tmc","tmcHwType",self.axis,'?')

0 commit comments

Comments
 (0)