Browse Source

- projects at startup don't work in another thread so there is no multithreading if I want to double click an project and to load it

Marius Stanciu 6 years ago
parent
commit
2720bc34b7
2 changed files with 39 additions and 25 deletions
  1. 38 25
      FlatCAMApp.py
  2. 1 0
      README.md

+ 38 - 25
FlatCAMApp.py

@@ -183,6 +183,9 @@ class App(QtCore.QObject):
     # in the worker task.
     # in the worker task.
     thread_exception = QtCore.pyqtSignal(object)
     thread_exception = QtCore.pyqtSignal(object)
 
 
+    # used to signal that there are arguments for the app
+    args_at_startup = QtCore.pyqtSignal()
+
     def __init__(self, user_defaults=True, post_gui=None):
     def __init__(self, user_defaults=True, post_gui=None):
         """
         """
         Starts the application.
         Starts the application.
@@ -1682,6 +1685,9 @@ class App(QtCore.QObject):
         self.ui.excellon_options_form.excellon_opt_group.excellon_defaults_button.clicked.connect(
         self.ui.excellon_options_form.excellon_opt_group.excellon_defaults_button.clicked.connect(
             self.on_excellon_options_button)
             self.on_excellon_options_button)
 
 
+        # when there are arguments at application startup this get launched
+        self.args_at_startup.connect(self.on_startup_args)
+
         # this is a flag to signal to other tools that the ui tooltab is locked and not accessible
         # this is a flag to signal to other tools that the ui tooltab is locked and not accessible
         self.tool_tab_locked = False
         self.tool_tab_locked = False
 
 
@@ -2113,8 +2119,31 @@ class App(QtCore.QObject):
 
 
         App.log.debug("END of constructor. Releasing control.")
         App.log.debug("END of constructor. Releasing control.")
 
 
-        # accept a project file as command line parameter
+        # accept some type file as command line parameter: FlatCAM project, FlatCAM preferences or scripts
         # the path/file_name must be enclosed in quotes if it contain spaces
         # the path/file_name must be enclosed in quotes if it contain spaces
+        if App.args:
+            self.args_at_startup.emit()
+
+
+    @staticmethod
+    def copy_and_overwrite(from_path, to_path):
+        """
+        From here:
+        https://stackoverflow.com/questions/12683834/how-to-copy-directory-recursively-in-python-and-overwrite-all
+        :param from_path: source path
+        :param to_path: destination path
+        :return: None
+        """
+        if os.path.exists(to_path):
+            shutil.rmtree(to_path)
+        try:
+            shutil.copytree(from_path, to_path)
+        except FileNotFoundError:
+            from_new_path = os.path.dirname(os.path.realpath(__file__)) + '\\flatcamGUI\\VisPyData\\data'
+            shutil.copytree(from_new_path, to_path)
+
+    def on_startup_args(self):
+        log.debug("Application was started with an argument. Processing ...")
         for argument in App.args:
         for argument in App.args:
             if '.FlatPrj' in argument:
             if '.FlatPrj' in argument:
                 try:
                 try:
@@ -2125,12 +2154,13 @@ class App(QtCore.QObject):
                     else:
                     else:
                         # self.open_project(project_name)
                         # self.open_project(project_name)
                         run_from_arg = True
                         run_from_arg = True
-                        self.worker_task.emit({'fcn': self.open_project,
-                                               'params': [project_name, run_from_arg]})
+                        # self.worker_task.emit({'fcn': self.open_project,
+                        #                        'params': [project_name, run_from_arg]})
+                        self.open_project(filename=project_name, run_from_arg=run_from_arg)
                 except Exception as e:
                 except Exception as e:
                     log.debug("Could not open FlatCAM project file as App parameter due: %s" % str(e))
                     log.debug("Could not open FlatCAM project file as App parameter due: %s" % str(e))
 
 
-            if '.FlatConfig' in argument:
+            elif '.FlatConfig' in argument:
                 try:
                 try:
                     file_name = str(argument)
                     file_name = str(argument)
 
 
@@ -2144,7 +2174,7 @@ class App(QtCore.QObject):
                 except Exception as e:
                 except Exception as e:
                     log.debug("Could not open FlatCAM Config file as App parameter due: %s" % str(e))
                     log.debug("Could not open FlatCAM Config file as App parameter due: %s" % str(e))
 
 
-            if '.FlatScript' in argument:
+            elif '.FlatScript' in argument:
                 try:
                 try:
                     file_name = str(argument)
                     file_name = str(argument)
 
 
@@ -2158,23 +2188,6 @@ class App(QtCore.QObject):
                 except Exception as e:
                 except Exception as e:
                     log.debug("Could not open FlatCAM Script file as App parameter due: %s" % str(e))
                     log.debug("Could not open FlatCAM Script file as App parameter due: %s" % str(e))
 
 
-    @staticmethod
-    def copy_and_overwrite(from_path, to_path):
-        """
-        From here:
-        https://stackoverflow.com/questions/12683834/how-to-copy-directory-recursively-in-python-and-overwrite-all
-        :param from_path: source path
-        :param to_path: destination path
-        :return: None
-        """
-        if os.path.exists(to_path):
-            shutil.rmtree(to_path)
-        try:
-            shutil.copytree(from_path, to_path)
-        except FileNotFoundError:
-            from_new_path = os.path.dirname(os.path.realpath(__file__)) + '\\flatcamGUI\\VisPyData\\data'
-            shutil.copytree(from_new_path, to_path)
-
     def set_ui_title(self, name):
     def set_ui_title(self, name):
         self.ui.setWindowTitle('FlatCAM %s %s - %s    %s' %
         self.ui.setWindowTitle('FlatCAM %s %s - %s    %s' %
                                (self.version,
                                (self.version,
@@ -8293,7 +8306,7 @@ class App(QtCore.QObject):
         self.set_screen_units(self.options["units"])
         self.set_screen_units(self.options["units"])
 
 
         # Re create objects
         # Re create objects
-        App.log.debug("Started Project loading...")
+        App.log.debug(" **************** Started PROEJCT loading... **************** ")
 
 
         for obj in d['objs']:
         for obj in d['objs']:
             def obj_init(obj_inst, app_inst):
             def obj_init(obj_inst, app_inst):
@@ -8302,14 +8315,14 @@ class App(QtCore.QObject):
                           (obj['kind'].capitalize(), obj['options']['name']))
                           (obj['kind'].capitalize(), obj['options']['name']))
             self.new_object(obj['kind'], obj['options']['name'], obj_init, active=False, fit=False, plot=True)
             self.new_object(obj['kind'], obj['options']['name'], obj_init, active=False, fit=False, plot=True)
 
 
-        self.plot_all()
+        # self.plot_all()
         self.inform.emit(_("[success] Project loaded from: %s") % filename)
         self.inform.emit(_("[success] Project loaded from: %s") % filename)
 
 
         self.should_we_save = False
         self.should_we_save = False
         self.file_opened.emit("project", filename)
         self.file_opened.emit("project", filename)
         self.set_ui_title(name=self.project_filename)
         self.set_ui_title(name=self.project_filename)
 
 
-        App.log.debug("Finished Project loading...")
+        App.log.debug(" **************** Finished PROJECT loading... **************** ")
 
 
     def propagate_defaults(self, silent=False):
     def propagate_defaults(self, silent=False):
         """
         """

+ 1 - 0
README.md

@@ -12,6 +12,7 @@ CAD program, and create G-Code for Isolation routing.
 18.08.2019
 18.08.2019
 
 
 - made the exported preferences formatted therefore more easily read
 - made the exported preferences formatted therefore more easily read
+- projects at startup don't work in another thread so there is no multithreading if I want to double click an project and to load it
 
 
 17.08.2019
 17.08.2019