First great commit for Gtk. It is partially functional now

This commit is contained in:
2015-04-03 16:57:08 -06:00
parent 9356a0544f
commit 2e32fa7ef2
44 changed files with 1814 additions and 110 deletions

View File

@@ -1,33 +1,31 @@
from gi.repository import Gtk
import widgetUtils
class sessionManagerWindow(Gtk.Dialog):
class sessionManagerWindow(widgetUtils.baseDialog):
def __init__(self):
super(sessionManagerWindow, self).__init__("Session Manager", None, 0, (Gtk.STOCK_OK, widgetUtils.OK, Gtk.STOCK_CANCEL, widgetUtils.CANCEL))
box = self.get_content_area()
self.list = widgetUtils.list("Session")
box.add(self.list.list)
self.box.add(self.list.list)
btnBox = Gtk.Box(spacing=6)
self.new = Gtk.Button("New account")
self.remove = Gtk.Button("Remove account")
btnBox.add(self.new)
btnBox.add(self.remove)
box.add(btnBox)
self.box.add(btnBox)
self.show_all()
def fill_list(self, sessionsList):
for i in sessionsList:
self.list.insert_item(i)
self.list.insert_item(False, i)
if self.list.get_count() > 0:
self.list.select_item(0)
def get_response(self):
return self.run()
def new_account_dialog(self):
dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, "Authorization")
dialog.format_secondary_text("The request for the required Twitter authorization to continue will be opened on your browser. You only need to do it once. Would you like to autorhise a new account now?")
return dialog.run()
answer = dialog.run()
dialog.destroy()
return answer
def add_new_session_to_list(self):
total = self.list.get_count()
@@ -39,12 +37,14 @@ class sessionManagerWindow(Gtk.Dialog):
def show_unauthorised_error(self):
dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.CANCEL, "Invalid user token")
dialog.format_secondary_text("Your access token is invalid or the authorisation has failed. Please try again.")
return dialog.run()
answer = dialog.run()
return answer
def remove_account_dialog(self):
dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, "Remove account")
dialog.format_secondary_text("Do you really want delete this account?")
return dialog.run()
answer = dialog.run()
return answer
def get_selected(self):
return self.list.get_selected()

View File

@@ -48,6 +48,8 @@ class sessionManagerController(object):
def show(self):
if self.view.get_response() == widgetUtils.OK:
self.do_ok()
# else:
self.view.destroy()
def do_ok(self):
log.debug("Starting sessions...")
@@ -59,6 +61,7 @@ class sessionManagerController(object):
s.login()
session.sessions[i] = s
self.new_sessions[i] = s
# self.view.destroy()
def manage_new_account(self, *args, **kwargs):
if self.view.new_account_dialog() == widgetUtils.YES:
@@ -67,14 +70,14 @@ class sessionManagerController(object):
s = session.Session(location)
manager.manager.add_session(location)
s.get_configuration()
try:
s.authorise()
self.sessions.append(location)
self.view.add_new_session_to_list()
except:
log.exception("Error authorising the session")
self.view.show_unauthorised_error()
return
# try:
s.authorise()
self.sessions.append(location)
self.view.add_new_session_to_list()
# except:
# log.exception("Error authorising the session")
# self.view.show_unauthorised_error()
# return
def remove(self, *args, **kwargs):
if self.view.remove_account_dialog() == widgetUtils.YES:
@@ -83,3 +86,4 @@ class sessionManagerController(object):
self.removed_sessions.append(selected_account)
self.sessions.remove(selected_account)
shutil.rmtree(path=paths.config_path(selected_account), ignore_errors=True)