diff --git a/src/extra/autocompletionUsers/manage.py b/src/extra/autocompletionUsers/manage.py new file mode 100644 index 00000000..d0e8b42c --- /dev/null +++ b/src/extra/autocompletionUsers/manage.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +import storage +import wx +import wx_manage + +class autocompletionManage(object): + def __init__(self, window): + super(autocompletionManage, self).__init__() + self.window = window + self.dialog = wx_manage.autocompletionManageDialog() + self.database = storage.storage() + self.users = self.database.get_all_users() + self.dialog.put_users(self.users) + self.dialog.add.Bind(wx.EVT_BUTTON, self.add_user) + self.dialog.remove.Bind(wx.EVT_BUTTON, self.remove_user) + self.dialog.ShowModal() + + def update_list(self): + item = self.dialog.users.get_selected() + self.dialog.users.clear() + self.users = self.database.get_all_users() + self.dialog.put_users(self.users) + self.dialog.users.select_item(item) + + def add_user(self, event=None): + usr = self.dialog.get_user() + if usr == False: + return + try: + data = self.window.twitter.twitter.show_user(screen_name=usr) + except: + self.dialog.show_invalid_user_error() + return + self.database.set_user(data["screen_name"], data["name"], 0) + self.update_list() + + def remove_user(self, ev): + ask = wx.MessageDialog(None, _(u"Are you sure you want to delete this user from the database? This user will not appear on the autocomplete results anymore."), _(u"Confirm"), wx.YES_NO|wx.ICON_QUESTION) + if ask.ShowModal() == wx.ID_YES: + item = self.dialog.users.get_selected() + user = self.users[item] + self.database.remove_user(user[0]) + self.update_list() \ No newline at end of file diff --git a/src/extra/autocompletionUsers/settings.py b/src/extra/autocompletionUsers/settings.py index 92cf4257..4d57ed6e 100644 --- a/src/extra/autocompletionUsers/settings.py +++ b/src/extra/autocompletionUsers/settings.py @@ -3,6 +3,7 @@ import storage import wx import config import wx_settings +import manage import output from mysc.thread_utils import call_threaded @@ -13,6 +14,7 @@ class autocompletionSettings(object): self.dialog = wx_settings.autocompletionSettingsDialog() self.dialog.friends_buffer.SetValue(config.main["mysc"]["save_friends_in_autocompletion_db"]) self.dialog.followers_buffer.SetValue(config.main["mysc"]["save_followers_in_autocompletion_db"]) + self.dialog.viewList.Bind(wx.EVT_BUTTON, self.view_list) if self.dialog.ShowModal() == wx.ID_OK: call_threaded(self.add_users_to_database) @@ -36,6 +38,10 @@ class autocompletionSettings(object): wx_settings.show_success_dialog() self.dialog.Destroy() + def view_list(self, ev): + q = manage.autocompletionManage(self.window) + + def execute_at_startup(window): database = storage.storage() if config.main["mysc"]["save_followers_in_autocompletion_db"] == True: diff --git a/src/extra/autocompletionUsers/storage.py b/src/extra/autocompletionUsers/storage.py index a2af1c1e..477608e5 100644 --- a/src/extra/autocompletionUsers/storage.py +++ b/src/extra/autocompletionUsers/storage.py @@ -17,6 +17,10 @@ class storage(object): else: return True + def get_all_users(self): + self.cursor.execute("""select * from users""") + return self.cursor.fetchall() + def get_users(self, term): self.cursor.execute("""SELECT * FROM users WHERE user LIKE ?""", ('{}%'.format(term),)) return self.cursor.fetchall() diff --git a/src/extra/autocompletionUsers/wx_manage.py b/src/extra/autocompletionUsers/wx_manage.py new file mode 100644 index 00000000..93fa0deb --- /dev/null +++ b/src/extra/autocompletionUsers/wx_manage.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +import wx +from multiplatform_widgets import widgets + +class autocompletionManageDialog(wx.Dialog): + def __init__(self): + super(autocompletionManageDialog, self).__init__(parent=None, id=-1, title=_(u"Manage Autocomplete users’ database")) + panel = wx.Panel(self) + sizer = wx.BoxSizer(wx.VERTICAL) + label = wx.StaticText(panel, -1, _(u"Users in your database")) + self.users = widgets.list(panel, _(u"Username"), _(u"Name"), style=wx.LC_REPORT) + sizer.Add(label, 0, wx.ALL, 5) + sizer.Add(self.users.list, 0, wx.ALL, 5) + self.add = wx.Button(panel, -1, _(u"Add new user")) + self.remove = wx.Button(panel, -1, _(u"Remove user")) + optionsBox = wx.BoxSizer(wx.HORIZONTAL) + optionsBox.Add(self.add, 0, wx.ALL, 5) + optionsBox.Add(self.remove, 0, wx.ALL, 5) + sizer.Add(optionsBox, 0, wx.ALL, 5) + ok = wx.Button(panel, wx.ID_OK) + cancel = wx.Button(panel, wx.ID_CANCEL) + sizerBtn = wx.BoxSizer(wx.HORIZONTAL) + sizerBtn.Add(ok, 0, wx.ALL, 5) + sizer.Add(cancel, 0, wx.ALL, 5) + sizer.Add(sizerBtn, 0, wx.ALL, 5) + panel.SetSizer(sizer) + self.SetClientSize(sizer.CalcMin()) + + def put_users(self, users): + for i in users: + j = [i[0], i[1]] + self.users.insert_item(False, *j) + + def get_user(self): + usr = False + userDlg = wx.TextEntryDialog(None, _(u"Twitter username"), _(u"Add user to database")) + if userDlg.ShowModal() == wx.ID_OK: + usr = userDlg.GetValue() + return usr + + def show_invalid_user_error(self): + wx.MessageDialog(None, _(u"The user does not exist"), _(u"Error!"), wx.ICON_ERROR).ShowModal() \ No newline at end of file diff --git a/src/extra/autocompletionUsers/wx_settings.py b/src/extra/autocompletionUsers/wx_settings.py index f4be9212..e50416a2 100644 --- a/src/extra/autocompletionUsers/wx_settings.py +++ b/src/extra/autocompletionUsers/wx_settings.py @@ -10,6 +10,8 @@ class autocompletionSettingsDialog(wx.Dialog): self.friends_buffer = wx.CheckBox(panel, -1, _(u"Add users from friends buffer")) sizer.Add(self.followers_buffer, 0, wx.ALL, 5) sizer.Add(self.friends_buffer, 0, wx.ALL, 5) + self.viewList = wx.Button(panel, -1, _(u"See the user list")) + sizer.Add(self.viewList, 0, wx.ALL, 5) ok = wx.Button(panel, wx.ID_OK) cancel = wx.Button(panel, wx.ID_CANCEL) sizerBtn = wx.BoxSizer(wx.HORIZONTAL)