diff --git a/CHANGELOG.md b/CHANGELOG.md index bb2ad8f0..e055882a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ CHANGELOG for FlatCAM beta - fixed some issues in the convert_units - added a new GUI element, a radio button that can change a setting in the self.defaults preferences dict - made sure that the update of the default properties tab (in the Notebook) is done only for certain keys in self.defaults not for all +- fixed the "headless" feature; running headless still start the GUI just it does not show it +- when running headless the sys tray icon will always be shown so the user can close the app correctly +- in the systray icon context menu I've added a menu entry to toggle the GUI 24.08.2021 diff --git a/appGUI/GUIElements.py b/appGUI/GUIElements.py index 3240f455..a9aa18d7 100644 --- a/appGUI/GUIElements.py +++ b/appGUI/GUIElements.py @@ -5149,6 +5149,7 @@ class FlatCAMSystemTray(QtWidgets.QSystemTrayIcon): menu = QtWidgets.QMenu(parent) + # Run Script menu_runscript = QtGui.QAction(QtGui.QIcon(self.app.resource_location + '/script14.png'), '%s' % _('Run Script ...'), self) menu_runscript.setToolTip( @@ -5158,6 +5159,14 @@ class FlatCAMSystemTray(QtWidgets.QSystemTrayIcon): ) menu.addAction(menu_runscript) + # Toggle GUI + menu_toggle_gui = QtGui.QAction(QtGui.QIcon(self.app.resource_location + '/grid_lines32.png'), + '%s' % _('Toggle GUI ...'), self) + menu_toggle_gui.setToolTip( + _("Will show/hide the GUI.") + ) + menu.addAction(menu_toggle_gui) + menu.addSeparator() if headless is None: @@ -5195,6 +5204,8 @@ class FlatCAMSystemTray(QtWidgets.QSystemTrayIcon): exitAction.setIcon(QtGui.QIcon(self.app.resource_location + '/power16.png')) self.setContextMenu(menu) + menu_toggle_gui.triggered.connect(self.app.ui.on_toggle_gui) + menu_runscript.triggered.connect(lambda: self.app.on_filerunscript( silent=True if self.app.cmd_line_headless == 1 else False)) diff --git a/appGUI/MainGUI.py b/appGUI/MainGUI.py index caac3b8d..a14e8522 100644 --- a/appGUI/MainGUI.py +++ b/appGUI/MainGUI.py @@ -2017,6 +2017,20 @@ class MainGUI(QtWidgets.QMainWindow): self.app.version, ('BETA' if self.app.beta else ''), platform.architecture()[0], self.app.engine, name) self.setWindowTitle(title) + def on_toggle_gui(self): + if self.isHidden(): + mgui_settings = QSettings("Open Source", "FlatCAM") + if mgui_settings.contains("maximized_gui"): + maximized_ui = mgui_settings.value('maximized_gui', type=bool) + if maximized_ui is True: + self.showMaximized() + else: + self.show() + else: + self.show() + else: + self.hide() + def save_geometry(self, x, y, width, height, notebook_width): """ Will save the application geometry and positions in the defaults dicitionary to be restored at the next diff --git a/app_Main.py b/app_Main.py index 1f34bd9a..61f8326c 100644 --- a/app_Main.py +++ b/app_Main.py @@ -492,8 +492,6 @@ class App(QtCore.QObject): if param[0] == 'headless': if param[2].lower() == 'true': self.cmd_line_headless = 1 - else: - self.cmd_line_headless = None except Exception as e: self.log.error('App.__init__() -->%s' % str(e)) return @@ -1352,16 +1350,16 @@ class App(QtCore.QObject): # ########################################################################################################### # ############################################### SYS TRAY ################################################## # ########################################################################################################### - if self.defaults["global_systray_icon"]: - self.parent_w = QtWidgets.QWidget() - - if self.cmd_line_headless == 1: - self.trayIcon = FlatCAMSystemTray(app=self, - icon=QtGui.QIcon(self.resource_location + - '/flatcam_icon32_green.png'), - headless=True, - parent=self.parent_w) - else: + self.parent_w = QtWidgets.QWidget() + if self.cmd_line_headless == 1: + # if running headless always have the systray to be able to quit the app correctly + self.trayIcon = FlatCAMSystemTray(app=self, + icon=QtGui.QIcon(self.resource_location + + '/flatcam_icon32_green.png'), + headless=True, + parent=self.parent_w) + else: + if self.defaults["global_systray_icon"]: self.trayIcon = FlatCAMSystemTray(app=self, icon=QtGui.QIcon(self.resource_location + '/flatcam_icon32_green.png'), @@ -1576,6 +1574,10 @@ class App(QtCore.QObject): if self.defaults["global_systray_icon"]: self.trayIcon.show() else: + try: + self.trayIcon.show() + except Exception as err: + self.log.error("App.__init__() Running headless and trying to show the systray got: %s" % str(err)) self.log.warning("******************* RUNNING HEADLESS *******************") # ###########################################################################################################