2014-06-13 19:21:11 +00:00
|
|
|
from PyQt4 import QtCore
|
2015-09-11 18:45:08 +00:00
|
|
|
#import FlatCAMApp
|
2014-03-28 22:18:18 +00:00
|
|
|
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
class Worker(QtCore.QObject):
|
2014-03-28 22:18:18 +00:00
|
|
|
"""
|
|
|
|
Implements a queue of tasks to be carried out in order
|
|
|
|
in a single independent thread.
|
|
|
|
"""
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
def __init__(self, app, name=None):
|
2014-03-28 22:18:18 +00:00
|
|
|
super(Worker, self).__init__()
|
2014-06-13 19:21:11 +00:00
|
|
|
self.app = app
|
|
|
|
self.name = name
|
2014-03-28 22:18:18 +00:00
|
|
|
|
|
|
|
def run(self):
|
2015-09-11 18:45:08 +00:00
|
|
|
# FlatCAMApp.App.log.debug("Worker Started!")
|
|
|
|
self.app.log.debug("Worker Started!")
|
2014-10-28 21:39:38 +00:00
|
|
|
|
|
|
|
# Tasks are queued in the event listener.
|
2014-06-13 19:21:11 +00:00
|
|
|
self.app.worker_task.connect(self.do_worker_task)
|
|
|
|
|
|
|
|
def do_worker_task(self, task):
|
2015-09-11 18:45:08 +00:00
|
|
|
# FlatCAMApp.App.log.debug("Running task: %s" % str(task))
|
|
|
|
self.app.log.debug("Running task: %s" % str(task))
|
2014-10-28 21:39:38 +00:00
|
|
|
|
|
|
|
# 'worker_name' property of task allows to target
|
|
|
|
# specific worker.
|
2014-06-13 19:21:11 +00:00
|
|
|
if 'worker_name' in task and task['worker_name'] == self.name:
|
|
|
|
task['fcn'](*task['params'])
|
|
|
|
return
|
|
|
|
|
|
|
|
if 'worker_name' not in task and self.name is None:
|
|
|
|
task['fcn'](*task['params'])
|
2015-02-13 19:37:54 +00:00
|
|
|
return
|
|
|
|
|
2015-09-11 18:45:08 +00:00
|
|
|
# FlatCAMApp.App.log.debug("Task ignored.")
|
|
|
|
self.app.log.debug("Task ignored.")
|