port over qt6 migrations

Fixes #498
This commit is contained in:
Jarrett Johnson
2026-02-24 01:05:23 -05:00
parent d30a289129
commit 87d27daafb
19 changed files with 168 additions and 214 deletions

View File

@@ -142,11 +142,11 @@ Execute the pipeline (prep, apbs, surface vis)
if warnings:
@form._callInMainThread
def result():
msgbox = QMessageBox(QMessageBox.Question, 'Continue?',
msgbox = QMessageBox(QMessageBox.Icon.Question, 'Continue?',
method + ' emmitted warnings, do you want to continue?',
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No , form._dialog)
msgbox.setDetailedText(warnings)
return msgbox.exec_()
return msgbox.exec()
if result == QMessageBox.StandardButton.No:
raise SilentAbort

View File

@@ -4,13 +4,13 @@ from pymol.Qt import QtCore, QtWidgets
class ResizableMessageBox(QtWidgets.QMessageBox):
_EVENT_TYPES = (
QtCore.QEvent.UpdateRequest,
QtCore.QEvent.WinIdChange,
QtCore.QEvent.ShowToParent,
QtCore.QEvent.Type.UpdateRequest,
QtCore.QEvent.Type.WinIdChange,
QtCore.QEvent.Type.ShowToParent,
)
_UNWANTED_WINDOW_FLAGS = (
QtCore.Qt.MSWindowsFixedSizeDialogHint |
QtCore.Qt.WindowType.MSWindowsFixedSizeDialogHint |
0)
def _make_resizable(self):
@@ -20,7 +20,7 @@ class ResizableMessageBox(QtWidgets.QMessageBox):
self.setSizeGripEnabled(True)
ex = QtWidgets.QSizePolicy.Expanding
ex = QtWidgets.QSizePolicy.Policy.Expanding
for w in [self, textEdit]:
w.setMaximumSize(0xffffff, 0xffffff)
w.setSizePolicy(ex, ex)

View File

@@ -13,7 +13,7 @@ Qt = QtCore.Qt
class SettingSlider(QtWidgets.QSlider):
def __init__(self, parent, setting, min_val, max_val, res, line_edit):
super(SettingSlider, self).__init__(Qt.Horizontal, parent)
super(SettingSlider, self).__init__(Qt.Orientation.Horizontal, parent)
self.setting = setting
self.min_val = float(min_val)
@@ -211,7 +211,7 @@ def create_dialog():
form_layout = QtWidgets.QFormLayout()
form_layout.setContentsMargins(0, 0, 0, 0)
form_layout.setVerticalSpacing(0)
form_layout.setLabelAlignment(Qt.AlignLeft)
form_layout.setLabelAlignment(Qt.AlignmentFlag.AlignLeft)
layout.addLayout(form_layout)
for i, item in enumerate(sliders, 1):

View File

@@ -94,11 +94,11 @@ class TextEditor(QtWidgets.QMainWindow):
QMessageBox = QtWidgets.QMessageBox
if self._get() != self._savedcontent:
ok = QMessageBox.question(None, "Save?", "Save changes?",
QMessageBox.Yes | QMessageBox.No |
QMessageBox.Cancel, QMessageBox.Yes)
if ok == QMessageBox.Yes:
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No |
QMessageBox.StandardButton.Cancel, QMessageBox.StandardButton.Yes)
if ok == QMessageBox.StandardButton.Yes:
self.doSave()
elif ok == QMessageBox.Cancel:
elif ok == QMessageBox.StandardButton.Cancel:
return False
return True
@@ -118,10 +118,10 @@ class TextEditor(QtWidgets.QMainWindow):
menubar = self.root.menuBar()
filemenu = menubar.addMenu("File")
filemenu.addAction("Open", self.doOpen, QtGui.QKeySequence("Ctrl+O"))
filemenu.addAction("Save", self.doSave, QtGui.QKeySequence("Ctrl+S"))
filemenu.addAction("Save as ...", self.doSaveAs,
QtGui.QKeySequence("Ctrl+Shift+S"))
filemenu.addAction("Open", QtGui.QKeySequence("Ctrl+O"), self.doOpen)
filemenu.addAction("Save", QtGui.QKeySequence("Ctrl+S"), self.doSave)
filemenu.addAction("Save as ...", QtGui.QKeySequence("Ctrl+Shift+S"),
self.doSaveAs)
syntaxmenu = menubar.addMenu("Syntax")
syntaxgroup = QtWidgets.QActionGroup(self)
@@ -176,7 +176,7 @@ def _edit_pymolrc(app, _list=()):
pymolrc, ok = QtWidgets.QInputDialog.getText(
None, 'Create new pymolrc?', 'Filename of new pymolrc',
QtWidgets.QLineEdit.Normal, pymolrc)
QtWidgets.QLineEdit.EchoMode.Normal, pymolrc)
if not ok:
return

View File

@@ -11,7 +11,7 @@ class PyMOLAdvancedSettings(QtWidgets.QWidget):
options and adds them to a filterable table.
"""
def __init__(self, parent, cmd):
QtWidgets.QWidget.__init__(self, parent, Qt.Window)
QtWidgets.QWidget.__init__(self, parent, Qt.WindowType.Window)
self.setMinimumSize(400, 500)
self.cmd = cmd
@@ -25,7 +25,7 @@ class PyMOLAdvancedSettings(QtWidgets.QWidget):
self.filter_le = QtWidgets.QLineEdit(self)
layout.addWidget(self.filter_le)
self.filter_le.setPlaceholderText("Filter")
self.filter_le.textChanged.connect(self.proxy_model.setFilterRegExp)
self.filter_le.textChanged.connect(self.proxy_model.setFilterRegularExpression)
self.populateData()
@@ -51,12 +51,12 @@ class PyMOLAdvancedSettings(QtWidgets.QWidget):
value_item = QSI()
name_item = QSI(name)
name_item.setFlags(Qt.ItemIsEnabled)
name_item.setFlags(Qt.ItemFlag.ItemIsEnabled)
if v_type == 1: # CheckBox type
value_item.setCheckable(True)
value_item.setEditable(False) # Can't edit text (but toggles)
if v_list[0]:
value_item.setCheckState(Qt.Checked)
value_item.setCheckState(Qt.CheckState.Checked)
else: # Text type
if v_type in (2, 6): # int, str
value_item.setText(str(v_list[0]))
@@ -93,7 +93,7 @@ class PyMOLAdvancedSettings(QtWidgets.QWidget):
index = item.data()
if item.isCheckable():
checked = item.checkState() == Qt.Checked
checked = item.checkState() == Qt.CheckState.Checked
self.cmd.set(index, checked, log=1, quiet=0)
else:
self.cmd.set(index, item.text(), log=1, quiet=0)

View File

@@ -1020,10 +1020,10 @@ class NucleicAcidProperties:
def makeFragmentButton():
btn = QtWidgets.QPushButton()
btn.setAttribute(Qt.WA_LayoutUsesWidgetRect) # OS X workaround
btn.setAttribute(Qt.WidgetAttribute.WA_LayoutUsesWidgetRect) # OS X workaround
btn.setSizePolicy(
QtWidgets.QSizePolicy.Minimum,
QtWidgets.QSizePolicy.MinimumExpanding)
QtWidgets.QSizePolicy.Policy.Minimum,
QtWidgets.QSizePolicy.Policy.MinimumExpanding)
btn.setAutoDefault(False)
return btn
@@ -1315,8 +1315,8 @@ class _BuilderPanel(QtWidgets.QWidget):
check = QMB.question(None, 'Enable for objects?',
'Building "Undo" is disabled for the following objects:\n\n' +
'\n'.join(on_per_object) + '\n\n'
'Enable "Undo" for these objects?', QMB.Yes | QMB.No)
if check == QMB.Yes:
'Enable "Undo" for these objects?', QMB.StandardButton.Yes | QMB.StandardButton.No)
if check == QMB.StandardButton.Yes:
for oname in on_per_object:
self.cmd.unset('suspend_undo', oname)
@@ -1527,8 +1527,8 @@ class _BuilderPanel(QtWidgets.QWidget):
def clear(self):
QMB = QtWidgets.QMessageBox
check = QMB.question(None, "Confirm",
"Really delete everything?", QMB.Yes | QMB.No)
if check == QMB.Yes:
"Really delete everything?", QMB.StandardButton.Yes | QMB.StandardButton.No)
if check == QMB.StandardButton.Yes:
self.cmd.delete("all")
self.cmd.refresh_wizard()

View File

@@ -271,7 +271,7 @@ def load_aln_dialog(parent, filename, format):
if format == 'fasta' and QtWidgets.QMessageBox.question(
parent, "Load as structures?",
"Load sequences as extended structures instead?"
) == QtWidgets.QMessageBox.Yes:
) == QtWidgets.QMessageBox.StandardButton.Yes:
_self.load(filename)
# hook up events

View File

@@ -8,36 +8,36 @@ Qt = QtCore.Qt
DEBUG = False
keyMap = {
Qt.Key_Escape: 27,
Qt.Key_Tab: 9,
Qt.Key_Backspace: 8,
Qt.Key_Return: 13,
Qt.Key_Enter: 13,
Qt.Key_Delete: 127,
Qt.Key.Key_Escape: 27,
Qt.Key.Key_Tab: 9,
Qt.Key.Key_Backspace: 8,
Qt.Key.Key_Return: 13,
Qt.Key.Key_Enter: 13,
Qt.Key.Key_Delete: 127,
}
specialMap = {
Qt.Key_Left: 100,
Qt.Key_Up: 101,
Qt.Key_Right: 102,
Qt.Key_Down: 103,
Qt.Key_PageUp: 104,
Qt.Key_PageDown: 105,
Qt.Key_Home: 106,
Qt.Key_End: 107,
Qt.Key_Insert: 108,
Qt.Key_F1: 1,
Qt.Key_F2: 2,
Qt.Key_F3: 3,
Qt.Key_F4: 4,
Qt.Key_F5: 5,
Qt.Key_F6: 6,
Qt.Key_F7: 7,
Qt.Key_F8: 8,
Qt.Key_F9: 9,
Qt.Key_F10: 10,
Qt.Key_F11: 11,
Qt.Key_F12: 12,
Qt.Key.Key_Left: 100,
Qt.Key.Key_Up: 101,
Qt.Key.Key_Right: 102,
Qt.Key.Key_Down: 103,
Qt.Key.Key_PageUp: 104,
Qt.Key.Key_PageDown: 105,
Qt.Key.Key_Home: 106,
Qt.Key.Key_End: 107,
Qt.Key.Key_Insert: 108,
Qt.Key.Key_F1: 1,
Qt.Key.Key_F2: 2,
Qt.Key.Key_F3: 3,
Qt.Key.Key_F4: 4,
Qt.Key.Key_F5: 5,
Qt.Key.Key_F6: 6,
Qt.Key.Key_F7: 7,
Qt.Key.Key_F8: 8,
Qt.Key.Key_F9: 9,
Qt.Key.Key_F10: 10,
Qt.Key.Key_F11: 11,
Qt.Key.Key_F12: 12,
}
@@ -47,10 +47,10 @@ def get_modifiers(ev):
qtmodifiers = ev.modifiers()
for mask, qtm in [
(0x1, Qt.ShiftModifier),
(0x2, Qt.MetaModifier), # CTRL on Mac
(0x2, Qt.ControlModifier),
(0x4, Qt.AltModifier)
(0x1, Qt.KeyboardModifier.ShiftModifier),
(0x2, Qt.KeyboardModifier.MetaModifier), # CTRL on Mac
(0x2, Qt.KeyboardModifier.ControlModifier),
(0x4, Qt.KeyboardModifier.AltModifier)
]:
if qtmodifiers & qtm:
pymolmod |= mask
@@ -115,7 +115,7 @@ def get_wheel_delta(ev):
if abs(delta_y) < abs(delta_x):
# Shift+Wheel emulates horizontal scrolling
if not (ev.modifiers() & Qt.ShiftModifier):
if not (ev.modifiers() & Qt.KeyboardModifier.ShiftModifier):
return 0
return delta_x

View File

@@ -15,13 +15,13 @@ class _qtMessageBox:
QMB = QtWidgets.QMessageBox
variants = {
'askyesno': ('question', QMB.Yes, QMB.No),
'askquestion': ('question', QMB.Yes, QMB.No),
'askokcancel': ('question', QMB.Ok, QMB.Cancel),
'askretrycancel': ('question', QMB.Retry, QMB.Cancel),
'showinfo': ('information', QMB.Ok, QMB.NoButton),
'showerror': ('critical', QMB.Ok, QMB.NoButton),
'showwarning': ('warning', QMB.Ok, QMB.NoButton),
'askyesno': ('question', QMB.StandardButton.Yes, QMB.StandardButton.No),
'askquestion': ('question', QMB.StandardButton.Yes, QMB.StandardButton.No),
'askokcancel': ('question', QMB.StandardButton.Ok, QMB.StandardButton.Cancel),
'askretrycancel': ('question', QMB.StandardButton.Retry, QMB.StandardButton.Cancel),
'showinfo': ('information', QMB.StandardButton.Ok, QMB.StandardButton.NoButton),
'showerror': ('critical', QMB.StandardButton.Ok, QMB.StandardButton.NoButton),
'showwarning': ('warning', QMB.StandardButton.Ok, QMB.StandardButton.NoButton),
}
try:

View File

@@ -52,9 +52,9 @@ class PropsDialog(QtWidgets.QWidget):
def make_entry(self, parent, label):
item = QtWidgets.QTreeWidgetItem(parent)
item.setText(0, str(label))
item.setFlags(QtCore.Qt.ItemIsEditable |
QtCore.Qt.ItemIsEnabled |
QtCore.Qt.ItemIsSelectable )
item.setFlags(QtCore.Qt.ItemFlag.ItemIsEditable |
QtCore.Qt.ItemFlag.ItemIsEnabled |
QtCore.Qt.ItemFlag.ItemIsSelectable )
return item
def make_cat(self, parent, label):
@@ -63,7 +63,7 @@ class PropsDialog(QtWidgets.QWidget):
item.setFirstColumnSpanned(True)
item.setExpanded(True)
item.setChildIndicatorPolicy(
QtWidgets.QTreeWidgetItem.ShowIndicator)
QtWidgets.QTreeWidgetItem.ChildIndicatorPolicy.ShowIndicator)
return item
def setup_tree_widget(self):
@@ -279,8 +279,8 @@ class PropsDialog(QtWidgets.QWidget):
'''
Event filter for creating new shortcuts. Processes the key event before passing it on.
'''
if (event.type() == QtCore.QEvent.KeyPress and source is self.form.treeWidget):
if (event.key() == QtCore.Qt.Key_Delete):
if (event.type() == QtCore.QEvent.Type.KeyPress and source is self.form.treeWidget):
if (event.key() == QtCore.Qt.Key.Key_Delete):
self.unset_caller()
return 0
return super().eventFilter(source, event)

View File

@@ -7,7 +7,7 @@ import pymol
from pymol.Qt import QtCore
from pymol.Qt import QtGui
from pymol.Qt import QtWidgets
Gesture = QtCore.QEvent.Gesture
Gesture = QtCore.QEvent.Type.Gesture
Qt = QtCore.Qt
from .keymapping import get_modifiers
@@ -43,9 +43,9 @@ class PyMOLGLWidget(BaseGLWidget):
# mouse button map
_buttonMap = {
Qt.LeftButton: 0,
Qt.MidButton: 1,
Qt.RightButton: 2,
Qt.MouseButton.LeftButton: 0,
Qt.MouseButton.MiddleButton: 1,
Qt.MouseButton.RightButton: 2,
}
def __enter__(self):
@@ -91,7 +91,7 @@ class PyMOLGLWidget(BaseGLWidget):
if USE_QOPENGLWIDGET:
super(PyMOLGLWidget, self).__init__(parent=parent)
self.setFormat(f)
self.setUpdateBehavior(QtWidgets.QOpenGLWidget.PartialUpdate)
self.setUpdateBehavior(QtWidgets.QOpenGLWidget.UpdateBehavior.PartialUpdate)
else:
super(PyMOLGLWidget, self).__init__(f, parent=parent)
@@ -108,7 +108,7 @@ class PyMOLGLWidget(BaseGLWidget):
self.setMouseTracking(True)
# for accepting keyboard input (command line, shortcuts)
self.setFocusPolicy(Qt.ClickFocus)
self.setFocusPolicy(Qt.FocusPolicy.ClickFocus)
# for idle rendering
self._timer = QtCore.QTimer()
@@ -119,7 +119,7 @@ class PyMOLGLWidget(BaseGLWidget):
self.setAcceptDrops(True)
# pinch-zoom
self.grabGesture(Qt.PinchGesture)
self.grabGesture(Qt.GestureType.PinchGesture)
def sizeHint(self):
# default 640 + internal_gui, 480 + internal_feedback

View File

@@ -87,8 +87,8 @@ class PyMOLQtGUI(QtWidgets.QMainWindow, pymol._gui.PyMOLDesktopGUI):
def __init__(self): # noqa
QtWidgets.QMainWindow.__init__(self)
self.setDockOptions(QtWidgets.QMainWindow.AllowTabbedDocks |
QtWidgets.QMainWindow.AllowNestedDocks)
self.setDockOptions(QtWidgets.QMainWindow.DockOption.AllowTabbedDocks |
QtWidgets.QMainWindow.DockOption.AllowNestedDocks)
# resize Window before it is shown
options = pymol.invocation.options
@@ -163,7 +163,7 @@ PyMOL> color ye<TAB> (will autocomplete "yellow")
quickbuttonslayout = QtWidgets.QVBoxLayout()
quickbuttonslayout.setSpacing(2)
extguilayout = QtWidgets.QBoxLayout(QtWidgets.QBoxLayout.LeftToRight)
extguilayout = QtWidgets.QBoxLayout(QtWidgets.QBoxLayout.Direction.LeftToRight)
extguilayout.setContentsMargins(2, 2, 2, 2)
extguilayout.addLayout(layout)
extguilayout.addLayout(quickbuttonslayout)
@@ -190,16 +190,16 @@ PyMOL> color ye<TAB> (will autocomplete "yellow")
else:
dockWidget.hide()
self.addDockWidget(Qt.TopDockWidgetArea, dockWidget)
self.addDockWidget(Qt.DockWidgetArea.TopDockWidgetArea, dockWidget)
# rearrange vertically if docking left or right
@dockWidget.dockLocationChanged.connect
def _(area):
if area == Qt.LeftDockWidgetArea or area == Qt.RightDockWidgetArea:
extguilayout.setDirection(QtWidgets.QBoxLayout.BottomToTop)
if area == Qt.DockWidgetArea.LeftDockWidgetArea or area == Qt.DockWidgetArea.RightDockWidgetArea:
extguilayout.setDirection(QtWidgets.QBoxLayout.Direction.BottomToTop)
quickbuttonslayout.takeAt(quickbuttons_stretch_index)
else:
extguilayout.setDirection(QtWidgets.QBoxLayout.LeftToRight)
extguilayout.setDirection(QtWidgets.QBoxLayout.Direction.LeftToRight)
if quickbuttons_stretch_index >= quickbuttonslayout.count():
quickbuttonslayout.addStretch()
@@ -258,7 +258,7 @@ PyMOL> color ye<TAB> (will autocomplete "yellow")
for name, callback in row:
btn = QtWidgets.QPushButton(name)
btn.setProperty("quickbutton", True)
btn.setAttribute(Qt.WA_LayoutUsesWidgetRect) # OS X workaround
btn.setAttribute(Qt.WidgetAttribute.WA_LayoutUsesWidgetRect) # OS X workaround
hbox.addWidget(btn)
if callback is None:
@@ -274,8 +274,8 @@ PyMOL> color ye<TAB> (will autocomplete "yellow")
hbox = QtWidgets.QHBoxLayout()
self.progressbar = QtWidgets.QProgressBar()
self.progressbar.setSizePolicy(
QtWidgets.QSizePolicy.Minimum,
QtWidgets.QSizePolicy.Minimum)
QtWidgets.QSizePolicy.Policy.Minimum,
QtWidgets.QSizePolicy.Policy.Minimum)
hbox.addWidget(self.progressbar)
self.abortbutton = QtWidgets.QPushButton('Abort')
self.abortbutton.setStyleSheet("background: #FF0000; color: #FFFFFF")
@@ -420,16 +420,16 @@ PyMOL> color ye<TAB> (will autocomplete "yellow")
def lineeditKeyPressEventFilter(self, watched, event):
key = event.key()
if key == Qt.Key_Tab:
if key == Qt.Key.Key_Tab:
self.complete()
elif key == Qt.Key_Up:
if event.modifiers() & Qt.ControlModifier:
elif key == Qt.Key.Key_Up:
if event.modifiers() & Qt.KeyboardModifier.ControlModifier:
self.back_search()
else:
self.back()
elif key == Qt.Key_Down:
elif key == Qt.Key.Key_Down:
self.forward()
elif key == Qt.Key_Return or key == Qt.Key_Enter:
elif key == Qt.Key.Key_Return or key == Qt.Key.Key_Enter:
# filter out "Return" instead of binding lineedit.returnPressed,
# because otherwise OrthoKey would capture it as well.
self.doPrompt()
@@ -442,14 +442,14 @@ PyMOL> color ye<TAB> (will autocomplete "yellow")
Filter out <Tab> event to do tab-completion instead of move focus
'''
type_ = event.type()
if type_ == QtCore.QEvent.KeyRelease:
if event.key() == Qt.Key_Tab:
if type_ == QtCore.QEvent.Type.KeyRelease:
if event.key() == Qt.Key.Key_Tab:
# silently skip tab release
return True
elif type_ == QtCore.QEvent.KeyPress:
elif type_ == QtCore.QEvent.Type.KeyPress:
if watched is self.lineedit:
return self.lineeditKeyPressEventFilter(watched, event)
elif event.key() == Qt.Key_Tab:
elif event.key() == Qt.Key.Key_Tab:
self.keyPressEvent(event)
return True
return False
@@ -473,7 +473,7 @@ PyMOL> color ye<TAB> (will autocomplete "yellow")
'''
Full screen
'''
is_fullscreen = self.windowState() == Qt.WindowFullScreen
is_fullscreen = self.windowState() == Qt.WindowState.WindowFullScreen
if toggle == -1:
toggle = not is_fullscreen
@@ -592,10 +592,10 @@ PyMOL> color ye<TAB> (will autocomplete "yellow")
(name, R, G, B))
# if new color, insert and make current row
if not form.list_colors.findItems(name, Qt.MatchExactly):
if not form.list_colors.findItems(name, Qt.MatchFlag.MatchExactly):
form.list_colors.addItem(name)
form.list_colors.setCurrentItem(
form.list_colors.findItems(name, Qt.MatchExactly)[0])
form.list_colors.findItems(name, Qt.MatchFlag.MatchExactly)[0])
# hook up events
form.slider_R.valueChanged.connect(lambda v: update_spinbox(form.input_R, v))
@@ -617,7 +617,7 @@ PyMOL> color ye<TAB> (will autocomplete "yellow")
app = plugins.get_pmgapp()
if not self.builder:
self.builder = BuilderPanelDocked(self, app)
self.addDockWidget(Qt.TopDockWidgetArea, self.builder)
self.addDockWidget(Qt.DockWidgetArea.TopDockWidgetArea, self.builder)
self.builder.show()
self.builder.raise_()
@@ -1009,9 +1009,9 @@ PyMOL> color ye<TAB> (will autocomplete "yellow")
self.showMaximized()
elif action == 6: # fit
if hasattr(QtGui, 'QWindow') and self.windowHandle().visibility() in (
QtGui.QWindow.Maximized, QtGui.QWindow.FullScreen):
QtGui.QWindow.Visibility.Maximized, QtGui.QWindow.Visibility.FullScreen):
return
a = QtWidgets.QApplication.desktop().availableGeometry(self)
a = self.screen().availableGeometry()
g = self.geometry()
f = self.frameGeometry()
w = min(f.width(), a.width())
@@ -1025,7 +1025,7 @@ PyMOL> color ye<TAB> (will autocomplete "yellow")
h - f.height() + g.height(),
)
elif action == 7: # focus
self.setFocus(Qt.OtherFocusReason)
self.setFocus(Qt.FocusReason.OtherFocusReason)
elif action == 8: # defocus
self.clearFocus()
@@ -1133,12 +1133,12 @@ class PyMOLApplication(QtWidgets.QApplication):
# handled by Qt, we don't want that.
def handle_file_open(self, ev):
if ev.type() == QtCore.QEvent.ApplicationActivate:
if ev.type() == QtCore.QEvent.Type.ApplicationActivate:
self.handle_file_open = self.handle_file_open_active
return False
def handle_file_open_active(self, ev):
if ev.type() != QtCore.QEvent.FileOpen:
if ev.type() != QtCore.QEvent.Type.FileOpen:
return False
# When double clicking a file in Finder, open it in a new instance
@@ -1203,13 +1203,13 @@ def execapp():
# use QT_OPENGL=desktop (auto-detection may fail on Windows)
if hasattr(Qt, 'AA_UseDesktopOpenGL') and pymol.IS_WINDOWS:
QtCore.QCoreApplication.setAttribute(Qt.AA_UseDesktopOpenGL)
QtCore.QCoreApplication.setAttribute(Qt.ApplicationAttribute.AA_UseDesktopOpenGL)
# enable 4K scaling on Windows and Linux
if hasattr(Qt, 'AA_EnableHighDpiScaling') and not any(
v in os.environ
for v in ['QT_SCALE_FACTOR', 'QT_SCREEN_SCALE_FACTORS']):
QtCore.QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QtCore.QCoreApplication.setAttribute(Qt.ApplicationAttribute.AA_EnableHighDpiScaling)
# fix Windows taskbar icon
if pymol.IS_WINDOWS:

View File

@@ -79,7 +79,7 @@ class ScenePanel(QtWidgets.QWidget):
self.sceneTableWidget.selectionModel().selectionChanged.connect(
self._selection_changed)
self.sceneTableWidget.setSelectionBehavior(
QtWidgets.QAbstractItemView.SelectRows)
QtWidgets.QAbstractItemView.SelectionBehavior.SelectRows)
self.sceneTableWidget.verticalHeader().setSectionsMovable(True)
# Lower Buttom Elements

View File

@@ -23,10 +23,10 @@ def get_shortcut_key_map():
_SHORTCUT_KEY_MAP = get_shortcut_key_map()
_SHORTCUT_MODIFIER_MAP = {
Qt.ControlModifier: _SHORTCUT_KEY_MAP[Qt.Key_Control],
Qt.AltModifier: _SHORTCUT_KEY_MAP[Qt.Key_Alt],
Qt.ShiftModifier: _SHORTCUT_KEY_MAP[Qt.Key_Shift],
Qt.MetaModifier: _SHORTCUT_KEY_MAP[Qt.Key_Meta],
Qt.KeyboardModifier.ControlModifier: _SHORTCUT_KEY_MAP[Qt.Key.Key_Control],
Qt.KeyboardModifier.AltModifier: _SHORTCUT_KEY_MAP[Qt.Key.Key_Alt],
Qt.KeyboardModifier.ShiftModifier: _SHORTCUT_KEY_MAP[Qt.Key.Key_Shift],
Qt.KeyboardModifier.MetaModifier: _SHORTCUT_KEY_MAP[Qt.Key.Key_Meta],
}
_REPLACE_KEYS = {
@@ -48,7 +48,7 @@ class PyMOLShortcutMenu(QtWidgets.QWidget):
'''
def __init__(self, parent, saved_shortcuts, cmd):
QtWidgets.QWidget.__init__(self, parent, Qt.Window)
QtWidgets.QWidget.__init__(self, parent, Qt.WindowType.Window)
self.resize(700, 700)
self.cmd = cmd
self.shortcut_manager = ShortcutManager(saved_shortcuts, cmd)
@@ -66,7 +66,7 @@ class PyMOLShortcutMenu(QtWidgets.QWidget):
self.model = QtGui.QStandardItemModel(self)
self.proxy_model = QtCoreModels.QSortFilterProxyModel(self)
self.proxy_model.setSourceModel(self.model)
self.proxy_model.setFilterCaseSensitivity(Qt.CaseInsensitive)
self.proxy_model.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
self.proxy_model.setFilterKeyColumn(-1)
self.setWindowTitle('Keyboard Shortcut Menu')
@@ -81,7 +81,7 @@ class PyMOLShortcutMenu(QtWidgets.QWidget):
self.filter_le = QtWidgets.QLineEdit(self)
top_layout.addWidget(self.filter_le)
self.filter_le.setPlaceholderText("Filter")
self.filter_le.textChanged.connect(self.proxy_model.setFilterRegExp)
self.filter_le.textChanged.connect(self.proxy_model.setFilterRegularExpression)
self.refresh_button = QtWidgets.QPushButton(self)
self.refresh_button.resize(26, 26)
@@ -166,8 +166,8 @@ class PyMOLShortcutMenu(QtWidgets.QWidget):
key_item = QSI(key)
command_item = QSI()
descript_item = QSI()
key_item.setFlags(Qt.ItemIsEnabled)
descript_item.setFlags(Qt.ItemIsEditable)
key_item.setFlags(Qt.ItemFlag.ItemIsEnabled)
descript_item.setFlags(Qt.ItemFlag.ItemIsEditable)
if shortcut_list[ShortcutIndex.USER_DEF]:
if shortcut_list[ShortcutIndex.USER_DEF] != "Deleted":
@@ -286,7 +286,7 @@ class PyMOLShortcutMenu(QtWidgets.QWidget):
'''
Event filter for creating new shortcuts. Processes the key event before passing it on.
'''
if (event.type() == QtCore.QEvent.KeyPress and source is self.create_new_form.keyEdit):
if (event.type() == QtCore.QEvent.Type.KeyPress and source is self.create_new_form.keyEdit):
raw_string = self.keyevent_to_string(event)
processed_string = self.process_keyevent_string(raw_string)

View File

@@ -7,7 +7,7 @@ def textformat(color, style=''):
for word in style.split():
if word == 'bold':
fmt.setFontWeight(QtGui.QFont.Bold)
fmt.setFontWeight(QtGui.QFont.Weight.Bold)
elif word == 'italic':
fmt.setFontItalic(True)
elif word.startswith('bg:'):

View File

@@ -109,7 +109,7 @@ class VolumeEditorWidget(QtWidgets.QWidget):
painter.drawLine(x0, y0, x0, y1)
h = rect.height()
num_lines = 10
pen.setStyle(Qt.DashLine)
pen.setStyle(Qt.PenStyle.DashLine)
painter.setPen(pen)
for line in range(1, num_lines):
y = y0 + h * (1.0 - self.alphaToY(line / float(num_lines)))
@@ -117,8 +117,8 @@ class VolumeEditorWidget(QtWidgets.QWidget):
painter.drawLine(x0, y, x1, y)
def paintColorDots(self, painter, rect):
pen = QtGui.QPen(Qt.gray)
pen.setStyle(Qt.SolidLine)
pen = QtGui.QPen(Qt.GlobalColor.gray)
pen.setStyle(Qt.PenStyle.SolidLine)
painter.setPen(pen)
scaled_pts = []
h = rect.height()
@@ -171,8 +171,8 @@ class VolumeEditorWidget(QtWidgets.QWidget):
else:
painter_path.lineTo(x, y)
pen = QtGui.QPen(Qt.red)
pen.setStyle(Qt.SolidLine)
pen = QtGui.QPen(Qt.GlobalColor.red)
pen.setStyle(Qt.PenStyle.SolidLine)
painter.setPen(pen)
painter.drawPath(painter_path)
@@ -192,7 +192,7 @@ class VolumeEditorWidget(QtWidgets.QWidget):
else:
rect = QtCore.QRect(x, y - sh, sw + 4, sh + 2)
painter.fillRect(rect,
QtGui.QColor(96, 96, 128) if self.line_color == Qt.lightGray else
QtGui.QColor(96, 96, 128) if self.line_color == Qt.GlobalColor.lightGray else
QtGui.QColor(0xFF, 0xFF, 0xFF))
painter.drawRect(rect)
painter.drawText(rect.x() + 2, y - 2, s)
@@ -202,7 +202,7 @@ class VolumeEditorWidget(QtWidgets.QWidget):
low = int(math.ceil(self.vmin))
hi = int(math.floor(self.vmax)) + 1
pen = painter.pen()
pen.setStyle(Qt.SolidLine)
pen.setStyle(Qt.PenStyle.SolidLine)
pen.setColor(self.line_color)
painter.setPen(pen)
fm = QtGui.QFontMetrics(painter.font())
@@ -265,10 +265,10 @@ class VolumeEditorWidget(QtWidgets.QWidget):
# tweak color depening on the panel floating state
# disabled: always use default style
is_floating = True # self.parent().parent().isFloating()
self.line_color = Qt.darkGray if is_floating else Qt.lightGray
self.line_color = Qt.GlobalColor.darkGray if is_floating else Qt.GlobalColor.lightGray
painter.begin(self)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
painter.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing)
self.paintGrid(painter, self.paint_rect)
self.paintAxes(painter, self.paint_rect)
painter.setClipRect(self.paint_rect)
@@ -291,7 +291,7 @@ class VolumeEditorWidget(QtWidgets.QWidget):
def mousePressEvent(self, event):
# process textbox clicks
if event.button() == Qt.LeftButton:
if event.button() == Qt.MouseButton.LeftButton:
for key, rect in self.text_boxes.items():
if rect.contains(event.pos()):
if key == "amax":
@@ -316,24 +316,24 @@ class VolumeEditorWidget(QtWidgets.QWidget):
self.init_pos = event.pos()
self.zoom_pos = None
self.constraint = None
if self.point < 0 and event.button() == Qt.LeftButton:
if self.point < 0 and event.button() == Qt.MouseButton.LeftButton:
self.addPoint(
event.pos(), event.modifiers() == Qt.ControlModifier)
event.pos(), event.modifiers() == Qt.KeyboardModifier.ControlModifier)
# suppress color picker
self.dragged = True
def mouseReleaseEvent(self, event):
if not self.dragged and self.point >= 0:
if event.button() == Qt.RightButton:
if event.button() == Qt.MouseButton.RightButton:
x, y, r, g, b = self.points[self.point]
# in 2.0: help says NoModifier, implemented is ControlModifier
if event.modifiers() in (Qt.ControlModifier, Qt.NoModifier):
if event.modifiers() in (Qt.KeyboardModifier.ControlModifier, Qt.KeyboardModifier.NoModifier):
value = self.points[self.point][0]
prev_x = self.points[self.point-1][0] if self.point > 0 else self.vmin
next_x = self.points[self.point+1][0] if self.point < len(self.points)-1 else self.vmax
x = self.enterValue("Data value",
value, prev_x, next_x)
elif event.modifiers() == Qt.ShiftModifier:
elif event.modifiers() == Qt.KeyboardModifier.ShiftModifier:
value = self.points[self.point][1]
y = self.enterValue("Alpha value (opacity)",
value, 0.0, 1.0)
@@ -341,14 +341,14 @@ class VolumeEditorWidget(QtWidgets.QWidget):
self.repaint()
if self.real_time:
self.updateVolumeColors()
if (event.button() == Qt.MidButton or
(event.button() == Qt.LeftButton and
event.modifiers() & Qt.ShiftModifier)):
if (event.button() == Qt.MouseButton.MiddleButton or
(event.button() == Qt.MouseButton.LeftButton and
event.modifiers() & Qt.KeyboardModifier.ShiftModifier)):
self.removePoints(
event.modifiers() & Qt.ControlModifier)
elif event.button() == Qt.LeftButton:
event.modifiers() & Qt.KeyboardModifier.ControlModifier)
elif event.button() == Qt.MouseButton.LeftButton:
self.setPointColor(self.point,
event.modifiers() == Qt.ControlModifier)
event.modifiers() == Qt.KeyboardModifier.ControlModifier)
self.point = -1
self.hover_point = -1
@@ -396,7 +396,7 @@ class VolumeEditorWidget(QtWidgets.QWidget):
"""
This is called when color dialog is closed.
"""
if result == QtWidgets.QDialog.Accepted:
if result == QtWidgets.QDialog.DialogCode.Accepted:
color = self.color_dialog.currentColor()
else:
color = self.original_color
@@ -491,16 +491,16 @@ class VolumeEditorWidget(QtWidgets.QWidget):
self.ignore_set_colors = False
def mouseMoveEvent(self, event):
if event.buttons() in (Qt.LeftButton, Qt.RightButton):
if (event.buttons() == Qt.RightButton and
event.modifiers() == Qt.ControlModifier):
if event.buttons() in (Qt.MouseButton.LeftButton, Qt.MouseButton.RightButton):
if (event.buttons() == Qt.MouseButton.RightButton and
event.modifiers() == Qt.KeyboardModifier.ControlModifier):
# zoom in
self.zoom_pos = event.pos()
self.repaint()
elif self.point >= 0:
self.dragged = True
if event.buttons(
) & Qt.RightButton and not self.constraint:
) & Qt.MouseButton.RightButton and not self.constraint:
# constrained movement
dpos = event.pos() - self.init_pos
self.constraint = 'x' if (
@@ -558,7 +558,7 @@ class VolumeEditorWidget(QtWidgets.QWidget):
Moves selected point(s).
"""
# delta == 2 if moving three points
delta = 2 if event.modifiers() == Qt.ControlModifier else 1
delta = 2 if event.modifiers() == Qt.KeyboardModifier.ControlModifier else 1
num_points = len(self.points)
x, y, r, g, b = self.points[self.point]
@@ -813,7 +813,7 @@ def VolumePanelDocked(parent, *args, **kwargs):
window = QtWidgets.QDockWidget(parent)
_VolumePanel(widget, window, *args, **kwargs)
window.setWidget(widget)
parent.addDockWidget(Qt.BottomDockWidgetArea, window)
parent.addDockWidget(Qt.DockWidgetArea.BottomDockWidgetArea, window)
# disabled: always use default style
# window.topLevelChanged.connect(widget.editor.windowTopLevelChanged)

View File

@@ -13,15 +13,6 @@ DEBUG = False
PYQT_NAME = None
QtWidgets = None
try:
from pymol._Qt_pre import *
except ImportError:
if DEBUG:
print('import _Qt_pre failed')
PYQT_NAME = None
QtWidgets = None
try:
from pymol._Qt_pre import *
except ImportError:
@@ -85,43 +76,6 @@ if PYQT_NAME.endswith('6'):
QtWidgets.QActionGroup = QtGui.QActionGroup
QtWidgets.QAction = QtGui.QAction
QtWidgets.QShortcut = QtGui.QShortcut
QtCore.QSortFilterProxyModel.setFilterRegExp = QtCore.QSortFilterProxyModel.setFilterRegularExpression
QtGui.QFont.Monospace = QtGui.QFont.StyleHint.Monospace
def copy_attributes(target_class, source_class):
for attr in dir(source_class):
if not attr.startswith('_'):
setattr(target_class, attr, getattr(source_class, attr))
copy_attributes(QtCore.QEvent, QtCore.QEvent.Type)
copy_attributes(QtCore.Qt, QtCore.Qt.AlignmentFlag)
copy_attributes(QtCore.Qt, QtCore.Qt.CaseSensitivity)
copy_attributes(QtCore.Qt, QtCore.Qt.CheckState)
copy_attributes(QtCore.Qt, QtCore.Qt.ContextMenuPolicy)
copy_attributes(QtCore.Qt, QtCore.Qt.DockWidgetArea)
copy_attributes(QtCore.Qt, QtCore.Qt.FocusPolicy)
copy_attributes(QtCore.Qt, QtCore.Qt.GestureType)
copy_attributes(QtCore.Qt, QtCore.Qt.ItemFlag)
copy_attributes(QtCore.Qt, QtCore.Qt.Key)
copy_attributes(QtCore.Qt, QtCore.Qt.KeyboardModifier)
copy_attributes(QtCore.Qt, QtCore.Qt.MouseButton)
copy_attributes(QtCore.Qt, QtCore.Qt.Orientation)
copy_attributes(QtCore.Qt, QtCore.Qt.WindowType)
copy_attributes(QtGui.QFont, QtGui.QFont.StyleHint)
copy_attributes(QtWidgets.QAbstractItemView, QtWidgets.QAbstractItemView.ScrollHint)
copy_attributes(QtWidgets.QAbstractItemView, QtWidgets.QAbstractItemView.SelectionBehavior)
copy_attributes(QtWidgets.QAbstractItemView, QtWidgets.QAbstractItemView.SelectionMode)
copy_attributes(QtWidgets.QBoxLayout, QtWidgets.QBoxLayout.Direction)
copy_attributes(QtWidgets.QMainWindow, QtWidgets.QMainWindow.DockOption)
copy_attributes(QtWidgets.QOpenGLWidget, QtOpenGLWidgets.QOpenGLWidget.UpdateBehavior)
copy_attributes(QtWidgets.QSizePolicy, QtWidgets.QSizePolicy.Policy)
copy_attributes(QtWidgets.QFrame, QtWidgets.QFrame.Shadow)
copy_attributes(QtWidgets.QFrame, QtWidgets.QFrame.Shape)
copy_attributes(QtWidgets.QTreeWidgetItem, QtWidgets.QTreeWidgetItem.ChildIndicatorPolicy)
QtCore.Qt.MidButton = QtCore.Qt.MiddleButton
QtCore.Qt.WA_LayoutUsesWidgetRect = QtCore.Qt.WidgetAttribute.WA_LayoutUsesWidgetRect
if PYQT_NAME[:4] == 'PyQt':
QtCore.Signal = QtCore.pyqtSignal

View File

@@ -208,7 +208,7 @@ def connectFontContextMenu(widget):
@type widget: QWidget
"""
widget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
widget.setContextMenuPolicy(QtCore.Qt.ContextMenuPolicy.CustomContextMenu)
@widget.customContextMenuRequested.connect
def _(pt):
@@ -219,7 +219,7 @@ def connectFontContextMenu(widget):
@action.triggered.connect
def _():
font, ok = QtWidgets.QFontDialog.getFont(widget.font(), widget,
"Select Font", QtWidgets.QFontDialog.DontUseNativeDialog)
"Select Font", QtWidgets.QFontDialog.FontDialogOption.DontUseNativeDialog)
if ok:
widget.setFont(font)
@@ -261,7 +261,7 @@ def getMonospaceFont(size=9):
family = 'Monospace'
font = QtGui.QFont(family, size)
font.setStyleHint(font.Monospace)
font.setStyleHint(QtGui.QFont.StyleHint.Monospace)
return font
@@ -353,7 +353,7 @@ class PopupOnException:
parent = QtWidgets.QApplication.focusWidget()
msg = str(e) or 'unknown error'
msgbox = QMB(QMB.Critical, 'Error', msg, QMB.Close, parent)
msgbox = QMB(QMB.Icon.Critical, 'Error', msg, QMB.StandardButton.Close, parent)
msgbox.setDetailedText(''.join(traceback.format_tb(tb)))
msgbox.exec()

View File

@@ -21,7 +21,7 @@ def confirm_network_access():
return True
if QtWidgets.QMessageBox.question(None, 'Confirm',
'PyMOL will now download executable code from the internet!'
' Proceed?') == QtWidgets.QMessageBox.Yes:
' Proceed?') == QtWidgets.QMessageBox.StandardButton.Yes:
self.ok = 1
else:
self.ok = 0
@@ -57,7 +57,7 @@ class PluginManager(QtCore.QObject):
self.form.b_remove_repo.pressed.connect(self.remove_repository)
self.reload_plugins()
self.form.l_repo_plugins.setSelectionMode(
QtWidgets.QAbstractItemView.ExtendedSelection)
QtWidgets.QAbstractItemView.SelectionMode.ExtendedSelection)
self.form.b_install.pressed.connect(self.install_repo_plugins)
self.form.b_info.pressed.connect(self.info_repo_plugin)
self.populate_repositories()
@@ -98,15 +98,15 @@ class PluginManager(QtCore.QObject):
for row, key in enumerate(self.t_preferences_keys):
item = QtWidgets.QTableWidgetItem(key)
item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
item.setFlags(Qt.ItemFlag.ItemIsSelectable | Qt.ItemFlag.ItemIsEnabled)
w.setItem(row, 0, item)
item = QtWidgets.QTableWidgetItem()
value = preferences[key]
if isinstance(value, bool):
item.setCheckState(Qt.Checked if value else Qt.Unchecked)
item.setCheckState(Qt.CheckState.Checked if value else Qt.CheckState.Unchecked)
else:
item.setFlags(item.flags() & ~Qt.ItemIsUserCheckable)
item.setFlags(item.flags() & ~Qt.ItemFlag.ItemIsUserCheckable)
item.setText(str(value))
w.setItem(row, 1, item)
@@ -116,8 +116,8 @@ class PluginManager(QtCore.QObject):
from . import pref_get, pref_set
key = self.t_preferences_keys[item.row()]
if item.flags() & Qt.ItemIsUserCheckable:
value = item.checkState() == Qt.Checked
if item.flags() & Qt.ItemFlag.ItemIsUserCheckable:
value = item.checkState() == Qt.CheckState.Checked
else:
value = item.data(0)
@@ -225,8 +225,8 @@ class PluginManager(QtCore.QObject):
def add_plugin_item(info):
item = window.load_form('pluginitem', QtWidgets.QFrame())
item._widget = item._dialog
item._widget.setFrameStyle(QtWidgets.QFrame.Sunken)
item._widget.setFrameShape(QtWidgets.QFrame.Panel)
item._widget.setFrameStyle(QtWidgets.QFrame.Shadow.Sunken)
item._widget.setFrameShape(QtWidgets.QFrame.Shape.Panel)
item.w_title.setText(info.name)
item.w_version.setText(info.get_version())
@@ -351,11 +351,11 @@ class PluginManager(QtCore.QObject):
table.insertRow(table.rowCount())
table_item = QtWidgets.QTableWidgetItem(label)
table_item.setFlags(table_item.flags() &
~(Qt.ItemIsEditable))
~(Qt.ItemFlag.ItemIsEditable))
table.setItem(row, 0, table_item)
table_item = QtWidgets.QTableWidgetItem(text)
table_item.setFlags(table_item.flags() &
~(Qt.ItemIsEditable))
~(Qt.ItemFlag.ItemIsEditable))
table.setItem(row, 1, table_item)
add_line('Name', info.name)