Skip to content

Commit

Permalink
Update InitGui.py
Browse files Browse the repository at this point in the history
Added save settings to disk when you close the preferences window
  • Loading branch information
Grubuntu committed Mar 14, 2024
1 parent a2eb567 commit c89939d
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions InitGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
# http://forum.freecadweb.org/
# http://www.freecadweb.org/wiki/index.php?title=Code_snippets

# global shortcut toggle
# workbench dependant
# piemenu without opened file
# modify Pie shape with command name
# shapes "concentric" and "star
# triggermode for each PieMenu
# clean some code
# add ability to add separators in PieMenus
# in progress : save settings to disk when you close the preferences window

global PIE_MENU_VERSION
PIE_MENU_VERSION = "1.4"
Expand All @@ -52,7 +43,7 @@ def pieMenuStart():
from PySide2.QtGui import QKeyEvent, QFontMetrics
from PySide.QtWidgets import QApplication, QLineEdit, QWidget, QAction, \
QPushButton, QLabel, QVBoxLayout, QHBoxLayout, QDoubleSpinBox, QCheckBox, \
QMessageBox, QShortcut, QListWidgetItem, QListWidget, QComboBox
QMessageBox, QShortcut, QListWidgetItem, QListWidget, QComboBox, QDialog
from PySide2.QtGui import QKeySequence
from PySide2.QtCore import Qt
from TranslateUtils import translate
Expand Down Expand Up @@ -980,8 +971,8 @@ def add_commands(self, commands, context=False, keyValue=None):
# layout for icon and command string
layout = QtGui.QHBoxLayout(button)
layout.setContentsMargins((icon/4), 0, 0, 0)
if (commands[commands.index(i)].text()) == "Separator":

if (commands[commands.index(i)].text()) == translate('PieMenuTab', 'Separator'):
iconButton = QtGui.QIcon(iconSeparator)
else:
iconButton = QtGui.QIcon(commands[commands.index(i)].icon())
Expand Down Expand Up @@ -1137,7 +1128,7 @@ def add_commands(self, commands, context=False, keyValue=None):
layout.addStretch(1)
iconMarging = "#iconLabel {margin-right: " + str(icon/4) + "px;}"

if (commands[commands.index(i)].text()) == "Separator":
if (commands[commands.index(i)].text()) == translate('PieMenuTab', 'Separator'):
iconButton = QtGui.QIcon(iconSeparator)
else:
iconButton = QtGui.QIcon(commands[commands.index(i)].icon())
Expand Down Expand Up @@ -1182,8 +1173,8 @@ def add_commands(self, commands, context=False, keyValue=None):
(math.cos(angle * num + angleStart)))
button.setProperty("ButtonY", self.radius *
(math.sin(angle * num + angleStart)))
if (commands[commands.index(i)].text()) == "Separator":

if (commands[commands.index(i)].text()) == translate('PieMenuTab', 'Separator'):
button.setObjectName("styleSeparator")
button.setIcon(QtGui.QIcon(iconSeparator))

Expand Down Expand Up @@ -3589,6 +3580,25 @@ def setDefaultPie(restore=False):
App.saveParameter()


class PieMenuDialog(QDialog):
mw = Gui.getMainWindow()
""" Class to handle PieMenuDialog events """
def __init__(self, parent=None):

super(PieMenuDialog, self).__init__(parent)
# Connect close event

self.resize(800, 450)
self.setObjectName("PieMenuPreferences")
self.setWindowTitle("PieMenu " + PIE_MENU_VERSION)
self.closeEvent = self.customCloseEvent

def customCloseEvent(self, event):
# Caught close event to save parameters on disk
App.saveParameter()
super(PieMenuDialog, self).closeEvent(event)


def onControl():
"""Initializes the preferences dialog."""
shape = getShape(cBox.currentText())
Expand Down Expand Up @@ -3798,11 +3808,6 @@ def updateShortcutKey(newShortcut):
layoutHoverDelay.addLayout(layoutHoverDelayLeft, 1)
layoutHoverDelay.addLayout(layoutHoverDelayRight, 1)


def close_dialog():
App.saveParameter()
pieMenuDialog.accept()

def updateGlobalShortcutKey(newShortcut):
global globalShortcutKey
touches_speciales = {'CTRL', 'ALT', 'SHIFT', 'META', 'TAB'}
Expand Down Expand Up @@ -3831,7 +3836,6 @@ def updateGlobalShortcutKey(newShortcut):

getGlobalShortcutKey()


labelGlobalShortcut.setText(translate("GlobalSettingsTab",\
"Global shortcut : ") + globalShortcutKey)
layoutGlobalShortcut = QtGui.QHBoxLayout()
Expand Down Expand Up @@ -3945,13 +3949,12 @@ def updateGlobalShortcutKey(newShortcut):
preferencesWidget.setLayout(preferencesLayout)
preferencesLayout.addWidget(vSplitter)

pieMenuDialog = QtGui.QDialog(mw)
pieMenuDialog.resize(800, 450)
pieMenuDialog.setObjectName("PieMenuPreferences")
pieMenuDialog.setWindowTitle("PieMenu " + PIE_MENU_VERSION)
pieMenuDialog = PieMenuDialog()

pieMenuDialogLayout = QtGui.QVBoxLayout()
pieMenuDialog.setLayout(pieMenuDialogLayout)
pieMenuDialog.show()

def infoPopup():
msg = """
<h2>Pie menu</h2>
Expand Down Expand Up @@ -3979,7 +3982,7 @@ def infoPopup():
close_button = QtGui.QPushButton(translate("MainWindow", "Close"), \
pieMenuDialog)
close_button.setMaximumWidth(120)
close_button.clicked.connect(close_dialog)
close_button.clicked.connect(pieMenuDialog.close)

# Create a horizontal layout for the buttons
button_row_layout = QtGui.QHBoxLayout()
Expand All @@ -3993,7 +3996,6 @@ def infoPopup():

button_layout.addLayout(button_row_layout)


pieMenuDialogLayout.addWidget(preferencesWidget)
pieMenuDialogLayout.addLayout(button_layout)

Expand All @@ -4002,13 +4004,12 @@ def infoPopup():

class PieMenuSeparator:
"""Class PieMenuSeparator"""

def __init__(self):
pass

def GetResources(self):
"""Return a dictionary with data that will be used by the button or menu item."""
return {'Pixmap' : iconAddSeparator, 'MenuText': 'Separator', 'ToolTip': 'Separator for PieMenu '}
return {'Pixmap' : iconAddSeparator, 'MenuText': translate('PieMenuTab', 'Separator'), 'ToolTip': translate('PieMenuTab', 'Separator for PieMenu ')}

def Activated(self):
"""Run the following code when the command is activated (button press)."""
Expand Down

0 comments on commit c89939d

Please sign in to comment.