This commit is contained in:
jmdaweb 2014-11-27 22:05:21 +01:00
commit 2b3e1099f6
13 changed files with 222 additions and 59 deletions

View File

@ -297,14 +297,21 @@ class basePanel(wx.Panel):
ev.Skip()
return
if event == "audio" and len(urls) > 0:
if len(urls) == 1:
self.streamer(urls[0])
elif len(urls) > 1:
urlList = gui.dialogs.urlList.urlList(urls)
if urlList.ShowModal() == wx.ID_OK:
self.streamer(urls[urlList.lista.GetSelection()])
elif event == "url":
if len(urls) == 0: return
elif len(urls) == 1:
output.speak(_(u"Opening URL..."), True)
webbrowser.open(urls[0])
elif len(urls) > 1:
gui.dialogs.urlList.urlList(urls).ShowModal()
urlList = gui.dialogs.urlList.urlList(urls)
if urlList.ShowModal() == wx.ID_OK:
webbrowser.open_new_tab(urls[urlList.lista.GetSelection()])
elif event == "volume_down":
if config.main["sound"]["volume"] > 0.05:
config.main["sound"]["volume"] = config.main["sound"]["volume"]-0.05

View File

@ -30,6 +30,7 @@ class dmPanel(basePanel):
super(dmPanel, self).__init__(parent, window, name_buffer, function, argumento=argumento, sound=sound)
self.retweetBtn.Disable()
self.responseBtn.Disable()
self.type = "direct_message"
def destroy_status(self, ev):
index = self.list.get_selected()

View File

@ -140,3 +140,9 @@ class peoplePanel(basePanel):
def remove_buffer(self):
pos = None
return pos
def get_message(self, dialog=False):
if dialog == False: return " ".join(self.compose_function(self.db.settings[self.name_buffer][self.list.get_selected()], self.db))
else:
list = self.compose_function(self.db.settings[self.name_buffer][self.list.get_selected()], self.db)
return " ".join(list)

View File

@ -40,7 +40,7 @@ class searchUsersPanel(peoplePanel):
self.create_list()
self.args = args
self.kwargs = kwargs
self.type = "timeline"
self.type = "user_search"
def start_streams(self):
num = twitter.starting.search_users(self.db, self.twitter, self.name_buffer, **self.kwargs)

View File

@ -342,10 +342,10 @@ class reply(tweet):
class viewTweet(wx.Dialog):
def __init__(self, tweet):
super(viewTweet, self).__init__(None, size=(850,850))
self.SetTitle(_(u"Tweet - %i characters ") % (len(tweet)))
self.SetTitle(_(u"Tweet - %i characters ") % (len(tweet["text"])))
panel = wx.Panel(self)
label = wx.StaticText(panel, -1, _(u"Tweet"))
self.text = wx.TextCtrl(panel, -1, tweet, style=wx.TE_READONLY|wx.TE_MULTILINE, size=(250, 180))
self.text = wx.TextCtrl(panel, -1, tweet["text"], style=wx.TE_READONLY|wx.TE_MULTILINE, size=(250, 180))
dc = wx.WindowDC(self.text)
dc.SetFont(self.text.GetFont())
(x, y, z) = dc.GetMultiLineTextExtent("0"*140)
@ -356,6 +356,20 @@ class viewTweet(wx.Dialog):
textBox.Add(self.text, 1, wx.EXPAND, 5)
mainBox = wx.BoxSizer(wx.VERTICAL)
mainBox.Add(textBox, 0, wx.ALL, 5)
rtCountLabel = wx.StaticText(panel, -1, _(u"Retweets: "))
rtCount = wx.TextCtrl(panel, -1, str(tweet["retweet_count"]), size=wx.DefaultSize, style=wx.TE_READONLY|wx.TE_MULTILINE)
rtBox = wx.BoxSizer(wx.HORIZONTAL)
rtBox.Add(rtCountLabel, 0, wx.ALL, 5)
rtBox.Add(rtCount, 0, wx.ALL, 5)
favsCountLabel = wx.StaticText(panel, -1, _(u"Favourites: "))
favsCount = wx.TextCtrl(panel, -1, str(tweet["favorite_count"]), size=wx.DefaultSize, style=wx.TE_READONLY|wx.TE_MULTILINE)
favsBox = wx.BoxSizer(wx.HORIZONTAL)
favsBox.Add(favsCountLabel, 0, wx.ALL, 5)
favsBox.Add(favsCount, 0, wx.ALL, 5)
infoBox = wx.BoxSizer(wx.HORIZONTAL)
infoBox.Add(rtBox, 0, wx.ALL, 5)
infoBox.Add(favsBox, 0, wx.ALL, 5)
mainBox.Add(infoBox, 0, wx.ALL, 5)
if platform.system() != "Darwin":
spellcheck = wx.Button(panel, -1, _("Spelling correction"), size=wx.DefaultSize)
spellcheck.Bind(wx.EVT_BUTTON, self.onCheck)
@ -427,3 +441,87 @@ class viewTweet(wx.Dialog):
urlList.unshorten(urls, self).ShowModal()
self.text.SetFocus()
class viewNonTweet(wx.Dialog):
def __init__(self, tweet):
super(viewNonTweet, self).__init__(None, size=(850,850))
self.SetTitle(_(u"View"))
panel = wx.Panel(self)
label = wx.StaticText(panel, -1, _(u"Item"))
self.text = wx.TextCtrl(parent=panel, id=-1, value=tweet, style=wx.TE_READONLY|wx.TE_MULTILINE, size=(250, 180))
dc = wx.WindowDC(self.text)
dc.SetFont(self.text.GetFont())
(x, y, z) = dc.GetMultiLineTextExtent("0"*140)
self.text.SetSize((x, y))
self.text.SetFocus()
textBox = wx.BoxSizer(wx.HORIZONTAL)
textBox.Add(label, 0, wx.ALL, 5)
textBox.Add(self.text, 1, wx.EXPAND, 5)
mainBox = wx.BoxSizer(wx.VERTICAL)
mainBox.Add(textBox, 0, wx.ALL, 5)
spellcheck = wx.Button(panel, -1, _("Spelling correction"), size=wx.DefaultSize)
spellcheck.Bind(wx.EVT_BUTTON, self.onCheck)
self.unshortenButton = wx.Button(panel, -1, _(u"Expand URL"), size=wx.DefaultSize)
self.unshortenButton.Bind(wx.EVT_BUTTON, self.onUnshorten)
self.unshortenButton.Disable()
translateButton = wx.Button(panel, -1, _(u"Translate message"), size=wx.DefaultSize)
translateButton.Bind(wx.EVT_BUTTON, self.onTranslate)
cancelButton = wx.Button(panel, wx.ID_CANCEL, _(u"Close"), size=wx.DefaultSize)
cancelButton.SetDefault()
buttonsBox = wx.BoxSizer(wx.HORIZONTAL)
buttonsBox.Add(spellcheck, 0, wx.ALL, 5)
buttonsBox.Add(self.unshortenButton, 0, wx.ALL, 5)
buttonsBox.Add(translateButton, 0, wx.ALL, 5)
buttonsBox.Add(cancelButton, 0, wx.ALL, 5)
mainBox.Add(buttonsBox, 0, wx.ALL, 5)
selectId = wx.NewId()
self.Bind(wx.EVT_MENU, self.onSelect, id=selectId)
self.accel_tbl = wx.AcceleratorTable([
(wx.ACCEL_CTRL, ord('A'), selectId),
])
self.SetAcceleratorTable(self.accel_tbl)
panel.SetSizer(mainBox)
self.SetClientSize(mainBox.CalcMin())
self.check_urls()
def check_urls(self):
if len(twitter.utils.find_urls_in_text(self.text.GetValue())) > 0:
self.unshortenButton.Enable()
def onCheck(self, ev):
text = self.text.GetValue()
dlg = spellCheckerGUI.spellCheckerDialog(text, "")
if dlg.ShowModal() == wx.ID_OK:
self.text.ChangeValue(dlg.checker.get_text())
dlg.Destroy()
def onTranslate(self, ev):
dlg = translator.gui.translateDialog()
selection = dlg.ShowModal()
if selection != wx.ID_CANCEL:
text_to_translate = self.text.GetValue().encode("utf-8")
source = [x[0] for x in translator.available_languages()][dlg.source_lang.GetSelection()]
dest = [x[0] for x in translator.available_languages()][dlg.dest_lang.GetSelection()]
t = translator.translator.Translator()
t.from_lang = source
t.to_lang = dest
msg = t.translate(text_to_translate)
self.text.ChangeValue(msg)
output.speak(_(u"Translated"))
self.text.SetFocus()
else:
return
dlg.Destroy()
def onSelect(self, ev):
self.text.SelectAll()
def onUnshorten(self, ev):
urls = twitter.utils.find_urls_in_text(self.text.GetValue())
if len(urls) == 0:
output.speak(_(u"There's no URL to be expanded"))
elif len(urls) == 1:
self.text.SetValue(self.text.GetValue().replace(urls[0], url_shortener.unshorten(urls[0])))
output.speak(_(u"URL expanded"))
elif len(urls) > 1:
urlList.unshorten(urls, self).ShowModal()
self.text.SetFocus()

View File

@ -46,8 +46,7 @@ class urlList(wx.Dialog):
self.SetClientSize(sizer.CalcMin())
def onGo(self, ev):
webbrowser.open(self.lista.GetStringSelection())
self.Destroy()
self.EndModal(wx.ID_OK)
def populate_list(self):
for i in self.urls:

View File

@ -32,6 +32,7 @@ import output
import platform
import urllib2
import sysTrayIcon
import switchModule
import languageHandler
from sessionmanager import manager
from mysc import event
@ -56,6 +57,8 @@ class mainFrame(wx.Frame):
# Application menu
app = wx.Menu()
switch_account = app.Append(wx.NewId(), _(u"S&witch account"))
self.Bind(wx.EVT_MENU, self.switch_account)
updateProfile = app.Append(wx.NewId(), _(u"&Update profile"))
self.Bind(wx.EVT_MENU, self.update_profile, updateProfile)
show_hide = app.Append(wx.NewId(), _(u"&Hide window"))
@ -501,7 +504,7 @@ class mainFrame(wx.Frame):
dlg = dialogs.lists.removeUserListDialog(self)
if dlg.ShowModal() == wx.ID_OK:
try:
list = self.twitter.twitter.delete_list_member(list_id=self.db.settings["lists"][dlg.get_selected()]["id"], screen_name=user)
list = self.twitter.twitter.delete_list_member(list_id=self.db.settings["lists"][dlg.lista.get_selected()]["id"], screen_name=user)
older_list = twitter.utils.find_item(self.db.settings["lists"][dlg.get_selected()]["id"], self.db.settings["lists"])
if list["mode"] == "private":
self.db.settings["lists"].pop(older_list)
@ -662,8 +665,18 @@ class mainFrame(wx.Frame):
self.nb.GetCurrentPage().onRetweet(ev)
def view(self, ev=None):
tweet = self.nb.GetCurrentPage().get_message(dialog=True)
tp = self.nb.GetCurrentPage().type
if tp == "buffer" or tp == "timeline" or tp == "favourites_timeline" or tp == "list" or tp == "search":
try:
id = self.db.settings[self.nb.GetCurrentPage().name_buffer][self.nb.GetCurrentPage().list.get_selected()]["id"]
tweet = self.twitter.twitter.show_status(id=id)
dialogs.message.viewTweet(tweet).ShowModal()
except TwythonError as e:
non_tweet = self.nb.GetCurrentPage().get_message(dialog=True)
dialogs.message.viewNonTweet(non_tweet).ShowModal()
else:
non_tweet = self.nb.GetCurrentPage().get_message(dialog=True)
dialogs.message.viewNonTweet(non_tweet).ShowModal()
def fav(self, ev=None):
if self.nb.GetCurrentPage().name_buffer != "direct_messages" and self.nb.GetCurrentPage().name_buffer != "followers" and self.nb.GetCurrentPage().name_buffer != "friends":
@ -960,6 +973,9 @@ class mainFrame(wx.Frame):
return page
return page
def switch_account(self, ev):
switchModule.switcher(self)
### Close App
def Destroy(self):
self.sysTray.Destroy()

23
src/gui/switchModule.py Normal file
View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
import wx
import gui
import config
from sessionmanager import gui as sessionManagerUI
class switcher(object):
def __init__(self, window):
self.hold_window = window
self.hold_window.Hide()
sessionManagerWindow = sessionManagerUI.sessionManagerWindow()
if sessionManagerWindow.ShowModal() == wx.ID_OK:
self.hold_window.Destroy()
self.window = gui.main.mainFrame()
self.window.Show()
self.window.showing = True
if config.main != None and config.main["general"]["hide_gui"] == True:
self.window.show_hide()
self.window.Hide()
wx.GetApp().SetTopWindow(self.window)
else:
self.window.Show()

View File

@ -55,7 +55,7 @@ class SysTrayIcon(wx.TaskBarIcon):
if (self.frame.showing):
self.frame.SetFocus()
else:
self.frame.onShow_hide()
self.frame.show_hide()
def Destroy(self):
self.menu.Destroy()

View File

@ -20,56 +20,53 @@ A twitter accessible, easy of use and cross platform application."""
#
############################################################
import wx
import os
ssmg = None
import gui
import paths
import config
import commandline
import platform
if platform.system() == "Windows":
from logger import logger as logging
if platform.system() == "Darwin":
import osx_prepare
osx_prepare.setup()
from logger import logger as logging
from sessionmanager import manager
from sessionmanager import gui as smGUI
manager.setup()
import sys
import config
import output
import sound
import languageHandler
if hasattr(sys, 'frozen'):
sys.stderr = open(paths.logs_path("stderr.log"), 'w')
sys.stdout = open(paths.logs_path("stdout.log"), 'w')
class app(wx.App):
def __init__(self, *args, **kwargs):
super(app, self).__init__(*args, **kwargs)
if platform.system() != "Darwin":
self.start()
else:
self.mac()
def mac(self):
self.hold_frame = wx.Frame(title="None", parent=None)
self.hold_frame.Show()
wx.CallLater(10, self.start)
def start(self):
app = wx.App()
configured = False
configs = []
for i in os.listdir(paths.config_path()):
if os.path.isdir(paths.config_path(i)): configs.append(i)
if len(configs) == 1:
manager.manager.set_current_session(configs[0])
config.MAINFILE = "%s/session.conf" % (manager.manager.get_current_session())
config.setup()
lang=config.main['general']['language']
languageHandler.setLanguage(lang)
sound.setup()
output.setup()
configured = True
else:
ssmg = smGUI.sessionManagerWindow()
if ssmg.ShowModal() == wx.ID_OK:
if configured == True or ssmg.ShowModal() == wx.ID_OK:
frame = gui.main.mainFrame()
frame.Show()
frame.showing = True
if config.main != None and config.main["general"]["hide_gui"] == True and platform.system() == "Windows":
frame.show_hide()
frame.Hide()
self.SetTopWindow(frame)
if hasattr(self, "frame"): self.hold_frame.Hide()
# If the user press on cancel.
else:
self.Exit()
ap = app()
app.SetTopWindow(frame)
else:
app.Exit()
### I should uncomment this
#if platform.system() != "Windows":
# local = wx.Locale(wx.LANGUAGE_DEFAULT)
@ -77,5 +74,5 @@ ap = app()
# local.AddCatalog("twblue")
#ap = app(redirect=True, useBestVisual=True, filename=paths.logs_path('tracebacks.log'))
#wx.CallLater(10, start)
ap.MainLoop()
app.MainLoop()

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import shutil
import time
import wx
import manager
@ -23,28 +24,26 @@ class sessionManagerWindow(wx.Dialog):
label = wx.StaticText(panel, -1, _(u"Select a twitter account to start TW Blue"), size=wx.DefaultSize)
listSizer = wx.BoxSizer(wx.HORIZONTAL)
self.list = widgets.list(panel, _(u"Account"), style=wx.LC_SINGLE_SEL|wx.LC_REPORT)
self.fill_list()
listSizer.Add(label, 0, wx.ALL, 5)
listSizer.Add(self.list.list, 0, wx.ALL, 5)
sizer.Add(listSizer, 0, wx.ALL, 5)
new = wx.Button(panel, -1, _(u"New account"), size=wx.DefaultSize)
new.Bind(wx.EVT_BUTTON, self.new_account)
self.removeSession = wx.Button(panel, -1, _(u"Remove session"))
self.removeSession.Disable()
self.removeSession.Bind(wx.EVT_BUTTON, self.remove)
ok = wx.Button(panel, wx.ID_OK, size=wx.DefaultSize)
ok.SetDefault()
ok.Bind(wx.EVT_BUTTON, self.ok)
cancel = wx.Button(panel, wx.ID_CANCEL, size=wx.DefaultSize)
buttons = wx.BoxSizer(wx.HORIZONTAL)
buttons.Add(new, 0, wx.ALL, 5)
buttons.Add(self.removeSession, 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)
# sizer.Layout()
# self.Fit()
# self.SetSize(panel.GetBestSize())
# panelSizer.Add(panel)
# self.SetSizerAndFit(sizer)
# sizer.Layout()
self.fill_list()
min = sizer.CalcMin()
self.SetClientSize(min)
@ -55,12 +54,16 @@ class sessionManagerWindow(wx.Dialog):
strconfig = "%s/session.conf" % (paths.config_path(i))
config_test = Configuration(strconfig)
name = config_test["twitter"]["user_name"]
if name != "" and config_test["twitter"]["user_key"] != "" and config_test["twitter"]["user_secret"] != "":
if name != "" or (config_test["twitter"]["user_key"] != "" and config_test["twitter"]["user_secret"] != ""):
self.list.insert_item(False, name)
self.sessions.append(i)
else:
del config_test
shutil.rmtree(path=paths.config_path(i), ignore_errors=True)
if self.list.get_count() > 0:
self.list.select_item(0)
self.list.list.SetSize(self.list.list.GetBestSize())
self.removeSession.Enable()
def ok(self, ev):
if self.list.get_count() == 0:
@ -74,8 +77,6 @@ class sessionManagerWindow(wx.Dialog):
languageHandler.setLanguage(lang)
sound.setup()
output.setup()
# else:
# self.name = current_session
self.EndModal(wx.ID_OK)
def new_account(self, ev):
@ -99,3 +100,12 @@ class sessionManagerWindow(wx.Dialog):
if self.list.get_count() == 1:
self.list.select_item(0)
self.sessions.append(location)
def remove(self, ev):
selected_item = self.list.get_selected()
selected_session = self.sessions[selected_item]
ask = wx.MessageDialog(self, _(u"Do you really want delete this account?"), _(u"Remove account"), wx.YES_NO)
if ask.ShowModal() == wx.ID_YES:
self.sessions.remove(selected_session)
shutil.rmtree(path=paths.config_path(selected_session), ignore_errors=True)
self.list.remove_item(selected_item)

View File

@ -34,6 +34,10 @@ class streamer(TwythonStreamer):
tweet_event.SetItem(data)
announce = _(u"One tweet from %s in the list %s") % (data["user"]["name"], self.parent.nb.GetPage(i).name_buffer[:-5])
tweet_event.SetAnnounce(announce)
usr = data["in_reply_to_user_id"]
if (usr != None and usr in self.friends) or data.has_key("retweeted_status"):
wx.PostEvent(self.parent.nb.GetPage(i), tweet_event)
elif usr == None:
wx.PostEvent(self.parent.nb.GetPage(i), tweet_event)
except ValueError:
pass
@ -42,5 +46,7 @@ class streamer(TwythonStreamer):
try:
if data.has_key("text"):
self.check_tls(data)
elif "friends" in data:
self.friends = data["friends"]
except:
pass

View File

@ -68,7 +68,7 @@ class streamer(TwythonStreamer):
tweet_event.SetItem(data["direct_message"])
text = _(u"One direct message")
tweet_event.SetAnnounce(text)
wx.PostEvent(self.parent.search_buffer("buffer", "direct_messages"), tweet_event)
wx.PostEvent(self.parent.search_buffer("direct_message", "direct_messages"), tweet_event)
def check_follower(self, data):
if data["target"]["screen_name"] == self.db.settings["user_name"] and config.main["other_buffers"]["show_followers"] == True: