Просмотр исходного кода

Merged jpcgt/flatcam into master

Kamil Sopko 9 лет назад
Родитель
Сommit
ec60f9ecf3
1 измененных файлов с 69 добавлено и 0 удалено
  1. 69 0
      FlatCAMApp.py

+ 69 - 0
FlatCAMApp.py

@@ -2044,6 +2044,71 @@ class App(QtCore.QObject):
 
 
             return a, kwa
             return a, kwa
 
 
+        from contextlib import contextmanager
+        @contextmanager
+        def wait_signal(signal, timeout=10000):
+            """Block loop until signal emitted, or timeout (ms) elapses."""
+            loop = QtCore.QEventLoop()
+            signal.connect(loop.quit)
+
+            status = {'timed_out': False}
+
+            def report_quit():
+                status['timed_out'] = True
+                loop.quit()
+
+            yield
+
+            if timeout is not None:
+                QtCore.QTimer.singleShot(timeout, report_quit)
+
+            loop.exec_()
+
+            if status['timed_out']:
+                raise Exception('Timed out!')
+
+        def wait_signal2(signal, timeout=10000):
+            """Block loop until signal emitted, or timeout (ms) elapses."""
+            loop = QtCore.QEventLoop()
+            signal.connect(loop.quit)
+            status = {'timed_out': False}
+
+            def report_quit():
+                status['timed_out'] = True
+                loop.quit()
+
+            if timeout is not None:
+                QtCore.QTimer.singleShot(timeout, report_quit)
+            loop.exec_()
+
+            if status['timed_out']:
+                raise Exception('Timed out!')
+
+        def mytest(*args):
+            to = int(args[0])
+
+            try:
+                for rec in self.recent:
+                    if rec['kind'] == 'gerber':
+                        self.open_gerber(str(rec['filename']))
+                        break
+
+                basename = self.collection.get_names()[0]
+                isolate(basename, '-passes', '10', '-combine', '1')
+                iso = self.collection.get_by_name(basename + "_iso")
+
+                with wait_signal(self.new_object_available, to):
+                    iso.generatecncjob()
+                # iso.generatecncjob()
+                # wait_signal2(self.new_object_available, to)
+
+                return str(self.collection.get_names())
+
+            except Exception as e:
+                return str(e)
+
+            return str(self.collection.get_names())
+
         def import_svg(filename, *args):
         def import_svg(filename, *args):
             a, kwa = h(*args)
             a, kwa = h(*args)
             types = {'outname': str}
             types = {'outname': str}
@@ -3146,6 +3211,10 @@ class App(QtCore.QObject):
         '''
         '''
 
 
         commands = {
         commands = {
+            'mytest': {
+                'fcn': mytest,
+                'help': "Test function. Only for testing."
+            },
             'help': {
             'help': {
                 'fcn': shelp,
                 'fcn': shelp,
                 'help': "Shows list of commands."
                 'help': "Shows list of commands."