comparison frontends/src/jp/base.py @ 1862:6d9c87bdc452

jp (base): added a CommandBase.start method which is called by run or connected, so subclasses can implement it (this is for simplicity sake, as it's not always clear if run or connected must be used)
author Goffi <goffi@goffi.org>
date Mon, 29 Feb 2016 16:52:51 +0100
parents afc7f6328394
children b2ddd7f5dcdf
comparison
equal deleted inserted replaced
1861:3b2a236fa743 1862:6d9c87bdc452
581 # now we add subcommands to ourself 581 # now we add subcommands to ourself
582 for cls in subcommands: 582 for cls in subcommands:
583 cls(self) 583 cls(self)
584 584
585 def run(self): 585 def run(self):
586 if self.need_connect is not None: 586 """this method is called when a command is actually run
587 self.host.connect_profile(self.connected) 587
588 588 It set stuff like progression callbacks and profile connection
589 You should not overide this method: you should call self.start instead
590 """
589 try: 591 try:
590 show_progress = self.args.progress 592 show_progress = self.args.progress
591 except AttributeError: 593 except AttributeError:
592 # the command doesn't use progress bar 594 # the command doesn't use progress bar
593 pass 595 pass
597 # we need to register the following signal even if we don't display the progress bar 599 # we need to register the following signal even if we don't display the progress bar
598 self.host.bridge.register("progressStarted", self.progressStartedHandler) 600 self.host.bridge.register("progressStarted", self.progressStartedHandler)
599 self.host.bridge.register("progressFinished", self.progressFinishedHandler) 601 self.host.bridge.register("progressFinished", self.progressFinishedHandler)
600 self.host.bridge.register("progressError", self.progressErrorHandler) 602 self.host.bridge.register("progressError", self.progressErrorHandler)
601 603
604 if self.need_connect is not None:
605 self.host.connect_profile(self.connected)
606 else:
607 self.start()
608
602 def connected(self): 609 def connected(self):
610 """this method is called when profile is connected (or session is started)
611
612 this method is only called when use_profile is True
613 most of time you should override self.start instead of this method, but if loop
614 if not always needed depending on your arguments, you may override this method,
615 but don't forget to call the parent one (i.e. this one) after self.need_loop is set
616 """
603 if not self.need_loop: 617 if not self.need_loop:
604 self.host.stop_loop() 618 self.host.stop_loop()
619 self.start()
620
621 def start(self):
622 """This is the starting point of the command, this method should be overriden
623
624 at this point, profile are connected if needed
625 """
626 pass
605 627
606 628
607 class CommandAnswering(CommandBase): 629 class CommandAnswering(CommandBase):
608 """Specialised commands which answer to specific actions 630 """Specialised commands which answer to specific actions
609 631