Skip to content

Commit

Permalink
Merge pull request #1562 from willend/main
Browse files Browse the repository at this point in the history
Port mc/xgui go PyQt6 (seems OK for PyQt5 but needs checks->PR)
  • Loading branch information
farhi authored Feb 9, 2024
2 parents b3f902e + 7709f28 commit eecfd13
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 99 deletions.
22 changes: 15 additions & 7 deletions tools/Python/mcgui/mcgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@
import re
import pathlib
import shutil
from PyQt5 import QtCore, QtWidgets
import PyQt5
try:
from PyQt5 import Qsci
from PyQt6 import QtWidgets, QtCore
from PyQt6.QtWidgets import QApplication, QWidget
import PyQt6 as PyQt

except ImportError:
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtWidgets import QApplication, QWidget
import PyQt5 as PyQt

try:
from PyQt import Qsci
except ImportError:
Qsci = None

Expand Down Expand Up @@ -221,7 +229,7 @@ def compile(self, mpi=False):
self.__cFile = ''

# that wait cursor
QtWidgets.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
QtWidgets.QApplication.setOverrideCursor(QtCore.Qt.CursorShape.WaitCursor)
def compile_complete():
self.__emitter.message('compile thread done\n')
QtWidgets.QApplication.restoreOverrideCursor()
Expand Down Expand Up @@ -571,7 +579,7 @@ def handleRunOrInterruptSim(self):
self.view.ew.save()

self.emitter.status("Getting instrument params...")
QtWidgets.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
QtWidgets.QApplication.setOverrideCursor(QtCore.Qt.CursorShape.WaitCursor)
self.view.disableRunBtn()
try:
class ThreadInfoHandler():
Expand Down Expand Up @@ -969,10 +977,10 @@ def main():
mccode_config.load_config("user")
mccode_config.check_env_vars()

mcguiApp = PyQt5.QtWidgets.QApplication(sys.argv)
mcguiApp = QtWidgets.QApplication(sys.argv)
mcguiApp.ctr = McGuiAppController()

sys.exit(mcguiApp.exec_())
sys.exit(mcguiApp.exec())

except Exception as e:
print(e)
Expand Down
43 changes: 27 additions & 16 deletions tools/Python/mcgui/viewclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@
import re
import pathlib
from widgets import *
from PyQt5 import QtWidgets

try:
from PyQt5 import Qsci
from PyQt6 import QtGui, QtWidgets, QtCore
from PyQt6.QtWidgets import QApplication, QWidget
from PyQt6.QtGui import QAction
import PyQt6 as PyQt

except ImportError:
from PyQt5 import QtGui, QtWidgets, QtCore
from PyQt5.QtWidgets import QApplication, QWidget, QAction
from PyQt5.QtWidgets import QAction
import PyQt5 as PyQt

try:
from PyQt import Qsci
except ImportError:
Qsci = None

Expand Down Expand Up @@ -45,7 +56,7 @@ def showErrorDialogue(self, title, message):
msg.setIcon(QtWidgets.QMessageBox.Critical)
msg.setWindowTitle(title)
msg.setText(message)
msg.exec_()
msg.exec()

def showCodeEditorWindow(self, instr):
self.ew.initCodeEditor(instr)
Expand Down Expand Up @@ -144,7 +155,7 @@ def showOpenInstrumentDlg(self, lookDir):

dlg.setNameFilters([mccode_config.configuration["MCCODE"]+" instruments (*.instr)", "All files (*)"]);
dlg.selectNameFilter(mccode_config.configuration["MCCODE"]+" instruments (*.instr)")
if dlg.exec_():
if dlg.exec():
return dlg.selectedFiles()[0]

def showOpenPlotDirDlg(self, lookDir):
Expand All @@ -157,7 +168,7 @@ def showChangeWorkDirDlg(self, lookDir):
dlg = QtWidgets.QFileDialog()
dlg.setFileMode(QtWidgets.QFileDialog.Directory)
dlg.setDirectory(lookDir)
if dlg.exec_():
if dlg.exec():
return dlg.selectedFiles()[0]

def showStartSimDialog(self, params, comps, mcdisplays, mcplots, formats):
Expand All @@ -168,7 +179,7 @@ def showStartSimDialog(self, params, comps, mcdisplays, mcplots, formats):
self.__ssd.set_mcdisplays(mcdisplays)
self.__ssd.set_mcplots(mcplots)
self.__ssd.set_formats(formats)
if self.__ssd.exec_():
if self.__ssd.exec():
return self.__ssd.getValues()
else:
return None, None, None, None, None, None
Expand All @@ -191,7 +202,7 @@ def showSaveAsDialog(self, instr):
def showConfigDialog(self):
dlg = McConfigDialog()
dlg.initConfigData(None)
dlg.exec_()
dlg.exec()

def showAboutBox(self, text):
if mccode_config.configuration["MCCODE"] == "mcstas":
Expand Down Expand Up @@ -256,10 +267,10 @@ def handle(self):
action.triggered.connect(h.handle)

def add_conf_menu(self,label):
confmenu = QtWidgets.QAction(self)
confmenu = QAction(self)
self.ui.menuFile.addAction(confmenu)
confmenu.setText(QtWidgets.QApplication.translate("MainWindow", label, None))
confmenu.setToolTip(QtWidgets.QApplication.translate("MainWindow", "mccode " + label, None))
confmenu.setText(QApplication.translate("MainWindow", label, None))
confmenu.setToolTip(QApplication.translate("MainWindow", "mccode " + label, None))
return confmenu

def closeEvent(self, event):
Expand All @@ -280,7 +291,7 @@ def __init__(self, parent=None):
self.ui = Ui_EditorWindow()
self.ui.setupUi(self)

sheight = QtWidgets.QDesktopWidget().availableGeometry().height()
sheight = QtGui.QGuiApplication.primaryScreen().availableGeometry().height()
if sheight < 1080:
self.resize(920, sheight)

Expand Down Expand Up @@ -447,7 +458,7 @@ def closeEvent(self, event):
def __handleComponentClicked(self, comp_parser):
dlg = McInsertComponentDialog()
dlg.initComponentData(comp_parser)
if dlg.exec_():
if dlg.exec():
comp_type, inst_name, params, atrel = dlg.getValues()
else:
return
Expand Down Expand Up @@ -599,7 +610,7 @@ def __handleComponentBrowser(self):
dlg = QtWidgets.QFileDialog()
dlg.setDirectory(mccode_config.configuration["MCCODE_LIB_DIR"])
dlg.setNameFilter(mccode_config.configuration["MCCODE"]+"component files (*.comp)");
if dlg.exec_():
if dlg.exec():
comp_file = dlg.selectedFiles()[0]
parser = ComponentParser(comp_file)
self.__handleComponentClicked(parser)
Expand Down Expand Up @@ -842,7 +853,7 @@ def createParamsWidgets(self, params):
y = i // (int(mccode_config.configuration["GUICOLS"])*2)

lbl = QtWidgets.QLabel(self.ui.gbxGrid)
lbl.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
lbl.setAlignment(QtCore.Qt.AlignmentFlag.AlignRight|QtCore.Qt.AlignmentFlag.AlignTrailing|QtCore.Qt.AlignmentFlag.AlignVCenter)
lbl.setObjectName("lbl" + name)
lbl.setText(name + ':')
self.ui.gridGrid.addWidget(lbl, y, x, 1, 1)
Expand All @@ -851,7 +862,7 @@ def createParamsWidgets(self, params):
x = i % (int(mccode_config.configuration["GUICOLS"])*2)

edt = QtWidgets.QLineEdit(self.ui.gbxGrid)
edt.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
edt.setAlignment(QtCore.Qt.AlignmentFlag.AlignRight|QtCore.Qt.AlignmentFlag.AlignTrailing|QtCore.Qt.AlignmentFlag.AlignVCenter)
edt.setObjectName("edt" + name)
edt.setText(value)
self.ui.gridGrid.addWidget(edt, y, x, 1, 1)
Expand Down Expand Up @@ -961,7 +972,7 @@ def initComponentData(self, comp_parser):
# parameter value line-edit
x = 1
edt = QtWidgets.QLineEdit()
edt.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
edt.setAlignment(QtCore.Qt.AlignmentFlag.AlignRight|QtCore.Qt.AlignmentFlag.AlignTrailing|QtCore.Qt.AlignmentFlag.AlignVCenter)
edt.setObjectName("edt" + par.par_name)
edt.defval = par.default_value
self._initTbwFocusEvents(edt)
Expand Down
Loading

0 comments on commit eecfd13

Please sign in to comment.