Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scoped enums for PyQt6 proper support #400

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ REQUIREMENTS
https://github.com/schrodinger/pmw-patched
- OpenGL
- GLEW
- GLUT (freeglut) (optional, enable with --glut)
- GLUT (freeglut) (optional, enable with --glut=true)
- libpng
- freetype
- libxml2 (optional, for COLLADA export, disable with --no-libxml)
- libxml2 (optional, for COLLADA export, disable with --libxml=false)
- msgpack-c 2.1.5+ (optional, for fast MMTF loading and export,
disable with --use-msgpackc=no)
- mmtf-cpp (for fast MMTF export, disable with --use-msgpackc=no)
- PyQt5, PyQt6, PySide2 or PySide6 (optional, will fall back to Tk
interface if compiled with --glut)
- glm
- catch2 (optional, enable with --testing)
- catch2 (optional, enable with --testing=true)
- openvr 1.0.x (optional, enable with --openvr)
- libnetcdf (optional, disable with --no-vmd-plugins)
- libnetcdf (optional, disable with --vmd-plugins=no)

SETUP OPTIONS

Expand Down Expand Up @@ -57,7 +57,9 @@ INSTALLATION

RUNNING PyMOL

~/someplace/bin/pymol
$PYMOL_PATH/bin/pymol
or
$PYTHONUSERBASE/bin/pymol

Good luck!

8 changes: 4 additions & 4 deletions data/startup/apbs_gui/qtwidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
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):
Expand Down
4 changes: 2 additions & 2 deletions data/startup/lightingsettings_gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
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)
Expand Down Expand Up @@ -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):
Expand Down
22 changes: 8 additions & 14 deletions modules/pmg_qt/TextEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@
import sys
import importlib

try:
from pymol.Qt import QtCore, QtWidgets, QtGui
from pymol.Qt.utils import connectFontContextMenu, getMonospaceFont
except ImportError:
from PyQt5 import QtCore, QtWidgets, QtGui
connectFontContextMenu = lambda *a: None
getMonospaceFont = lambda: QtGui.QFont()
from pymol.Qt import QtCore, QtWidgets, QtGui
from pymol.Qt.utils import connectFontContextMenu, getMonospaceFont


class TextEditor(QtWidgets.QMainWindow):

def sizeHint(self):
return QtCore.QSize(600, 400)

Expand Down Expand Up @@ -91,14 +85,14 @@ def doOpen(self, *args):
self._open(fnames[0])

def check_ask_save(self):
QMessageBox = QtWidgets.QMessageBox
SB = QtWidgets.QMessageBox.StandardButton
if self._get() != self._savedcontent:
ok = QMessageBox.question(None, "Save?", "Save changes?",
QMessageBox.Yes | QMessageBox.No |
QMessageBox.Cancel, QMessageBox.Yes)
if ok == QMessageBox.Yes:
SB.Yes | SB.No |
SB.Cancel, SB.Yes)
if ok == SB.Yes:
self.doSave()
elif ok == QMessageBox.Cancel:
elif ok == SB.Cancel:
return False
return True

Expand Down Expand Up @@ -176,7 +170,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
Expand Down
8 changes: 4 additions & 4 deletions modules/pmg_qt/advanced_settings_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -51,12 +51,12 @@ def populateData(self):

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]))
Expand Down Expand Up @@ -93,7 +93,7 @@ def itemChanged(self, item):
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)
2 changes: 1 addition & 1 deletion modules/pmg_qt/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ def __init__(self, form="B", double_helix=True):

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)
Expand Down
64 changes: 32 additions & 32 deletions modules/pmg_qt/keymapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,36 @@
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,
}


Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
23 changes: 13 additions & 10 deletions modules/pmg_qt/mimic_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,28 @@

class _qtMessageBox:
def __getattr__(self, name):
QMB = QtWidgets.QMessageBox
SB = QtWidgets.QMessageBox.StandardButton

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', SB.Yes, SB.No),
'askquestion': ('question', SB.Yes, SB.No),
'askokcancel': ('question', SB.Ok, SB.Cancel),
'askretrycancel': ('question', SB.Retry, SB.Cancel),
'showinfo': ('information', SB.Ok, SB.NoButton),
'showerror': ('critical', SB.Ok, SB.NoButton),
'showwarning': ('warning', SB.Ok, SB.NoButton),
}

try:
method, ok, others = variants[name]
except KeyError:
raise AttributeError(name)

return lambda title, message, **kw: ok == getattr(QMB, method)(
None, title, message, buttons=ok | others)
func = getattr(QtWidgets.QMessageBox, method)
def wrapper(title, message, **kw):
reply = func(None, title, message, buttons=ok | others)
return reply == ok
return wrapper


class _qtFileDialog:
Expand Down
8 changes: 4 additions & 4 deletions modules/pmg_qt/properties_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def __init__(self, parent):
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(Qt.ItemFlag.ItemIsEditable |
Qt.ItemFlag.ItemIsEnabled |
Qt.ItemFlag.ItemIsSelectable )
return item

def make_cat(self, parent, label):
Expand Down Expand Up @@ -280,7 +280,7 @@ def eventFilter(self, source, event):
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.key() == Qt.Key.Key_Delete):
self.unset_caller()
return 0
return super().eventFilter(source, event)
Expand Down
22 changes: 10 additions & 12 deletions modules/pmg_qt/pymol_gl_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

import pymol

from pymol.Qt import QtCore
from pymol.Qt import QtGui
from pymol.Qt import QtWidgets
Gesture = QtCore.QEvent.Gesture
from pymol.Qt import QtCore, QtGui, QtWidgets
Gesture = QtCore.QEvent.Type.Gesture
Qt = QtCore.Qt

from .keymapping import get_modifiers
Expand Down Expand Up @@ -43,9 +41,9 @@ class PyMOLGLWidget(BaseGLWidget):

# mouse button map
_buttonMap = {
Qt.LeftButton: 0,
Qt.MidButton: 1,
Qt.RightButton: 2,
Qt.MouseButton.LeftButton: 0,
Qt.MouseButton.MidButton: 1,
Qt.MouseButton.RightButton: 2,
}

def __enter__(self):
Expand Down Expand Up @@ -91,7 +89,7 @@ def __init__(self, parent):
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)

Expand All @@ -108,7 +106,7 @@ def __init__(self, parent):
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()
Expand All @@ -119,7 +117,7 @@ def __init__(self, parent):
self.setAcceptDrops(True)

# pinch-zoom
self.grabGesture(Qt.PinchGesture)
self.grabGesture(Qt.GestureType.PinchGesture)

def sizeHint(self):
# default 640 + internal_gui, 480 + internal_feedback
Expand All @@ -136,12 +134,12 @@ def event(self, ev):
return super(PyMOLGLWidget, self).event(ev)

def gestureEvent(self, ev):
gesture = ev.gesture(Qt.PinchGesture)
gesture = ev.gesture(Qt.GestureType.PinchGesture)

if gesture is None:
return False

if gesture.state() == Qt.GestureStarted:
if gesture.state() == Qt.GestureState.GestureStarted:
self.pinch_start_z = self.cmd.get_view()[11]

changeFlags = gesture.changeFlags()
Expand Down
Loading