Added a basic configuration dialog and an application menu in the menu bar
This commit is contained in:
parent
eda0b406c8
commit
9f619ae2c0
22
src/controller/configuration.py
Normal file
22
src/controller/configuration.py
Normal file
@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import widgetUtils
|
||||
from wxUI.dialogs import configuration as configurationUI
|
||||
|
||||
class configuration(object):
|
||||
|
||||
def __init__(self, session):
|
||||
self.session = session
|
||||
self.dialog = configurationUI.configurationDialog(_(u"Preferences"))
|
||||
self.create_config()
|
||||
|
||||
def create_config(self):
|
||||
self.dialog.create_general()
|
||||
self.dialog.set_value("general", "wall_buffer_count", self.session.settings["buffers"]["count_for_wall_buffers"])
|
||||
self.dialog.set_value("general", "audio_buffers_count", self.session.settings["buffers"]["count_for_audio_buffers"])
|
||||
self.dialog.realize()
|
||||
self.response = self.dialog.get_response()
|
||||
|
||||
def save_configuration(self):
|
||||
self.session.settings["buffers"]["count_for_audio_buffers"] = self.dialog.get_value("general", "wall_buffer_count")
|
||||
self.session.settings["buffers"]["count_for_audio_buffers"] = self.dialog.get_value("general", "audio_buffers_count")
|
||||
self.session.settings.write()
|
@ -5,6 +5,7 @@ import utils
|
||||
import widgetUtils
|
||||
import messages
|
||||
import buffers
|
||||
import configuration
|
||||
import player
|
||||
import posts
|
||||
import webbrowser
|
||||
@ -83,6 +84,7 @@ class Controller(object):
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU,self.remove_buffer, menuitem=self.window.remove_buffer_)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.get_more_items, menuitem=self.window.load_previous_items)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.changelog, menuitem=self.window.changelog)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.configuration, menuitem=self.window.settings_dialog)
|
||||
|
||||
def disconnect_events(self):
|
||||
pub.unsubscribe(self.in_post, "posted")
|
||||
@ -178,3 +180,9 @@ class Controller(object):
|
||||
os.chdir("documentation")
|
||||
webbrowser.open("changelog.html")
|
||||
os.chdir("../")
|
||||
|
||||
def configuration(self, *args, **kwargs):
|
||||
""" Opens the global settings dialogue."""
|
||||
d = configuration.configuration(self.session)
|
||||
if d.response == widgetUtils.OK:
|
||||
d.save_configuration()
|
||||
|
59
src/wxUI/dialogs/configuration.py
Normal file
59
src/wxUI/dialogs/configuration.py
Normal file
@ -0,0 +1,59 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import wx
|
||||
import widgetUtils
|
||||
|
||||
class general(wx.Panel, widgetUtils.BaseDialog):
|
||||
def __init__(self, panel):
|
||||
super(general, self).__init__(panel)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
lbl1 = wx.StaticText(self, wx.NewId(), _(u"Number of items to load for newsfeed and wall buffers (maximun 100)"))
|
||||
self.wall_buffer_count = wx.SpinCtrl(self, wx.NewId())
|
||||
self.wall_buffer_count.SetRange(1, 100)
|
||||
box1 = wx.BoxSizer(wx.HORIZONTAL)
|
||||
box1.Add(lbl1, 0, wx.ALL, 5)
|
||||
box1.Add(self.wall_buffer_count, 0, wx.ALL, 5)
|
||||
sizer.Add(box1, 0, wx.ALL, 5)
|
||||
lbl2 = wx.StaticText(self, wx.NewId(), _(u"Number of items to load in audio buffers (maximun 1000)"))
|
||||
self.audio_buffers_count = wx.SpinCtrl(self, wx.NewId())
|
||||
self.audio_buffers_count.SetRange(1, 1000)
|
||||
box2 = wx.BoxSizer(wx.HORIZONTAL)
|
||||
box2.Add(lbl2, 0, wx.ALL, 5)
|
||||
box2.Add(self.audio_buffers_count, 0, wx.ALL, 5)
|
||||
sizer.Add(box2, 0, wx.ALL, 5)
|
||||
self.SetSizer(sizer)
|
||||
|
||||
class configurationDialog(widgetUtils.BaseDialog):
|
||||
|
||||
def __init__(self, title):
|
||||
super(configurationDialog, self).__init__(None, -1, title=title)
|
||||
self.panel = wx.Panel(self)
|
||||
self.sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.notebook = wx.Notebook(self.panel)
|
||||
|
||||
def create_general(self):
|
||||
self.general = general(self.notebook)
|
||||
self.notebook.AddPage(self.general, _(u"General"))
|
||||
self.general.SetFocus()
|
||||
|
||||
def realize(self):
|
||||
self.sizer.Add(self.notebook, 0, wx.ALL, 5)
|
||||
ok_cancel_box = wx.BoxSizer(wx.HORIZONTAL)
|
||||
ok = wx.Button(self.panel, wx.ID_OK, _(u"Save"))
|
||||
ok.SetDefault()
|
||||
cancel = wx.Button(self.panel, wx.ID_CANCEL, _(u"Close"))
|
||||
self.SetEscapeId(cancel.GetId())
|
||||
ok_cancel_box.Add(ok, 0, wx.ALL, 5)
|
||||
ok_cancel_box.Add(cancel, 0, wx.ALL, 5)
|
||||
self.sizer.Add(ok_cancel_box, 0, wx.ALL, 5)
|
||||
self.panel.SetSizer(self.sizer)
|
||||
self.SetClientSize(self.sizer.CalcMin())
|
||||
|
||||
def get_value(self, panel, key):
|
||||
p = getattr(self, panel)
|
||||
return getattr(p, key).GetValue()
|
||||
|
||||
def set_value(self, panel, key, value):
|
||||
p = getattr(self, panel)
|
||||
control = getattr(p, key)
|
||||
getattr(control, "SetValue")(value)
|
||||
|
@ -5,6 +5,8 @@ import application
|
||||
class mainWindow(wx.Frame):
|
||||
def makeMenu(self):
|
||||
mb = wx.MenuBar()
|
||||
app_ = wx.Menu()
|
||||
self.settings_dialog = app_.Append(wx.NewId(), _(u"Preferences"))
|
||||
buffer = wx.Menu()
|
||||
self.new_buffer = wx.Menu()
|
||||
self.search_audios = self.new_buffer.Append(wx.NewId(), _(u"Audio"))
|
||||
@ -12,6 +14,7 @@ class mainWindow(wx.Frame):
|
||||
self.update_buffer = buffer.Append(wx.NewId(), _(u"Update current buffer"))
|
||||
self.load_previous_items = buffer.Append(wx.NewId(), _(u"Load previous items"))
|
||||
self.remove_buffer_ = buffer.Append(wx.NewId(), _(u"&Remove buffer"))
|
||||
mb.Append(app_, _(u"Application"))
|
||||
mb.Append(buffer, _(u"Buffer"))
|
||||
help_ = wx.Menu()
|
||||
self.about = help_.Append(wx.NewId(), _(u"About {0}").format(application.name,))
|
||||
|
Loading…
Reference in New Issue
Block a user