mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-23 03:38:08 -06:00
Added a filter manager for deleting filters #102
This commit is contained in:
parent
b832e36c7d
commit
2d9124c336
@ -3,9 +3,10 @@ import time
|
|||||||
import widgetUtils
|
import widgetUtils
|
||||||
import application
|
import application
|
||||||
from wxUI.dialogs import filterDialogs
|
from wxUI.dialogs import filterDialogs
|
||||||
|
from wxUI import commonMessageDialogs
|
||||||
|
|
||||||
class filter(object):
|
class filter(object):
|
||||||
def __init__(self, buffer):
|
def __init__(self, buffer, filter_title=None, if_word_exists=None, in_lang=None, regexp=None, word=None, in_buffer=None):
|
||||||
self.buffer = buffer
|
self.buffer = buffer
|
||||||
self.dialog = filterDialogs.filterDialog(languages=[i["name"] for i in application.supported_languages])
|
self.dialog = filterDialogs.filterDialog(languages=[i["name"] for i in application.supported_languages])
|
||||||
if self.dialog.get_response() == widgetUtils.OK:
|
if self.dialog.get_response() == widgetUtils.OK:
|
||||||
@ -28,3 +29,44 @@ class filter(object):
|
|||||||
filter_title = "filter_{0}".format(str(time.time()))
|
filter_title = "filter_{0}".format(str(time.time()))
|
||||||
self.buffer.session.settings["filters"][filter_title] = d
|
self.buffer.session.settings["filters"][filter_title] = d
|
||||||
self.buffer.session.settings.write()
|
self.buffer.session.settings.write()
|
||||||
|
|
||||||
|
class filterManager(object):
|
||||||
|
|
||||||
|
def __init__(self, session):
|
||||||
|
self.session = session
|
||||||
|
self.dialog = filterDialogs.filterManagerDialog()
|
||||||
|
self.insert_filters(self.session.settings["filters"])
|
||||||
|
if self.dialog.filters.get_count() == 0:
|
||||||
|
self.dialog.edit.Enable(False)
|
||||||
|
self.dialog.delete.Enable(False)
|
||||||
|
else:
|
||||||
|
widgetUtils.connect_event(self.dialog.edit, widgetUtils.BUTTON_PRESSED, self.edit_filter)
|
||||||
|
widgetUtils.connect_event(self.dialog.delete, widgetUtils.BUTTON_PRESSED, self.delete_filter)
|
||||||
|
response = self.dialog.get_response()
|
||||||
|
|
||||||
|
def insert_filters(self, filters):
|
||||||
|
self.dialog.filters.clear()
|
||||||
|
for f in filters.keys():
|
||||||
|
# ToDo: Add titles to filters.
|
||||||
|
filterName = f
|
||||||
|
buffer = filters[f]["in_buffer"]
|
||||||
|
if filters[f]["if_word_exists"] == "True" and filters[f]["word"] != "":
|
||||||
|
filter_by_word = "True"
|
||||||
|
else:
|
||||||
|
filter_by_word = "False"
|
||||||
|
filter_by_lang = ""
|
||||||
|
if filters[f]["in_lang"] != "None":
|
||||||
|
filter_by_lang = "True"
|
||||||
|
b = [f, buffer, filter_by_word, filter_by_lang]
|
||||||
|
self.dialog.filters.insert_item(False, *b)
|
||||||
|
|
||||||
|
def edit_filter(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def delete_filter(self, *args, **kwargs):
|
||||||
|
filter_title = self.dialog.filters.get_text_column(self.dialog.filters.get_selected(), 0)
|
||||||
|
response = commonMessageDialogs.delete_filter()
|
||||||
|
if response == widgetUtils.YES:
|
||||||
|
self.session.settings["filters"].pop(filter_title)
|
||||||
|
self.session.settings.write()
|
||||||
|
self.insert_filters(self.session.settings["filters"])
|
@ -141,6 +141,7 @@ class Controller(object):
|
|||||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.list_manager, menuitem=self.view.lists)
|
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.list_manager, menuitem=self.view.lists)
|
||||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.get_trending_topics, menuitem=self.view.trends)
|
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.get_trending_topics, menuitem=self.view.trends)
|
||||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.filter, menuitem=self.view.filter)
|
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.filter, menuitem=self.view.filter)
|
||||||
|
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.manage_filters, menuitem=self.view.manage_filters)
|
||||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.find, menuitem=self.view.find)
|
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.find, menuitem=self.view.find)
|
||||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.accountConfiguration, menuitem=self.view.account_settings)
|
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.accountConfiguration, menuitem=self.view.account_settings)
|
||||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.configuration, menuitem=self.view.prefs)
|
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.configuration, menuitem=self.view.prefs)
|
||||||
@ -496,6 +497,10 @@ class Controller(object):
|
|||||||
return
|
return
|
||||||
new_filter = filterController.filter(page)
|
new_filter = filterController.filter(page)
|
||||||
|
|
||||||
|
def manage_filters(self, *args, **kwargs):
|
||||||
|
page = self.get_best_buffer()
|
||||||
|
manage_filters = filterController.filterManager(page.session)
|
||||||
|
|
||||||
def seekLeft(self, *args, **kwargs):
|
def seekLeft(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
sound.URLPlayer.seek(-5)
|
sound.URLPlayer.seek(-5)
|
||||||
|
@ -80,3 +80,6 @@ def blocked_timeline():
|
|||||||
|
|
||||||
def suspended_user():
|
def suspended_user():
|
||||||
return wx.MessageDialog(None, _(u"TWBlue cannot load this timeline because the user has been suspended from Twitter."), _(u"Error"), wx.OK).ShowModal()
|
return wx.MessageDialog(None, _(u"TWBlue cannot load this timeline because the user has been suspended from Twitter."), _(u"Error"), wx.OK).ShowModal()
|
||||||
|
|
||||||
|
def delete_filter():
|
||||||
|
return wx.MessageDialog(None, _(u"Do you really want to delete this filter?"), _(u"Attention"), style=wx.ICON_QUESTION|wx.YES_NO).ShowModal()
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import baseDialog
|
import baseDialog
|
||||||
import wx
|
import wx
|
||||||
import widgetUtils
|
import widgetUtils
|
||||||
|
from multiplatform_widgets import widgets
|
||||||
|
|
||||||
class filterDialog(baseDialog.BaseWXDialog):
|
class filterDialog(baseDialog.BaseWXDialog):
|
||||||
def __init__(self, value="", languages=[]):
|
def __init__(self, value="", languages=[]):
|
||||||
@ -96,3 +97,32 @@ class filterDialog(baseDialog.BaseWXDialog):
|
|||||||
def show_language_options(self, *args, **kwargs):
|
def show_language_options(self, *args, **kwargs):
|
||||||
for i in [self.cb, self.add, self.langs, self.remove]:
|
for i in [self.cb, self.add, self.langs, self.remove]:
|
||||||
i.Show()
|
i.Show()
|
||||||
|
|
||||||
|
class filterManagerDialog(widgetUtils.BaseDialog):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(filterManagerDialog, self).__init__(parent=None, *args, **kwargs)
|
||||||
|
self.SetTitle(_(u"Manage filters"))
|
||||||
|
panel = wx.Panel(self)
|
||||||
|
label = wx.StaticText(panel, -1, _(u"Filters"))
|
||||||
|
self.filters = widgets.list(panel, _(u"Filter"), _(u"Buffer"), _(u"Filter by word"), _(u"Filter by language"), size=(800, 800), style=wx.LC_REPORT|wx.LC_SINGLE_SEL)
|
||||||
|
self.filters.list.SetFocus()
|
||||||
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
|
sizer.Add(label)
|
||||||
|
sizer.Add(self.filters.list)
|
||||||
|
self.edit = wx.Button(panel, wx.NewId(), _(u"Edit"))
|
||||||
|
self.edit.Enable(False)
|
||||||
|
self.delete = wx.Button(panel, wx.NewId(), _(u"Remove"))
|
||||||
|
self.cancel = wx.Button(panel, wx.ID_CANCEL)
|
||||||
|
btnSizer = wx.BoxSizer()
|
||||||
|
btnSizer.Add(self.edit, 0, wx.ALL, 5)
|
||||||
|
btnSizer.Add(self.delete, 0, wx.ALL, 5)
|
||||||
|
btnSizer.Add(self.cancel, 0, wx.ALL, 5)
|
||||||
|
sizer.Add(btnSizer, 0, wx.ALL, 5)
|
||||||
|
panel.SetSizer(sizer)
|
||||||
|
|
||||||
|
def get_item(self):
|
||||||
|
return self.filters.get_selected()
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
self.filters.clear()
|
||||||
|
@ -51,6 +51,7 @@ class mainFrame(wx.Frame):
|
|||||||
self.update_buffer = buffer.Append(wx.NewId(), _(u"&Update buffer"))
|
self.update_buffer = buffer.Append(wx.NewId(), _(u"&Update buffer"))
|
||||||
self.trends = buffer.Append(wx.NewId(), _(u"New &trending topics buffer..."))
|
self.trends = buffer.Append(wx.NewId(), _(u"New &trending topics buffer..."))
|
||||||
self.filter = buffer.Append(wx.NewId(), _(u"Create a filter"))
|
self.filter = buffer.Append(wx.NewId(), _(u"Create a filter"))
|
||||||
|
self.manage_filters = buffer.Append(wx.NewId(), _(u"Manage filters"))
|
||||||
self.find = buffer.Append(wx.NewId(), _(u"Find a string in the currently focused buffer..."))
|
self.find = buffer.Append(wx.NewId(), _(u"Find a string in the currently focused buffer..."))
|
||||||
self.load_previous_items = buffer.Append(wx.NewId(), _(u"&Load previous items"))
|
self.load_previous_items = buffer.Append(wx.NewId(), _(u"&Load previous items"))
|
||||||
buffer.AppendSeparator()
|
buffer.AppendSeparator()
|
||||||
|
Loading…
Reference in New Issue
Block a user