Skip to content

Commit 6bf0eef

Browse files
authored
Merge pull request #114 from dihm/pyside6
Pyside6 support
2 parents 83cb199 + 48f9cfc commit 6bf0eef

9 files changed

Lines changed: 87 additions & 50 deletions

File tree

blacs/__main__.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,24 @@
3232
import time
3333
from pathlib import Path
3434
import platform
35+
import importlib.metadata
3536
WINDOWS = platform.system() == 'Windows'
3637

3738
# No splash update for Qt - the splash code has already imported it:
3839
from qtutils import inmain_decorator, inmain_later, inmain, inthread, UiLoader
3940
import qtutils.icons # import has side-effects we rely on
40-
from qtutils.qt.QtCore import PYQT_VERSION_STR, QT_VERSION_STR, QTimer, Qt
41-
from qtutils.qt.QtGui import QIcon
41+
from qtutils.qt.QtCore import QTimer, Qt, qVersion, QEvent
42+
from qtutils.qt.QtGui import QIcon, QColor, QPalette
4243
from qtutils.qt.QtWidgets import (
4344
QMainWindow,
4445
QToolButton,
4546
QMessageBox,
4647
QFileDialog,
47-
QApplication
48+
QApplication,
49+
QWidget
4850
)
4951
from qtutils.qt import QT_ENV
52+
PYQT_VERSION_STR = importlib.metadata.version(QT_ENV)
5053

5154

5255
splash.update_text("importing zmq and zprocess")
@@ -84,7 +87,7 @@
8487
logger.info(f'h5py version: {h5py.version.info}')
8588
logger.info(f'Qt enviroment: {QT_ENV}')
8689
logger.info(f'PySide/PyQt version: {PYQT_VERSION_STR}')
87-
logger.info(f'Qt version: {QT_VERSION_STR}')
90+
logger.info(f'Qt version: {qVersion()}')
8891
logger.info(f'qtutils version: {qtutils.__version__}')
8992
logger.info(f'zprocess version: {zprocess.__version__}')
9093
logger.info(f'labscript_utils version: {labscript_utils.__version__}')
@@ -141,6 +144,23 @@ def closeEvent(self, event):
141144

142145
QTimer.singleShot(100,self.close)
143146

147+
def changeEvent(self, event):
148+
149+
# theme update only for PySide6/PyQt6
150+
if QT_ENV.endswith('6') and event.type() == QEvent.Type.ThemeChange:
151+
for widget in self.findChildren(QWidget):
152+
# Complex widgets, like TreeView and TableView require triggering styleSheet and palette updates
153+
widget.setStyleSheet(widget.styleSheet())
154+
widget.setPalette(widget.palette())
155+
# tab header text colors have to be done explicitly by tab
156+
# because they use setTabTextColor
157+
app = QApplication.instance()
158+
self.blacs.update_all_tab_icon_and_text(
159+
app.palette().color(QPalette.ColorRole.Text)
160+
)
161+
162+
return super().changeEvent(event)
163+
144164

145165
class EasterEggButton(QToolButton):
146166
def __init__(self):
@@ -530,14 +550,23 @@ def update_all_tab_settings(self,settings,tab_data):
530550
self.settings_dict[tab_name]["saved_data"] = tab_data[tab_name]['data'] if tab_name in tab_data else {}
531551
tab.update_from_settings(self.settings_dict[tab_name])
532552

553+
def update_all_tab_icon_and_text(self, text_colour):
554+
# used to repaint tab header text after theme change
555+
556+
for tab in self.tablist.values():
557+
if tab._tab_text_colour == QColor('red'):
558+
# ensure error tabs keep their red text
559+
continue
560+
tab._tab_text_colour = text_colour
561+
tab.set_tab_icon_and_colour()
533562

534563
def on_load_front_panel(self,*args,**kwargs):
535564
# get the file:
536565
# create file chooser dialog
537566
dialog = QFileDialog(None,"Select file to load", self.exp_config.get('paths','experiment_shot_storage'), "HDF5 files (*.h5 *.hdf5)")
538567
dialog.setViewMode(QFileDialog.Detail)
539568
dialog.setFileMode(QFileDialog.ExistingFile)
540-
if dialog.exec_():
569+
if dialog.exec():
541570
selected_files = dialog.selectedFiles()
542571
filepath = str(selected_files[0])
543572
# Qt has this weird behaviour where if you type in the name of a file that exists
@@ -556,7 +585,7 @@ def on_load_front_panel(self,*args,**kwargs):
556585
message.setWindowTitle("BLACS")
557586
message.setStandardButtons(QMessageBox.Yes|QMessageBox.No)
558587

559-
if message.exec_() == QMessageBox.Yes:
588+
if message.exec() == QMessageBox.Yes:
560589
front_panel_settings = FrontPanelSettings(filepath, self.connection_table)
561590
settings,question,error,tab_data = front_panel_settings.restore()
562591
#TODO: handle question/error
@@ -588,7 +617,7 @@ def on_load_front_panel(self,*args,**kwargs):
588617
message.setText("Unable to load the front panel. The error encountered is printed below.\n\n%s"%str(e))
589618
message.setIcon(QMessageBox.Information)
590619
message.setWindowTitle("BLACS")
591-
message.exec_()
620+
message.exec()
592621
finally:
593622
dialog.deleteLater()
594623
else:
@@ -597,7 +626,7 @@ def on_load_front_panel(self,*args,**kwargs):
597626
message.setText("You did not select a file ending with .h5 or .hdf5. Please try again")
598627
message.setIcon(QMessageBox.Information)
599628
message.setWindowTitle("BLACS")
600-
message.exec_()
629+
message.exec()
601630
QTimer.singleShot(10,self.on_load_front_panel)
602631

603632
def on_save_exit(self):
@@ -684,7 +713,7 @@ def on_save_front_panel(self,*args,**kwargs):
684713
dialog.setFileMode(QFileDialog.AnyFile)
685714
dialog.setAcceptMode(QFileDialog.AcceptSave)
686715

687-
if dialog.exec_():
716+
if dialog.exec():
688717
current_file = str(dialog.selectedFiles()[0])
689718
if not current_file.endswith('.h5'):
690719
current_file += '.h5'
@@ -780,6 +809,6 @@ def process(self,h5_filepath):
780809
splash.hide()
781810

782811
def execute_program():
783-
qapplication.exec_()
812+
qapplication.exec()
784813

785814
sys.exit(execute_program())

blacs/device_base_class.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -957,18 +957,20 @@ class MyWindow(QWidget):
957957
def __init__(self,*args,**kwargs):
958958
QWidget.__init__(self,*args,**kwargs)
959959
self.are_we_closed = False
960+
self.my_tabs = []
960961

961962
def closeEvent(self,event):
962963
if not self.are_we_closed:
963964
event.ignore()
964-
self.my_tab.close_tab()
965+
for tab in self.my_tabs:
966+
tab.close_tab()
965967
self.are_we_closed = True
966968
QTimer.singleShot(1000,self.close)
967969
else:
968970
event.accept()
969971

970972
def add_my_tab(self,tab):
971-
self.my_tab = tab
973+
self.my_tabs.append(tab)
972974

973975
app = QApplication(sys.argv)
974976
window = MyWindow()
@@ -979,8 +981,9 @@ def add_my_tab(self,tab):
979981
tab1 = MyDAQTab(notebook,settings = {'device_name': 'ni_pcie_6363_0', 'connection_table':connection_table})
980982
tab2 = MyDummyTab(notebook,settings = {'device_name': 'intermediate_device', 'connection_table':connection_table})
981983
window.add_my_tab(tab1)
984+
window.add_my_tab(tab2)
982985
window.show()
983986
def run():
984-
app.exec_()
987+
app.exec()
985988

986989
sys.exit(run())

blacs/front_panel_settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def save_front_panel_to_h5(self,current_file,states,tab_positions,window_data,pl
294294
message.setDefaultButton(QMessageBox.No)
295295
message.setIcon(QMessageBox.Question)
296296
message.setWindowTitle("BLACS")
297-
resp = message.exec_()
297+
resp = message.exec()
298298

299299
if resp == QMessageBox.Yes :
300300
overwrite = True
@@ -311,7 +311,7 @@ def save_front_panel_to_h5(self,current_file,states,tab_positions,window_data,pl
311311
message.setText("Front Panel not saved.")
312312
message.setIcon(QMessageBox.Information)
313313
message.setWindowTitle("BLACS")
314-
message.exec_()
314+
message.exec()
315315
else:
316316
logger.info("Front Panel not saved as it already existed in the h5 file '"+current_file+"'")
317317
return
@@ -325,7 +325,7 @@ def save_front_panel_to_h5(self,current_file,states,tab_positions,window_data,pl
325325
message.setText("The Front Panel was not saved as the file selected contains a connection table which is not a subset of the BLACS connection table.")
326326
message.setIcon(QMessageBox.Information)
327327
message.setWindowTitle("BLACS")
328-
message.exec_()
328+
message.exec()
329329
else:
330330
logger.info("Front Panel not saved as the connection table in the h5 file '"+current_file+"' didn't match the current connection table.")
331331
return

blacs/main.ui

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,28 @@
2626

2727
QPushButton:hover {
2828
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
29-
stop: 0 #f6f7fa, stop: 1 #dadbde);
30-
border: 1px solid #8f8f91;
29+
stop: 0 palette(light), stop: 1 palette(window));
30+
border: 1px solid palette(dark);
3131
border-radius: 3px;
3232
}
3333

3434
QPushButton:pressed {
3535
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
36-
stop: 0 #dadbde, stop: 1 #f6f7fa);
37-
border: 1px solid #8f8f91;
36+
stop: 0 palette(window), stop: 1 palette(light));
37+
border: 1px solid palette(dark);
3838
border-radius: 3px;
3939
}
4040

4141
QPushButton:checked {
42-
background-color: #dadbde;
43-
border: 1px solid #8f8f91;
42+
background-color: palette(window);
43+
border: 1px solid palette(dark);
4444
border-radius: 3px;
4545
}
4646

4747
QPushButton:hover:checked {
4848
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
49-
stop: 0 #dadbde, stop: 1 #f6f7fa);
50-
border: 1px solid #8f8f91;
49+
stop: 0 palette(window), stop: 1 palette(light));
50+
border: 1px solid palette(dark);
5151
border-radius: 3px;
5252
}
5353

@@ -58,28 +58,28 @@ QToolButton {
5858

5959
QToolButton:hover {
6060
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
61-
stop: 0 #f6f7fa, stop: 1 #dadbde);
62-
border: 1px solid #8f8f91;
61+
stop: 0 palette(light), stop: 1 palette(window));
62+
border: 1px solid palette(dark);
6363
border-radius: 3px;
6464
}
6565

6666
QToolButton:pressed {
6767
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
68-
stop: 0 #dadbde, stop: 1 #f6f7fa);
69-
border: 1px solid #8f8f91;
68+
stop: 0 palette(window), stop: 1 palette(light));
69+
border: 1px solid palette(dark);
7070
border-radius: 3px;
7171
}
7272

7373
QToolButton:checked {
74-
background-color: #dadbde;
75-
border: 1px solid #8f8f91;
74+
background-color: palette(window);
75+
border: 1px solid palette(dark);
7676
border-radius: 3px;
7777
}
7878

7979
QToolButton:hover:checked {
8080
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
81-
stop: 0 #dadbde, stop: 1 #f6f7fa);
82-
border: 1px solid #8f8f91;
81+
stop: 0 palette(window), stop: 1 palette(light));
82+
border: 1px solid palette(dark);
8383
border-radius: 3px;
8484
}
8585
</string>

blacs/output_classes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,4 +1037,4 @@ def print_something():
10371037

10381038

10391039
window.show()
1040-
sys.exit(qapplication.exec_())
1040+
sys.exit(qapplication.exec())

blacs/plugins/connection_table/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def add_global_file(self,*args,**kwargs):
393393
dialog.setViewMode(QFileDialog.Detail)
394394
dialog.setFileMode(QFileDialog.ExistingFiles)
395395

396-
if dialog.exec_():
396+
if dialog.exec():
397397
selected_files = dialog.selectedFiles()
398398
for filepath in selected_files:
399399
filepath = os.path.normpath(filepath)
@@ -430,7 +430,7 @@ def add_calibration_file(self):
430430
dialog.setViewMode(QFileDialog.Detail)
431431
dialog.setFileMode(QFileDialog.ExistingFiles)
432432

433-
if dialog.exec_():
433+
if dialog.exec():
434434
selected_files = dialog.selectedFiles()
435435
for filepath in selected_files:
436436
filepath = os.path.normpath(filepath)
@@ -453,7 +453,7 @@ def add_calibration_folder(self):
453453
dialog.setViewMode(QFileDialog.Detail)
454454
dialog.setFileMode(QFileDialog.Directory)
455455

456-
if dialog.exec_():
456+
if dialog.exec():
457457
selected_files = dialog.selectedFiles()
458458
for filepath in selected_files:
459459
filepath = os.path.normpath(filepath)

blacs/plugins/theme/__init__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
DEFAULT_STYLESHEET = """DigitalOutput {
2626
font-size: 12px;
27-
background-color: rgb(50,100,50,255);
28-
border: 1px solid rgb(50,100,50,128);
27+
background-color: rgb(50,100,50);
28+
border: 1px solid rgb(50,100,50);
2929
border-radius: 3px;
3030
padding: 2px;
3131
color: #202020;
@@ -37,7 +37,7 @@
3737
}
3838
3939
DigitalOutput:disabled{
40-
background-color: rgb(50,100,50,128);
40+
background-color: rgb(50,100,50);
4141
color: #505050;
4242
}
4343
@@ -56,14 +56,15 @@
5656
5757
DigitalOutput:checked:disabled{
5858
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
59-
stop: 0 rgba(32,200,32,128), stop: 1 rgba(32,255,32,128));
59+
stop: 0 rgba(32,200,32), stop: 1 rgba(32,255,32));
60+
border: 1px solid #8f8f91;
6061
color: #606060;
6162
}
6263
6364
InvertedDigitalOutput {
6465
font-size: 12px;
65-
background-color: rgb(70,100,170,255);
66-
border: 1px solid rgb(70,100,170,128);
66+
background-color: rgb(70,100,170);
67+
border: 1px solid rgb(70,100,170);
6768
border-radius: 3px;
6869
padding: 2px;
6970
color: #202020;
@@ -75,7 +76,7 @@
7576
}
7677
7778
InvertedDigitalOutput:disabled{
78-
background-color: rgba(70,100,170,128);
79+
background-color: rgba(70,100,170);
7980
color: #505050;
8081
}
8182
@@ -94,7 +95,8 @@
9495
9596
InvertedDigitalOutput:checked:disabled{
9697
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
97-
stop: 0 rgba(50,150,221,128), stop: 1 rgba(32,192,255,128));
98+
stop: 0 rgba(50,150,221), stop: 1 rgba(32,192,255));
99+
border: 1px solid #8f8f91;
98100
color: #606060;
99101
}
100102
"""

0 commit comments

Comments
 (0)