Modified presenters to use basePresenter as parent

This commit is contained in:
Manuel Cortez 2019-01-06 17:22:23 -06:00
parent 9604869639
commit 9083fc65d4
3 changed files with 37 additions and 36 deletions

View File

@ -6,19 +6,17 @@ import tempfile
import sound_lib import sound_lib
import sound import sound
import output import output
from pubsub import pub
from mysc.thread_utils import call_threaded from mysc.thread_utils import call_threaded
from . import base
class audioRecorderPresenter(object): class audioRecorderPresenter(base.basePresenter):
def __init__(self, view, interactor): def __init__(self, view, interactor):
self.view = view super(audioRecorderPresenter, self).__init__(view=view, interactor=interactor, modulename="audiorecorder")
self.interactor = interactor
self.interactor.install(view=view, presenter=self)
self.recorded = False self.recorded = False
self.recording = None self.recording = None
self.duration = 0 self.duration = 0
self.playing = None self.playing = None
self.interactor.start() self.run()
def toggle_recording(self, *args, **kwargs): def toggle_recording(self, *args, **kwargs):
if self.recording != None: if self.recording != None:
@ -31,9 +29,9 @@ class audioRecorderPresenter(object):
self.recording = sound.get_recording(self.file) self.recording = sound.get_recording(self.file)
self.duration = time.time() self.duration = time.time()
self.recording.play() self.recording.play()
pub.sendMessage("audiorecorder_set_label", control="record", label=_("&Stop")) self.send_message("set_label", control="record", label=_("&Stop"))
output.speak(_("Recording")) output.speak(_("Recording"))
pub.sendMessage("audiorecorder_disable_control", control="ok") self.send_message("disable_control", control="ok")
def stop_recording(self): def stop_recording(self):
self.recording.stop() self.recording.stop()
@ -41,24 +39,24 @@ class audioRecorderPresenter(object):
self.recording.free() self.recording.free()
output.speak(_("Stopped")) output.speak(_("Stopped"))
self.recorded = True self.recorded = True
pub.sendMessage("audiorecorder_set_label", control="record", label=_("&Record")) self.send_message("set_label", control="record", label=_("&Record"))
pub.sendMessage("audiorecorder_disable_control", control="record") self.send_message("disable_control", control="record")
pub.sendMessage("audiorecorder_enable_control", control="play") self.send_message("enable_control", control="play")
pub.sendMessage("audiorecorder_enable_control", control="discard") self.send_message("enable_control", control="discard")
pub.sendMessage("audiorecorder_enable_control", control="ok") self.send_message("enable_control", control="ok")
pub.sendMessage("audiorecorder_focus_control", control="play") self.send_message("focus_control", control="play")
def discard_recording(self, *args, **kwargs): def discard_recording(self, *args, **kwargs):
if self.playing: if self.playing:
self._stop() self._stop()
if self.recording != None: if self.recording != None:
self.cleanup() self.cleanup()
pub.sendMessage("audiorecorder_disable_control", control="play") self.send_message("disable_control", control="play")
pub.sendMessage("audiorecorder_disable_control", control="ok") self.send_message("disable_control", control="ok")
self.file = None self.file = None
pub.sendMessage("audiorecorder_enable_control", control="record") self.send_message("enable_control", control="record")
pub.sendMessage("audiorecorder_focus_control", control="record") self.send_message("focus_control", control="record")
pub.sendMessage("audiorecorder_disable_control", control="discard") self.send_message("disable_control", control="discard")
self.recording = None self.recording = None
output.speak(_("Discarded")) output.speak(_("Discarded"))
@ -73,11 +71,11 @@ class audioRecorderPresenter(object):
# try: # try:
self.playing = sound_lib.stream.FileStream(file=str(self.file), flags=sound_lib.stream.BASS_UNICODE) self.playing = sound_lib.stream.FileStream(file=str(self.file), flags=sound_lib.stream.BASS_UNICODE)
self.playing.play() self.playing.play()
pub.sendMessage("audiorecorder_set_label", control="play", label=_("&Stop")) self.send_message("set_label", control="play", label=_("&Stop"))
try: try:
while self.playing.is_playing: while self.playing.is_playing:
pass pass
pub.sendMessage("audiorecorder_set_label", control="play", label=_("&Play")) self.send_message("set_label", control="play", label=_("&Play"))
self.playing.free() self.playing.free()
self.playing = None self.playing = None
except: except:
@ -87,7 +85,7 @@ class audioRecorderPresenter(object):
output.speak(_("Stopped")) output.speak(_("Stopped"))
self.playing.stop() self.playing.stop()
self.playing.free() self.playing.free()
pub.sendMessage("audiorecorder_set_label", control="play", label=_("&Play")) self.send_message("set_label", control="play", label=_("&Play"))
self.playing = None self.playing = None
def postprocess(self): def postprocess(self):
@ -96,6 +94,7 @@ class audioRecorderPresenter(object):
sound.recode_audio(self.file) sound.recode_audio(self.file)
self.wav_file = self.file self.wav_file = self.file
self.file = '%s.ogg' % self.file[:-4] self.file = '%s.ogg' % self.file[:-4]
self.cleanup()
def cleanup(self): def cleanup(self):
if self.playing and self.playing.is_playing: if self.playing and self.playing.is_playing:
@ -107,6 +106,5 @@ class audioRecorderPresenter(object):
self.recording.free() self.recording.free()
except: except:
pass pass
os.remove(self.file)
if hasattr(self, 'wav_file'): if hasattr(self, 'wav_file'):
os.remove(self.wav_file) os.remove(self.wav_file)

View File

@ -6,6 +6,7 @@ from interactors import configuration as interactor
class basePresenter(object): class basePresenter(object):
def __init__(self, view, interactor, modulename): def __init__(self, view, interactor, modulename):
self.modulename = modulename
self.interactor = interactor self.interactor = interactor
self.view = view self.view = view
self.interactor.install(view=view, presenter=self, modulename=modulename) self.interactor.install(view=view, presenter=self, modulename=modulename)
@ -13,3 +14,6 @@ class basePresenter(object):
def run(self): def run(self):
self.interactor.start() self.interactor.start()
self.interactor.uninstall() self.interactor.uninstall()
def send_message(self, msg, *args, **kwargs):
pub.sendMessage(self.modulename+"_"+msg, *args, **kwargs)

View File

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from pubsub import pub
from . import base from . import base
class configurationPresenter(base.basePresenter): class configurationPresenter(base.basePresenter):
@ -41,17 +40,17 @@ class configurationPresenter(base.basePresenter):
return "alpha" return "alpha"
def create_config(self): def create_config(self):
pub.sendMessage("configuration_create_tab", tab="general") self.send_message("create_tab", tab="general")
pub.sendMessage("configuration_set", tab="general", setting="wall_buffer_count", value=self.session.settings["buffers"]["count_for_wall_buffers"]) self.send_message("set", tab="general", setting="wall_buffer_count", value=self.session.settings["buffers"]["count_for_wall_buffers"])
pub.sendMessage("configuration_set", tab="general", setting="video_buffers_count", value=self.session.settings["buffers"]["count_for_video_buffers"]) self.send_message("set", tab="general", setting="video_buffers_count", value=self.session.settings["buffers"]["count_for_video_buffers"])
pub.sendMessage("configuration_set", tab="general", setting="load_images", value=self.session.settings["general"]["load_images"]) self.send_message("set", tab="general", setting="load_images", value=self.session.settings["general"]["load_images"])
pub.sendMessage("configuration_set", tab="general", setting="update_channel", value=self.get_update_channel_label(self.session.settings["general"]["update_channel"])) self.send_message("set", tab="general", setting="update_channel", value=self.get_update_channel_label(self.session.settings["general"]["update_channel"]))
pub.sendMessage("configuration_create_tab", tab="chat") self.send_message("create_tab", tab="chat")
pub.sendMessage("configuration_set", tab="chat", setting="notify_online", value=self.session.settings["chat"]["notify_online"]) self.send_message("set", tab="chat", setting="notify_online", value=self.session.settings["chat"]["notify_online"])
pub.sendMessage("configuration_set", tab="chat", setting="notify_offline", value=self.session.settings["chat"]["notify_offline"]) self.send_message("set", tab="chat", setting="notify_offline", value=self.session.settings["chat"]["notify_offline"])
pub.sendMessage("configuration_set", tab="chat", setting="open_unread_conversations", value=self.session.settings["chat"]["open_unread_conversations"]) self.send_message("set", tab="chat", setting="open_unread_conversations", value=self.session.settings["chat"]["open_unread_conversations"])
pub.sendMessage("configuration_set", tab="chat", setting="automove_to_conversations", value=self.session.settings["chat"]["automove_to_conversations"]) self.send_message("set", tab="chat", setting="automove_to_conversations", value=self.session.settings["chat"]["automove_to_conversations"])
pub.sendMessage("configuration_set", tab="chat", setting="notifications", value=self.get_notification_label(self.session.settings["chat"]["notifications"])) self.send_message("set", tab="chat", setting="notifications", value=self.get_notification_label(self.session.settings["chat"]["notifications"]))
def update_setting(self, section, setting, value): def update_setting(self, section, setting, value):
if section not in self.session.settings: if section not in self.session.settings: