kete: clean up a little bit the Worker class

The Worker subclasses now only need to implement run() and stop().
pull/61/head
Benjamin Tissoires 2018-01-31 15:56:49 +01:00
parent e4b0f9768d
commit c2ceba7483
1 changed files with 2 additions and 19 deletions

View File

@ -337,16 +337,10 @@ class TuhiKeteManager(_DBusObject):
class Worker(GObject.Object): class Worker(GObject.Object):
'''Implements a command to be executed. '''Implements a command to be executed.
Subclasses need to overwrite run() that will be executed Subclasses need to overwrite run() that will be executed
to setup the command (before the mainloop). while calling the command.
Subclass can also implement the stop() method which Subclass can also implement the stop() method which
will be executed to terminate the command, once the will be executed to terminate the command, once the
mainloop has finished. mainloop has finished.'''
The variable need_mainloop needs to be set from the
subclass if the command requires the mainloop to be
run from an undetermined amount of time.'''
need_mainloop = False
def __init__(self, manager, args=None): def __init__(self, manager, args=None):
GObject.GObject.__init__(self) GObject.GObject.__init__(self)
@ -358,17 +352,8 @@ class Worker(GObject.Object):
def stop(self): def stop(self):
pass pass
def start(self):
self.run()
if self.need_mainloop:
self.manager.run()
self.stop()
class Searcher(Worker): class Searcher(Worker):
need_mainloop = True
interactive = True interactive = True
def __init__(self, manager, args): def __init__(self, manager, args):
@ -430,8 +415,6 @@ class Searcher(Worker):
class Listener(Worker): class Listener(Worker):
need_mainloop = True
def __init__(self, manager, args): def __init__(self, manager, args):
super(Listener, self).__init__(manager) super(Listener, self).__init__(manager)