Skip to content

Commit

Permalink
Merge pull request #1670 from willend/main
Browse files Browse the repository at this point in the history
Allow configuration of font size in mcgui (and to some degree in Scintilla)
  • Loading branch information
willend authored Aug 7, 2024
2 parents 4330b5e + d8b47c5 commit 7d06b93
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions tools/Python/mccodelib/mccode_config.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"PARTICLE": "@MCCODE_PARTICLE@",
"BROWSER": "@BROWSER@",
"GUICOLS": "3",
"GUIFONTSIZE": "12",
"EDITOR": "@EDITOR@",
"FORMAT": "McCode",
"ISCONDAPKG": "@MCCODE_IS_CONDA_PKG@"
Expand Down
17 changes: 16 additions & 1 deletion tools/Python/mcgui/mcgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
try:
from PyQt6 import QtWidgets, QtCore
from PyQt6.QtWidgets import QApplication, QWidget
from PyQt6.QtGui import QFont, QFontDatabase
import PyQt6 as PyQt
try:
from PyQt6 import Qsci
Expand All @@ -25,6 +26,7 @@
except ImportError:
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import QFont, QFontDatabase
import PyQt5 as PyQt
try:
from PyQt5 import Qsci
Expand Down Expand Up @@ -869,6 +871,11 @@ def handleSaveAs(self):
self.emitter.status("Instrument saved as: " + newinstr)

def handleNewInstrument(self):
if not self.state.getInstrumentFile() == '':
instrbase = pathlib.PurePath(self.state.getInstrumentFile())
wd = pathlib.PurePath(self.state.getWorkDir())
if wd.stem==instrbase.stem:
self.state.setWorkDir("..")
new_instr_req = self.view.showNewInstrDialog(self.state.getWorkDir())
if self.displayNotSavedWhitespaceError(lambda: self.state.checkInstrFileCandidate(new_instr_req))==False:
return
Expand All @@ -884,6 +891,11 @@ def handleNewInstrument(self):
self.emitter.status("Editing new instrument: " + os.path.basename(str(new_instr)))

def handleNewFromTemplate(self, instr_templ=''):
if not self.state.getInstrumentFile() == '':
instrbase = pathlib.PurePath(self.state.getInstrumentFile())
wd = pathlib.PurePath(self.state.getWorkDir())
if wd.stem==instrbase.stem:
self.state.setWorkDir("..")
new_instr_req = self.view.showNewInstrFromTemplateDialog(os.path.join(self.state.getWorkDir(), os.path.basename(os.path.dirname(str(instr_templ)))))
if self.displayNotSavedWhitespaceError(lambda: self.state.checkInstrFileCandidate(new_instr_req))==False:
return
Expand Down Expand Up @@ -1040,7 +1052,10 @@ def main():

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

font = QFont()
font.setFixedPitch(True)
font.setPointSize(int(mccode_config.configuration["GUIFONTSIZE"]))
mcguiApp.setFont(font)
sys.exit(mcguiApp.exec())

except Exception as e:
Expand Down
7 changes: 5 additions & 2 deletions tools/Python/mcgui/viewclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,8 @@ def __initScintilla(self):
# setup scintilla
# set default font
font = QtGui.QFont()
font.setFamily('DejaVu Sans Mono')
font.setFixedPitch(True)
font.setPointSize(11)
font.setPointSize(int(mccode_config.configuration["GUIFONTSIZE"]))

# brace matching
scintilla.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch)
Expand Down Expand Up @@ -1201,6 +1200,9 @@ def initConfigData(self, args):
self.ui.edtNumCols.setText(mccode_config.configuration["GUICOLS"])
self.ui.edtNumCols.conf_var = "GUICOLS"

self.ui.edtFontSize.setText(mccode_config.configuration["GUIFONTSIZE"])
self.ui.edtFontSize.conf_var = "GUIFONTSIZE"

self.ui.editor.setText(mccode_config.configuration["EDITOR"])
self.ui.editor.conf_var = "EDITOR"

Expand All @@ -1225,6 +1227,7 @@ def __pullValuesTo_mccode_config(self):
mccode_config.compilation[str(self.ui.edtMPIrun.conf_var)] = str(self.ui.edtMPIrun.text())
mccode_config.compilation[str(self.ui.edtNumNodes.conf_var)] = str(self.ui.edtNumNodes.text())
mccode_config.configuration[str(self.ui.edtNumCols.conf_var)] = str(self.ui.edtNumCols.text())
mccode_config.configuration[str(self.ui.edtFontSize.conf_var)] = str(self.ui.edtFontSize.text())
mccode_config.configuration[str(self.ui.editor.conf_var)] = str(self.ui.editor.text())
# Export selected variables to the system / mcrun
target_mccode=mccode_config.configuration["MCCODE"].upper()
Expand Down
11 changes: 9 additions & 2 deletions tools/Python/mcgui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,13 +916,19 @@ def setupUi(self, dlgConfig):
self.gridFlags.addWidget(self.lblNumocols, 12, 0, 1, 1)
self.edtNumCols = QtWidgets.QLineEdit(dlgConfig)
self.edtNumCols.setObjectName("edtNumCols")
self.lblFontSize = QtWidgets.QLabel(dlgConfig)
self.lblFontSize.setObjectName("lblFontSize")
self.gridFlags.addWidget(self.lblFontSize, 14, 0, 1, 1)
self.edtFontSize = QtWidgets.QLineEdit(dlgConfig)
self.edtFontSize.setObjectName("edtFontSize")
self.editor = QtWidgets.QLineEdit(dlgConfig)
self.editor.setObjectName("editor")
self.gridFlags.addWidget(self.edtNumCols, 13, 0, 1, 1)
self.gridFlags.addWidget(self.edtFontSize, 15, 0, 1, 1)
self.lbleditor = QtWidgets.QLabel(dlgConfig)
self.lbleditor.setObjectName("lbleditor")
self.gridFlags.addWidget(self.lbleditor, 14, 0, 1, 1)
self.gridFlags.addWidget(self.editor, 15, 0, 1, 1)
self.gridFlags.addWidget(self.lbleditor, 16, 0, 1, 1)
self.gridFlags.addWidget(self.editor, 17, 0, 1, 1)
self.verticalLayout.addLayout(self.gridFlags)
self.hlayoutButtons = QtWidgets.QHBoxLayout()
self.hlayoutButtons.setObjectName("hlayoutButtons")
Expand Down Expand Up @@ -968,6 +974,7 @@ def retranslateUi(self, dlgConfig):
self.lblNumnodes.setText(_translate("dlgConfig", "# nodes"))
self.lblMpicc.setText(_translate("dlgConfig", "MPIcc"))
self.lblNumocols.setText(_translate("dlgConfig", "# parameter columns in run dialogue"))
self.lblFontSize.setText(_translate("dlgConfig", "GUI fontsize"))
self.lbleditor.setText(_translate("dlgConfig", "Choice of external editor"))
self.btnOk.setToolTip(_translate("dlgConfig", "Keep for this session"))
self.btnOk.setText(_translate("dlgConfig", "Ok"))
Expand Down

0 comments on commit 7d06b93

Please sign in to comment.