2015-01-27 17:09:28 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import widgetUtils
|
2021-10-28 13:18:02 -05:00
|
|
|
from tweepy.errors import TweepyException
|
2021-02-04 12:30:20 -06:00
|
|
|
from . import storage, wx_manage
|
2015-01-27 17:09:28 -06:00
|
|
|
from wxUI import commonMessageDialogs
|
|
|
|
|
|
|
|
class autocompletionManage(object):
|
2021-06-16 16:18:41 -05:00
|
|
|
def __init__(self, session):
|
|
|
|
super(autocompletionManage, self).__init__()
|
|
|
|
self.session = session
|
|
|
|
self.dialog = wx_manage.autocompletionManageDialog()
|
|
|
|
self.database = storage.storage(self.session.session_id)
|
|
|
|
self.users = self.database.get_all_users()
|
|
|
|
self.dialog.put_users(self.users)
|
|
|
|
widgetUtils.connect_event(self.dialog.add, widgetUtils.BUTTON_PRESSED, self.add_user)
|
|
|
|
widgetUtils.connect_event(self.dialog.remove, widgetUtils.BUTTON_PRESSED, self.remove_user)
|
|
|
|
self.dialog.get_response()
|
2015-01-27 17:09:28 -06:00
|
|
|
|
2021-06-16 16:18:41 -05:00
|
|
|
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)
|
2015-01-27 17:09:28 -06:00
|
|
|
|
2021-06-16 16:18:41 -05:00
|
|
|
def add_user(self, *args, **kwargs):
|
|
|
|
usr = self.dialog.get_user()
|
|
|
|
if usr == False:
|
|
|
|
return
|
|
|
|
try:
|
2021-10-28 13:18:02 -05:00
|
|
|
data = self.session.twitter.get_user(screen_name=usr)
|
|
|
|
except TweepyException as e:
|
|
|
|
log.exception("Exception raised when attempting to add an user to the autocomplete database manually.")
|
2021-06-16 16:18:41 -05:00
|
|
|
self.dialog.show_invalid_user_error()
|
|
|
|
return
|
|
|
|
self.database.set_user(data.screen_name, data.name, 0)
|
|
|
|
self.update_list()
|
2015-01-27 17:09:28 -06:00
|
|
|
|
2021-06-16 16:18:41 -05:00
|
|
|
def remove_user(self, ev):
|
|
|
|
if commonMessageDialogs.delete_user_from_db() == widgetUtils.YES:
|
|
|
|
item = self.dialog.users.get_selected()
|
|
|
|
user = self.users[item]
|
|
|
|
self.database.remove_user(user[0])
|
|
|
|
self.update_list()
|