Some code changes to having a more consistent MVC application.

This commit is contained in:
Manuel Cortez 2015-01-01 21:40:57 -06:00
parent a6dd5d602f
commit 186f70afc3
2 changed files with 63 additions and 100 deletions

View File

@ -58,10 +58,14 @@ class Controller(object):
def bind_other_events(self): def bind_other_events(self):
pub.subscribe(self.editing_keystroke, "editing_keystroke") pub.subscribe(self.editing_keystroke, "editing_keystroke")
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.search, menuitem=self.view.menuitem_search)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.learn_sounds, menuitem=self.view.sounds_tutorial)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.exit, menuitem=self.view.close)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.post_tweet, self.view.compose)
def __init__(self): def __init__(self):
super(Controller, self).__init__() super(Controller, self).__init__()
self.view = view.mainFrame(self) self.view = view.mainFrame()
self.buffers = [] self.buffers = []
self.view.prepare() self.view.prepare()
self.bind_stream_events() self.bind_stream_events()
@ -138,7 +142,7 @@ class Controller(object):
tl.timer = RepeatingTimer(180, tl.start_stream) tl.timer = RepeatingTimer(180, tl.start_stream)
tl.timer.start() tl.timer.start()
def search(self, event=None): def search(self, *args, **kwargs):
dlg = dialogs.search.searchDialog() dlg = dialogs.search.searchDialog()
if dlg.get_response() == widgetUtils.OK: if dlg.get_response() == widgetUtils.OK:
term = dlg.get("term") term = dlg.get("term")
@ -200,7 +204,7 @@ class Controller(object):
def delete(self): def delete(self):
pass pass
def exit(self, event=None): def exit(self, *args, **kwargs):
for item in session.sessions: for item in session.sessions:
session.sessions[item].settings.write() session.sessions[item].settings.write()
session.sessions[item].main_stream.disconnect() session.sessions[item].main_stream.disconnect()

View File

@ -11,96 +11,57 @@ class mainFrame(wx.Frame):
# Application menu # Application menu
app = wx.Menu() app = wx.Menu()
updateProfile = app.Append(wx.NewId(), _(u"&Update profile")) self.updateProfile = app.Append(wx.NewId(), _(u"&Update profile"))
# self.Bind(wx.EVT_MENU, self.controller.update_profile, updateProfile) self.show_hide = app.Append(wx.NewId(), _(u"&Hide window"))
show_hide = app.Append(wx.NewId(), _(u"&Hide window")) self.menuitem_search = app.Append(wx.NewId(), _(u"&Search"))
# self.Bind(wx.EVT_MENU, self.controller.show_hide, show_hide) self.lists = app.Append(wx.NewId(), _(u"&Lists manager"))
search = app.Append(wx.NewId(), _(u"&Search")) self.sounds_tutorial = app.Append(wx.NewId(), _(u"Sounds &tutorial"))
self.Bind(wx.EVT_MENU, self.controller.search, search) self.keystroke_editor = app.Append(wx.NewId(), _(u"&Edit keystrokes"))
lists = app.Append(wx.NewId(), _(u"&Lists manager")) self.prefs = app.Append(wx.ID_PREFERENCES, _(u"&Preferences"))
# self.view.Bind(wx.EVT_MENU, self.list_manager, lists) self.close = app.Append(wx.ID_EXIT, _(u"E&xit"))
sounds_tutorial = app.Append(wx.NewId(), _(u"Sounds &tutorial"))
self.Bind(wx.EVT_MENU, self.controller.learn_sounds, sounds_tutorial)
keystroke_editor = app.Append(wx.NewId(), _(u"&Edit keystrokes"))
self.Bind(wx.EVT_MENU, self.controller.edit_keystrokes, keystroke_editor)
prefs = app.Append(wx.ID_PREFERENCES, _(u"&Preferences"))
# self.view.Bind(wx.EVT_MENU, self.preferences, prefs)
close = app.Append(wx.ID_EXIT, _(u"E&xit"))
# self.view.Bind(wx.EVT_MENU, self.close, close)
# Tweet menu # Tweet menu
tweet = wx.Menu() tweet = wx.Menu()
compose = tweet.Append(wx.NewId(), _(u"&Tweet")) self.compose = tweet.Append(wx.NewId(), _(u"&Tweet"))
self.Bind(wx.EVT_MENU, self.controller.post_tweet, compose) self.reply = tweet.Append(wx.NewId(), _(u"Re&ply"))
response = tweet.Append(wx.NewId(), _(u"Re&ply")) self.retweet = tweet.Append(wx.NewId(), _(u"&Retweet"))
# self.view.Bind(wx.EVT_MENU, self.reply, response) self.fav = tweet.Append(wx.NewId(), _(u"Add to &favourites"))
retweet = tweet.Append(wx.NewId(), _(u"&Retweet")) self.unfav = tweet.Append(wx.NewId(), _(u"Remove from favo&urites"))
# self.view.Bind(wx.EVT_MENU, self.retweet, retweet) self.view = tweet.Append(wx.NewId(), _(u"&Show tweet"))
fav = tweet.Append(wx.NewId(), _(u"Add to &favourites")) self.delete = tweet.Append(wx.NewId(), _(u"&Delete"))
# self.view.Bind(wx.EVT_MENU, self.fav, fav)
unfav = tweet.Append(wx.NewId(), _(u"Remove from favo&urites"))
# self.view.Bind(wx.EVT_MENU, self.unfav, unfav)
view = tweet.Append(wx.NewId(), _(u"&Show tweet"))
# self.view.Bind(wx.EVT_MENU, self.view, view)
delete = tweet.Append(wx.NewId(), _(u"&Delete"))
# self.view.Bind(wx.EVT_MENU, self.delete, delete)
# User menu # User menu
user = wx.Menu() user = wx.Menu()
follow = user.Append(wx.NewId(), _(u"&Follow")) self.follow = user.Append(wx.NewId(), _(u"&Follow"))
# self.view.Bind(wx.EVT_MENU, self.onFollow, follow) self.unfollow = user.Append(wx.NewId(), _(u"&Unfollow"))
unfollow = user.Append(wx.NewId(), _(u"&Unfollow")) self.mute = user.Append(wx.NewId(), _(u"&Mute"))
# self.view.Bind(wx.EVT_MENU, self.onUnfollow, unfollow) self.unmute = user.Append(wx.NewId(), _(u"U&nmute"))
mute = user.Append(wx.NewId(), _(u"&Mute")) self.report = user.Append(wx.NewId(), _(u"&Report as spam"))
# self.view.Bind(wx.EVT_MENU, self.onMute, mute) self.block = user.Append(wx.NewId(), _(u"&Block"))
unmute = user.Append(wx.NewId(), _(u"U&nmute")) self.unblock = user.Append(wx.NewId(), _(u"Unb&lock"))
# self.view.Bind(wx.EVT_MENU, self.onUnmute, unmute) self.dm = user.Append(wx.NewId(), _(u"Direct me&ssage"))
report = user.Append(wx.NewId(), _(u"&Report as spam")) self.addToList = user.Append(wx.NewId(), _(u"&Add to list"))
# self.view.Bind(wx.EVT_MENU, self.onReport, report) self.removeFromList = user.Append(wx.NewId(), _(u"R&emove from list"))
block = user.Append(wx.NewId(), _(u"&Block")) self.viewLists = user.Append(wx.NewId(), _(u"&View lists"))
# self.view.Bind(wx.EVT_MENU, self.onBlock, block) self.details = user.Append(wx.NewId(), _(u"Show user &profile"))
unblock = user.Append(wx.NewId(), _(u"Unb&lock")) self.timeline = user.Append(wx.NewId(), _(u"&Timeline"))
# self.view.Bind(wx.EVT_MENU, self.onUnblock, unblock) self.favs = user.Append(wx.NewId(), _(u"V&iew favourites"))
dm = user.Append(wx.NewId(), _(u"Direct me&ssage"))
# self.view.Bind(wx.EVT_MENU, self.dm, dm)
addToList = user.Append(wx.NewId(), _(u"&Add to list"))
# self.view.Bind(wx.EVT_MENU, self.add_to_list, addToList)
removeFromList = user.Append(wx.NewId(), _(u"R&emove from list"))
# self.view.Bind(wx.EVT_MENU, self.remove_from_list, removeFromList)
viewLists = user.Append(wx.NewId(), _(u"&View lists"))
# self.view.Bind(wx.EVT_MENU, self.view_user_lists, viewLists)
details = user.Append(wx.NewId(), _(u"Show user &profile"))
# self.view.Bind(wx.EVT_MENU, self.details, details)
timeline = user.Append(wx.NewId(), _(u"&Timeline"))
# self.view.Bind(wx.EVT_MENU, self.open_timeline, timeline)
favs = user.Append(wx.NewId(), _(u"V&iew favourites"))
# self.view.Bind(wx.EVT_MENU, self.favs_timeline, favs)
# buffer menu # buffer menu
buffer = wx.Menu() buffer = wx.Menu()
mute = buffer.Append(wx.NewId(), _(u"&Mute")) self.mute = buffer.Append(wx.NewId(), _(u"&Mute"))
# self.view.Bind(wx.EVT_MENU, self.toggle_mute, mute) self.autoread = buffer.Append(wx.NewId(), _(u"&Autoread tweets for this buffer"))
autoread = buffer.Append(wx.NewId(), _(u"&Autoread tweets for this buffer")) self.clear = buffer.Append(wx.NewId(), _(u"&Clear buffer"))
# self.view.Bind(wx.EVT_MENU, self.toggle_autoread, autoread) self.deleteTl = buffer.Append(wx.NewId(), _(u"&Remove buffer"))
clear = buffer.Append(wx.NewId(), _(u"&Clear buffer"))
# self.view.Bind(wx.EVT_MENU, self.clear_list, clear)
deleteTl = buffer.Append(wx.NewId(), _(u"&Remove buffer"))
# self.view.Bind(wx.EVT_MENU, self.delete_buffer, deleteTl)
# Help Menu # Help Menu
help = wx.Menu() help = wx.Menu()
doc = help.Append(-1, _(u"&Documentation")) self.doc = help.Append(-1, _(u"&Documentation"))
# self.view.Bind(wx.EVT_MENU, self.onManual, doc) self.changelog = help.Append(wx.NewId(), _(u"&What's new in this version?"))
changelog = help.Append(wx.NewId(), _(u"&What's new in this version?")) self.check_for_updates = help.Append(wx.NewId(), _(u"&Check for updates"))
# self.view.Bind(wx.EVT_MENU, self.onChangelog, changelog) self.reportError = help.Append(wx.NewId(), _(u"&Report an error"))
check_for_updates = help.Append(wx.NewId(), _(u"&Check for updates")) self.visit_website = help.Append(-1, _(u"TW Blue &website"))
# self.view.Bind(wx.EVT_MENU, self.onCheckForUpdates, check_for_updates) self.about = help.Append(-1, _(u"About &TW Blue"))
reportError = help.Append(wx.NewId(), _(u"&Report an error"))
# self.view.Bind(wx.EVT_MENU, self.onReportBug, reportError)
visit_website = help.Append(-1, _(u"TW Blue &website"))
# self.view.Bind(wx.EVT_MENU, self.onVisit_website, visit_website)
about = help.Append(-1, _(u"About &TW Blue"))
# self.view.Bind(wx.EVT_MENU, self.onAbout, about)
# Add all to the menu Bar # Add all to the menu Bar
menuBar.Append(app, _(u"&Application")) menuBar.Append(app, _(u"&Application"))
@ -110,40 +71,38 @@ class mainFrame(wx.Frame):
menuBar.Append(help, _(u"&Help")) menuBar.Append(help, _(u"&Help"))
self.accel_tbl = wx.AcceleratorTable([ self.accel_tbl = wx.AcceleratorTable([
(wx.ACCEL_CTRL, ord('N'), compose.GetId()), (wx.ACCEL_CTRL, ord('N'), self.compose.GetId()),
(wx.ACCEL_CTRL, ord('R'), response.GetId()), (wx.ACCEL_CTRL, ord('R'), self.reply.GetId()),
(wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('R'), retweet.GetId()), (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('R'), self.retweet.GetId()),
(wx.ACCEL_CTRL, ord('F'), fav.GetId()), (wx.ACCEL_CTRL, ord('F'), self.fav.GetId()),
(wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), unfav.GetId()), (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), self.unfav.GetId()),
(wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('V'), view.GetId()), (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('V'), self.view.GetId()),
(wx.ACCEL_CTRL, ord('D'), dm.GetId()), (wx.ACCEL_CTRL, ord('D'), self.dm.GetId()),
(wx.ACCEL_CTRL, ord('Q'), close.GetId()), (wx.ACCEL_CTRL, ord('Q'), self.close.GetId()),
(wx.ACCEL_CTRL, ord('S'), follow.GetId()), (wx.ACCEL_CTRL, ord('S'), self.follow.GetId()),
(wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('S'), unfollow.GetId()), (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('S'), self.unfollow.GetId()),
(wx.ACCEL_CTRL, ord('K'), block.GetId()), (wx.ACCEL_CTRL, ord('K'), self.block.GetId()),
(wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('K'), report.GetId()), (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('K'), self.report.GetId()),
(wx.ACCEL_CTRL, ord('I'), timeline.GetId()), (wx.ACCEL_CTRL, ord('I'), self.timeline.GetId()),
(wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('I'), deleteTl.GetId()), (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('I'), self.deleteTl.GetId()),
(wx.ACCEL_CTRL, ord('M'), show_hide.GetId()), (wx.ACCEL_CTRL, ord('M'), self.show_hide.GetId()),
(wx.ACCEL_CTRL, ord('P'), updateProfile.GetId()), (wx.ACCEL_CTRL, ord('P'), self.updateProfile.GetId()),
]) ])
self.SetAcceleratorTable(self.accel_tbl) self.SetAcceleratorTable(self.accel_tbl)
return menuBar return menuBar
### MAIN ### MAIN
def __init__(self, controller): def __init__(self):
""" Main function of this class.""" """ Main function of this class."""
super(mainFrame, self).__init__(None, -1, "TW Blue", size=(1600, 1600)) super(mainFrame, self).__init__(None, -1, "TW Blue", size=(1600, 1600))
self.controller = controller
self.panel = wx.Panel(self) self.panel = wx.Panel(self)
self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer = wx.BoxSizer(wx.VERTICAL)
self.SetTitle("TW Blue") self.SetTitle("TW Blue")
self.SetMenuBar(self.makeMenus()) self.SetMenuBar(self.makeMenus())
self.nb = wx.Treebook(self.panel, wx.NewId()) self.nb = wx.Treebook(self.panel, wx.NewId())
self.buffers = {} self.buffers = {}
self.SetMenuBar(self.makeMenus())
def add_buffer(self, buffer, name): def add_buffer(self, buffer, name):
self.nb.AddPage(buffer, name) self.nb.AddPage(buffer, name)