mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-07-24 16:46:08 -04:00
Merge pull request #442 from manuelcortez/templates
Add Templates for invisible interface
This commit is contained in:
@@ -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 +1,2 @@
|
||||
from .tweetDialogs import tweet, reply, dm, viewTweet, viewNonTweet, poll
|
||||
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()
|
Reference in New Issue
Block a user