Implemented a selection control in audio buffers (not working yet)
This commit is contained in:
parent
976e90f0a0
commit
194ca2d380
@ -373,7 +373,7 @@ class baseBuffer(object):
|
||||
else:
|
||||
return [post["source_id"]]
|
||||
|
||||
def onFocus(self, *args,**kwargs):
|
||||
def onFocus(self, event, *args,**kwargs):
|
||||
""" Function executed when the item in a list is selected.
|
||||
For this buffer it updates the date of posts in the list."""
|
||||
post = self.get_post()
|
||||
@ -382,6 +382,7 @@ class baseBuffer(object):
|
||||
original_date = arrow.get(post["date"])
|
||||
created_at = original_date.humanize(locale=languageHandler.curLang[:2])
|
||||
self.tab.list.list.SetItem(self.tab.list.get_selected(), 2, created_at)
|
||||
event.Skip()
|
||||
|
||||
def open_in_browser(self, *args, **kwargs):
|
||||
post = self.get_post()
|
||||
@ -508,8 +509,8 @@ class topicBuffer(feedBuffer):
|
||||
if hasattr(self, "can_post") and self.can_post == False and hasattr(self.tab, "post"):
|
||||
self.tab.post.Enable(False)
|
||||
|
||||
def onFocus(self, *args, **kwargs):
|
||||
pass
|
||||
def onFocus(self, event, *args, **kwargs):
|
||||
event.Skip()
|
||||
|
||||
def open_post(self, *args, **kwargs):
|
||||
""" Opens the currently focused post."""
|
||||
@ -539,13 +540,14 @@ class documentBuffer(feedBuffer):
|
||||
if hasattr(self, "can_post") and self.can_post == False and hasattr(self.tab, "post"):
|
||||
self.tab.post.Enable(False)
|
||||
|
||||
def onFocus(self, *args,**kwargs):
|
||||
def onFocus(self, event, *args,**kwargs):
|
||||
post = self.get_post()
|
||||
if post == None:
|
||||
return
|
||||
original_date = arrow.get(post["date"])
|
||||
created_at = original_date.humanize(locale=languageHandler.curLang[:2])
|
||||
self.tab.list.list.SetItem(self.tab.list.get_selected(), 4, created_at)
|
||||
event.Skip()
|
||||
|
||||
def connect_events(self):
|
||||
super(documentBuffer, self).connect_events()
|
||||
@ -713,8 +715,8 @@ class audioBuffer(feedBuffer):
|
||||
# Translators: Some buffers can't use the get previous item feature due to API limitations.
|
||||
output.speak(_("This buffer doesn't support getting more items."))
|
||||
|
||||
def onFocus(self, *args, **kwargs):
|
||||
pass
|
||||
def onFocus(self, event, *args, **kwargs):
|
||||
event.Skip()
|
||||
|
||||
def add_to_library(self, *args, **kwargs):
|
||||
post = self.get_post()
|
||||
@ -879,8 +881,8 @@ class videoBuffer(feedBuffer):
|
||||
# Translators: Some buffers can't use the get previous item feature due to API limitations.
|
||||
output.speak(_("This buffer doesn't support getting more items."))
|
||||
|
||||
def onFocus(self, *args, **kwargs):
|
||||
pass
|
||||
def onFocus(self, event, *args, **kwargs):
|
||||
event.Skip()
|
||||
|
||||
def add_to_library(self, *args, **kwargs):
|
||||
post = self.get_post()
|
||||
|
@ -115,9 +115,14 @@ class vkSession(object):
|
||||
log.debug("Creating config file %s" % (file_,))
|
||||
self.settings = Configuration(os.path.join(paths.config_path(), file_), os.path.join(paths.app_path(), "session.defaults"))
|
||||
self.soundplayer = sound.soundSystem(config.app["sound"])
|
||||
pub.subscribe(self.play_sound, "play-sound")
|
||||
# except:
|
||||
# log.exception("The session configuration has failed.")
|
||||
|
||||
def play_sound(self, sound):
|
||||
print(sound)
|
||||
self.soundplayer.play(sound)
|
||||
|
||||
def login(self):
|
||||
""" Logging in VK.com. This is basically the first method interacting with VK. """
|
||||
# If user is already logged in, we should skip this method.
|
||||
|
BIN
src/sounds/default/checked.ogg
Normal file
BIN
src/sounds/default/checked.ogg
Normal file
Binary file not shown.
BIN
src/sounds/default/selected.ogg
Normal file
BIN
src/sounds/default/selected.ogg
Normal file
Binary file not shown.
BIN
src/sounds/default/unchecked.ogg
Normal file
BIN
src/sounds/default/unchecked.ogg
Normal file
Binary file not shown.
@ -6,6 +6,7 @@ import paths
|
||||
import wx
|
||||
import wx.lib.mixins.listctrl as listmix
|
||||
from builtins import range
|
||||
from pubsub import pub
|
||||
|
||||
toolkit = "wx"
|
||||
|
||||
@ -135,22 +136,29 @@ class mainLoopObject(wx.App):
|
||||
def run(self):
|
||||
self.app.MainLoop()
|
||||
|
||||
class selectableBaseList(wx.ListCtrl, listmix.CheckListCtrlMixin):
|
||||
class multiselectionBaseList(wx.ListCtrl, listmix.CheckListCtrlMixin):
|
||||
def __init__(self, *args, **kwargs):
|
||||
wx.ListCtrl.__init__(self, *args, **kwargs)
|
||||
listmix.CheckListCtrlMixin.__init__(self)
|
||||
listmix.ListCtrlAutoWidthMixin.__init__(self)
|
||||
self.Bind(wx.EVT_CHAR_HOOK, self.on_keydown)
|
||||
self.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.on_focus)
|
||||
|
||||
def on_focus(self, event):
|
||||
currentItem = self.GetFocusedItem()
|
||||
if self.IsChecked(currentItem):
|
||||
pub.sendMessage("play-sound", sound="selected.ogg")
|
||||
event.Skip()
|
||||
|
||||
def OnCheckItem(self, index, flag):
|
||||
print(index, flag)
|
||||
if flag == True:
|
||||
pub.sendMessage("play-sound", sound="checked.ogg")
|
||||
else:
|
||||
pub.sendMessage("play-sound", sound="unchecked.ogg")
|
||||
|
||||
def on_keydown(self, event):
|
||||
if event.GetKeyCode() == wx.WXK_SPACE:
|
||||
print("spacebar")
|
||||
self.ToggleItem(self.GetFocusedItem())
|
||||
event.Skip()
|
||||
|
||||
class list(object):
|
||||
def __init__(self, parent, *columns, **listArguments):
|
||||
self.columns = columns
|
||||
@ -200,9 +208,20 @@ class list(object):
|
||||
def Enable(self, value):
|
||||
return self.list.Enable(value)
|
||||
|
||||
class selectableList(list):
|
||||
class multiselectionList(list):
|
||||
|
||||
def create_list(self, parent):
|
||||
self.list = selectableBaseList(parent, -1, **self.listArguments)
|
||||
self.list = multiselectionBaseList(parent, -1, **self.listArguments)
|
||||
for i in range(0, len(self.columns)):
|
||||
self.list.InsertColumn(i, "%s" % (self.columns[i]))
|
||||
self.list.InsertColumn(i, "%s" % (self.columns[i]))
|
||||
|
||||
def get_selected(self):
|
||||
selected = []
|
||||
for item in range(0, self.list.GetItemCount()):
|
||||
if self.list.IsChecked(item):
|
||||
selected.append(item)
|
||||
if len(selected) == 1:
|
||||
return selected
|
||||
elif len(selected) == 0:
|
||||
return self.list.GetFocusedItem()
|
||||
return selected
|
@ -64,7 +64,7 @@ class communityTab(feedTab):
|
||||
class audioTab(homeTab):
|
||||
def create_list(self):
|
||||
self.lbl = wx.StaticText(self, wx.NewId(), _("Mu&sic"))
|
||||
self.list = widgetUtils.list(self, *[_("Title"), _("Artist"), _("Duration")], style=wx.LC_REPORT)
|
||||
self.list = widgetUtils.multiselectionList(self, *[_("Title"), _("Artist"), _("Duration")], style=wx.LC_REPORT)
|
||||
self.list.set_windows_size(0, 160)
|
||||
self.list.set_windows_size(1, 380)
|
||||
self.list.set_windows_size(2, 80)
|
||||
|
Loading…
Reference in New Issue
Block a user