Putting all the code from the current master branch of TWBlue

This commit is contained in:
2014-10-27 16:29:04 -06:00
parent 58c82e5486
commit 1af4a8b291
284 changed files with 58760 additions and 0 deletions

View File

@@ -0,0 +1 @@
import message, urlList, follow, utils, show_user, update_profile, configuration, lists, search

View File

@@ -0,0 +1,420 @@
# -*- coding: utf-8 -*-
############################################################
# Copyright (c) 2013, 2014 Manuel Eduardo Cortéz Vallejo <manuel@manuelcortez.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################
import wx
import config
#import gui
from gui import buffers
import sound as snd
import sound_lib
import languageHandler
import logging as original_logger
import os
import webbrowser
import paths
import platform
from mysc import restart
log = original_logger.getLogger("configuration")
system = platform.system()
class general(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
sizer = wx.BoxSizer(wx.VERTICAL)
language = wx.StaticText(self, -1, _(u"Language"))
self.langs = languageHandler.getAvailableLanguages()
langs = []
[langs.append(i[1]) for i in self.langs]
self.codes = []
[self.codes.append(i[0]) for i in self.langs]
self.language = wx.ListBox(self, -1, choices=langs)
id = self.codes.index(config.main["general"]["language"])
self.language.SetSelection(id)
self.language.SetSize(self.language.GetBestSize())
langBox = wx.BoxSizer(wx.HORIZONTAL)
langBox.Add(language, 0, wx.ALL, 5)
langBox.Add(self.language, 0, wx.ALL, 5)
sizer.Add(langBox, 0, wx.ALL, 5)
self.relative_time = wx.CheckBox(self, -1, _(U"Relative times"))
self.relative_time.SetValue(config.main["general"]["relative_times"])
sizer.Add(self.relative_time, 0, wx.ALL, 5)
if platform.system() == "Windows":
self.disable_sapi5 = wx.CheckBox(self, -1, _(u"Activate Sapi5 when any other screen reader is not being run"))
self.disable_sapi5.SetValue(config.main["general"]["voice_enabled"])
sizer.Add(self.disable_sapi5, 0, wx.ALL, 5)
self.show_gui = wx.CheckBox(self, -1, _(u"Activate the auto-start of the invisible interface"))
self.show_gui.SetValue(config.main["general"]["hide_gui"])
sizer.Add(self.show_gui, 0, wx.ALL, 5)
apiCallsBox = wx.BoxSizer(wx.HORIZONTAL)
apiCallsBox.Add(wx.StaticText(self, -1, _(u"API calls when the stream is started (One API call equals to 200 tweetts, two API calls equals 400 tweets, etc):")), 0, wx.ALL, 5)
self.apiCalls = wx.SpinCtrl(self, -1)
self.apiCalls.SetRange(1, 10)
self.apiCalls.SetValue(config.main["general"]["max_api_calls"])
self.apiCalls.SetSize(self.apiCalls.GetBestSize())
apiCallsBox.Add(self.apiCalls, 0, wx.ALL, 5)
sizer.Add(apiCallsBox, 0, wx.ALL, 5)
tweetsPerCallBox = wx.BoxSizer(wx.HORIZONTAL)
tweetsPerCallBox.Add(wx.StaticText(self, -1, _(u"Items on each API call")), 0, wx.ALL, 5)
self.itemsPerApiCall = wx.SpinCtrl(self, -1)
self.itemsPerApiCall.SetRange(0, 200)
self.itemsPerApiCall.SetValue(config.main["general"]["max_tweets_per_call"])
self.itemsPerApiCall.SetSize(self.itemsPerApiCall.GetBestSize())
tweetsPerCallBox.Add(self.itemsPerApiCall, 0, wx.ALL, 5)
sizer.Add(tweetsPerCallBox, 0, wx.ALL, 5)
self.reverse_timelines = wx.CheckBox(self, -1, _(u"Inverted buffers: The newest tweets will be shown at the beginning of the lists while the oldest at the end"))
self.reverse_timelines.SetValue(config.main["general"]["reverse_timelines"])
sizer.Add(self.reverse_timelines, 0, wx.ALL, 5)
self.SetSizer(sizer)
class other_buffers(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
sizer = wx.BoxSizer(wx.VERTICAL)
self.followers_value = config.main["other_buffers"]["show_followers"]
self.friends_value = config.main["other_buffers"]["show_friends"]
self.favs_value = config.main["other_buffers"]["show_favourites"]
self.events_value = config.main["other_buffers"]["show_events"]
self.blocks_value = config.main["other_buffers"]["show_blocks"]
self.mutes_value = config.main["other_buffers"]["show_muted_users"]
self.followers = wx.CheckBox(self, -1, _(u"Show followers"))
self.followers.SetValue(config.main["other_buffers"]["show_followers"])
sizer.Add(self.followers, 0, wx.ALL, 5)
self.friends = wx.CheckBox(self, -1, _(u"Show friends"))
self.friends.SetValue(config.main["other_buffers"]["show_friends"])
sizer.Add(self.friends, 0, wx.ALL, 5)
self.favs = wx.CheckBox(self, -1, _(u"Show favourites"))
self.favs.SetValue(config.main["other_buffers"]["show_favourites"])
sizer.Add(self.favs, 0, wx.ALL, 5)
self.blocks = wx.CheckBox(self, -1, _(u"Show blocked users"))
self.blocks.SetValue(config.main["other_buffers"]["show_blocks"])
sizer.Add(self.blocks, 0, wx.ALL, 5)
self.mutes = wx.CheckBox(self, -1, _(u"Show muted users"))
self.mutes.SetValue(config.main["other_buffers"]["show_muted_users"])
sizer.Add(self.mutes, 0, wx.ALL, 5)
self.events = wx.CheckBox(self, -1, _(u"Show events"))
self.events.SetValue(config.main["other_buffers"]["show_events"])
sizer.Add(self.events, 0, wx.ALL, 5)
self.SetSizer(sizer)
class ignoredClients(wx.Panel):
def __init__(self, parent):
super(ignoredClients, self).__init__(parent=parent)
sizer = wx.BoxSizer(wx.VERTICAL)
choices = config.main["twitter"]["ignored_clients"]
label = wx.StaticText(self, -1, _(u"Ignored clients"))
self.clients = wx.ListBox(self, -1, choices=choices)
self.clients.SetSize(self.clients.GetBestSize())
clientsBox = wx.BoxSizer(wx.HORIZONTAL)
clientsBox.Add(label, 0, wx.ALL, 5)
clientsBox.Add(self.clients, 0, wx.ALL, 5)
add = wx.Button(self, -1, _(u"Add client"))
remove = wx.Button(self, -1, _(u"Remove client"))
self.Bind(wx.EVT_BUTTON, self.add, add)
self.Bind(wx.EVT_BUTTON, self.remove, remove)
btnBox = wx.BoxSizer(wx.HORIZONTAL)
btnBox.Add(add, 0, wx.ALL, 5)
btnBox.Add(remove, 0, wx.ALL, 5)
sizer.Add(clientsBox, 0, wx.ALL, 5)
sizer.Add(btnBox, 0, wx.ALL, 5)
self.SetSizer(sizer)
def add(self, ev):
entry = wx.TextEntryDialog(self, _(u"Enter the name of the client here"), _(u"Add a new ignored client"))
if entry.ShowModal() == wx.ID_OK:
client = entry.GetValue()
if client not in config.main["twitter"]["ignored_clients"]:
config.main["twitter"]["ignored_clients"].append(client)
self.clients.Append(client)
def remove(self, ev):
if self.clients.GetCount() == 0: return
id = self.clients.GetSelection()
config.main["twitter"]["ignored_clients"].pop(id)
self.clients.Delete(id)
class sound(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
sizer = wx.BoxSizer(wx.VERTICAL)
volume = wx.StaticText(self, -1, _(u"Volume"))
self.volumeCtrl = wx.Slider(self)
self.volumeCtrl.SetRange(0, 100)
self.volumeCtrl.SetValue(config.main["sound"]["volume"]*100)
self.volumeCtrl.SetSize(self.volumeCtrl.GetBestSize())
volumeBox = wx.BoxSizer(wx.HORIZONTAL)
volumeBox.Add(volume, 0, wx.ALL, 5)
volumeBox.Add(self.volumeCtrl, 0, wx.ALL, 5)
sizer.Add(volumeBox, 0, wx.ALL, 5)
self.global_mute = wx.CheckBox(self, -1, _(u"Global mute"))
self.global_mute.SetValue(config.main["sound"]["global_mute"])
sizer.Add(self.global_mute, 0, wx.ALL, 5)
self.output_devices = sound_lib.output.Output.get_device_names()
output_label = wx.StaticText(self, -1, _(u"Output device"))
self.output = wx.ComboBox(self, -1, choices=self.output_devices, style=wx.CB_READONLY)
self.output.SetValue(config.main["sound"]["output_device"])
self.output.SetSize(self.output.GetBestSize())
outputBox = wx.BoxSizer(wx.HORIZONTAL)
outputBox.Add(output_label, 0, wx.ALL, 5)
outputBox.Add(self.output, 0, wx.ALL, 5)
sizer.Add(outputBox, 0, wx.ALL, 5)
self.input_devices = sound_lib.input.Input.get_device_names()
input_label = wx.StaticText(self, -1, _(u"Input device"))
self.input = wx.ComboBox(self, -1, choices=self.input_devices, style=wx.CB_READONLY)
self.input.SetValue(config.main["sound"]["input_device"])
self.input.SetSize(self.input.GetBestSize())
inputBox = wx.BoxSizer(wx.HORIZONTAL)
inputBox.Add(input_label, 0, wx.ALL, 5)
inputBox.Add(self.input, 0, wx.ALL, 5)
sizer.Add(inputBox, 0, wx.ALL, 5)
soundBox = wx.BoxSizer(wx.VERTICAL)
self.soundpacks = []
[self.soundpacks.append(i) for i in os.listdir(paths.sound_path()) if os.path.isdir(paths.sound_path(i)) == True ]
soundpack_label = wx.StaticText(self, -1, _(u"Sound pack"))
self.soundpack = wx.ComboBox(self, -1, choices=self.soundpacks, style=wx.CB_READONLY)
self.soundpack.SetValue(config.main["sound"]["current_soundpack"])
self.soundpack.SetSize(self.soundpack.GetBestSize())
soundBox.Add(soundpack_label, 0, wx.ALL, 5)
soundBox.Add(self.soundpack, 0, wx.ALL, 5)
sizer.Add(soundBox, 0, wx.ALL, 5)
self.SetSizer(sizer)
class audioServicesPanel(wx.Panel):
def __init__(self, parent):
super(audioServicesPanel, self).__init__(parent)
mainSizer = wx.BoxSizer(wx.VERTICAL)
apiKeyLabel = wx.StaticText(self, -1, _(u"If you've got a SndUp account, enter your API Key here. Whether the API Key is wrong, the App will fail to upload anything to the server. Whether there's no API Key here, then the audio files will be uploaded anonimously"))
self.apiKey = wx.TextCtrl(self, -1)
self.apiKey.SetValue(config.main["sound"]["sndup_api_key"])
dc = wx.WindowDC(self.apiKey)
dc.SetFont(self.apiKey.GetFont())
self.apiKey.SetSize(dc.GetTextExtent("0"*100))
apiKeyBox = wx.BoxSizer(wx.HORIZONTAL)
apiKeyBox.Add(apiKeyLabel, 0, wx.ALL, 5)
apiKeyBox.Add(self.apiKey, 0, wx.ALL, 5)
mainSizer.Add(apiKeyBox, 0, wx.ALL, 5)
first_sizer = wx.BoxSizer(wx.HORIZONTAL)
self.dropbox = wx.Button(self, -1)
if len(config.main["services"]["dropbox_token"]) > 0:
self.dropbox.SetLabel(_(u"Unlink your Dropbox account"))
else:
self.dropbox.SetLabel(_(u"Link your Dropbox account"))
self.dropbox.Bind(wx.EVT_BUTTON, self.onLink_unlink)
first_sizer.Add(self.dropbox, 0, wx.ALL, 5)
mainSizer.Add(first_sizer, 0, wx.ALL, 5)
self.SetSizer(mainSizer)
def setup_dropbox(self):
from extra.AudioUploader import dropbox_transfer
auth = dropbox_transfer.dropboxLogin()
url = auth.get_url()
wx.MessageDialog(self, _(u"The authorisation request will be shown on your browser. Copy the code tat Dropbox will provide and, in the text box that will appear on TW Blue, paste it. This code is necessary to continue. You only need to do it once."), _(u"Authorisation"), wx.OK).ShowModal()
webbrowser.open(url)
dlg = wx.TextEntryDialog(self, _(u"Enter the code here."), _(u"Verification code"))
if dlg.ShowModal() == wx.ID_CANCEL:
return False
resp = dlg.GetValue()
if resp == "":
self.dropbox.SetLabel(_(u"Link your Dropbox account"))
return False
else:
try:
auth.authorise(resp)
self.dropbox.SetLabel(_(u"Unlink your Dropbox account"))
except:
wx.MessageDialog(self, _(u"Error during authorisation. Try again later."), _(u"Error!"), wx.ICON_ERROR).ShowModal()
self.dropbox.SetLabel(_(u"Link your Dropbox account"))
return False
def onLink_unlink(self, ev):
if self.dropbox.GetLabel() == _(u"Link your Dropbox account"):
self.setup_dropbox()
else:
self.disconnect_dropbox()
def disconnect_dropbox(self):
config.main["services"]["dropbox_token"] = ""
self.dropbox.SetLabel(_(u"Link your Dropbox account"))
class configurationDialog(wx.Dialog):
def __init__(self, parent):
self.parent = parent
wx.Dialog.__init__(self, None, -1)
panel = wx.Panel(self)
self.SetTitle(_(u"TW Blue preferences"))
sizer = wx.BoxSizer(wx.VERTICAL)
notebook = wx.Notebook(panel)
self.general = general(notebook)
notebook.AddPage(self.general, _(u"General"))
self.general.SetFocus()
self.buffers = other_buffers(notebook)
notebook.AddPage(self.buffers, _(u"Show other buffers"))
self.ignored_clients = ignoredClients(notebook)
notebook.AddPage(self.ignored_clients, _(u"Ignored clients"))
self.sound = sound(notebook)
notebook.AddPage(self.sound, _(u"Sound"))
self.services = audioServicesPanel(notebook)
notebook.AddPage(self.services, _(u"Audio Services"))
sizer.Add(notebook, 0, wx.ALL, 5)
ok_cancel_box = wx.BoxSizer(wx.HORIZONTAL)
ok = wx.Button(panel, wx.ID_OK, _(u"Save"))
ok.Bind(wx.EVT_BUTTON, self.onSave)
ok.SetDefault()
cancel = wx.Button(panel, wx.ID_CANCEL, _(u"Close"))
self.SetEscapeId(cancel.GetId())
ok_cancel_box.Add(ok, 0, wx.ALL, 5)
ok_cancel_box.Add(cancel, 0, wx.ALL, 5)
sizer.Add(ok_cancel_box, 0, wx.ALL, 5)
panel.SetSizer(sizer)
self.SetClientSize(sizer.CalcMin())
def check_followers_change(self):
if self.buffers.followers.GetValue() != self.buffers.followers_value:
if self.buffers.followers.GetValue() == True:
log.debug("Creating followers list...")
followers = buffers.peoplePanel(self.parent.nb, self.parent, "followers", self.parent.twitter.twitter.get_followers_list, argumento=self.parent.db.settings["user_name"])
self.parent.nb.InsertSubPage(self.parent.db.settings["buffers"].index(self.parent.db.settings["user_name"]), followers, _(u"Followers"))
num = followers.start_streams()
followers.put_items(num)
self.parent.db.settings["buffers"].append("followers")
elif self.buffers.followers.GetValue() == False:
self.parent.nb.DeletePage(self.parent.db.settings["buffers"].index("followers"))
self.parent.db.settings.pop("followers")
self.parent.db.settings["buffers"].remove("followers")
def check_friends_change(self):
if self.buffers.friends.GetValue() != self.buffers.friends_value:
if self.buffers.friends.GetValue() == True:
log.debug("Creating friends list...")
friends = buffers.peoplePanel(self.parent.nb, self.parent, "friends", self.parent.twitter.twitter.get_friends_list, argumento=self.parent.db.settings["user_name"])
self.parent.nb.InsertSubPage(self.parent.db.settings["buffers"].index(self.parent.db.settings["user_name"]), friends, _(u"friends"))
num = friends.start_streams()
friends.put_items(num)
self.parent.db.settings["buffers"].append("friends")
elif self.buffers.friends.GetValue() == False:
self.parent.nb.DeletePage(self.parent.db.settings["buffers"].index("friends"))
self.parent.db.settings.pop("friends")
self.parent.db.settings["buffers"].remove("friends")
def check_favs_change(self):
if self.buffers.favs.GetValue() != self.buffers.favs_value:
if self.buffers.favs.GetValue() == True:
log.debug("Creating favorites...")
favs = buffers.basePanel(self.parent.nb, self.parent, "favs", self.parent.twitter.twitter.get_favorites)
self.parent.nb.InsertSubPage(self.parent.db.settings["buffers"].index(self.parent.db.settings["user_name"]), favs, _(u"Favorites"))
num = favs.start_streams()
favs.put_items(num)
self.parent.db.settings["buffers"].append("favs")
elif self.buffers.favs.GetValue() == False:
self.parent.nb.DeletePage(self.parent.db.settings["buffers"].index("favs"))
self.parent.db.settings.pop("favs")
self.parent.db.settings["buffers"].remove("favs")
def check_events_change(self):
if self.buffers.events.GetValue() != self.buffers.events_value:
if self.buffers.events.GetValue() == True:
log.debug("Creating events...")
events = buffers.eventsPanel(self.parent.nb, self.parent)
self.parent.nb.InsertSubPage(self.parent.db.settings["buffers"].index(self.parent.db.settings["user_name"]), events, _(u"Events"))
self.parent.db.settings["buffers"].append("events")
elif self.buffers.events.GetValue() == False:
self.parent.nb.DeletePage(self.parent.db.settings["buffers"].index("events"))
self.parent.db.settings["buffers"].remove("events")
def check_blocks_change(self):
if self.buffers.blocks.GetValue() != self.buffers.blocks_value:
if self.buffers.blocks.GetValue() == True:
log.debug("Creating blocked users list...")
blocks = buffers.peoplePanel(self.parent.nb, self.parent, "blocks", self.parent.twitter.twitter.list_blocks)
self.parent.nb.InsertSubPage(self.parent.db.settings["buffers"].index(self.parent.db.settings["user_name"]), blocks, _(u"Blocked users"))
num = blocks.start_streams()
blocks.put_items(num)
self.parent.db.settings["buffers"].append("blocks")
elif self.buffers.blocks.GetValue() == False:
self.parent.nb.DeletePage(self.parent.db.settings["buffers"].index("blocks"))
self.parent.db.settings.pop("blocks")
self.parent.db.settings["buffers"].remove("blocks")
def check_mutes_change(self):
if self.buffers.mutes.GetValue() != self.buffers.mutes_value:
if self.buffers.mutes.GetValue() == True:
log.debug("Creating muted users list...")
mutes = buffers.peoplePanel(self.parent.nb, self.parent, "muteds", self.parent.twitter.twitter.get_muted_users_list)
self.parent.nb.InsertSubPage(self.parent.db.settings["buffers"].index(self.parent.db.settings["user_name"]), mutes, _(u"Muted users"))
num = mutes.start_streams()
mutes.put_items(num)
self.parent.db.settings["buffers"].append("muteds")
elif self.buffers.mutes.GetValue() == False:
self.parent.nb.DeletePage(self.parent.db.settings["buffers"].index("muteds"))
self.parent.db.settings.pop("muteds")
self.parent.db.settings["buffers"].remove("muteds")
def onSave(self, ev):
need_restart = False
# Check general settings
if config.main["general"]["language"] != self.general.langs[self.general.language.GetSelection()][0]:
if self.general.langs[self.general.language.GetSelection()][0] in self.general.codes: config.main["general"]["language"] = self.general.langs[self.general.language.GetSelection()][0]
languageHandler.setLanguage(config.main["general"]["language"])
need_restart = True
if platform.system() == "Windows":
config.main["general"]["voice_enabled"] = self.general.disable_sapi5.GetValue()
config.main["general"]["hide_gui"] = self.general.show_gui.GetValue()
config.main["general"]["max_api_calls"] = self.general.apiCalls.GetValue()
config.main["general"]["max_tweets_per_call"] = self.general.itemsPerApiCall.GetValue()
if config.main["general"]["relative_times"] != self.general.relative_time.GetValue():
config.main["general"]["relative_times"] = self.general.relative_time.GetValue()
need_restart = True
if config.main["general"]["reverse_timelines"] != self.general.reverse_timelines.GetValue():
config.main["general"]["reverse_timelines"] = self.general.reverse_timelines.GetValue()
need_restart = True
## Check buffers settings
config.main["other_buffers"]["show_followers"] = self.buffers.followers.GetValue()
self.check_followers_change()
config.main["other_buffers"]["show_friends"] = self.buffers.friends.GetValue()
self.check_friends_change()
config.main["other_buffers"]["show_favourites"] = self.buffers.favs.GetValue()
self.check_favs_change()
config.main["other_buffers"]["show_events"] = self.buffers.events.GetValue()
self.check_events_change()
config.main["other_buffers"]["show_blocks"] = self.buffers.blocks.GetValue()
self.check_blocks_change()
config.main["other_buffers"]["show_muted_users"] = self.buffers.mutes.GetValue()
self.check_mutes_change()
## Check sound settings
config.main["sound"]["volume"] = self.sound.volumeCtrl.GetValue()/100.0
config.main["sound"]["global_mute"] = self.sound.global_mute.GetValue()
if system == "Windows":
config.main["sound"]["output_device"] = self.sound.output.GetStringSelection()
config.main["sound"]["input_device"] = self.sound.input.GetValue()
try:
snd.player.input.set_device(snd.player.input.find_device_by_name(config.main["sound"]["input_device"]))
snd.player.output.set_device(snd.player.output.find_device_by_name(config.main["sound"]["output_device"]))
except:
config.main["sound"]["output_device"] = "Default"
config.main["sound"]["input_device"] = "Default"
config.main["sound"]["sndup_api_key"] = self.services.apiKey.GetValue()
config.main["sound"]["current_soundpack"] = self.sound.soundpack.GetStringSelection()
snd.player.check_soundpack()
if need_restart == True:
config.main.write()
wx.MessageDialog(None, _(u"The application requires to be restarted to save these changes. Press OK to do it now."), _("Restart TW Blue"), wx.OK).ShowModal()
restart.restart_program()
config.main.write()
self.EndModal(wx.ID_OK)

151
src/gui/dialogs/follow.py Normal file
View File

@@ -0,0 +1,151 @@
# -*- coding: utf-8 -*-
############################################################
# Copyright (c) 2013, 2014 Manuel Eduardo Cortéz Vallejo <manuel@manuelcortez.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################
import wx
import config
from mysc import event
import twitter
from twitter import utils
from twython import TwythonError
import output
class follow(wx.Dialog):
def __init__(self, parent, default="follow"):
self.parent = parent
wx.Dialog.__init__(self, None, -1)
panel = wx.Panel(self)
userSizer = wx.BoxSizer()
self.SetTitle(_(u"Action"))
if self.parent.name_buffer == "followers" or self.parent.name_buffer == "friends":
list = [self.parent.db.settings[self.parent.name_buffer][self.parent.list.get_selected()]["screen_name"]]
else:
try: list =twitter.utils.get_all_users(self.parent.db.settings[self.parent.name_buffer][self.parent.list.get_selected()], self.parent.db)
except KeyError: list = [self.parent.db.settings[self.parent.name_buffer][self.parent.list.get_selected()]["screen_name"]]
self.cb = wx.ComboBox(panel, -1, choices=list, value=list[0])
self.cb.SetFocus()
userSizer.Add(self.cb)
actionSizer = wx.BoxSizer(wx.VERTICAL)
label2 = wx.StaticText(panel, -1, _(u"Action"))
self.follow = wx.RadioButton(panel, -1, _(u"Follow"), style=wx.RB_GROUP)
self.unfollow = wx.RadioButton(panel, -1, _(u"Unfollow"))
self.mute = wx.RadioButton(panel, -1, _(u"Mute"))
self.unmute = wx.RadioButton(panel, -1, _(u"Unmute"))
self.block = wx.RadioButton(panel, -1, _(u"Block"))
self.unblock = wx.RadioButton(panel, -1, _(u"Unblock"))
self.reportSpam = wx.RadioButton(panel, -1, _(u"Report as spam"))
self.setup_default(default)
actionSizer.Add(label2)
actionSizer.Add(self.follow)
actionSizer.Add(self.unfollow)
actionSizer.Add(self.mute)
actionSizer.Add(self.unmute)
actionSizer.Add(self.block)
actionSizer.Add(self.unblock)
actionSizer.Add(self.reportSpam)
sizer = wx.BoxSizer(wx.VERTICAL)
ok = wx.Button(panel, wx.ID_OK, _(u"OK"))
ok.Bind(wx.EVT_BUTTON, self.onok)
ok.SetDefault()
cancel = wx.Button(panel, wx.ID_CANCEL, _(u"Close"))
btnsizer = wx.BoxSizer()
btnsizer.Add(ok)
btnsizer.Add(cancel)
sizer.Add(userSizer)
sizer.Add(actionSizer)
sizer.Add(btnsizer)
panel.SetSizer(sizer)
self.Bind(wx.EVT_CHAR_HOOK, self.onEscape, self.cb)
def onEscape(self, ev):
if ev.GetKeyCode() == wx.WXK_RETURN:
self.onok(wx.EVT_BUTTON)
ev.Skip()
def onok(self, ev):
if self.follow.GetValue() == True:
try:
self.parent.twitter.twitter.create_friendship(screen_name=self.cb.GetValue())
self.Destroy()
except TwythonError as err:
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
elif self.unfollow.GetValue() == True:
try:
id = self.parent.twitter.twitter.destroy_friendship(screen_name=self.cb.GetValue())
self.Destroy()
except TwythonError as err:
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
elif self.mute.GetValue() == True:
try:
id = self.parent.twitter.twitter.create_mute(screen_name=self.cb.GetValue())
if config.main["other_buffers"]["show_muted_users"] == True:
tweet_event = event.event(event.EVT_OBJECT, 1)
tweet_event.SetItem(id)
wx.PostEvent(self.parent.parent.nb.GetPage(self.parent.db.settings["buffers"].index("muteds")), tweet_event)
self.parent.db.settings["muted_users"].append(id["id"])
self.Destroy()
output.speak(_(u"You've muted to %s") % (id["screen_name"]))
except TwythonError as err:
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
elif self.unmute.GetValue() == True:
try:
id = self.parent.twitter.twitter.destroy_mute(screen_name=self.cb.GetValue())
if config.main["other_buffers"]["show_muted_users"] == True:
item = utils.find_item(id, self.parent.db.settings["muteds"])
if item > 0:
deleted_event = event.event(event.EVT_DELETED, 1)
deleted_event.SetItem(item)
wx.PostEvent(self.parent.parent.nb.GetPage(self.parent.db.settings["buffers"].index("muteds")), deleted_event)
if id["id"] in self.parent.db.settings["muted_users"]: self.parent.db.settings["muted_users"].remove(id["id"])
self.Destroy()
output.speak(_(u"You've unmuted to %s") % (id["screen_name"]))
except TwythonError as err:
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
elif self.reportSpam.GetValue() == True:
try:
self.parent.twitter.twitter.report_spam(screen_name=self.cb.GetValue())
self.Destroy()
except TwythonError as err:
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
elif self.block.GetValue() == True:
try:
self.parent.twitter.twitter.create_block(screen_name=self.cb.GetValue())
self.Destroy()
except TwythonError as err:
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
elif self.unblock.GetValue() == True:
try:
self.parent.twitter.twitter.destroy_block(screen_name=self.cb.GetValue())
self.Destroy()
except TwythonError as err:
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
def setup_default(self, default):
if default == "follow":
self.follow.SetValue(True)
elif default == "unfollow":
self.unfollow.SetValue(True)
elif default == "mute":
self.mute.SetValue(True)
elif default == "unmute":
self.unmute.SetValue(True)
elif default == "report":
self.reportSpam.SetValue(True)
elif default == "block":
self.block.SetValue(True)
elif default == "unblock":
self.unblock.SetValue(True)

244
src/gui/dialogs/lists.py Normal file
View File

@@ -0,0 +1,244 @@
# -*- coding: utf-8 -*-
############################################################
# Copyright (c) 2013, 2014 Manuel Eduardo Cortéz Vallejo <manuel@manuelcortez.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################
import wx
import platform
import output
import config
import gui
from multiplatform_widgets import widgets
from twython import TwythonError
from twitter import compose, utils
class listViewer(wx.Dialog):
def __init__(self, parent):
self.twitter = parent.twitter
self.db = parent.db
self.nb = parent.nb
self.parent = parent
wx.Dialog.__init__(self, None)
self.SetTitle(_(u"Lists manager"))
panel = wx.Panel(self)
label = wx.StaticText(panel, -1, _(u"Lists"))
self.lista = widgets.list(panel, _(u"List"), _(u"Description"), _(u"Owner"), _(u"Members"), _(u"mode"), size=(800, 800), style=wx.LC_REPORT|wx.LC_SINGLE_SEL)
self.lista.list.SetFocus()
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(label)
sizer.Add(self.lista.list)
self.createBtn = wx.Button(panel, wx.NewId(), _(u"Create a new list"))
self.createBtn.Bind(wx.EVT_BUTTON, self.onGo)
self.editBtn = wx.Button(panel, -1, _(u"Edit"))
self.Bind(wx.EVT_BUTTON, self.onEdit, self.editBtn)
self.deleteBtn = wx.Button(panel, -1, _(u"Remove"))
self.Bind(wx.EVT_BUTTON, self.onDelete, self.deleteBtn)
self.view = wx.Button(panel, -1, _(u"Open in buffer"))
self.Bind(wx.EVT_BUTTON, self.onView, self.view)
# self.members = wx.Button(panel, -1, _(u"View members"))
# self.members.Disable()
# self.subscriptors = wx.Button(panel, -1, _(u"View subscribers"))
# self.subscriptors.Disable()
# self.get_linkBtn = wx.Button(panel, -1, _(u"Get link for the list"))
# self.get_linkBtn.Bind(wx.EVT_BUTTON, self.onGetLink)
self.cancelBtn = wx.Button(panel, wx.ID_CANCEL)
btnSizer = wx.BoxSizer()
btnSizer.Add(self.createBtn)
btnSizer.Add(self.editBtn)
btnSizer.Add(self.cancelBtn)
panel.SetSizer(sizer)
self.populate_list()
self.lista.select_item(0)
def onGo(self, ev):
ev.Skip()
dlg = createListDialog()
if dlg.ShowModal() == wx.ID_OK:
name = dlg.name.GetValue()
description = dlg.description.GetValue()
if dlg.public.GetValue() == True: mode = "public"
else: mode = "private"
try:
new_list = self.twitter.twitter.create_list(name=name, description=description, mode=mode)
self.db.settings["lists"].append(new_list)
self.lista.insert_item(False, *compose.compose_list(new_list))
except TwythonError as e:
output.speak("error %s: %s" % (e.status_code, e.msg))
else:
return
dlg.Destroy()
def onEdit(self, ev):
ev.Skip()
if self.lista.get_count() == 0: return
list = self.db.settings["lists"][self.lista.get_selected()]
dlg = editListDialog(list)
if dlg.ShowModal() == wx.ID_OK:
name = dlg.name.GetValue()
description = dlg.description.GetValue()
if dlg.public.GetValue() == True: mode = "public"
else: mode = "private"
try:
self.twitter.twitter.update_list(list_id=self.lists[self.get_selected()]["id"], name=name, description=description, mode=mode)
except TwythonError as e:
output.speak("error %s: %s" % (e.error_code, e.msg))
else:
return
dlg.Destroy()
def onDelete(self, ev):
ev.Skip()
if self.lista.get_count() == 0: return
list = self.db.settings["lists"][self.lista.get_selected()]["id"]
dlg = wx.MessageDialog(self, _("Do you really want to delete this list?"), _("Delete"), wx.YES_NO)
if dlg.ShowModal() == wx.ID_YES:
try:
self.twitter.twitter.delete_list(list_id=list)
self.db.settings["lists"].pop(self.lista.get_selected())
self.remove_item(self.lista.get_selected())
except TwythonError as e:
output.speak("error %s: %s" % (e.error_code, e.msg))
dlg.Destroy()
def onView(self, ev):
ev.Skip()
if self.lista.get_count() == 0: return
list_id = self.db.settings["lists"][self.lista.get_selected()]["id"]
list_updated = self.twitter.twitter.get_specific_list(list_id=list_id)
self.db.settings["lists"][self.lista.get_selected()] = list_updated
if list_updated["slug"] not in config.main["other_buffers"]["lists"]:
config.main["other_buffers"]["lists"].append(list_updated["slug"])
output.speak(_(u"List opened"))
else:
output.speak(_(u"This list is arready opened."))
return
listUI = gui.buffers.lists.listPanel(self.nb, self.parent, list_updated["slug"]+"-list", argumento=utils.find_list(list_updated["slug"], self.db.settings["lists"]))
self.nb.AddPage(listUI, _(u"List for %s") % (list_updated["slug"],))
self.db.settings["buffers"].append(list_updated["slug"]+"-list")
num = listUI.start_streams()
listUI.put_items(num)
listUI.sound = "tweet_timeline.wav"
self.parent.stream2.disconnect()
del self.parent.stream2
self.parent.get_tls()
def populate_list(self):
for i in self.db.settings["lists"]:
item = compose.compose_list(i)
self.lista.insert_item(False, *item)
class userListViewer(listViewer):
def __init__(self, parent, username):
self.username = username
super(userListViewer, self).__init__(parent)
self.SetTitle(_(u"Viewing lists for %s") % (self.username))
self.createBtn.SetLabel(_(u"Subscribe"))
self.deleteBtn.SetLabel(_(u"Unsubscribe"))
self.editBtn.Disable()
self.view.Disable()
def populate_list(self):
self.lists = self.twitter.twitter.show_owned_lists(screen_name=self.username, count=200)["lists"]
for i in self.lists:
item = compose.compose_list(i)
self.lista.insert_item(False, *item)
def onGo(self, ev):
list_id = self.lists[self.lista.get_selected()]["id"]
try:
list = self.twitter.twitter.subscribe_to_list(list_id=list_id)
item = utils.find_item(list["id"], self.db.settings["lists"])
self.db.settings["lists"].append(list)
except TwythonError as e:
output.speak("error %s: %s" % (e.status_code, e.msg))
class createListDialog(wx.Dialog):
def __init__(self):
wx.Dialog.__init__(self, None, size=(450, 400))
self.SetTitle(_(u"Create a new list"))
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
name = wx.StaticText(panel, -1, _(u"Name (20 characters maximun)"))
self.name = wx.TextCtrl(panel, -1)
nameSizer = wx.BoxSizer(wx.HORIZONTAL)
nameSizer.Add(name)
nameSizer.Add(self.name)
description = wx.StaticText(panel, -1, _(u"Description"))
self.description = wx.TextCtrl(panel, -1)
descriptionSizer = wx.BoxSizer(wx.HORIZONTAL)
descriptionSizer.Add(description)
descriptionSizer.Add(self.description)
mode = wx.StaticText(panel, -1, _(u"Mode"))
self.public = wx.RadioButton(panel, -1, _(u"Public"), style=wx.RB_GROUP)
self.private = wx.RadioButton(panel, -1, _(u"Private"))
modeBox = wx.BoxSizer(wx.HORIZONTAL)
modeBox.Add(mode)
modeBox.Add(self.public)
modeBox.Add(self.private)
ok = wx.Button(panel, wx.ID_OK)
ok.SetDefault()
cancel = wx.Button(panel, wx.ID_CANCEL)
btnBox = wx.BoxSizer(wx.HORIZONTAL)
btnBox.Add(ok)
btnBox.Add(cancel)
sizer.Add(nameSizer)
sizer.Add(descriptionSizer)
sizer.Add(modeBox)
sizer.Add(btnBox)
class editListDialog(createListDialog):
def __init__(self, list):
createListDialog.__init__(self)
self.SetTitle(_(u"Editing the list %s") % (list["name"]))
self.name.ChangeValue(list["name"])
self.description.ChangeValue(list["description"])
if list["mode"] == "public":
self.public.SetValue(True)
else:
self.private.SetValue(True)
class addUserListDialog(listViewer):
def __init__(self, parent):
listViewer.__init__(self, parent)
self.SetTitle(_(u"Select a list to add the user"))
self.createBtn.SetLabel(_(u"Add"))
self.createBtn.SetDefault()
self.editBtn.Disable()
self.view.Disable()
# self.subscriptors.Disable()
# self.members.Disable()
self.deleteBtn.Disable()
def onGo(self, ev):
self.EndModal(wx.ID_OK)
class removeUserListDialog(listViewer):
def __init__(self, parent):
listViewer.__init__(self, parent)
self.SetTitle(_(u"Select a list to remove the user"))
self.createBtn.SetLabel(_(u"Remove"))
self.createBtn.SetDefault()
self.editBtn.Disable()
self.view.Disable()
# self.subscriptors.Disable()
# self.members.Disable()
self.deleteBtn.Disable()
def onGo(self, ev):
self.EndModal(wx.ID_OK)

415
src/gui/dialogs/message.py Normal file
View File

@@ -0,0 +1,415 @@
# -*- coding: utf-8 -*-
############################################################
# Copyright (c) 2013, 2014 Manuel Eduardo Cortéz Vallejo <manuel@manuelcortez.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################
import wx
import twitter
import config
import output
import sound
import urlList
import url_shortener
import json
from mysc.thread_utils import call_threaded
from mysc.repeating_timer import RepeatingTimer
from twython import TwythonError
from extra import translator, AudioUploader
import platform
from extra.AudioUploader import transfer
if platform.system() != "Darwin":
from extra.AudioUploader import dropbox_transfer
from extra.SpellChecker import gui as spellCheckerGUI
class textLimited(wx.Dialog):
def __init__(self, message, title, text, parent):
wx.Dialog.__init__(self, parent)
self.twitter = parent.twitter
self.parent = parent
self.SetTitle(_(u"New tweet"))
self.panel = wx.Panel(self)
def createTextArea(self, message, text):
self.label = wx.StaticText(self.panel, -1, str(len(text)))
self.text = wx.TextCtrl(self.panel, -1, text)
font = self.text.GetFont()
dc = wx.WindowDC(self.text)
dc.SetFont(font)
x, y = dc.GetTextExtent("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
self.text.SetSize((x, y))
self.text.SetFocus()
if platform.system() != "Darwin":
self.text.Bind(wx.EVT_TEXT, self.onTimer)
self.textBox = wx.BoxSizer(wx.HORIZONTAL)
self.textBox.Add(self.label, 0, wx.ALL, 5)
self.textBox.Add(self.text, 0, wx.ALL, 5)
def onCheck(self, ev):
if platform.system() == "Darwin":
return
text = self.text.GetValue()
dlg = spellCheckerGUI.spellCheckerDialog(text, "")
if dlg.ShowModal() == wx.ID_OK:
self.text.ChangeValue(dlg.checker.get_text())
dlg.Destroy()
def onAttach(self, ev):
ev.Skip()
self.recording = AudioUploader.gui.audioDialog(self.parent)
if self.recording.ShowModal() != wx.ID_OK:
self.recording.cleanup()
return
self.recording.postprocess()
output.speak(_(u"Attaching..."))
self.uploaderDialog = AudioUploader.transfer_dialogs.UploadDialog(parent=self.parent, title=_(u"Uploading..."), filename=self.recording.file)
if self.recording.services.GetValue() == "Dropbox" and platform.system() != "Darwin":
self.uploader = dropbox_transfer.dropboxUploader(filename=self.recording.file, completed_callback=self.upload_completed, wxDialog=self.uploaderDialog)
elif self.recording.services.GetValue() == "SNDUp":
base_url = 'http://sndup.net/post.php'
if len(config.main["sound"]["sndup_api_key"]) > 0:
url = base_url + '?apikey=' + config.main['sound']['sndup_api_key']
else:
url = base_url
self.uploader = transfer.Upload(field='file', url=url, filename=self.recording.file, completed_callback=self.upload_completed, wxDialog=self.uploaderDialog)
self.uploaderDialog.Show()
self.uploader.perform_threaded()
def upload_completed(self):
url = self.uploader.get_url()
self.uploaderDialog.Destroy()
if url != 0:
self.text.SetValue(self.text.GetValue()+url+" #audio")
else:
output.speak(_(u"Unable to upload the audio"))
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 onShorten(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 shortened"))
elif len(urls) == 1:
self.text.SetValue(self.text.GetValue().replace(urls[0], url_shortener.shorten(urls[0])))
output.speak(_(u"URL shortened"))
elif len(urls) > 1:
urlList.shorten(urls, self).ShowModal()
self.text.SetFocus()
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()
def onTimer(self, ev):
self.label.SetLabel(str(len(self.text.GetValue())))
if len(self.text.GetValue()) > 1:
self.shortenButton.Enable()
self.unshortenButton.Enable()
else:
self.shortenButton.Disable()
self.unshortenButton.Disable()
if len(self.text.GetValue()) > 140:
sound.player.play("max_length.ogg")
self.okButton.Disable()
elif len(self.text.GetValue()) <= 140:
self.okButton.Enable()
def onCancel(self, ev):
self.Destroy()
class tweet(textLimited):
def createControls(self, message, title, text):
self.mainBox = wx.BoxSizer(wx.VERTICAL)
self.createTextArea(message, text)
self.mainBox.Add(self.textBox, 0, wx.ALL, 5)
self.upload_image = wx.Button(self.panel, -1, _(u"Upload a picture"), size=wx.DefaultSize)
self.upload_image.Bind(wx.EVT_BUTTON, self.onUpload_image)
if platform.system() != "Darwin":
self.spellcheck = wx.Button(self.panel, -1, _("Spelling correction"), size=wx.DefaultSize)
self.spellcheck.Bind(wx.EVT_BUTTON, self.onCheck)
self.attach = wx.Button(self.panel, -1, _(u"Attach audio"), size=wx.DefaultSize)
self.attach.Bind(wx.EVT_BUTTON, self.onAttach)
self.shortenButton = wx.Button(self.panel, -1, _(u"Shorten URL"), size=wx.DefaultSize)
self.shortenButton.Bind(wx.EVT_BUTTON, self.onShorten)
self.unshortenButton = wx.Button(self.panel, -1, _(u"Expand URL"), size=wx.DefaultSize)
self.unshortenButton.Bind(wx.EVT_BUTTON, self.onUnshorten)
self.shortenButton.Disable()
self.unshortenButton.Disable()
self.translateButton = wx.Button(self.panel, -1, _(u"Translate message"), size=wx.DefaultSize)
self.translateButton.Bind(wx.EVT_BUTTON, self.onTranslate)
self.okButton = wx.Button(self.panel, wx.ID_OK, _(u"Send"), size=wx.DefaultSize)
self.okButton.Bind(wx.EVT_BUTTON, self.onSend)
self.okButton.SetDefault()
cancelButton = wx.Button(self.panel, wx.ID_CANCEL, _(u"Close"), size=wx.DefaultSize)
cancelButton.Bind(wx.EVT_BUTTON, self.onCancel)
self.buttonsBox1 = wx.BoxSizer(wx.HORIZONTAL)
self.buttonsBox1.Add(self.upload_image, 0, wx.ALL, 5)
if platform.system() != "Darwin":
self.buttonsBox1.Add(self.spellcheck, 0, wx.ALL, 5)
self.buttonsBox1.Add(self.attach, 0, wx.ALL, 5)
self.mainBox.Add(self.buttonsBox1, 0, wx.ALL, 5)
self.buttonsBox2 = wx.BoxSizer(wx.HORIZONTAL)
self.buttonsBox2.Add(self.shortenButton, 0, wx.ALL, 5)
self.buttonsBox2.Add(self.unshortenButton, 0, wx.ALL, 5)
self.buttonsBox2.Add(self.translateButton, 0, wx.ALL, 5)
self.mainBox.Add(self.buttonsBox2, 0, wx.ALL, 5)
self.ok_cancelSizer = wx.BoxSizer(wx.HORIZONTAL)
self.ok_cancelSizer.Add(self.okButton, 0, wx.ALL, 5)
self.ok_cancelSizer.Add(cancelButton, 0, wx.ALL, 5)
self.mainBox.Add(self.ok_cancelSizer)
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)
self.panel.SetSizer(self.mainBox)
def __init__(self, message, title, text, parent):
super(tweet, self).__init__(message, title, text, parent)
self.image = None
self.createControls(message, title, text)
self.onTimer(wx.EVT_CHAR_HOOK)
self.SetClientSize(self.mainBox.CalcMin())
def onUpload_image(self, ev):
if self.upload_image.GetLabel() == _(u"Discard image"):
self.image = None
del self.file
output.speak(_(u"Discarded"))
self.upload_image.SetLabel(_(u"Upload a picture"))
else:
openFileDialog = wx.FileDialog(self, _(u"Select the picture to be uploaded"), "", "", _("Image files (*.png, *.jpg, *.gif)|*.png; *.jpg; *.gif"), wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return
self.file = open(openFileDialog.GetPath(), "rb")
self.image = True
self.upload_image.SetLabel(_(u"Discard image"))
ev.Skip()
def onSend(self, ev):
self.EndModal(wx.ID_OK)
class retweet(tweet):
def __init__(self, message, title, text, parent):
super(retweet, self).__init__(message, title, text, parent)
# self.createControls(message, title, text)
self.in_reply_to = parent.db.settings[parent.name_buffer][parent.list.get_selected()]["id"]
self.text.SetInsertionPoint(0)
def onSend(self, ev):
self.EndModal(wx.ID_OK)
class dm(textLimited):
def createControls(self, message, title, text):
self.mainBox = wx.BoxSizer(wx.VERTICAL)
if self.parent.name_buffer == "followers" or self.parent.name_buffer == "friends":
list = [self.parent.db.settings[self.parent.name_buffer][self.parent.list.get_selected()]["screen_name"]]
else:
list =twitter.utils.get_all_users(self.parent.db.settings[self.parent.name_buffer][self.parent.list.get_selected()], self.parent.db)
label = wx.StaticText(self.panel, -1, _(u"Recipient"))
self.cb = wx.ComboBox(self.panel, -1, choices=list, value=list[0], size=wx.DefaultSize)
self.createTextArea(message, text)
self.mainBox.Add(self.cb, 0, wx.ALL, 5)
self.mainBox.Add(self.textBox, 0, wx.ALL, 5)
if platform.system() != "Darwin":
self.spellcheck = wx.Button(self.panel, -1, _("Spelling correction"), size=wx.DefaultSize)
self.spellcheck.Bind(wx.EVT_BUTTON, self.onCheck)
self.attach = wx.Button(self.panel, -1, _(u"Attach audio"), size=wx.DefaultSize)
self.attach.Bind(wx.EVT_BUTTON, self.onAttach)
self.shortenButton = wx.Button(self.panel, -1, _(u"Shorten URL"), size=wx.DefaultSize)
self.shortenButton.Bind(wx.EVT_BUTTON, self.onShorten)
self.unshortenButton = wx.Button(self.panel, -1, _(u"Expand URL"), size=wx.DefaultSize)
self.unshortenButton.Bind(wx.EVT_BUTTON, self.onUnshorten)
self.shortenButton.Disable()
self.unshortenButton.Disable()
self.translateButton = wx.Button(self.panel, -1, _(u"Translate message"), size=wx.DefaultSize)
self.translateButton.Bind(wx.EVT_BUTTON, self.onTranslate)
self.okButton = wx.Button(self.panel, wx.ID_OK, _(u"Send"), size=wx.DefaultSize)
self.okButton.Bind(wx.EVT_BUTTON, self.onSend)
self.okButton.SetDefault()
cancelButton = wx.Button(self.panel, wx.ID_CANCEL, _(u"Close"), size=wx.DefaultSize)
cancelButton.Bind(wx.EVT_BUTTON, self.onCancel)
self.buttonsBox = wx.BoxSizer(wx.HORIZONTAL)
if platform.system() != "Darwin":
self.buttonsBox.Add(self.spellcheck, 0, wx.ALL, 5)
self.buttonsBox.Add(self.attach, 0, wx.ALL, 5)
self.mainBox.Add(self.buttonsBox, 0, wx.ALL, 5)
self.buttonsBox1 = wx.BoxSizer(wx.HORIZONTAL)
self.buttonsBox1.Add(self.shortenButton, 0, wx.ALL, 5)
self.buttonsBox1.Add(self.unshortenButton, 0, wx.ALL, 5)
self.buttonsBox1.Add(self.translateButton, 0, wx.ALL, 5)
self.mainBox.Add(self.buttonsBox1, 0, wx.ALL, 5)
self.buttonsBox3 = wx.BoxSizer(wx.HORIZONTAL)
self.buttonsBox3.Add(self.okButton, 0, wx.ALL, 5)
self.buttonsBox3.Add(cancelButton, 0, wx.ALL, 5)
self.mainBox.Add(self.buttonsBox3, 0, wx.ALL, 5)
self.panel.SetSizer(self.mainBox)
def __init__(self, message, title, text, parent):
super(dm, self).__init__(message, title, text, parent)
self.parent = parent
self.image = None
self.createControls(message, title, text)
self.onTimer(wx.EVT_CHAR_HOOK)
self.SetClientSize(self.mainBox.CalcMin())
def onSend(self, ev):
self.EndModal(wx.ID_OK)
class reply(tweet):
def __init__(self, message, title, text, parent):
super(reply, self).__init__(message, title, text, parent)
self.in_reply_to = parent.db.settings[parent.name_buffer][parent.list.get_selected()]["id"]
self.text.SetInsertionPoint(len(self.text.GetValue()))
self.mentionAll = wx.Button(self, -1, _(u"Mention to all"), size=wx.DefaultSize)
self.mentionAll.Disable()
self.mentionAll.Bind(wx.EVT_BUTTON, self.mentionAllUsers)
self.buttonsBox1.Add(self.mentionAll, 0, wx.ALL, 5)
self.buttonsBox1.Layout()
self.mainBox.Layout()
self.check_if_users()
self.SetClientSize(self.mainBox.CalcMin())
def check_if_users(self):
try:
if len(self.parent.db.settings[self.parent.name_buffer][self.parent.list.get_selected()]["entities"]["user_mentions"]) > 0:
self.mentionAll.Enable()
except KeyError:
pass
def mentionAllUsers(self, ev):
self.text.SetValue(self.text.GetValue()+twitter.utils.get_all_mentioned(self.parent.db.settings[self.parent.name_buffer][self.parent.list.get_selected()], self.parent.db))
self.text.SetInsertionPoint(len(self.text.GetValue()))
self.text.SetFocus()
def onSend(self, ev):
self.EndModal(wx.ID_OK)
class viewTweet(wx.Dialog):
def __init__(self, tweet):
super(viewTweet, self).__init__(None, size=(850,850))
self.SetTitle(_(u"Tweet - %i characters ") % (len(tweet)))
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))
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)
if platform.system() != "Darwin":
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)
if platform.system() != "Darwin":
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.check_urls()
self.SetClientSize(mainBox.CalcMin())
def check_urls(self):
if len(twitter.utils.find_urls_in_text(self.text.GetValue())) > 0:
self.unshortenButton.Enable()
def onCheck(self, ev):
if platform.system() != "Darwin": return
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()

48
src/gui/dialogs/search.py Normal file
View File

@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
############################################################
# Copyright (c) 2013, 2014 Manuel Eduardo Cortéz Vallejo <manuel@manuelcortez.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################
import wx
class searchDialog(wx.Dialog):
def __init__(self):
super(searchDialog, self).__init__(None, -1)
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
self.SetTitle(_(u"Search on Twitter"))
label = wx.StaticText(panel, -1, _(u"Search"))
self.term = wx.TextCtrl(panel, -1,)
dc = wx.WindowDC(self.term)
dc.SetFont(self.term.GetFont())
self.term.SetSize(dc.GetTextExtent("0"*40))
sizer.Add(label, 0, wx.ALL, 5)
sizer.Add(self.term, 0, wx.ALL, 5)
self.tweets = wx.RadioButton(panel, -1, _(u"Tweets"), style=wx.RB_GROUP)
self.users = wx.RadioButton(panel, -1, _(u"Users"))
radioSizer = wx.BoxSizer(wx.HORIZONTAL)
radioSizer.Add(self.tweets, 0, wx.ALL, 5)
radioSizer.Add(self.users, 0, wx.ALL, 5)
sizer.Add(radioSizer, 0, wx.ALL, 5)
ok = wx.Button(panel, wx.ID_OK, _(u"OK"))
ok.SetDefault()
cancel = wx.Button(panel, wx.ID_CANCEL, _(u"Close"))
btnsizer = wx.BoxSizer()
btnsizer.Add(ok, 0, wx.ALL, 5)
btnsizer.Add(cancel, 0, wx.ALL, 5)
sizer.Add(btnsizer, 0, wx.ALL, 5)
panel.SetSizer(sizer)
self.SetClientSize(sizer.CalcMin())

View File

@@ -0,0 +1,83 @@
# -*- coding: utf-8 -*-
############################################################
# Copyright (c) 2013, 2014 Manuel Eduardo Cortéz Vallejo <manuel@manuelcortez.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################
import wx, twitter, config, gui.dialogs, sound, webbrowser
class showUserProfile(wx.Dialog):
def __init__(self, twitter, screen_name):
self.twitter = twitter
self.screen_name = screen_name
wx.Dialog.__init__(self, None, -1)
self.SetTitle(_(u"Information for %s") % (screen_name))
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
self.get_data()
static = wx.StaticText(panel, -1, _(u"Details"))
sizer.Add(static, 0, wx.ALL, 5)
text = wx.TextCtrl(panel, -1, style=wx.TE_MULTILINE|wx.TE_READONLY)
# dc = wx.WindowDC(text)
# dc.SetFont(text.GetFont())
# (x, y, z) = dc.GetMultiLineTextExtent("0"*10000)
# text.SetSize((x, y))
text.SetFocus()
sizer.Add(text, 0, wx.ALL|wx.EXPAND, 5)
self.url = wx.Button(panel, -1, _(u"Go to URL"), size=wx.DefaultSize)
self.url.Bind(wx.EVT_BUTTON, self.onUrl)
self.url.Disable()
close = wx.Button(panel, wx.ID_CANCEL, _(u"Close"))
close.Bind(wx.EVT_BUTTON, self.onClose)
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
btnSizer.Add(self.url, 0, wx.ALL, 5)
btnSizer.Add(close, 0, wx.ALL, 5)
sizer.Add(btnSizer, 0, wx.ALL, 5)
text.ChangeValue(self.compose_string())
text.SetSize(text.GetBestSize())
panel.SetSizer(sizer)
self.SetClientSize(sizer.CalcMin())
def onUrl(self, ev):
webbrowser.open(self.data["url"])
def onClose(self, ev):
self.Destroy()
def get_data(self):
try:
self.data = self.twitter.twitter.show_user(screen_name=self.screen_name)
except:
wx.MessageDialog(self, _(u"This user does not exist on Twitter"), _(u"Error"), wx.ICON_ERROR).ShowModal()
self.EndModal()
def compose_string(self):
string = u""
string = string + _(u"Username: @%s\n") % (self.data["screen_name"])
string = string + _(u"Name: %s\n") % (self.data["name"])
if self.data["location"] != "":
string = string + _(u"Location: %s\n") % (self.data["location"])
if self.data["url"] != None:
string = string+ _(u"URL: %s\n") % (self.data["url"])
self.url.Enable()
if self.data["description"] != "":
string = string+ _(u"Bio: %s\n") % (self.data["description"])
if self.data["protected"] == True: protected = _(u"Yes")
else: protected = _(u"No")
string = string+ _(u"Protected: %s\n") % (protected)
string = string+_(u"Followers: %s\n Friends: %s\n") % (self.data["followers_count"], self.data["friends_count"])
string = string+ _(u"Tweets: %s\n") % (self.data["statuses_count"])
string = string+ _(u"Favourites: %s") % (self.data["favourites_count"])
return string

View File

@@ -0,0 +1,119 @@
# -*- coding: utf-8 -*-
############################################################
# Copyright (c) 2013, 2014 Manuel Eduardo Cortéz Vallejo <manuel@manuelcortez.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################
import wx
from twython import TwythonError
class updateProfile(wx.Dialog):
def __init__(self, parent):
self.twitter = parent.twitter
self.parent = parent
super(updateProfile, self).__init__(parent=None, id=-1)
self.SetTitle(_(u"Update your profile"))
panel = wx.Panel(self)
labelName = wx.StaticText(panel, -1, _(u"Name (20 characters maximum)"))
self.name = wx.TextCtrl(panel, -1)
self.name.SetFocus()
dc = wx.WindowDC(self.name)
dc.SetFont(self.name.GetFont())
self.name.SetSize(dc.GetTextExtent("0"*20))
labelLocation = wx.StaticText(panel, -1, _(u"Location"))
self.location = wx.TextCtrl(panel, -1)
dc = wx.WindowDC(self.location)
dc.SetFont(self.location.GetFont())
self.location.SetSize(dc.GetTextExtent("0"*35))
labelUrl = wx.StaticText(panel, -1, _(u"Website"))
self.url = wx.TextCtrl(panel, -1)
dc = wx.WindowDC(self.url)
dc.SetFont(self.url.GetFont())
self.url.SetSize(dc.GetTextExtent("0"*22))
labelDescription = wx.StaticText(panel, -1, _(u"Bio (160 characters maximum)"))
self.description = wx.TextCtrl(panel, -1, size=(400, 400))
dc = wx.WindowDC(self.description)
dc.SetFont(self.description.GetFont())
self.description.SetSize(dc.GetTextExtent("0"*160))
self.image = None
self.upload_image = wx.Button(panel, -1, _(u"Upload a picture"))
self.upload_image.Bind(wx.EVT_BUTTON, self.onUpload_picture)
ok = wx.Button(panel, wx.ID_OK, _(u"Update profile"))
ok.Bind(wx.EVT_BUTTON, self.onUpdateProfile)
ok.SetDefault()
close = wx.Button(panel, wx.ID_CANCEL, _("Close"))
sizer = wx.BoxSizer(wx.VERTICAL)
nameBox = wx.BoxSizer(wx.HORIZONTAL)
nameBox.Add(labelName, 0, wx.ALL, 5)
nameBox.Add(self.name, 0, wx.ALL, 5)
sizer.Add(nameBox, 0, wx.ALL, 5)
locationBox = wx.BoxSizer(wx.HORIZONTAL)
locationBox.Add(labelLocation, 0, wx.ALL, 5)
locationBox.Add(self.location, 0, wx.ALL, 5)
sizer.Add(locationBox, 0, wx.ALL, 5)
urlBox = wx.BoxSizer(wx.HORIZONTAL)
urlBox.Add(labelUrl, 0, wx.ALL, 5)
urlBox.Add(self.url, 0, wx.ALL, 5)
sizer.Add(urlBox, 0, wx.ALL, 5)
descriptionBox = wx.BoxSizer(wx.HORIZONTAL)
descriptionBox.Add(labelDescription, 0, wx.ALL, 5)
descriptionBox.Add(self.description, 0, wx.ALL, 5)
sizer.Add(descriptionBox, 0, wx.ALL, 5)
sizer.Add(self.upload_image, 5, wx.CENTER, 5)
btnBox = wx.BoxSizer(wx.HORIZONTAL)
btnBox.Add(ok, 0, wx.ALL, 5)
btnBox.Add(close, 0, wx.ALL, 5)
sizer.Add(btnBox, 0, wx.ALL, 5)
panel.SetSizer(sizer)
self.SetClientSize(sizer.CalcMin())
self.get_data()
def onUpload_picture(self, ev):
if self.upload_image.GetLabel() == _(u"Discard image"):
self.image = None
del self.file
output.speak(_(u"Discarded"))
self.upload_image.SetLabel(_(u"Upload a picture"))
else:
openFileDialog = wx.FileDialog(self, _(u"Select the picture to be uploaded"), "", "", _("Image files (*.png, *.jpg, *.gif)|*.png; *.jpg; *.gif"), wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return
self.file = open(openFileDialog.GetPath(), "rb")
self.image = True
self.upload_image.SetLabel(_(u"Discard image"))
ev.Skip()
def onUpdateProfile(self, ev):
try:
if self.image != None:
self.twitter.twitter.update_profile_image(image=self.file)
except TwythonError as e:
output.speak(u"Error %s. %s" % (e.error_code, e.msg))
try:
f = self.twitter.twitter.update_profile(name=self.name.GetValue(), location=self.location.GetValue(), url=self.url.GetValue(), description=self.description.GetValue())
self.EndModal(wx.ID_OK)
except TwythonError as e:
output.speak(u"Error %s. %s" % (e.error_code, e.msg))
return
def get_data(self):
data = self.twitter.twitter.show_user(screen_name=self.parent.db.settings["user_name"])
self.name.ChangeValue(data["name"])
if data["url"] != None:
self.url.ChangeValue(data["url"])
if len(data["location"]) > 0:
self.location.ChangeValue(data["location"])
if len(data["description"]) > 0:
self.description.ChangeValue(data["description"])

View File

@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
############################################################
# Copyright (c) 2013, 2014 Manuel Eduardo Cortéz Vallejo <manuel@manuelcortez.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################
import wx
import webbrowser
import url_shortener
class urlList(wx.Dialog):
def __init__(self, urls):
self.urls = urls
super(urlList, self).__init__(parent=None, title=_(u"Select an URL"))
panel = wx.Panel(self)
# label = wx.StaticText(panel, -1, _(u"Select a URL"))
self.lista = wx.ListBox(panel, -1)
self.lista.SetFocus()
self.populate_list()
self.lista.SetSelection(0)
self.lista.SetSize(self.lista.GetBestSize())
sizer = wx.BoxSizer(wx.VERTICAL)
# sizer.Add(label, 0, wx.ALL, 5)
sizer.Add(self.lista, 0, wx.ALL, 5)
goBtn = wx.Button(panel, wx.ID_OK)
goBtn.SetDefault()
goBtn.Bind(wx.EVT_BUTTON, self.onGo)
cancelBtn = wx.Button(panel, wx.ID_CANCEL)
btnSizer = wx.BoxSizer()
btnSizer.Add(goBtn, 0, wx.ALL, 5)
btnSizer.Add(cancelBtn, 0, wx.ALL, 5)
sizer.Add(btnSizer, 0, wx.ALL, 5)
panel.SetSizer(sizer)
self.SetClientSize(sizer.CalcMin())
def onGo(self, ev):
webbrowser.open(self.lista.GetStringSelection())
self.Destroy()
def populate_list(self):
for i in self.urls:
self.lista.Append(i)
class shorten(urlList):
def __init__(self, urls, parent):
urlList.__init__(self, urls)
self.parent = parent
def onGo(self, ev):
self.parent.text.SetValue(self.parent.text.GetValue().replace(self.lista.GetStringSelection(), url_shortener.shorten(self.lista.GetStringSelection())))
self.Destroy()
class unshorten(shorten):
def __init__(self, urls, parent):
shorten.__init__(self, urls, parent)
def onGo(self, ev):
self.parent.text.SetValue(self.parent.text.GetValue().replace(self.lista.GetStringSelection(), url_shortener.unshorten(self.lista.GetStringSelection())))
self.Destroy()

49
src/gui/dialogs/utils.py Normal file
View File

@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
############################################################
# Copyright (c) 2013, 2014 Manuel Eduardo Cortéz Vallejo <manuel@manuelcortez.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################
import wx, twitter, gui.dialogs, sound, config
from mysc.repeating_timer import RepeatingTimer
class selectUserDialog(wx.Dialog):
def __init__(self, parent, title):
self.parent = parent
wx.Dialog.__init__(self, None, -1)
panel = wx.Panel(self)
userSizer = wx.BoxSizer()
self.SetTitle(title)
if self.parent.nb.GetCurrentPage().name_buffer == "followers" or self.parent.nb.GetCurrentPage().name_buffer == "friends":
list = [self.parent.db.settings[self.parent.nb.GetCurrentPage().name_buffer][self.parent.nb.GetCurrentPage().list.get_selected()]["screen_name"]]
else:
try: list =twitter.utils.get_all_users(self.parent.db.settings[self.parent.nb.GetCurrentPage().name_buffer][self.parent.nb.GetCurrentPage().list.get_selected()], self.parent.db)
except KeyError: list = [self.parent.db.settings[self.parent.nb.GetCurrentPage().name_buffer][self.parent.nb.GetCurrentPage().list.get_selected()]["screen_name"]]
self.cb = wx.ComboBox(panel, -1, choices=list, value=list[0], size=wx.DefaultSize)
self.cb.SetFocus()
userSizer.Add(wx.StaticText(panel, -1, _(u"User")), 0, wx.ALL, 5)
userSizer.Add(self.cb)
sizer = wx.BoxSizer(wx.VERTICAL)
ok = wx.Button(panel, wx.ID_OK, _(u"OK"))
ok.SetDefault()
# ok.Bind(wx.EVT_BUTTON, self.onok)
cancel = wx.Button(panel, wx.ID_CANCEL, _(u"Close"))
btnsizer = wx.BoxSizer()
btnsizer.Add(ok, 0, wx.ALL, 5)
btnsizer.Add(cancel, 0, wx.ALL, 5)
sizer.Add(userSizer, 0, wx.ALL, 5)
sizer.Add(btnsizer, 0, wx.ALL, 5)
panel.SetSizer(sizer)
self.SetClientSize(sizer.CalcMin())