Removed unneeded code fin the session manager
This commit is contained in:
parent
b1b154c282
commit
776c8338f3
@ -29,10 +29,6 @@ def setup():
|
|||||||
from sessionmanager import sessionManager
|
from sessionmanager import sessionManager
|
||||||
app = widgetUtils.mainLoopObject()
|
app = widgetUtils.mainLoopObject()
|
||||||
sm = sessionManager.sessionManagerController()
|
sm = sessionManager.sessionManagerController()
|
||||||
sm.fill_list()
|
|
||||||
if len(sm.sessions) == 0: sm.show()
|
|
||||||
else:
|
|
||||||
sm.do_ok()
|
|
||||||
del sm
|
del sm
|
||||||
r = mainController.Controller()
|
r = mainController.Controller()
|
||||||
call_threaded(r.login)
|
call_threaded(r.login)
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
import os
|
||||||
import shutil
|
import sys
|
||||||
import widgetUtils
|
import widgetUtils
|
||||||
import wxUI as view
|
import wxUI as view
|
||||||
import paths
|
import paths
|
||||||
import time
|
import time
|
||||||
import os
|
|
||||||
import logging
|
import logging
|
||||||
import session
|
import session
|
||||||
from config_utils import Configuration
|
from config_utils import Configuration
|
||||||
@ -16,41 +15,24 @@ 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()
|
self.fill_list()
|
||||||
widgetUtils.connect_event(self.view.new, widgetUtils.BUTTON_PRESSED, self.manage_new_account)
|
if not hasattr(self, "session"):
|
||||||
widgetUtils.connect_event(self.view.remove, widgetUtils.BUTTON_PRESSED, self.remove)
|
self.manage_new_account()
|
||||||
self.new_sessions = {}
|
|
||||||
self.removed_sessions = []
|
|
||||||
|
|
||||||
def fill_list(self):
|
def fill_list(self):
|
||||||
sessionsList = []
|
|
||||||
log.debug("Filling the sessions list.")
|
|
||||||
self.sessions = []
|
|
||||||
for i in os.listdir(paths.config_path()):
|
for i in os.listdir(paths.config_path()):
|
||||||
if os.path.isdir(paths.config_path(i)):
|
if os.path.isdir(paths.config_path(i)):
|
||||||
log.debug("Adding session %s" % (i,))
|
log.debug("Adding session %s" % (i,))
|
||||||
strconfig = "%s/session.conf" % (paths.config_path(i))
|
strconfig = "%s/session.conf" % (paths.config_path(i))
|
||||||
config_test = Configuration(strconfig)
|
config_test = Configuration(strconfig)
|
||||||
name = config_test["vk"]["user"]
|
name = config_test["vk"]["user"]
|
||||||
sessionsList.append(name)
|
self.session = i
|
||||||
self.sessions.append(i)
|
s = session.vkSession(self.session)
|
||||||
self.view.fill_list(sessionsList)
|
|
||||||
|
|
||||||
def show(self):
|
|
||||||
if self.view.get_response() == widgetUtils.OK:
|
|
||||||
self.do_ok()
|
|
||||||
|
|
||||||
def do_ok(self):
|
|
||||||
log.debug("Starting sessions...")
|
|
||||||
for i in self.sessions:
|
|
||||||
if session.sessions.has_key(i) == True: continue
|
|
||||||
s = session.vkSession(i)
|
|
||||||
s.get_configuration()
|
s.get_configuration()
|
||||||
session.sessions[i] = s
|
session.sessions[self.session] = s
|
||||||
self.new_sessions[i] = s
|
|
||||||
|
|
||||||
def manage_new_account(self, *args, **kwargs):
|
def manage_new_account(self):
|
||||||
if self.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,))
|
||||||
s = session.vkSession(location)
|
s = session.vkSession(location)
|
||||||
@ -60,25 +42,13 @@ class sessionManagerController(object):
|
|||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
s.get_configuration()
|
s.get_configuration()
|
||||||
self.get_authorisation(s)
|
self.get_authorisation(s)
|
||||||
self.sessions.append(location)
|
session.sessions[location] = s
|
||||||
self.view.add_new_session_to_list()
|
else:
|
||||||
# except:
|
sys.exit()
|
||||||
# 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:
|
|
||||||
selected_account = self.sessions[self.view.get_selected()]
|
|
||||||
self.view.remove_session(self.view.get_selected())
|
|
||||||
self.removed_sessions.append(selected_account)
|
|
||||||
self.sessions.remove(selected_account)
|
|
||||||
shutil.rmtree(path=paths.config_path(selected_account), ignore_errors=True)
|
|
||||||
|
|
||||||
def get_authorisation(self, c):
|
def get_authorisation(self, c):
|
||||||
dl = view.newSessionDialog()
|
dl = view.newSessionDialog()
|
||||||
if dl.ShowModal() == widgetUtils.OK:
|
if dl.ShowModal() == widgetUtils.OK:
|
||||||
c.settings["vk"]["user"] = dl.get_email()
|
c.settings["vk"]["user"] = dl.get_email()
|
||||||
c.settings["vk"]["password"] = dl.get_password()
|
c.settings["vk"]["password"] = dl.get_password()
|
||||||
c.authorise()
|
|
||||||
c.settings.write()
|
c.settings.write()
|
||||||
|
@ -2,63 +2,8 @@
|
|||||||
import wx
|
import wx
|
||||||
import widgetUtils
|
import widgetUtils
|
||||||
|
|
||||||
class sessionManagerWindow(widgetUtils.BaseDialog):
|
def new_account_dialog():
|
||||||
def __init__(self):
|
return wx.MessageDialog(None, _(u"In order to continue, you need to configure your VK account before. Would you like to autorhise a new account now?"), _(u"Authorisation"), wx.YES_NO).ShowModal()
|
||||||
super(sessionManagerWindow, self).__init__(parent=None, title="Session manager", size=wx.DefaultSize)
|
|
||||||
panel = wx.Panel(self)
|
|
||||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
|
||||||
label = wx.StaticText(panel, -1, u"Accounts", size=wx.DefaultSize)
|
|
||||||
listSizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
||||||
self.list = widgetUtils.list(panel, u"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, u"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 fill_list(self, sessionsList):
|
|
||||||
for i in sessionsList:
|
|
||||||
self.list.insert_item(False, i)
|
|
||||||
if self.list.get_count() > 0:
|
|
||||||
self.list.select_item(0)
|
|
||||||
self.list.list.SetSize(self.list.list.GetBestSize())
|
|
||||||
|
|
||||||
def ok(self, ev):
|
|
||||||
if self.list.get_count() == 0:
|
|
||||||
wx.MessageDialog(None, _(u"You need to configure an account."), _(u"Account Error"), wx.ICON_ERROR).ShowModal()
|
|
||||||
return
|
|
||||||
self.controller.do_ok()
|
|
||||||
self.EndModal(wx.ID_OK)
|
|
||||||
|
|
||||||
def new_account_dialog(self):
|
|
||||||
return wx.MessageDialog(self, _(u"Would you like to autorhise a new account now?"), _(u"Authorisation"), wx.YES_NO).ShowModal()
|
|
||||||
|
|
||||||
def add_new_session_to_list(self):
|
|
||||||
total = self.list.get_count()
|
|
||||||
name = _(u"Authorised account %d") % (total+1)
|
|
||||||
self.list.insert_item(False, name)
|
|
||||||
if self.list.get_count() == 1:
|
|
||||||
self.list.select_item(0)
|
|
||||||
|
|
||||||
def remove_account_dialog(self):
|
|
||||||
return wx.MessageDialog(self, _(u"Do you really want delete this account?"), _(u"Remove account"), wx.YES_NO).ShowModal()
|
|
||||||
|
|
||||||
def get_selected(self):
|
|
||||||
return self.list.get_selected()
|
|
||||||
|
|
||||||
def remove_session(self, sessionID):
|
|
||||||
self.list.remove_item(sessionID)
|
|
||||||
|
|
||||||
class newSessionDialog(widgetUtils.BaseDialog):
|
class newSessionDialog(widgetUtils.BaseDialog):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user