Skip to content

Commit 4b4479c

Browse files
Support Qt 6
1 parent f3162d7 commit 4b4479c

18 files changed

+74
-39
lines changed

hab_gui/actions/edit_custom_variables_action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self, settings, parent=None):
2929

3030
def edit_custom_variables(self):
3131
dlg = CustomVariableEditor.create_dialog(self.settings, parent=self.parent())
32-
dlg.exec_()
32+
utils.exec_obj(dlg)
3333

3434
# Ensure the hab_gui respects any changes the user may have made
3535
self.settings.root_widget.refresh_cache()

hab_gui/actions/verbosity_action.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from Qt import QtCore, QtWidgets
1+
from Qt import QtWidgets
22

33

44
class VerbosityAction(QtWidgets.QAction):
@@ -48,10 +48,7 @@ def __init__(self, settings, parent=None):
4848
action = menu.addAction(key)
4949
action.setData(value)
5050
action.setCheckable(True)
51-
if verbosity == value:
52-
action.setChecked(QtCore.Qt.Checked)
53-
else:
54-
action.setChecked(QtCore.Qt.Unchecked)
51+
action.setChecked(verbosity == value)
5552
self.setMenu(menu)
5653

5754
def load_config(self):
@@ -71,7 +68,4 @@ def refresh(self):
7168
verbosity = self.settings.verbosity
7269
for action in self.menu().actions():
7370
value = action.data()
74-
if verbosity == value:
75-
action.setChecked(QtCore.Qt.Checked)
76-
else:
77-
action.setChecked(QtCore.Qt.Unchecked)
71+
action.setChecked(verbosity == value)

hab_gui/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def launch(settings, verbosity, uri, alias, args):
170170
if splash:
171171
splash.finish(window)
172172

173-
app.exec_()
173+
utils.exec_obj(app)
174174

175175

176176
@gui.command()

hab_gui/dialogs/error_message_box.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ def __init__(self, etype, value, tb, parent=None):
2424
self.stack_limit = -5
2525

2626
self.setWindowTitle("Exception")
27-
self.setTextFormat(QtCore.Qt.RichText)
28-
self.setStandardButtons(QtWidgets.QMessageBox.Ok)
27+
self.setTextFormat(QtCore.Qt.TextFormat.RichText)
28+
self.setStandardButtons(QtWidgets.QMessageBox.StandardButton.Ok)
2929
# Using detailedText seems to disable the close button, enable it
30-
self.setEscapeButton(QtWidgets.QMessageBox.Ok)
30+
self.setEscapeButton(QtWidgets.QMessageBox.StandardButton.Ok)
3131

3232
# Create a button allowing the user to copy the non-highlighted text
33-
copy_btn = self.addButton("Copy", QtWidgets.QMessageBox.ActionRole)
33+
copy_btn = self.addButton("Copy", QtWidgets.QMessageBox.ButtonRole.ActionRole)
3434
copy_btn.setToolTip("Copy the full traceback for error reporting.")
3535
# Disconnect the QMessageBox signals that would cause the box to close
3636
# when this button is pressed and add our own signal connection
3737
copy_btn.disconnect()
3838
copy_btn.released.connect(self.copy_traceback)
3939

40-
self.setDefaultButton(QtWidgets.QMessageBox.Ok)
40+
self.setDefaultButton(QtWidgets.QMessageBox.StandardButton.Ok)
4141
self.refresh()
4242

4343
@QtCore.Slot()

hab_gui/dialogs/uri_picker_dialog.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ def init_gui(self):
6868
)
6969

7070
self.uiButtonsBOX = QtWidgets.QDialogButtonBox(
71-
QtWidgets.QDialogButtonBox.Cancel, self
71+
QtWidgets.QDialogButtonBox.StandardButton.Cancel, self
72+
)
73+
self.uiButtonsBOX.addButton(
74+
"Launch", QtWidgets.QDialogButtonBox.ButtonRole.AcceptRole
7275
)
73-
self.uiButtonsBOX.addButton("Launch", QtWidgets.QDialogButtonBox.AcceptRole)
7476
self.uiButtonsBOX.accepted.connect(self.accept)
7577
self.uiButtonsBOX.rejected.connect(self.reject)
7678

@@ -151,7 +153,7 @@ def should_show(cls, settings, alias=None):
151153
# Note: Not using `keyboardModifiers` because it is not updated when
152154
# calling this from the cli module.
153155
modifiers = QtWidgets.QApplication.queryKeyboardModifiers()
154-
if modifiers == QtCore.Qt.ShiftModifier:
156+
if modifiers == QtCore.Qt.KeyboardModifier.ShiftModifier:
155157
return True
156158

157159
# always_ask is checked for this alias

hab_gui/entry_points/message_box.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22

3+
from .. import utils
34
from .logging_exception import LoggingExceptionInit
45

56
logger = logging.getLogger(__name__)
@@ -17,4 +18,4 @@ def excepthook(self, cls, exception, tb):
1718
from ..dialogs.error_message_box import ErrorMessageBox
1819

1920
box = ErrorMessageBox(cls, exception, tb, parent=None)
20-
box.exec_()
21+
utils.exec_obj(box)

hab_gui/utils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
@contextmanager
14-
def cursor_override(cursor=QtCore.Qt.BusyCursor):
14+
def cursor_override(cursor=QtCore.Qt.CursorShape.BusyCursor):
1515
"""Change the application cursor to wait while running the context/decorator.
1616
Ensures that the cursor is restored even if an exception is raised.
1717
"""
@@ -220,3 +220,14 @@ def block_signals(objs):
220220
finally:
221221
for o, b in blocked:
222222
o.blockSignals(b)
223+
224+
225+
def exec_obj(obj, *args, **kwargs):
226+
"""Work around the removal of `exec_` from Qt6(especially PyQt6).
227+
228+
This calls the `obj.exec` method if it exists, and falls back to `obj.exec_`
229+
otherwise.
230+
"""
231+
if hasattr(obj, "exec"):
232+
return obj.exec(*args, **kwargs)
233+
return obj.exec_(*args, **kwargs)

hab_gui/widgets/alias_button.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ def __init__(self, cfg, alias_name, parent=None):
2323
self.alias_name = alias_name
2424

2525
self.alias_dict = self.cfg.aliases
26-
qsize_policy = QtWidgets.QSizePolicy
27-
size_policy = qsize_policy(qsize_policy.Minimum, qsize_policy.Preferred)
26+
size_policy = QtWidgets.QSizePolicy(
27+
QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Preferred
28+
)
2829
self.setSizePolicy(size_policy)
2930
self.clicked.connect(self._button_action)
3031
self.refresh()

hab_gui/widgets/alias_icon_button.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AliasIconButton(AliasButton):
2222

2323
def __init__(self, *args, **kwargs):
2424
super().__init__(*args, **kwargs)
25-
self.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
25+
self.setToolButtonStyle(QtCore.Qt.ToolButtonStyle.ToolButtonTextBesideIcon)
2626

2727
def refresh(self):
2828
alias = self.alias_dict[self.alias_name]

hab_gui/widgets/custom_variable_editor/custom_variable_editor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def editing_finished(self, top_left, bottom_right, roles):
7070
if self._is_refreshing:
7171
return
7272

73-
if QtCore.Qt.EditRole in roles:
73+
if QtCore.Qt.ItemDataRole.EditRole in roles:
7474
item = self.uiVariableTREE.itemFromIndex(top_left)
7575
column = top_left.column()
7676
if column == 0:

0 commit comments

Comments
 (0)