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

View File

@ -6,6 +6,7 @@ from interactors import configuration as interactor
class basePresenter(object):
def __init__(self, view, interactor, modulename):
self.modulename = modulename
self.interactor = interactor
self.view = view
self.interactor.install(view=view, presenter=self, modulename=modulename)
@ -13,3 +14,6 @@ class basePresenter(object):
def run(self):
self.interactor.start()
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 -*-
from __future__ import unicode_literals
from pubsub import pub
from . import base
class configurationPresenter(base.basePresenter):
@ -41,17 +40,17 @@ class configurationPresenter(base.basePresenter):
return "alpha"
def create_config(self):
pub.sendMessage("configuration_create_tab", tab="general")
pub.sendMessage("configuration_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"])
pub.sendMessage("configuration_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"]))
pub.sendMessage("configuration_create_tab", tab="chat")
pub.sendMessage("configuration_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"])
pub.sendMessage("configuration_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"])
pub.sendMessage("configuration_set", tab="chat", setting="notifications", value=self.get_notification_label(self.session.settings["chat"]["notifications"]))
self.send_message("create_tab", tab="general")
self.send_message("set", tab="general", setting="wall_buffer_count", value=self.session.settings["buffers"]["count_for_wall_buffers"])
self.send_message("set", tab="general", setting="video_buffers_count", value=self.session.settings["buffers"]["count_for_video_buffers"])
self.send_message("set", tab="general", setting="load_images", value=self.session.settings["general"]["load_images"])
self.send_message("set", tab="general", setting="update_channel", value=self.get_update_channel_label(self.session.settings["general"]["update_channel"]))
self.send_message("create_tab", tab="chat")
self.send_message("set", tab="chat", setting="notify_online", value=self.session.settings["chat"]["notify_online"])
self.send_message("set", tab="chat", setting="notify_offline", value=self.session.settings["chat"]["notify_offline"])
self.send_message("set", tab="chat", setting="open_unread_conversations", value=self.session.settings["chat"]["open_unread_conversations"])
self.send_message("set", tab="chat", setting="automove_to_conversations", value=self.session.settings["chat"]["automove_to_conversations"])
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):
if section not in self.session.settings: