mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-07-24 16:46:08 -04:00
Merge branch 'next-gen' into mastodon
This commit is contained in:
@@ -32,3 +32,5 @@ class trendsPanel(wx.Panel):
|
||||
else:
|
||||
self.list.select_item(0)
|
||||
|
||||
def set_focus_in_list(self):
|
||||
self.list.list.SetFocus()
|
||||
|
@@ -91,5 +91,9 @@ def existing_filter():
|
||||
def common_error(reason):
|
||||
return wx.MessageDialog(None, reason, _(u"Error"), wx.OK).ShowModal()
|
||||
|
||||
def invalid_configuration():
|
||||
return wx.MessageDialog(None, _("The configuration file is invalid."), _("Error"), wx.ICON_ERROR).ShowModal()
|
||||
|
||||
def dead_pid():
|
||||
return wx.MessageDialog(None, _(u"{0} quit unexpectedly the last time it was run. If the problem persists, please report it to the {0} developers.").format(application.name), _(u"Warning"), wx.OK).ShowModal()
|
||||
|
||||
|
@@ -1,3 +1 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
from . import baseDialog, trends, configuration, lists, message, search, find, show_user, update_profile, urlList, userSelection, utils, filterDialogs, userAliasDialogs
|
||||
from . import baseDialog, trends, configuration, lists, search, find, show_user, update_profile, urlList, userSelection, utils, filterDialogs, userAliasDialogs
|
||||
|
@@ -1,48 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
""" Attach dialog. Taken from socializer: https://github.com/manuelcortez/socializer"""
|
||||
from __future__ import unicode_literals
|
||||
import wx
|
||||
import widgetUtils
|
||||
from multiplatform_widgets import widgets
|
||||
|
||||
class attachDialog(widgetUtils.BaseDialog):
|
||||
def __init__(self):
|
||||
super(attachDialog, self).__init__(None, title=_(u"Add an attachment"))
|
||||
panel = wx.Panel(self)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
lbl1 = wx.StaticText(panel, wx.ID_ANY, _(u"Attachments"))
|
||||
self.attachments = widgets.list(panel, _(u"Type"), _(u"Title"), style=wx.LC_REPORT)
|
||||
box = wx.BoxSizer(wx.HORIZONTAL)
|
||||
box.Add(lbl1, 0, wx.ALL, 5)
|
||||
box.Add(self.attachments.list, 0, wx.ALL, 5)
|
||||
sizer.Add(box, 0, wx.ALL, 5)
|
||||
static = wx.StaticBox(panel, label=_(u"Add attachments"))
|
||||
self.photo = wx.Button(panel, wx.ID_ANY, _(u"&Photo"))
|
||||
self.remove = wx.Button(panel, wx.ID_ANY, _(u"Remove attachment"))
|
||||
self.remove.Enable(False)
|
||||
btnsizer = wx.StaticBoxSizer(static, wx.HORIZONTAL)
|
||||
btnsizer.Add(self.photo, 0, wx.ALL, 5)
|
||||
sizer.Add(btnsizer, 0, wx.ALL, 5)
|
||||
ok = wx.Button(panel, wx.ID_OK)
|
||||
ok.SetDefault()
|
||||
cancelBtn = wx.Button(panel, wx.ID_CANCEL)
|
||||
btnSizer = wx.BoxSizer()
|
||||
btnSizer.Add(ok, 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 get_image(self):
|
||||
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 (None, None)
|
||||
dsc = self.ask_description()
|
||||
return (openFileDialog.GetPath(), dsc)
|
||||
|
||||
def ask_description(self):
|
||||
dlg = wx.TextEntryDialog(self, _(u"please provide a description"), _(u"Description"))
|
||||
dlg.ShowModal()
|
||||
result = dlg.GetValue()
|
||||
dlg.Destroy()
|
||||
return result
|
@@ -233,6 +233,20 @@ class other_buffers(wx.Panel):
|
||||
buffers_list.append(self.buffers.get_text_column(i, 0))
|
||||
return buffers_list
|
||||
|
||||
class templates(wx.Panel, baseDialog.BaseWXDialog):
|
||||
def __init__(self, parent, tweet_template, dm_template, sent_dm_template, person_template):
|
||||
super(templates, self).__init__(parent)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.tweet = wx.Button(self, wx.ID_ANY, _("Edit template for tweets. Current template: {}").format(tweet_template))
|
||||
sizer.Add(self.tweet, 0, wx.ALL, 5)
|
||||
self.dm = wx.Button(self, wx.ID_ANY, _("Edit template for direct messages. Current template: {}").format(dm_template))
|
||||
sizer.Add(self.dm, 0, wx.ALL, 5)
|
||||
self.sent_dm = wx.Button(self, wx.ID_ANY, _("Edit template for sent direct messages. Current template: {}").format(sent_dm_template))
|
||||
sizer.Add(self.sent_dm, 0, wx.ALL, 5)
|
||||
self.person = wx.Button(self, wx.ID_ANY, _("Edit template for persons. Current template: {}").format(person_template))
|
||||
sizer.Add(self.person, 0, wx.ALL, 5)
|
||||
self.SetSizer(sizer)
|
||||
|
||||
class ignoredClients(wx.Panel):
|
||||
def __init__(self, parent, choices):
|
||||
super(ignoredClients, self).__init__(parent=parent)
|
||||
@@ -380,6 +394,10 @@ class configurationDialog(baseDialog.BaseWXDialog):
|
||||
self.ignored_clients = ignoredClients(self.notebook, ignored_clients_list)
|
||||
self.notebook.AddPage(self.ignored_clients, _(u"Ignored clients"))
|
||||
|
||||
def create_templates(self, tweet_template, dm_template, sent_dm_template, person_template):
|
||||
self.templates = templates(self.notebook, tweet_template=tweet_template, dm_template=dm_template, sent_dm_template=sent_dm_template, person_template=person_template)
|
||||
self.notebook.AddPage(self.templates, _("Templates"))
|
||||
|
||||
def create_sound(self, output_devices, input_devices, soundpacks):
|
||||
self.sound = sound(self.notebook, output_devices, input_devices, soundpacks)
|
||||
self.notebook.AddPage(self.sound, _(u"Sound"))
|
||||
|
@@ -1,471 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import wx
|
||||
import widgetUtils
|
||||
|
||||
class textLimited(widgetUtils.BaseDialog):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(textLimited, self).__init__(parent=None, *args, **kwargs)
|
||||
|
||||
def createTextArea(self, message="", text=""):
|
||||
if not hasattr(self, "panel"):
|
||||
self.panel = wx.Panel(self)
|
||||
self.label = wx.StaticText(self.panel, -1, message)
|
||||
self.SetTitle(str(len(text)))
|
||||
self.text = wx.TextCtrl(self.panel, -1, text, size=(439, -1),style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER)
|
||||
# font = self.text.GetFont()
|
||||
# dc = wx.WindowDC(self.text)
|
||||
# dc.SetFont(font)
|
||||
# x, y = dc.GetTextExtent("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
|
||||
# self.text.SetSize((x, y))
|
||||
self.Bind(wx.EVT_CHAR_HOOK, self.handle_keys, self.text)
|
||||
self.text.SetFocus()
|
||||
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 text_focus(self):
|
||||
self.text.SetFocus()
|
||||
|
||||
def get_text(self):
|
||||
return self.text.GetValue()
|
||||
|
||||
def set_text(self, text):
|
||||
return self.text.ChangeValue(text)
|
||||
|
||||
def set_title(self, new_title):
|
||||
return self.SetTitle(new_title)
|
||||
|
||||
def enable_button(self, buttonName):
|
||||
if hasattr(self, buttonName):
|
||||
return getattr(self, buttonName).Enable()
|
||||
|
||||
def disable_button(self, buttonName):
|
||||
if hasattr(self, buttonName):
|
||||
return getattr(self, buttonName).Disable()
|
||||
|
||||
def onSelect(self, ev):
|
||||
self.text.SelectAll()
|
||||
|
||||
def handle_keys(self, event):
|
||||
shift=event.ShiftDown()
|
||||
if event.GetKeyCode() == wx.WXK_RETURN and shift==False and hasattr(self,'okButton'):
|
||||
wx.PostEvent(self.okButton.GetEventHandler(), wx.PyCommandEvent(wx.EVT_BUTTON.typeId,wx.ID_OK))
|
||||
else:
|
||||
event.Skip()
|
||||
|
||||
def set_cursor_at_end(self):
|
||||
self.text.SetInsertionPoint(len(self.text.GetValue()))
|
||||
|
||||
def set_cursor_at_position(self, position):
|
||||
self.text.SetInsertionPoint(position)
|
||||
|
||||
def get_position(self):
|
||||
return self.text.GetInsertionPoint()
|
||||
|
||||
def popup_menu(self, menu):
|
||||
self.PopupMenu(menu, self.text.GetPosition())
|
||||
|
||||
class tweet(textLimited):
|
||||
def createControls(self, title, message, text):
|
||||
self.mainBox = wx.BoxSizer(wx.VERTICAL)
|
||||
self.createTextArea(message, text)
|
||||
self.mainBox.Add(self.textBox, 0, wx.ALL, 5)
|
||||
self.long_tweet = wx.CheckBox(self.panel, -1, _(u"&Long tweet"))
|
||||
self.upload_image = wx.Button(self.panel, -1, _(u"&Upload image..."), size=wx.DefaultSize)
|
||||
self.spellcheck = wx.Button(self.panel, -1, _("Check &spelling..."), size=wx.DefaultSize)
|
||||
self.attach = wx.Button(self.panel, -1, _(u"&Attach audio..."), size=wx.DefaultSize)
|
||||
self.shortenButton = wx.Button(self.panel, -1, _(u"Sh&orten URL"), size=wx.DefaultSize)
|
||||
self.unshortenButton = wx.Button(self.panel, -1, _(u"&Expand URL"), size=wx.DefaultSize)
|
||||
self.shortenButton.Disable()
|
||||
self.unshortenButton.Disable()
|
||||
self.translateButton = wx.Button(self.panel, -1, _(u"&Translate..."), size=wx.DefaultSize)
|
||||
self.autocompletionButton = wx.Button(self.panel, -1, _(u"Auto&complete users"))
|
||||
self.okButton = wx.Button(self.panel, wx.ID_OK, _(u"Sen&d"), size=wx.DefaultSize)
|
||||
self.okButton.SetDefault()
|
||||
cancelButton = wx.Button(self.panel, wx.ID_CANCEL, _(u"C&lose"), size=wx.DefaultSize)
|
||||
self.buttonsBox1 = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.buttonsBox1.Add(self.upload_image, 0, wx.ALL, 10)
|
||||
self.buttonsBox1.Add(self.spellcheck, 0, wx.ALL, 10)
|
||||
self.buttonsBox1.Add(self.attach, 0, wx.ALL, 10)
|
||||
self.mainBox.Add(self.buttonsBox1, 0, wx.ALL, 10)
|
||||
self.buttonsBox2 = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.buttonsBox2.Add(self.shortenButton, 0, wx.ALL, 10)
|
||||
self.buttonsBox2.Add(self.unshortenButton, 0, wx.ALL, 10)
|
||||
self.buttonsBox2.Add(self.translateButton, 0, wx.ALL, 10)
|
||||
self.mainBox.Add(self.buttonsBox2, 0, wx.ALL, 10)
|
||||
self.ok_cancelSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.ok_cancelSizer.Add(self.autocompletionButton, 0, wx.ALL, 10)
|
||||
self.ok_cancelSizer.Add(self.okButton, 0, wx.ALL, 10)
|
||||
self.ok_cancelSizer.Add(cancelButton, 0, wx.ALL, 10)
|
||||
self.mainBox.Add(self.ok_cancelSizer)
|
||||
selectId = wx.ID_ANY
|
||||
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, title, message, text, *args, **kwargs):
|
||||
super(tweet, self).__init__()
|
||||
self.shift=False
|
||||
self.createControls(message, title, text)
|
||||
self.SetClientSize(self.mainBox.CalcMin())
|
||||
|
||||
def get_image(self):
|
||||
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 None
|
||||
return open(openFileDialog.GetPath(), "rb")
|
||||
|
||||
|
||||
class retweet(tweet):
|
||||
def createControls(self, title, message, text):
|
||||
self.mainBox = wx.BoxSizer(wx.VERTICAL)
|
||||
self.createTextArea(message, "")
|
||||
label = wx.StaticText(self.panel, -1, _(u"Retweet"))
|
||||
self.text2 = wx.TextCtrl(self.panel, -1, text, size=(439, -1), style=wx.TE_MULTILINE|wx.TE_READONLY)
|
||||
self.retweetBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.retweetBox.Add(label, 0, wx.ALL, 5)
|
||||
self.retweetBox.Add(self.text2, 0, wx.ALL, 5)
|
||||
self.mainBox.Add(self.textBox, 0, wx.ALL, 5)
|
||||
self.mainBox.Add(self.retweetBox, 0, wx.ALL, 5)
|
||||
self.upload_image = wx.Button(self.panel, -1, _(u"&Upload image..."), size=wx.DefaultSize)
|
||||
self.spellcheck = wx.Button(self.panel, -1, _("Check &spelling..."), size=wx.DefaultSize)
|
||||
self.attach = wx.Button(self.panel, -1, _(u"&Attach audio..."), size=wx.DefaultSize)
|
||||
self.shortenButton = wx.Button(self.panel, -1, _(u"Sh&orten URL"), size=wx.DefaultSize)
|
||||
self.unshortenButton = wx.Button(self.panel, -1, _(u"&Expand URL"), size=wx.DefaultSize)
|
||||
self.shortenButton.Disable()
|
||||
self.unshortenButton.Disable()
|
||||
self.translateButton = wx.Button(self.panel, -1, _(u"&Translate..."), size=wx.DefaultSize)
|
||||
self.autocompletionButton = wx.Button(self.panel, -1, _(u"Auto&complete users"))
|
||||
self.okButton = wx.Button(self.panel, wx.ID_OK, _(u"Sen&d"), size=wx.DefaultSize)
|
||||
self.okButton.SetDefault()
|
||||
cancelButton = wx.Button(self.panel, wx.ID_CANCEL, _(u"C&lose"), size=wx.DefaultSize)
|
||||
self.buttonsBox1 = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.buttonsBox1.Add(self.upload_image, 0, wx.ALL, 10)
|
||||
self.buttonsBox1.Add(self.spellcheck, 0, wx.ALL, 10)
|
||||
self.buttonsBox1.Add(self.attach, 0, wx.ALL, 10)
|
||||
self.mainBox.Add(self.buttonsBox1, 0, wx.ALL, 10)
|
||||
self.buttonsBox2 = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.buttonsBox2.Add(self.shortenButton, 0, wx.ALL, 10)
|
||||
self.buttonsBox2.Add(self.unshortenButton, 0, wx.ALL, 10)
|
||||
self.buttonsBox2.Add(self.translateButton, 0, wx.ALL, 10)
|
||||
self.mainBox.Add(self.buttonsBox2, 0, wx.ALL, 10)
|
||||
self.ok_cancelSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.ok_cancelSizer.Add(self.autocompletionButton, 0, wx.ALL, 10)
|
||||
self.ok_cancelSizer.Add(self.okButton, 0, wx.ALL, 10)
|
||||
self.ok_cancelSizer.Add(cancelButton, 0, wx.ALL, 10)
|
||||
self.mainBox.Add(self.ok_cancelSizer)
|
||||
selectId = wx.ID_ANY
|
||||
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, title, message, text, *args, **kwargs):
|
||||
super(tweet, self).__init__()
|
||||
self.createControls(message, title, text)
|
||||
# self.onTimer(wx.EVT_CHAR_HOOK)
|
||||
self.SetClientSize(self.mainBox.CalcMin())
|
||||
|
||||
def get_image(self):
|
||||
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 None
|
||||
return open(openFileDialog.GetPath(), "rb")
|
||||
|
||||
class dm(textLimited):
|
||||
def createControls(self, title, message, users):
|
||||
self.panel = wx.Panel(self)
|
||||
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"Auto&complete users"))
|
||||
self.createTextArea(message, text="")
|
||||
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.textBox, 0, wx.ALL, 5)
|
||||
self.spellcheck = wx.Button(self.panel, -1, _("Check &spelling..."), size=wx.DefaultSize)
|
||||
self.attach = wx.Button(self.panel, -1, _(u"&Attach audio..."), size=wx.DefaultSize)
|
||||
self.shortenButton = wx.Button(self.panel, -1, _(u"Sh&orten URL"), size=wx.DefaultSize)
|
||||
self.unshortenButton = wx.Button(self.panel, -1, _(u"&Expand URL"), size=wx.DefaultSize)
|
||||
self.shortenButton.Disable()
|
||||
self.unshortenButton.Disable()
|
||||
self.translateButton = wx.Button(self.panel, -1, _(u"&Translate..."), size=wx.DefaultSize)
|
||||
self.okButton = wx.Button(self.panel, wx.ID_OK, _(u"Sen&d"), size=wx.DefaultSize)
|
||||
self.okButton.SetDefault()
|
||||
cancelButton = wx.Button(self.panel, wx.ID_CANCEL, _(u"C&lose"), size=wx.DefaultSize)
|
||||
self.buttonsBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
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)
|
||||
self.SetClientSize(self.mainBox.CalcMin())
|
||||
|
||||
def __init__(self, title, message, users, *args, **kwargs):
|
||||
super(dm, self).__init__()
|
||||
self.createControls(title, message, users)
|
||||
# self.onTimer(wx.EVT_CHAR_HOOK)
|
||||
# self.SetClientSize(self.mainBox.CalcMin())
|
||||
|
||||
def get_user(self):
|
||||
return self.cb.GetValue()
|
||||
|
||||
def set_user(self, user):
|
||||
return self.cb.SetValue(user)
|
||||
|
||||
class reply(textLimited):
|
||||
|
||||
def get_image(self):
|
||||
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 None
|
||||
return open(openFileDialog.GetPath(), "rb")
|
||||
|
||||
def createControls(self, title, message, text):
|
||||
self.mainBox = wx.BoxSizer(wx.VERTICAL)
|
||||
self.createTextArea(message, text)
|
||||
self.mainBox.Add(self.textBox, 0, wx.ALL, 5)
|
||||
self.usersbox = wx.BoxSizer(wx.VERTICAL)
|
||||
self.mentionAll = wx.CheckBox(self.panel, -1, _(u"&Mention to all"), size=wx.DefaultSize)
|
||||
self.mentionAll.Disable()
|
||||
self.usersbox.Add(self.mentionAll, 0, wx.ALL, 5)
|
||||
self.checkboxes = []
|
||||
for i in self.users:
|
||||
user_checkbox = wx.CheckBox(self.panel, -1, "@"+i, size=wx.DefaultSize)
|
||||
self.checkboxes.append(user_checkbox)
|
||||
self.usersbox.Add(self.checkboxes[-1], 0, wx.ALL, 5)
|
||||
self.mainBox.Add(self.usersbox, 0, wx.ALL, 10)
|
||||
self.long_tweet = wx.CheckBox(self.panel, -1, _(u"&Long tweet"))
|
||||
self.upload_image = wx.Button(self.panel, -1, _(u"&Upload image..."), size=wx.DefaultSize)
|
||||
self.spellcheck = wx.Button(self.panel, -1, _("Check &spelling..."), size=wx.DefaultSize)
|
||||
self.attach = wx.Button(self.panel, -1, _(u"&Attach audio..."), size=wx.DefaultSize)
|
||||
self.shortenButton = wx.Button(self.panel, -1, _(u"Sh&orten URL"), size=wx.DefaultSize)
|
||||
self.unshortenButton = wx.Button(self.panel, -1, _(u"&Expand URL"), size=wx.DefaultSize)
|
||||
self.shortenButton.Disable()
|
||||
self.unshortenButton.Disable()
|
||||
self.translateButton = wx.Button(self.panel, -1, _(u"&Translate..."), size=wx.DefaultSize)
|
||||
self.autocompletionButton = wx.Button(self.panel, -1, _(u"Auto&complete users"))
|
||||
self.okButton = wx.Button(self.panel, wx.ID_OK, _(u"Sen&d"), size=wx.DefaultSize)
|
||||
self.okButton.SetDefault()
|
||||
cancelButton = wx.Button(self.panel, wx.ID_CANCEL, _(u"C&lose"), size=wx.DefaultSize)
|
||||
self.buttonsBox1 = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.buttonsBox1.Add(self.upload_image, 0, wx.ALL, 10)
|
||||
self.buttonsBox1.Add(self.spellcheck, 0, wx.ALL, 10)
|
||||
self.buttonsBox1.Add(self.attach, 0, wx.ALL, 10)
|
||||
self.mainBox.Add(self.buttonsBox1, 0, wx.ALL, 10)
|
||||
self.buttonsBox2 = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.buttonsBox2.Add(self.shortenButton, 0, wx.ALL, 10)
|
||||
self.buttonsBox2.Add(self.unshortenButton, 0, wx.ALL, 10)
|
||||
self.buttonsBox2.Add(self.translateButton, 0, wx.ALL, 10)
|
||||
self.mainBox.Add(self.buttonsBox2, 0, wx.ALL, 10)
|
||||
self.ok_cancelSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.ok_cancelSizer.Add(self.autocompletionButton, 0, wx.ALL, 10)
|
||||
self.ok_cancelSizer.Add(self.okButton, 0, wx.ALL, 10)
|
||||
self.ok_cancelSizer.Add(cancelButton, 0, wx.ALL, 10)
|
||||
self.mainBox.Add(self.ok_cancelSizer, 0, wx.ALL, 10)
|
||||
selectId = wx.ID_ANY
|
||||
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, title, message, text, users=[], *args, **kwargs):
|
||||
self.users = users
|
||||
super(reply, self).__init__()
|
||||
self.shift=False
|
||||
self.createControls(message, title, text)
|
||||
self.SetClientSize(self.mainBox.CalcMin())
|
||||
|
||||
class viewTweet(widgetUtils.BaseDialog):
|
||||
def set_title(self, lenght):
|
||||
self.SetTitle(_(u"Tweet - %i characters ") % (lenght,))
|
||||
|
||||
def __init__(self, text, rt_count, favs_count, source, date="", *args, **kwargs):
|
||||
super(viewTweet, self).__init__(None, size=(850,850))
|
||||
panel = wx.Panel(self)
|
||||
label = wx.StaticText(panel, -1, _(u"Tweet"))
|
||||
self.text = wx.TextCtrl(panel, -1, text, style=wx.TE_READONLY|wx.TE_MULTILINE, size=(250, 180))
|
||||
dc = wx.WindowDC(self.text)
|
||||
dc.SetFont(self.text.GetFont())
|
||||
(x, y) = 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)
|
||||
label2 = wx.StaticText(panel, -1, _(u"Image description"))
|
||||
self.image_description = wx.TextCtrl(panel, -1, style=wx.TE_READONLY|wx.TE_MULTILINE, size=(250, 180))
|
||||
dc = wx.WindowDC(self.image_description)
|
||||
dc.SetFont(self.image_description.GetFont())
|
||||
(x, y) = dc.GetMultiLineTextExtent("0"*450)
|
||||
self.image_description.SetSize((x, y))
|
||||
self.image_description.Enable(False)
|
||||
iBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
iBox.Add(label2, 0, wx.ALL, 5)
|
||||
iBox.Add(self.image_description, 1, wx.EXPAND, 5)
|
||||
mainBox.Add(iBox, 0, wx.ALL, 5)
|
||||
rtCountLabel = wx.StaticText(panel, -1, _(u"Retweets: "))
|
||||
rtCount = wx.TextCtrl(panel, -1, rt_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"Likes: "))
|
||||
favsCount = wx.TextCtrl(panel, -1, favs_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)
|
||||
sourceLabel = wx.StaticText(panel, -1, _(u"Source: "))
|
||||
sourceTweet = wx.TextCtrl(panel, -1, source, size=wx.DefaultSize, style=wx.TE_READONLY|wx.TE_MULTILINE)
|
||||
sourceBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
sourceBox.Add(sourceLabel, 0, wx.ALL, 5)
|
||||
sourceBox.Add(sourceTweet, 0, wx.ALL, 5)
|
||||
dateLabel = wx.StaticText(panel, -1, _(u"Date: "))
|
||||
dateTweet = wx.TextCtrl(panel, -1, date, size=wx.DefaultSize, style=wx.TE_READONLY|wx.TE_MULTILINE)
|
||||
dc = wx.WindowDC(dateTweet)
|
||||
dc.SetFont(dateTweet.GetFont())
|
||||
(x, y) = dc.GetTextExtent("0"*100)
|
||||
dateTweet.SetSize((x, y))
|
||||
dateBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
dateBox.Add(dateLabel, 0, wx.ALL, 5)
|
||||
dateBox.Add(dateTweet, 0, wx.ALL, 5)
|
||||
infoBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
infoBox.Add(rtBox, 0, wx.ALL, 5)
|
||||
infoBox.Add(favsBox, 0, wx.ALL, 5)
|
||||
infoBox.Add(sourceBox, 0, wx.ALL, 5)
|
||||
mainBox.Add(infoBox, 0, wx.ALL, 5)
|
||||
mainBox.Add(dateBox, 0, wx.ALL, 5)
|
||||
self.share = wx.Button(panel, wx.ID_ANY, _("Copy link to clipboard"))
|
||||
self.share.Enable(False)
|
||||
self.spellcheck = wx.Button(panel, -1, _("Check &spelling..."), size=wx.DefaultSize)
|
||||
self.unshortenButton = wx.Button(panel, -1, _(u"&Expand URL"), size=wx.DefaultSize)
|
||||
self.unshortenButton.Disable()
|
||||
self.translateButton = wx.Button(panel, -1, _(u"&Translate..."), size=wx.DefaultSize)
|
||||
cancelButton = wx.Button(panel, wx.ID_CANCEL, _(u"C&lose"), size=wx.DefaultSize)
|
||||
cancelButton.SetDefault()
|
||||
buttonsBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
buttonsBox.Add(self.share, 0, wx.ALL, 5)
|
||||
buttonsBox.Add(self.spellcheck, 0, wx.ALL, 5)
|
||||
buttonsBox.Add(self.unshortenButton, 0, wx.ALL, 5)
|
||||
buttonsBox.Add(self.translateButton, 0, wx.ALL, 5)
|
||||
buttonsBox.Add(cancelButton, 0, wx.ALL, 5)
|
||||
mainBox.Add(buttonsBox, 0, wx.ALL, 5)
|
||||
selectId = wx.ID_ANY
|
||||
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())
|
||||
|
||||
def set_text(self, text):
|
||||
self.text.ChangeValue(text)
|
||||
|
||||
def get_text(self):
|
||||
return self.text.GetValue()
|
||||
|
||||
def set_image_description(self, desc):
|
||||
self.image_description.Enable(True)
|
||||
if len(self.image_description.GetValue()) == 0:
|
||||
self.image_description.SetValue(desc)
|
||||
else:
|
||||
self.image_description.SetValue(self.image_description.GetValue()+"\n"+desc)
|
||||
|
||||
def text_focus(self):
|
||||
self.text.SetFocus()
|
||||
|
||||
def onSelect(self, ev):
|
||||
self.text.SelectAll()
|
||||
|
||||
def enable_button(self, buttonName):
|
||||
if hasattr(self, buttonName):
|
||||
return getattr(self, buttonName).Enable()
|
||||
|
||||
class viewNonTweet(widgetUtils.BaseDialog):
|
||||
|
||||
def __init__(self, text, date="", *args, **kwargs):
|
||||
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=text, style=wx.TE_READONLY|wx.TE_MULTILINE, size=(250, 180))
|
||||
dc = wx.WindowDC(self.text)
|
||||
dc.SetFont(self.text.GetFont())
|
||||
(x, y) = 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 date != "":
|
||||
dateLabel = wx.StaticText(panel, -1, _(u"Date: "))
|
||||
date = wx.TextCtrl(panel, -1, date, size=wx.DefaultSize, style=wx.TE_READONLY|wx.TE_MULTILINE)
|
||||
dc = wx.WindowDC(date)
|
||||
dc.SetFont(date.GetFont())
|
||||
(x, y) = dc.GetTextExtent("0"*100)
|
||||
date.SetSize((x, y))
|
||||
dateBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
dateBox.Add(dateLabel, 0, wx.ALL, 5)
|
||||
dateBox.Add(date, 0, wx.ALL, 5)
|
||||
mainBox.Add(dateBox, 0, wx.ALL, 5)
|
||||
self.share = wx.Button(panel, wx.ID_ANY, _("Copy link to clipboard"))
|
||||
self.share.Enable(False)
|
||||
self.spellcheck = wx.Button(panel, -1, _("Check &spelling..."), size=wx.DefaultSize)
|
||||
self.unshortenButton = wx.Button(panel, -1, _(u"&Expand URL"), size=wx.DefaultSize)
|
||||
self.unshortenButton.Disable()
|
||||
self.translateButton = wx.Button(panel, -1, _(u"&Translate..."), size=wx.DefaultSize)
|
||||
cancelButton = wx.Button(panel, wx.ID_CANCEL, _(u"C&lose"), size=wx.DefaultSize)
|
||||
cancelButton.SetDefault()
|
||||
buttonsBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
buttonsBox.Add(self.share, 0, wx.ALL, 5)
|
||||
buttonsBox.Add(self.spellcheck, 0, wx.ALL, 5)
|
||||
buttonsBox.Add(self.unshortenButton, 0, wx.ALL, 5)
|
||||
buttonsBox.Add(self.translateButton, 0, wx.ALL, 5)
|
||||
buttonsBox.Add(cancelButton, 0, wx.ALL, 5)
|
||||
mainBox.Add(buttonsBox, 0, wx.ALL, 5)
|
||||
selectId = wx.ID_ANY
|
||||
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())
|
||||
|
||||
def onSelect(self, ev):
|
||||
self.text.SelectAll()
|
||||
|
||||
def set_text(self, text):
|
||||
self.text.ChangeValue(text)
|
||||
|
||||
def get_text(self):
|
||||
return self.text.GetValue()
|
||||
|
||||
def text_focus(self):
|
||||
self.text.SetFocus()
|
||||
|
||||
def enable_button(self, buttonName):
|
||||
if hasattr(self, buttonName):
|
||||
return getattr(self, buttonName).Enable()
|
2
src/wxUI/dialogs/twitterDialogs/__init__.py
Normal file
2
src/wxUI/dialogs/twitterDialogs/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from .tweetDialogs import tweet, reply, dm, viewTweet, viewNonTweet, poll
|
||||
from .templateDialogs import EditTemplateDialog
|
52
src/wxUI/dialogs/twitterDialogs/templateDialogs.py
Normal file
52
src/wxUI/dialogs/twitterDialogs/templateDialogs.py
Normal file
@@ -0,0 +1,52 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
import wx
|
||||
import output
|
||||
from typing import List
|
||||
|
||||
class EditTemplateDialog(wx.Dialog):
|
||||
def __init__(self, template: str, variables: List[str] = [], default_template: str = "", *args, **kwds) -> None:
|
||||
super(EditTemplateDialog, self).__init__(parent=None, title=_("Edit Template"), *args, **kwds)
|
||||
self.default_template = default_template
|
||||
mainSizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
|
||||
mainSizer.Add(sizer_1, 1, wx.EXPAND, 0)
|
||||
label_1 = wx.StaticText(self, wx.ID_ANY, _("Edit template"))
|
||||
sizer_1.Add(label_1, 0, 0, 0)
|
||||
self.template = wx.TextCtrl(self, wx.ID_ANY, template)
|
||||
sizer_1.Add(self.template, 0, 0, 0)
|
||||
sizer_2 = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, _("Available variables")), wx.HORIZONTAL)
|
||||
mainSizer.Add(sizer_2, 1, wx.EXPAND, 0)
|
||||
self.variables = wx.ListBox(self, wx.ID_ANY, choices=["$"+v for v in variables])
|
||||
self.variables.Bind(wx.EVT_CHAR_HOOK, self.on_keypress)
|
||||
sizer_2.Add(self.variables, 0, 0, 0)
|
||||
sizer_3 = wx.StdDialogButtonSizer()
|
||||
mainSizer.Add(sizer_3, 0, wx.ALIGN_RIGHT | wx.ALL, 4)
|
||||
self.button_SAVE = wx.Button(self, wx.ID_SAVE)
|
||||
self.button_SAVE.SetDefault()
|
||||
sizer_3.AddButton(self.button_SAVE)
|
||||
self.button_CANCEL = wx.Button(self, wx.ID_CANCEL)
|
||||
sizer_3.AddButton(self.button_CANCEL)
|
||||
self.button_RESTORE = wx.Button(self, wx.ID_ANY, _("Restore template"))
|
||||
self.button_RESTORE.Bind(wx.EVT_BUTTON, self.on_restore)
|
||||
sizer_3.AddButton(self.button_CANCEL)
|
||||
sizer_3.Realize()
|
||||
self.SetSizer(mainSizer)
|
||||
mainSizer.Fit(self)
|
||||
self.SetAffirmativeId(self.button_SAVE.GetId())
|
||||
self.SetEscapeId(self.button_CANCEL.GetId())
|
||||
self.Layout()
|
||||
|
||||
def on_keypress(self, event, *args, **kwargs):
|
||||
if event.GetKeyCode() == wx.WXK_RETURN:
|
||||
self.template.ChangeValue(self.template.GetValue()+self.variables.GetStringSelection()+", ")
|
||||
output.speak(self.template.GetValue()+self.variables.GetStringSelection()+", ")
|
||||
return
|
||||
event.Skip()
|
||||
|
||||
def on_restore(self, *args, **kwargs) -> None:
|
||||
self.template.ChangeValue(self.default_template)
|
||||
output.speak(_("Restored template to {}.").format(self.default_template))
|
||||
self.template.SetFocus()
|
||||
|
||||
def invalid_template() -> None:
|
||||
wx.MessageDialog(None, _("the template you have specified include variables that do not exists for the object. Please fix the template and try again. For your reference, you can see a list of all available variables in the variables list while editing your template."), _("Invalid template"), wx.ICON_ERROR).ShowModal()
|
542
src/wxUI/dialogs/twitterDialogs/tweetDialogs.py
Normal file
542
src/wxUI/dialogs/twitterDialogs/tweetDialogs.py
Normal file
@@ -0,0 +1,542 @@
|
||||
""" GUI dialogs for tweet writing and displaying. """
|
||||
import wx
|
||||
from typing import List
|
||||
|
||||
class tweet(wx.Dialog):
|
||||
def __init__(self, title: str, caption: str, message: str = "", max_length: int = 280, thread_mode: bool = True, *args, **kwds) -> None:
|
||||
""" Creates the basic Tweet dialog. This might be considered the base class for other dialogs.
|
||||
title str: title to be used in the dialog.
|
||||
caption str: This is the text to be placed alongside the text field.
|
||||
message str: Text to be inserted in the tweet.
|
||||
max_length int: Maximum amount of characters the tweet will accept. By default is 280 chahracters.
|
||||
thread_mode bool: If set to False, disables the button that allows to make threads by adding more tweets.
|
||||
"""
|
||||
super(tweet, self).__init__(parent=None, *args, **kwds)
|
||||
self.SetTitle(title)
|
||||
self.create_controls(max_length=max_length, caption=caption, message=message, thread_mode=thread_mode)
|
||||
|
||||
def create_controls(self, message: str, caption: str, max_length: int, thread_mode: bool) -> None:
|
||||
panel = wx.Panel(self)
|
||||
mainBox = wx.BoxSizer(wx.VERTICAL)
|
||||
text_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
mainBox.Add(text_sizer, 1, wx.EXPAND, 0)
|
||||
label_1 = wx.StaticText(panel, wx.ID_ANY, caption)
|
||||
text_sizer.Add(label_1, 0, 0, 0)
|
||||
self.text = wx.TextCtrl(panel, wx.ID_ANY, "", size=(444, -1), style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER)
|
||||
self.Bind(wx.EVT_CHAR_HOOK, self.handle_keys, self.text)
|
||||
text_sizer.Add(self.text, 1, wx.EXPAND, 0)
|
||||
list_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
mainBox.Add(list_sizer, 1, wx.EXPAND, 0)
|
||||
Attachment_sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
list_sizer.Add(Attachment_sizer, 1, wx.EXPAND, 0)
|
||||
label_2 = wx.StaticText(panel, wx.ID_ANY, _("Attachments"))
|
||||
Attachment_sizer.Add(label_2, 0, 0, 0)
|
||||
self.attachments = wx.ListCtrl(panel, wx.ID_ANY, style=wx.BORDER_SUNKEN | wx.LC_HRULES | wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_VRULES)
|
||||
self.attachments.AppendColumn(_("File"))
|
||||
self.attachments.AppendColumn(_("Type"))
|
||||
self.attachments.AppendColumn(_("Description"))
|
||||
Attachment_sizer.Add(self.attachments, 1, wx.EXPAND, 0)
|
||||
self.remove_attachment = wx.Button(panel, wx.ID_ANY, _("Delete attachment"))
|
||||
self.remove_attachment.Enable(False)
|
||||
Attachment_sizer.Add(self.remove_attachment, 0, 0, 0)
|
||||
tweet_sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
list_sizer.Add(tweet_sizer, 1, wx.EXPAND, 0)
|
||||
label_3 = wx.StaticText(panel, wx.ID_ANY, _("Added Tweets"))
|
||||
tweet_sizer.Add(label_3, 0, 0, 0)
|
||||
self.tweets = wx.ListCtrl(panel, wx.ID_ANY, style=wx.BORDER_SUNKEN | wx.LC_HRULES | wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_VRULES)
|
||||
self.tweets.AppendColumn(_("Text"))
|
||||
self.tweets.AppendColumn(_("Attachments"))
|
||||
self.tweets.Enable(False)
|
||||
tweet_sizer.Add(self.tweets, 1, wx.EXPAND, 0)
|
||||
self.remove_tweet = wx.Button(panel, wx.ID_ANY, _("Delete tweet"))
|
||||
self.remove_tweet.Enable(False)
|
||||
tweet_sizer.Add(self.remove_tweet, 0, 0, 0)
|
||||
btn_sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
|
||||
mainBox.Add(btn_sizer_1, 1, wx.EXPAND, 0)
|
||||
self.add = wx.Button(panel, wx.ID_ANY, _("A&dd..."))
|
||||
btn_sizer_1.Add(self.add, 0, 0, 0)
|
||||
self.add_tweet = wx.Button(panel, wx.ID_ANY, _("Add t&weet"))
|
||||
self.add_tweet.Enable(thread_mode)
|
||||
btn_sizer_1.Add(self.add_tweet, 0, 0, 0)
|
||||
self.add_audio = wx.Button(panel, wx.ID_ANY, _("&Attach audio..."))
|
||||
btn_sizer_1.Add(self.add_audio, 0, 0, 0)
|
||||
btn_sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
|
||||
mainBox.Add(btn_sizer_2, 1, wx.EXPAND, 0)
|
||||
self.autocomplete_users = wx.Button(panel, wx.ID_ANY, _("Auto&complete users"))
|
||||
btn_sizer_2.Add(self.autocomplete_users, 0, 0, 0)
|
||||
self.spellcheck = wx.Button(panel, wx.ID_ANY, _("Check &spelling..."))
|
||||
btn_sizer_2.Add(self.spellcheck, 0, 0, 0)
|
||||
self.translate = wx.Button(panel, wx.ID_ANY, _("&Translate"))
|
||||
btn_sizer_2.Add(self.translate, 0, 0, 0)
|
||||
ok_cancel_sizer = wx.StdDialogButtonSizer()
|
||||
mainBox.Add(ok_cancel_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 4)
|
||||
self.send = wx.Button(panel, wx.ID_OK, _("Sen&d"))
|
||||
self.send.SetDefault()
|
||||
ok_cancel_sizer.Add(self.send, 0, 0, 0)
|
||||
self.cancel = wx.Button(panel, wx.ID_CANCEL, "")
|
||||
ok_cancel_sizer.AddButton(self.cancel)
|
||||
ok_cancel_sizer.Realize()
|
||||
panel.SetSizer(mainBox)
|
||||
self.Fit()
|
||||
self.SetAffirmativeId(self.send.GetId())
|
||||
self.SetEscapeId(self.cancel.GetId())
|
||||
self.Layout()
|
||||
|
||||
def handle_keys(self, event: wx.Event, *args, **kwargs) -> None:
|
||||
""" Allows to react to certain keyboard events from the text control. """
|
||||
shift=event.ShiftDown()
|
||||
if event.GetKeyCode() == wx.WXK_RETURN and shift==False and hasattr(self,'send'):
|
||||
self.EndModal(wx.ID_OK)
|
||||
else:
|
||||
event.Skip()
|
||||
|
||||
def reset_controls(self) -> None:
|
||||
""" Resetss text control and attachments to their default, empty values. This is used while adding more tweets in a thread. """
|
||||
self.text.ChangeValue("")
|
||||
self.attachments.DeleteAllItems()
|
||||
|
||||
def add_item(self, list_type: str = "attachment", item: List[str] = []) -> None:
|
||||
""" Adds an item to a list control. Item should be a list with the same amount of items for each column present in the ListCtrl. """
|
||||
if list_type == "attachment":
|
||||
self.attachments.Append(item)
|
||||
else:
|
||||
self.tweets.Append(item)
|
||||
|
||||
def remove_item(self, list_type: str = "attachment") -> None:
|
||||
if list_type == "attachment":
|
||||
item = self.attachments.GetFocusedItem()
|
||||
if item > -1:
|
||||
self.attachments.DeleteItem(item)
|
||||
else:
|
||||
item = self.tweets.GetFocusedItem()
|
||||
if item > -1:
|
||||
self.tweets.DeleteItem(item)
|
||||
|
||||
def attach_menu(self, event=None, enabled=True, *args, **kwargs):
|
||||
menu = wx.Menu()
|
||||
self.add_image = menu.Append(wx.ID_ANY, _("Image"))
|
||||
self.add_image.Enable(enabled)
|
||||
self.add_video = menu.Append(wx.ID_ANY, _("Video"))
|
||||
self.add_video.Enable(enabled)
|
||||
self.add_poll = menu.Append(wx.ID_ANY, _("Poll"))
|
||||
self.add_poll.Enable(enabled)
|
||||
return menu
|
||||
|
||||
def ask_description(self):
|
||||
dlg = wx.TextEntryDialog(self, _(u"please provide a description"), _(u"Description"))
|
||||
dlg.ShowModal()
|
||||
result = dlg.GetValue()
|
||||
dlg.Destroy()
|
||||
return result
|
||||
|
||||
def get_image(self):
|
||||
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 (None, None)
|
||||
dsc = self.ask_description()
|
||||
return (openFileDialog.GetPath(), dsc)
|
||||
|
||||
def get_video(self):
|
||||
openFileDialog = wx.FileDialog(self, _("Select the video to be uploaded"), "", "", _("Video files (*.mp4)|*.mp4"), wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
|
||||
if openFileDialog.ShowModal() == wx.ID_CANCEL:
|
||||
return None
|
||||
return openFileDialog.GetPath()
|
||||
|
||||
def unable_to_attach_file(self, *args, **kwargs):
|
||||
return wx.MessageDialog(self, _("It is not possible to add more attachments. Please make sure your tweet complies with Twitter'S attachment rules. You can add only one video or GIF in every tweet, and a maximum of 4 photos."), _("Error adding attachment"), wx.ICON_ERROR).ShowModal()
|
||||
|
||||
class reply(tweet):
|
||||
|
||||
def __init__(self, users: List[str] = [], *args, **kwargs) -> None:
|
||||
self.users = users
|
||||
super(reply, self).__init__(*args, **kwargs)
|
||||
|
||||
def create_controls(self, message: str, caption: str, max_length: int, thread_mode: bool) -> None:
|
||||
panel = wx.Panel(self)
|
||||
mainBox = wx.BoxSizer(wx.VERTICAL)
|
||||
text_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
mainBox.Add(text_sizer, 1, wx.EXPAND, 0)
|
||||
label_1 = wx.StaticText(panel, wx.ID_ANY, caption)
|
||||
text_sizer.Add(label_1, 0, 0, 0)
|
||||
self.text = wx.TextCtrl(panel, wx.ID_ANY, "", size=(500, 200), style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER)
|
||||
self.Bind(wx.EVT_CHAR_HOOK, self.handle_keys, self.text)
|
||||
text_sizer.Add(self.text, 1, wx.EXPAND, 0)
|
||||
list_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
mainBox.Add(list_sizer, 1, wx.EXPAND, 0)
|
||||
Attachment_sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
list_sizer.Add(Attachment_sizer, 1, wx.EXPAND, 0)
|
||||
label_2 = wx.StaticText(panel, wx.ID_ANY, _("Attachments"))
|
||||
Attachment_sizer.Add(label_2, 0, 0, 0)
|
||||
self.attachments = wx.ListCtrl(panel, wx.ID_ANY, style=wx.BORDER_SUNKEN | wx.LC_HRULES | wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_VRULES)
|
||||
self.attachments.AppendColumn(_("File"))
|
||||
self.attachments.AppendColumn(_("Type"))
|
||||
self.attachments.AppendColumn(_("Description"))
|
||||
Attachment_sizer.Add(self.attachments, 1, wx.EXPAND, 0)
|
||||
self.remove_attachment = wx.Button(panel, wx.ID_ANY, _("Delete attachment"))
|
||||
self.remove_attachment.Enable(False)
|
||||
Attachment_sizer.Add(self.remove_attachment, 0, 0, 0)
|
||||
user_sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
list_sizer.Add(user_sizer, 0, 0, 0)
|
||||
self.mention_all = wx.CheckBox(panel, -1, _(u"&Mention to all"), size=wx.DefaultSize)
|
||||
self.mention_all.Disable()
|
||||
user_sizer.Add(self.mention_all, 0, wx.ALL, 5)
|
||||
self.checkboxes = []
|
||||
for i in self.users:
|
||||
user_checkbox = wx.CheckBox(panel, -1, "@"+i, size=wx.DefaultSize)
|
||||
self.checkboxes.append(user_checkbox)
|
||||
user_sizer.Add(self.checkboxes[-1], 0, wx.ALL, 5)
|
||||
btn_sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
|
||||
mainBox.Add(btn_sizer_1, 1, wx.EXPAND, 0)
|
||||
self.add = wx.Button(panel, wx.ID_ANY, _("A&dd..."))
|
||||
btn_sizer_1.Add(self.add, 0, 0, 0)
|
||||
self.add_audio = wx.Button(panel, wx.ID_ANY, _("&Attach audio..."))
|
||||
btn_sizer_1.Add(self.add_audio, 0, 0, 0)
|
||||
btn_sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
|
||||
mainBox.Add(btn_sizer_2, 1, wx.EXPAND, 0)
|
||||
self.autocomplete_users = wx.Button(panel, wx.ID_ANY, _("Auto&complete users"))
|
||||
btn_sizer_2.Add(self.autocomplete_users, 0, 0, 0)
|
||||
self.spellcheck = wx.Button(panel, wx.ID_ANY, _("Check &spelling..."))
|
||||
btn_sizer_2.Add(self.spellcheck, 0, 0, 0)
|
||||
self.translate = wx.Button(panel, wx.ID_ANY, _("&Translate"))
|
||||
btn_sizer_2.Add(self.translate, 0, 0, 0)
|
||||
ok_cancel_sizer = wx.StdDialogButtonSizer()
|
||||
mainBox.Add(ok_cancel_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 4)
|
||||
self.send = wx.Button(panel, wx.ID_OK, _("Sen&d"))
|
||||
self.send.SetDefault()
|
||||
ok_cancel_sizer.Add(self.send, 0, 0, 0)
|
||||
self.cancel = wx.Button(panel, wx.ID_CANCEL, "")
|
||||
ok_cancel_sizer.AddButton(self.cancel)
|
||||
ok_cancel_sizer.Realize()
|
||||
panel.SetSizer(mainBox)
|
||||
self.Fit()
|
||||
self.SetAffirmativeId(self.send.GetId())
|
||||
self.SetEscapeId(self.cancel.GetId())
|
||||
self.Layout()
|
||||
|
||||
def attach_menu(self, event=None, enabled=True, *args, **kwargs):
|
||||
menu = wx.Menu()
|
||||
self.add_image = menu.Append(wx.ID_ANY, _("Image"))
|
||||
self.add_image.Enable(enabled)
|
||||
self.add_video = menu.Append(wx.ID_ANY, _("Video"))
|
||||
self.add_video.Enable(enabled)
|
||||
return menu
|
||||
|
||||
class dm(tweet):
|
||||
|
||||
def __init__(self, users: List[str] = [], *args, **kwargs) -> None:
|
||||
self.users = users
|
||||
super(dm, self).__init__(*args, **kwargs)
|
||||
|
||||
def create_controls(self, message: str, caption: str, max_length: int, thread_mode: bool) -> None:
|
||||
panel = wx.Panel(self)
|
||||
mainBox = wx.BoxSizer(wx.VERTICAL)
|
||||
label_recipient = wx.StaticText(panel, -1, _("&Recipient"))
|
||||
self.cb = wx.ComboBox(panel, -1, choices=self.users, value=self.users[0], size=wx.DefaultSize)
|
||||
self.autocomplete_users = wx.Button(panel, -1, _(u"Auto&complete users"))
|
||||
recipient_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
recipient_sizer.Add(label_recipient, 0, 0, 0)
|
||||
recipient_sizer.Add(self.cb, 1, wx.EXPAND, 0)
|
||||
mainBox.Add(recipient_sizer, 0, wx.EXPAND, 0)
|
||||
text_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
mainBox.Add(text_sizer, 1, wx.EXPAND, 0)
|
||||
label_1 = wx.StaticText(panel, wx.ID_ANY, caption)
|
||||
text_sizer.Add(label_1, 0, 0, 0)
|
||||
self.text = wx.TextCtrl(panel, wx.ID_ANY, "", size=(500, 200), style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER)
|
||||
self.Bind(wx.EVT_CHAR_HOOK, self.handle_keys, self.text)
|
||||
self.text.SetFocus()
|
||||
text_sizer.Add(self.text, 1, wx.EXPAND, 0)
|
||||
list_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
mainBox.Add(list_sizer, 1, wx.EXPAND, 0)
|
||||
Attachment_sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
list_sizer.Add(Attachment_sizer, 1, wx.EXPAND, 0)
|
||||
label_2 = wx.StaticText(panel, wx.ID_ANY, _("Attachments"))
|
||||
Attachment_sizer.Add(label_2, 0, 0, 0)
|
||||
self.attachments = wx.ListCtrl(panel, wx.ID_ANY, style=wx.BORDER_SUNKEN | wx.LC_HRULES | wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_VRULES)
|
||||
self.attachments.AppendColumn(_("File"))
|
||||
self.attachments.AppendColumn(_("Type"))
|
||||
self.attachments.AppendColumn(_("Description"))
|
||||
Attachment_sizer.Add(self.attachments, 1, wx.EXPAND, 0)
|
||||
self.remove_attachment = wx.Button(panel, wx.ID_ANY, _("Delete attachment"))
|
||||
self.remove_attachment.Enable(False)
|
||||
Attachment_sizer.Add(self.remove_attachment, 0, 0, 0)
|
||||
btn_sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
|
||||
mainBox.Add(btn_sizer_1, 1, wx.EXPAND, 0)
|
||||
self.add = wx.Button(panel, wx.ID_ANY, _("A&dd..."))
|
||||
btn_sizer_1.Add(self.add, 0, 0, 0)
|
||||
self.add_audio = wx.Button(panel, wx.ID_ANY, _("&Attach audio..."))
|
||||
btn_sizer_1.Add(self.add_audio, 0, 0, 0)
|
||||
btn_sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
|
||||
mainBox.Add(btn_sizer_2, 1, wx.EXPAND, 0)
|
||||
self.spellcheck = wx.Button(panel, wx.ID_ANY, _("Check &spelling..."))
|
||||
btn_sizer_2.Add(self.spellcheck, 0, 0, 0)
|
||||
self.translate = wx.Button(panel, wx.ID_ANY, _("&Translate"))
|
||||
btn_sizer_2.Add(self.translate, 0, 0, 0)
|
||||
ok_cancel_sizer = wx.StdDialogButtonSizer()
|
||||
mainBox.Add(ok_cancel_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 4)
|
||||
self.send = wx.Button(panel, wx.ID_OK, _("Sen&d"))
|
||||
self.send.SetDefault()
|
||||
ok_cancel_sizer.Add(self.send, 0, 0, 0)
|
||||
self.cancel = wx.Button(panel, wx.ID_CANCEL, "")
|
||||
ok_cancel_sizer.AddButton(self.cancel)
|
||||
ok_cancel_sizer.Realize()
|
||||
panel.SetSizer(mainBox)
|
||||
self.Fit()
|
||||
self.SetAffirmativeId(self.send.GetId())
|
||||
self.SetEscapeId(self.cancel.GetId())
|
||||
self.Layout()
|
||||
|
||||
def get_image(self):
|
||||
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 (None, None)
|
||||
return (openFileDialog.GetPath(), "")
|
||||
|
||||
def attach_menu(self, event=None, enabled=True, *args, **kwargs):
|
||||
menu = wx.Menu()
|
||||
self.add_image = menu.Append(wx.ID_ANY, _("Image"))
|
||||
self.add_image.Enable(enabled)
|
||||
self.add_video = menu.Append(wx.ID_ANY, _("Video"))
|
||||
self.add_video.Enable(enabled)
|
||||
return menu
|
||||
|
||||
class viewTweet(wx.Dialog):
|
||||
def set_title(self, lenght):
|
||||
self.SetTitle(_(u"Tweet - %i characters ") % (lenght,))
|
||||
|
||||
def __init__(self, text, rt_count, favs_count, source, date="", *args, **kwargs):
|
||||
super(viewTweet, self).__init__(None, size=(850,850))
|
||||
panel = wx.Panel(self)
|
||||
label = wx.StaticText(panel, -1, _(u"Tweet"))
|
||||
self.text = wx.TextCtrl(panel, -1, text, style=wx.TE_READONLY|wx.TE_MULTILINE, size=(250, 180))
|
||||
dc = wx.WindowDC(self.text)
|
||||
dc.SetFont(self.text.GetFont())
|
||||
(x, y) = dc.GetMultiLineTextExtent("W"*280)
|
||||
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)
|
||||
label2 = wx.StaticText(panel, -1, _(u"Image description"))
|
||||
self.image_description = wx.TextCtrl(panel, -1, style=wx.TE_READONLY|wx.TE_MULTILINE, size=(250, 180))
|
||||
dc = wx.WindowDC(self.image_description)
|
||||
dc.SetFont(self.image_description.GetFont())
|
||||
(x, y) = dc.GetMultiLineTextExtent("0"*450)
|
||||
self.image_description.SetSize((x, y))
|
||||
self.image_description.Enable(False)
|
||||
iBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
iBox.Add(label2, 0, wx.ALL, 5)
|
||||
iBox.Add(self.image_description, 1, wx.EXPAND, 5)
|
||||
mainBox.Add(iBox, 0, wx.ALL, 5)
|
||||
rtCountLabel = wx.StaticText(panel, -1, _(u"Retweets: "))
|
||||
rtCount = wx.TextCtrl(panel, -1, rt_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"Likes: "))
|
||||
favsCount = wx.TextCtrl(panel, -1, favs_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)
|
||||
sourceLabel = wx.StaticText(panel, -1, _(u"Source: "))
|
||||
sourceTweet = wx.TextCtrl(panel, -1, source, size=wx.DefaultSize, style=wx.TE_READONLY|wx.TE_MULTILINE)
|
||||
sourceBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
sourceBox.Add(sourceLabel, 0, wx.ALL, 5)
|
||||
sourceBox.Add(sourceTweet, 0, wx.ALL, 5)
|
||||
dateLabel = wx.StaticText(panel, -1, _(u"Date: "))
|
||||
dateTweet = wx.TextCtrl(panel, -1, date, size=wx.DefaultSize, style=wx.TE_READONLY|wx.TE_MULTILINE)
|
||||
dc = wx.WindowDC(dateTweet)
|
||||
dc.SetFont(dateTweet.GetFont())
|
||||
(x, y) = dc.GetTextExtent("0"*100)
|
||||
dateTweet.SetSize((x, y))
|
||||
dateBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
dateBox.Add(dateLabel, 0, wx.ALL, 5)
|
||||
dateBox.Add(dateTweet, 0, wx.ALL, 5)
|
||||
infoBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
infoBox.Add(rtBox, 0, wx.ALL, 5)
|
||||
infoBox.Add(favsBox, 0, wx.ALL, 5)
|
||||
infoBox.Add(sourceBox, 0, wx.ALL, 5)
|
||||
mainBox.Add(infoBox, 0, wx.ALL, 5)
|
||||
mainBox.Add(dateBox, 0, wx.ALL, 5)
|
||||
self.share = wx.Button(panel, wx.ID_ANY, _("Copy link to clipboard"))
|
||||
self.share.Enable(False)
|
||||
self.spellcheck = wx.Button(panel, -1, _("Check &spelling..."), size=wx.DefaultSize)
|
||||
self.translateButton = wx.Button(panel, -1, _(u"&Translate..."), size=wx.DefaultSize)
|
||||
cancelButton = wx.Button(panel, wx.ID_CANCEL, _(u"C&lose"), size=wx.DefaultSize)
|
||||
cancelButton.SetDefault()
|
||||
buttonsBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
buttonsBox.Add(self.share, 0, wx.ALL, 5)
|
||||
buttonsBox.Add(self.spellcheck, 0, wx.ALL, 5)
|
||||
buttonsBox.Add(self.translateButton, 0, wx.ALL, 5)
|
||||
buttonsBox.Add(cancelButton, 0, wx.ALL, 5)
|
||||
mainBox.Add(buttonsBox, 0, wx.ALL, 5)
|
||||
selectId = wx.ID_ANY
|
||||
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())
|
||||
|
||||
def set_text(self, text):
|
||||
self.text.ChangeValue(text)
|
||||
|
||||
def get_text(self):
|
||||
return self.text.GetValue()
|
||||
|
||||
def set_image_description(self, desc):
|
||||
self.image_description.Enable(True)
|
||||
if len(self.image_description.GetValue()) == 0:
|
||||
self.image_description.SetValue(desc)
|
||||
else:
|
||||
self.image_description.SetValue(self.image_description.GetValue()+"\n"+desc)
|
||||
|
||||
def text_focus(self):
|
||||
self.text.SetFocus()
|
||||
|
||||
def onSelect(self, ev):
|
||||
self.text.SelectAll()
|
||||
|
||||
def enable_button(self, buttonName):
|
||||
if hasattr(self, buttonName):
|
||||
return getattr(self, buttonName).Enable()
|
||||
|
||||
class viewNonTweet(wx.Dialog):
|
||||
|
||||
def __init__(self, text, date="", *args, **kwargs):
|
||||
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=text, style=wx.TE_READONLY|wx.TE_MULTILINE, size=(250, 180))
|
||||
dc = wx.WindowDC(self.text)
|
||||
dc.SetFont(self.text.GetFont())
|
||||
(x, y) = 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 date != "":
|
||||
dateLabel = wx.StaticText(panel, -1, _(u"Date: "))
|
||||
date = wx.TextCtrl(panel, -1, date, size=wx.DefaultSize, style=wx.TE_READONLY|wx.TE_MULTILINE)
|
||||
dc = wx.WindowDC(date)
|
||||
dc.SetFont(date.GetFont())
|
||||
(x, y) = dc.GetTextExtent("0"*100)
|
||||
date.SetSize((x, y))
|
||||
dateBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
dateBox.Add(dateLabel, 0, wx.ALL, 5)
|
||||
dateBox.Add(date, 0, wx.ALL, 5)
|
||||
mainBox.Add(dateBox, 0, wx.ALL, 5)
|
||||
self.share = wx.Button(panel, wx.ID_ANY, _("Copy link to clipboard"))
|
||||
self.share.Enable(False)
|
||||
self.spellcheck = wx.Button(panel, -1, _("Check &spelling..."), size=wx.DefaultSize)
|
||||
self.unshortenButton = wx.Button(panel, -1, _(u"&Expand URL"), size=wx.DefaultSize)
|
||||
self.unshortenButton.Disable()
|
||||
self.translateButton = wx.Button(panel, -1, _(u"&Translate..."), size=wx.DefaultSize)
|
||||
cancelButton = wx.Button(panel, wx.ID_CANCEL, _(u"C&lose"), size=wx.DefaultSize)
|
||||
cancelButton.SetDefault()
|
||||
buttonsBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
buttonsBox.Add(self.share, 0, wx.ALL, 5)
|
||||
buttonsBox.Add(self.spellcheck, 0, wx.ALL, 5)
|
||||
buttonsBox.Add(self.unshortenButton, 0, wx.ALL, 5)
|
||||
buttonsBox.Add(self.translateButton, 0, wx.ALL, 5)
|
||||
buttonsBox.Add(cancelButton, 0, wx.ALL, 5)
|
||||
mainBox.Add(buttonsBox, 0, wx.ALL, 5)
|
||||
selectId = wx.ID_ANY
|
||||
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())
|
||||
|
||||
def onSelect(self, ev):
|
||||
self.text.SelectAll()
|
||||
|
||||
def set_text(self, text):
|
||||
self.text.ChangeValue(text)
|
||||
|
||||
def get_text(self):
|
||||
return self.text.GetValue()
|
||||
|
||||
def text_focus(self):
|
||||
self.text.SetFocus()
|
||||
|
||||
def enable_button(self, buttonName):
|
||||
if hasattr(self, buttonName):
|
||||
return getattr(self, buttonName).Enable()
|
||||
|
||||
class poll(wx.Dialog):
|
||||
def __init__(self, *args, **kwds):
|
||||
super(poll, self).__init__(parent=None, id=wx.NewId(), title=_("Add a poll"))
|
||||
sizer_1 = wx.BoxSizer(wx.VERTICAL)
|
||||
period_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
sizer_1.Add(period_sizer, 1, wx.EXPAND, 0)
|
||||
label_period = wx.StaticText(self, wx.ID_ANY, _("Participation time (in days)"))
|
||||
period_sizer.Add(label_period, 0, 0, 0)
|
||||
self.period = wx.SpinCtrl(self, wx.ID_ANY)
|
||||
self.period.SetFocus()
|
||||
self.period.SetRange(1, 7)
|
||||
self.period.SetValue(7)
|
||||
period_sizer.Add(self.period, 0, 0, 0)
|
||||
sizer_2 = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, _("Choices")), wx.VERTICAL)
|
||||
sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
|
||||
option1_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
sizer_2.Add(option1_sizer, 1, wx.EXPAND, 0)
|
||||
label_2 = wx.StaticText(self, wx.ID_ANY, _("Option 1"))
|
||||
option1_sizer.Add(label_2, 0, 0, 0)
|
||||
self.option1 = wx.TextCtrl(self, wx.ID_ANY, "")
|
||||
self.option1.SetMaxLength(25)
|
||||
option1_sizer.Add(self.option1, 0, 0, 0)
|
||||
option2_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
sizer_2.Add(option2_sizer, 1, wx.EXPAND, 0)
|
||||
label_3 = wx.StaticText(self, wx.ID_ANY, _("Option 2"))
|
||||
option2_sizer.Add(label_3, 0, 0, 0)
|
||||
self.option2 = wx.TextCtrl(self, wx.ID_ANY, "")
|
||||
self.option2.SetMaxLength(25)
|
||||
option2_sizer.Add(self.option2, 0, 0, 0)
|
||||
option3_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
sizer_2.Add(option3_sizer, 1, wx.EXPAND, 0)
|
||||
label_4 = wx.StaticText(self, wx.ID_ANY, _("Option 3"))
|
||||
option3_sizer.Add(label_4, 0, 0, 0)
|
||||
self.option3 = wx.TextCtrl(self, wx.ID_ANY, "")
|
||||
self.option3.SetMaxLength(25)
|
||||
option3_sizer.Add(self.option3, 0, 0, 0)
|
||||
option4_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
sizer_2.Add(option4_sizer, 1, wx.EXPAND, 0)
|
||||
label_5 = wx.StaticText(self, wx.ID_ANY, _("Option 4"))
|
||||
option4_sizer.Add(label_5, 0, 0, 0)
|
||||
self.option4 = wx.TextCtrl(self, wx.ID_ANY, "")
|
||||
self.option4.SetMaxLength(25)
|
||||
option4_sizer.Add(self.option4, 0, 0, 0)
|
||||
btn_sizer = wx.StdDialogButtonSizer()
|
||||
sizer_1.Add(btn_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 4)
|
||||
self.button_OK = wx.Button(self, wx.ID_OK)
|
||||
self.button_OK.SetDefault()
|
||||
self.button_OK.Bind(wx.EVT_BUTTON, self.validate_data)
|
||||
btn_sizer.AddButton(self.button_OK)
|
||||
self.button_CANCEL = wx.Button(self, wx.ID_CANCEL, "")
|
||||
btn_sizer.AddButton(self.button_CANCEL)
|
||||
btn_sizer.Realize()
|
||||
self.SetSizer(sizer_1)
|
||||
sizer_1.Fit(self)
|
||||
self.SetAffirmativeId(self.button_OK.GetId())
|
||||
self.SetEscapeId(self.button_CANCEL.GetId())
|
||||
self.Layout()
|
||||
|
||||
def get_options(self):
|
||||
controls = [self.option1, self.option2, self.option3, self.option4]
|
||||
options = [option.GetValue() for option in controls if option.GetValue() != ""]
|
||||
return options
|
||||
|
||||
def validate_data(self, *args, **kwargs):
|
||||
options = self.get_options()
|
||||
if len(options) < 2:
|
||||
return wx.MessageDialog(self, _("Please make sure you have provided at least two options for the poll."), _("Not enough information"), wx.ICON_ERROR).ShowModal()
|
||||
self.EndModal(wx.ID_OK)
|
Reference in New Issue
Block a user