Added basic replacement for audioRecorder based in MVP+interactor

This commit is contained in:
2019-01-04 17:32:17 -06:00
parent 9d2fc5bc6e
commit 2804400910
6 changed files with 179 additions and 2 deletions

View File

@@ -0,0 +1 @@
from . audioRecorder import *

View File

@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import widgetUtils
from pubsub import pub
from . import base
class audioRecorderInteractor(base.baseInteractor):
def install(self, presenter, view, modulename="audiorecorder"):
super(audioRecorderInteractor, self).install(view=view, presenter=presenter, modulename=modulename)
widgetUtils.connect_event(view.play, widgetUtils.BUTTON_PRESSED, self.on_play)
widgetUtils.connect_event(view.record, widgetUtils.BUTTON_PRESSED, self.on_record)
widgetUtils.connect_event(view.discard, widgetUtils.BUTTON_PRESSED, self.on_discard)
def start(self):
result = self.view.get_response()
if result == widgetUtils.OK:
self.on_postprocess()
def on_record(self, *args, **kwargs):
self.presenter.toggle_recording()
def on_discard(self, *args, **kwargs):
self.presenter.discard_recording()
def on_play(self, *args, **kwargs):
self.presenter.play()
def on_postprocess(self):
pass

31
src/interactors/base.py Normal file
View File

@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
from pubsub import pub
class baseInteractor(object):
def install(self, view, presenter, modulename):
self.modulename = modulename
self.view = view
self.presenter = presenter
pub.subscribe(self.disable_control, "{modulename}_disable_control".format(modulename=modulename))
pub.subscribe(self.enable_control, "{modulename}_enable_control".format(modulename=modulename))
pub.subscribe(self.set_label, "{modulename}_set_label".format(modulename=modulename))
pub.subscribe(self.focus_control, "{modulename}_focus_control".format(modulename=modulename))
def uninstall(self):
pub.unsubscribe(self.disable_control, "{modulename}_disable_control".format(modulename=self.modulename))
pub.unsubscribe(self.enable_control, "{modulename}_enable_control".format(modulename=self.modulename))
pub.unsubscribe(self.set_label, "{modulename}_set_label".format(modulename=self.modulename))
pub.unsubscribe(self.focus_control, "{modulename}_focus_control".format(modulename=self.modulename))
def disable_control(self, control):
self.view.disable(control)
def enable_control(self, control):
self.view.enable(control)
def focus_control(self, control):
getattr(self.view, control).SetFocus()
def set_label(self, control, label):
self.view.set(control, label)