Added accounts dialog at startup in socializer (implementation is half pending)
This commit is contained in:
parent
d06a32311e
commit
9003d3c738
@ -52,6 +52,7 @@ def setup():
|
|||||||
|
|
||||||
log.debug("Created Application mainloop object")
|
log.debug("Created Application mainloop object")
|
||||||
sm = sessionManager.sessionManagerController()
|
sm = sessionManager.sessionManagerController()
|
||||||
|
sm.show()
|
||||||
del sm
|
del sm
|
||||||
r = mainController.Controller()
|
r = mainController.Controller()
|
||||||
call_threaded(r.login)
|
call_threaded(r.login)
|
||||||
|
@ -111,7 +111,7 @@ class vkSession(object):
|
|||||||
def is_logged(self):
|
def is_logged(self):
|
||||||
return self.logged
|
return self.logged
|
||||||
|
|
||||||
def get_configuration(self):
|
def get_configuration(self, nosound=False):
|
||||||
|
|
||||||
""" Gets settings for a session."""
|
""" Gets settings for a session."""
|
||||||
|
|
||||||
@ -119,9 +119,10 @@ class vkSession(object):
|
|||||||
# try:
|
# try:
|
||||||
log.debug("Creating config file %s" % (file_,))
|
log.debug("Creating config file %s" % (file_,))
|
||||||
self.settings = Configuration(os.path.join(paths.config_path(), file_), os.path.join(paths.app_path(), "session.defaults"))
|
self.settings = Configuration(os.path.join(paths.config_path(), file_), os.path.join(paths.app_path(), "session.defaults"))
|
||||||
self.soundplayer = sound.soundSystem(config.app["sound"])
|
if nosound == False:
|
||||||
pub.subscribe(self.play_sound, "play-sound")
|
self.soundplayer = sound.soundSystem(config.app["sound"])
|
||||||
pub.subscribe(self.post, "post")
|
pub.subscribe(self.play_sound, "play-sound")
|
||||||
|
pub.subscribe(self.post, "post")
|
||||||
# except:
|
# except:
|
||||||
# log.exception("The session configuration has failed.")
|
# log.exception("The session configuration has failed.")
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import widgetUtils
|
|||||||
import paths
|
import paths
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
import shutil
|
||||||
from authenticator.official import AuthenticationError
|
from authenticator.official import AuthenticationError
|
||||||
from . import wxUI as view
|
from . import wxUI as view
|
||||||
from . import session
|
from . import session
|
||||||
@ -16,12 +17,16 @@ class sessionManagerController(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(sessionManagerController, self).__init__()
|
super(sessionManagerController, self).__init__()
|
||||||
log.debug("Setting up the session manager.")
|
log.debug("Setting up the session manager.")
|
||||||
|
self.view = view.sessionManagerWindow()
|
||||||
|
widgetUtils.connect_event(self.view.new, widgetUtils.BUTTON_PRESSED, self.manage_new_account)
|
||||||
|
widgetUtils.connect_event(self.view.remove, widgetUtils.BUTTON_PRESSED, self.remove)
|
||||||
self.fill_list()
|
self.fill_list()
|
||||||
if not hasattr(self, "session"):
|
if len(self.sessions) == 0:
|
||||||
log.debug("the session list is empty, creating a new one...")
|
log.debug("the session list is empty, creating a new one...")
|
||||||
self.manage_new_account()
|
self.manage_new_account()
|
||||||
|
|
||||||
def fill_list(self):
|
def fill_list(self):
|
||||||
|
self.sessions = []
|
||||||
log.debug("Filling the session list...")
|
log.debug("Filling the session list...")
|
||||||
for i in os.listdir(paths.config_path()):
|
for i in os.listdir(paths.config_path()):
|
||||||
if os.path.isdir(os.path.join(paths.config_path(), i)):
|
if os.path.isdir(os.path.join(paths.config_path(), i)):
|
||||||
@ -29,12 +34,10 @@ class sessionManagerController(object):
|
|||||||
config_test = Configuration(os.path.join(paths.config_path(), i, "session.conf"))
|
config_test = Configuration(os.path.join(paths.config_path(), i, "session.conf"))
|
||||||
name = config_test["vk"]["user"]
|
name = config_test["vk"]["user"]
|
||||||
if name != "" and config_test["vk"]["password"] != "":
|
if name != "" and config_test["vk"]["password"] != "":
|
||||||
self.session = i
|
self.sessions.append((i, name))
|
||||||
s = session.vkSession(self.session)
|
self.view.list.insert_item(False, *[name])
|
||||||
s.get_configuration()
|
|
||||||
session.sessions[self.session] = s
|
|
||||||
|
|
||||||
def manage_new_account(self):
|
def manage_new_account(self, *args, **kwargs):
|
||||||
if view.new_account_dialog() == widgetUtils.YES:
|
if view.new_account_dialog() == widgetUtils.YES:
|
||||||
location = (str(time.time())[-6:])
|
location = (str(time.time())[-6:])
|
||||||
log.debug("Creating session in the %s path" % (location,))
|
log.debug("Creating session in the %s path" % (location,))
|
||||||
@ -42,11 +45,11 @@ class sessionManagerController(object):
|
|||||||
path = os.path.join(paths.config_path(), location)
|
path = os.path.join(paths.config_path(), location)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
s.get_configuration()
|
s.get_configuration(True)
|
||||||
self.get_authorisation(s)
|
self.get_authorisation(s)
|
||||||
session.sessions[location] = s
|
name = s.settings["vk"]["user"]
|
||||||
else:
|
self.sessions.append((location, name))
|
||||||
sys.exit()
|
self.view.list.insert_item(False, *[name])
|
||||||
|
|
||||||
def get_authorisation(self, c):
|
def get_authorisation(self, c):
|
||||||
log.debug("Starting the authorisation process...")
|
log.debug("Starting the authorisation process...")
|
||||||
@ -60,3 +63,28 @@ class sessionManagerController(object):
|
|||||||
c.settings["vk"]["password"] = ""
|
c.settings["vk"]["password"] = ""
|
||||||
c.settings["vk"]["user"]
|
c.settings["vk"]["user"]
|
||||||
return self.get_authorisation(c)
|
return self.get_authorisation(c)
|
||||||
|
|
||||||
|
def do_ok(self):
|
||||||
|
selected_session = self.sessions[self.view.list.get_selected()]
|
||||||
|
self.session = selected_session[0]
|
||||||
|
self.session = session.vkSession(self.session)
|
||||||
|
self.session.get_configuration()
|
||||||
|
session.sessions[selected_session[1]] = self.session
|
||||||
|
|
||||||
|
def show(self):
|
||||||
|
if len(self.sessions) > 1:
|
||||||
|
answer = self.view.get_response()
|
||||||
|
else:
|
||||||
|
answer = widgetUtils.OK
|
||||||
|
if answer == widgetUtils.OK:
|
||||||
|
self.do_ok()
|
||||||
|
else:
|
||||||
|
sys.exit()
|
||||||
|
self.view.destroy()
|
||||||
|
|
||||||
|
def remove(self, *args, **kwargs):
|
||||||
|
if self.view.remove_account_dialog() == widgetUtils.YES:
|
||||||
|
selected_session = self.sessions[self.view.list.get_selected()]
|
||||||
|
shutil.rmtree(path=os.path.join(paths.config_path(), selected_session[0]), ignore_errors=True)
|
||||||
|
self.sessions.remove(selected_session)
|
||||||
|
self.view.list.remove_item(self.view.list.get_selected())
|
@ -37,3 +37,31 @@ class newSessionDialog(widgetUtils.BaseDialog):
|
|||||||
|
|
||||||
def get_password(self):
|
def get_password(self):
|
||||||
return self.passw.GetValue()
|
return self.passw.GetValue()
|
||||||
|
|
||||||
|
class sessionManagerWindow(widgetUtils.BaseDialog):
|
||||||
|
def __init__(self):
|
||||||
|
super(sessionManagerWindow, self).__init__(parent=None, title=_("Select an account"), size=wx.DefaultSize)
|
||||||
|
panel = wx.Panel(self)
|
||||||
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
|
label = wx.StaticText(panel, -1, _(u"Accounts list"), size=wx.DefaultSize)
|
||||||
|
listSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
|
self.list = widgetUtils.list(panel, _("Account"), style=wx.LC_SINGLE_SEL|wx.LC_REPORT)
|
||||||
|
listSizer.Add(label, 0, wx.ALL, 5)
|
||||||
|
listSizer.Add(self.list.list, 0, wx.ALL, 5)
|
||||||
|
sizer.Add(listSizer, 0, wx.ALL, 5)
|
||||||
|
self.new = wx.Button(panel, -1, _("New account"), size=wx.DefaultSize)
|
||||||
|
self.remove = wx.Button(panel, -1, _(u"Remove account"))
|
||||||
|
ok = wx.Button(panel, wx.ID_OK, size=wx.DefaultSize)
|
||||||
|
ok.SetDefault()
|
||||||
|
cancel = wx.Button(panel, wx.ID_CANCEL, size=wx.DefaultSize)
|
||||||
|
buttons = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
|
buttons.Add(self.new, 0, wx.ALL, 5)
|
||||||
|
buttons.Add(ok, 0, wx.ALL, 5)
|
||||||
|
buttons.Add(cancel, 0, wx.ALL, 5)
|
||||||
|
sizer.Add(buttons, 0, wx.ALL, 5)
|
||||||
|
panel.SetSizer(sizer)
|
||||||
|
min = sizer.CalcMin()
|
||||||
|
self.SetClientSize(min)
|
||||||
|
|
||||||
|
def remove_account_dialog(self):
|
||||||
|
return wx.MessageDialog(self, _("Do you really want to delete this account?"), _("Remove account"), wx.YES_NO).ShowModal()
|
Loading…
Reference in New Issue
Block a user