mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-08-11 15:26:09 -04:00
Autocompletion for users has been implemented
This commit is contained in:
@@ -68,7 +68,8 @@ class audioDialog(wx.Dialog):
|
||||
services = []
|
||||
if config.main["services"]["dropbox_token"] != "":
|
||||
services.append("Dropbox")
|
||||
services.append("SNDUp")
|
||||
service.append("TwUp")
|
||||
services.append("SNDUp")
|
||||
return services
|
||||
|
||||
def onPause(self, ev):
|
||||
|
1
src/extra/autocompletionUsers/__init__.py
Normal file
1
src/extra/autocompletionUsers/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
31
src/extra/autocompletionUsers/completion.py
Normal file
31
src/extra/autocompletionUsers/completion.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import storage
|
||||
import output
|
||||
import wx_menu
|
||||
|
||||
class autocompletionUsers(object):
|
||||
def __init__(self, window):
|
||||
super(autocompletionUsers, self).__init__()
|
||||
self.window = window
|
||||
|
||||
def show_menu(self):
|
||||
position = self.window.text.GetInsertionPoint()
|
||||
text = self.window.text.GetValue()
|
||||
text = text[:position]
|
||||
try:
|
||||
pattern = text.split()[-1]
|
||||
except IndexError:
|
||||
output.speak(_(u"You have to start to write"))
|
||||
return
|
||||
if pattern.startswith("@") == True:
|
||||
db = storage.storage()
|
||||
menu = wx_menu.menu(self.window.text, pattern[1:])
|
||||
users = db.get_users(pattern[1:])
|
||||
if len(users) > 0:
|
||||
menu.append_options(users)
|
||||
self.window.PopupMenu(menu, self.window.text.GetPosition())
|
||||
menu.Destroy()
|
||||
else:
|
||||
output.speak(_(u"There is not results in your users database"))
|
||||
else:
|
||||
output.speak(_(u"Autocompletion only works for users."))
|
29
src/extra/autocompletionUsers/settings.py
Normal file
29
src/extra/autocompletionUsers/settings.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import storage
|
||||
import wx
|
||||
import wx_settings
|
||||
import output
|
||||
from mysc.thread_utils import call_threaded
|
||||
|
||||
class autocompletionSettings(object):
|
||||
def __init__(self, window):
|
||||
super(autocompletionSettings, self).__init__()
|
||||
self.window = window
|
||||
self.dialog = wx_settings.autocompletionSettingsDialog()
|
||||
if self.dialog.ShowModal() == wx.ID_OK:
|
||||
call_threaded(self.add_users_to_database)
|
||||
|
||||
def add_users_to_database(self):
|
||||
output.speak(_(u"Updating database... You can close this window now. A message will tell you when the process finishes."))
|
||||
database = storage.storage()
|
||||
if self.dialog.followers_buffer.GetValue() == True:
|
||||
buffer = self.window.search_buffer("people", "followers")
|
||||
for i in buffer.db.settings[buffer.name_buffer]:
|
||||
database.set_user(i["screen_name"], i["name"])
|
||||
if self.dialog.friends_buffer.GetValue() == True:
|
||||
buffer = self.window.search_buffer("people", "friends")
|
||||
for i in buffer.db.settings[buffer.name_buffer]:
|
||||
database.set_user(i["screen_name"], i["name"])
|
||||
wx_settings.show_success_dialog()
|
||||
self.dialog.Destroy()
|
||||
|
41
src/extra/autocompletionUsers/storage.py
Normal file
41
src/extra/autocompletionUsers/storage.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import sqlite3, paths
|
||||
from sessionmanager import manager
|
||||
|
||||
class storage(object):
|
||||
def __init__(self):
|
||||
self.connection = sqlite3.connect(paths.config_path("%s/autocompletionUsers.dat" % (manager.manager.get_current_session())))
|
||||
self.cursor = self.connection.cursor()
|
||||
if self.table_exist("users") == False:
|
||||
self.create_table()
|
||||
|
||||
def table_exist(self, table):
|
||||
ask = self.cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='%s'" % (table))
|
||||
answer = ask.fetchone()
|
||||
if answer == None:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def get_users(self, term):
|
||||
self.cursor.execute("""SELECT * FROM users WHERE user LIKE ?""", ('{}%'.format(term),))
|
||||
return self.cursor.fetchall()
|
||||
|
||||
def set_user(self, screen_name, user_name):
|
||||
self.cursor.execute("""insert or ignore into users values(?, ?)""", (screen_name, user_name))
|
||||
self.connection.commit()
|
||||
|
||||
def remove_user(self, user):
|
||||
self.cursor.execute("""DELETE FROM users WHERE user = ?""", (user,))
|
||||
return self.cursor.fetchone()
|
||||
|
||||
def create_table(self):
|
||||
self.cursor.execute("""
|
||||
create table users(
|
||||
user TEXT UNIQUE,
|
||||
name TEXT
|
||||
)""")
|
||||
|
||||
def __del__(self):
|
||||
self.cursor.close()
|
||||
self.connection.close()
|
18
src/extra/autocompletionUsers/wx_menu.py
Normal file
18
src/extra/autocompletionUsers/wx_menu.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import wx
|
||||
|
||||
class menu(wx.Menu):
|
||||
def __init__(self, window, pattern):
|
||||
super(menu, self).__init__()
|
||||
self.window = window
|
||||
self.pattern = pattern
|
||||
|
||||
def append_options(self, options):
|
||||
for i in options:
|
||||
item = wx.MenuItem(self, wx.NewId(), "%s (@%s)" % (i[1], i[0]))
|
||||
self.AppendItem(item)
|
||||
self.Bind(wx.EVT_MENU, lambda evt, temp=i[0]: self.select_text(evt, temp), item)
|
||||
|
||||
def select_text(self, ev, text):
|
||||
self.window.ChangeValue(self.window.GetValue().replace(self.pattern, text+" "))
|
||||
self.window.SetInsertionPointEnd()
|
23
src/extra/autocompletionUsers/wx_settings.py
Normal file
23
src/extra/autocompletionUsers/wx_settings.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import wx
|
||||
|
||||
class autocompletionSettingsDialog(wx.Dialog):
|
||||
def __init__(self):
|
||||
super(autocompletionSettingsDialog, self).__init__(parent=None, id=-1, title=_(u"Autocompletion settings"))
|
||||
panel = wx.Panel(self)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.followers_buffer = wx.CheckBox(panel, -1, _(u"Add users from followers buffer"))
|
||||
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)
|
||||
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 show_success_dialog():
|
||||
wx.MessageDialog(None, _(u"Users TwBlue-database has been updated with new users."), _(u"Done"), wx.OK).ShowModal()
|
Reference in New Issue
Block a user