mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 19:28:09 -06:00
Autocompletion works for the recipient in a direct message
This commit is contained in:
parent
4f4b8c6447
commit
4465f6e8aa
@ -141,6 +141,11 @@ class reply(tweet):
|
||||
class dm(basicTweet):
|
||||
def __init__(self, session, title, caption, text):
|
||||
super(dm, self).__init__(session, title, caption, text, messageType="dm")
|
||||
widgetUtils.connect_event(self.message.autocompletionButton, widgetUtils.BUTTON_PRESSED, self.autocomplete_users)
|
||||
|
||||
def autocomplete_users(self, *args, **kwargs):
|
||||
c = autocompletionUsers.completion.autocompletionUsers(self.message, self.session.session_id)
|
||||
c.show_menu("dm")
|
||||
|
||||
class viewTweet(basicTweet):
|
||||
def __init__(self, tweet, is_tweet=True):
|
||||
|
@ -9,23 +9,39 @@ class autocompletionUsers(object):
|
||||
self.window = window
|
||||
self.db = storage.storage(session_id)
|
||||
|
||||
def show_menu(self):
|
||||
def show_menu(self, mode="tweet"):
|
||||
position = self.window.get_position()
|
||||
text = self.window.get_text()
|
||||
text = text[:position]
|
||||
try:
|
||||
pattern = text.split()[-1]
|
||||
except IndexError:
|
||||
output.speak(_(u"You have to start writing"))
|
||||
return
|
||||
if pattern.startswith("@") == True:
|
||||
menu = wx_menu.menu(self.window.text, pattern[1:])
|
||||
users = self.db.get_users(pattern[1:])
|
||||
if mode == "tweet":
|
||||
text = self.window.get_text()
|
||||
text = text[:position]
|
||||
try:
|
||||
pattern = text.split()[-1]
|
||||
except IndexError:
|
||||
output.speak(_(u"You have to start writing"))
|
||||
return
|
||||
if pattern.startswith("@") == True:
|
||||
menu = wx_menu.menu(self.window.text, pattern[1:], mode=mode)
|
||||
users = self.db.get_users(pattern[1:])
|
||||
if len(users) > 0:
|
||||
menu.append_options(users)
|
||||
self.window.popup_menu(menu)
|
||||
menu.destroy()
|
||||
else:
|
||||
output.speak(_(u"There are no results in your users database"))
|
||||
else:
|
||||
output.speak(_(u"Autocompletion only works for users."))
|
||||
elif mode == "dm":
|
||||
text = self.window.get_user()
|
||||
try:
|
||||
pattern = text.split()[-1]
|
||||
except IndexError:
|
||||
output.speak(_(u"You have to start writing"))
|
||||
return
|
||||
menu = wx_menu.menu(self.window.cb, pattern, mode=mode)
|
||||
users = self.db.get_users(pattern)
|
||||
if len(users) > 0:
|
||||
menu.append_options(users)
|
||||
self.window.popup_menu(menu)
|
||||
menu.destroy()
|
||||
else:
|
||||
output.speak(_(u"There are no results in your users database"))
|
||||
else:
|
||||
output.speak(_(u"Autocompletion only works for users."))
|
||||
output.speak(_(u"There are no results in your users database"))
|
@ -2,10 +2,11 @@
|
||||
import wx
|
||||
|
||||
class menu(wx.Menu):
|
||||
def __init__(self, window, pattern):
|
||||
def __init__(self, window, pattern, mode):
|
||||
super(menu, self).__init__()
|
||||
self.window = window
|
||||
self.pattern = pattern
|
||||
self.mode = mode
|
||||
|
||||
def append_options(self, options):
|
||||
for i in options:
|
||||
@ -14,7 +15,10 @@ class menu(wx.Menu):
|
||||
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+" "))
|
||||
if self.mode == "tweet":
|
||||
self.window.ChangeValue(self.window.GetValue().replace("@"+self.pattern, "@"+text+" "))
|
||||
elif self.mode == "dm":
|
||||
self.window.SetValue(self.window.GetValue().replace(self.pattern, text))
|
||||
self.window.SetInsertionPointEnd()
|
||||
|
||||
def destroy(self):
|
||||
|
@ -114,8 +114,14 @@ class dm(textLimited):
|
||||
self.mainBox = wx.BoxSizer(wx.VERTICAL)
|
||||
label = wx.StaticText(self.panel, -1, _(u"Recipient"))
|
||||
self.cb = wx.ComboBox(self.panel, -1, choices=users, value=users[0], size=wx.DefaultSize)
|
||||
self.autocompletionButton = wx.Button(self.panel, -1, _(u"&Autocomplete users"))
|
||||
self.createTextArea(message, text="")
|
||||
self.mainBox.Add(self.cb, 0, wx.ALL, 5)
|
||||
userBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
userBox.Add(label, 0, wx.ALL, 5)
|
||||
userBox.Add(self.cb, 0, wx.ALL, 5)
|
||||
userBox.Add(self.autocompletionButton, 0, wx.ALL, 5)
|
||||
self.mainBox.Add(userBox, 0, wx.ALL, 5)
|
||||
# self.mainBox.Add(self.cb, 0, wx.ALL, 5)
|
||||
self.mainBox.Add(self.textBox, 0, wx.ALL, 5)
|
||||
self.spellcheck = wx.Button(self.panel, -1, _("Spelling correction"), size=wx.DefaultSize)
|
||||
self.attach = wx.Button(self.panel, -1, _(u"Attach audio"), size=wx.DefaultSize)
|
||||
@ -150,7 +156,10 @@ class dm(textLimited):
|
||||
|
||||
def get_user(self):
|
||||
return self.cb.GetValue()
|
||||
|
||||
|
||||
def set_user(self, user):
|
||||
return self.cb.SetValue(user)
|
||||
|
||||
class reply(tweet):
|
||||
def __init__(self, title, message, text):
|
||||
super(reply, self).__init__(message, title, text)
|
||||
|
Loading…
Reference in New Issue
Block a user