Added experimental changes for musicDL

This commit is contained in:
Manuel Cortez 2019-07-12 17:54:29 -05:00
parent 207a7110ef
commit adc1317401
4 changed files with 120 additions and 34 deletions

View File

@ -14,7 +14,7 @@ from issueReporter import issueReporter
from wxUI import mainWindow, menus from wxUI import mainWindow, menus
from update import updater from update import updater
from utils import get_services from utils import get_services
from . import player, configuration from . import player, configuration, search
log = logging.getLogger("controller.main") log = logging.getLogger("controller.main")
@ -25,10 +25,13 @@ class Controller(object):
log.debug("Starting main controller...") log.debug("Starting main controller...")
# Setting up the player object # Setting up the player object
player.setup() player.setup()
self.buffers = []
# Get main window # Get main window
self.window = mainWindow.mainWindow(extractors=[i.interface.name for i in get_services()]) self.window = mainWindow.mainWindow(extractors=[i.interface.name for i in get_services()])
log.debug("Main window created") log.debug("Main window created")
self.window.change_status(_(u"Ready")) self.window.change_status(_(u"Ready"))
search_buffer = search.search(view=self.window.get_buffer(0))
self.buffers.append(search_buffer)
# Here we will save results for searches as song objects. # Here we will save results for searches as song objects.
self.results = [] self.results = []
self.connect_events() self.connect_events()
@ -57,9 +60,6 @@ class Controller(object):
def connect_events(self): def connect_events(self):
""" connects all widgets to their corresponding events.""" """ connects all widgets to their corresponding events."""
log.debug("Binding events...") log.debug("Binding events...")
widgetUtils.connect_event(self.window.search, widgetUtils.BUTTON_PRESSED, self.on_search)
widgetUtils.connect_event(self.window.list, widgetUtils.LISTBOX_ITEM_ACTIVATED, self.on_activated)
widgetUtils.connect_event(self.window.list, widgetUtils.KEYPRESS, self.on_keypress)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_play, menuitem=self.window.player_play) widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_play, menuitem=self.window.player_play)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_settings, menuitem=self.window.settings) widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_settings, menuitem=self.window.settings)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_next, menuitem=self.window.player_next) widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_next, menuitem=self.window.player_next)
@ -82,8 +82,8 @@ class Controller(object):
self.window.Bind(wx.EVT_COMMAND_SCROLL_CHANGED, self.on_set_volume, self.window.vol_slider) self.window.Bind(wx.EVT_COMMAND_SCROLL_CHANGED, self.on_set_volume, self.window.vol_slider)
self.window.Bind(wx.EVT_COMMAND_SCROLL_THUMBTRACK, self.on_time_change, self.window.time_slider) self.window.Bind(wx.EVT_COMMAND_SCROLL_THUMBTRACK, self.on_time_change, self.window.time_slider)
self.window.Bind(wx.EVT_COMMAND_SCROLL_CHANGED, self.on_time_change, self.window.time_slider) self.window.Bind(wx.EVT_COMMAND_SCROLL_CHANGED, self.on_time_change, self.window.time_slider)
self.window.list.Bind(wx.EVT_LISTBOX_DCLICK, self.on_play) # self.window.list.Bind(wx.EVT_LISTBOX_DCLICK, self.on_play)
self.window.list.Bind(wx.EVT_CONTEXT_MENU, self.on_context) # self.window.list.Bind(wx.EVT_CONTEXT_MENU, self.on_context)
self.window.Bind(wx.EVT_CLOSE, self.on_close) self.window.Bind(wx.EVT_CLOSE, self.on_close)
pub.subscribe(self.change_status, "change_status") pub.subscribe(self.change_status, "change_status")
pub.subscribe(self.on_download_finished, "download_finished") pub.subscribe(self.on_download_finished, "download_finished")

25
src/controller/search.py Normal file
View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
import widgetUtils
from pubsub import pub
from . import player
class search(object):
def __init__(self, view):
super(search, self).__init__()
self.name = "search"
self.items = []
self.view = view
print(self.view)
self.connect_events()
def connect_events(self):
widgetUtils.connect_event(self.view.list, widgetUtils.LISTBOX_ITEM_ACTIVATED, self.on_activated)
pub.subscribe(self.search, "search")
widgetUtils.connect_event(self.view.list, widgetUtils.KEYPRESS, self.on_keypress)
def create_queue(self, parent):
pass
def search(self, text, service):
print("Clocked me")

View File

@ -7,6 +7,7 @@ except ImportError:
pass pass
import application import application
import widgetUtils import widgetUtils
from .search import searchPanel
class mainWindow(wx.Frame): class mainWindow(wx.Frame):
def makeMenu(self): def makeMenu(self):
@ -40,22 +41,10 @@ class mainWindow(wx.Frame):
self.panel = wx.Panel(self) self.panel = wx.Panel(self)
self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sb = self.CreateStatusBar() self.sb = self.CreateStatusBar()
lbl2 = wx.StaticText(self.panel, wx.NewId(), _(u"search")) self.tb = wx.Treebook(self.panel, -1)
self.text = wx.TextCtrl(self.panel, wx.NewId()) search = searchPanel(extractors, parent=self.tb)
box = wx.BoxSizer(wx.HORIZONTAL) self.add_buffer(search, _("Search"))
box.Add(lbl2, 0, wx.GROW) self.sizer.Add(self.tb, 1, wx.ALL|wx.EXPAND, 5)
box.Add(self.text, 1, wx.GROW)
box.Add(wx.StaticText(self.panel, wx.NewId(), _(u"Search in")), 0, wx.GROW)
self.extractor = wx.ComboBox(self.panel, wx.NewId(), choices=extractors, value=extractors[0], style=wx.CB_READONLY)
box.Add(self.extractor, 1, wx.GROW)
self.search = wx.Button(self.panel, wx.NewId(), _(u"Search"))
self.search.SetDefault()
box.Add(self.search, 0, wx.GROW)
self.sizer.Add(box, 0, wx.GROW)
lbl = wx.StaticText(self.panel, wx.NewId(), _(u"Results"))
self.list = wx.ListBox(self.panel, wx.NewId())
self.sizer.Add(lbl, 0, wx.GROW)
self.sizer.Add(self.list, 1, wx.GROW)
box1 = wx.BoxSizer(wx.HORIZONTAL) box1 = wx.BoxSizer(wx.HORIZONTAL)
box2 = wx.BoxSizer(wx.HORIZONTAL) box2 = wx.BoxSizer(wx.HORIZONTAL)
box1.Add(wx.StaticText(self.panel, wx.NewId(), _(u"Position")), 0, wx.GROW) box1.Add(wx.StaticText(self.panel, wx.NewId(), _(u"Position")), 0, wx.GROW)
@ -77,9 +66,6 @@ class mainWindow(wx.Frame):
self.progressbar = wx.Gauge(self.panel, wx.NewId(), range=100, style=wx.GA_HORIZONTAL) self.progressbar = wx.Gauge(self.panel, wx.NewId(), range=100, style=wx.GA_HORIZONTAL)
self.sizer.Add(self.progressbar, 0, wx.ALL, 5) self.sizer.Add(self.progressbar, 0, wx.ALL, 5)
self.panel.SetSizerAndFit(self.sizer) self.panel.SetSizerAndFit(self.sizer)
# self.SetClientSize(self.sizer.CalcMin())
# self.Layout()
# self.SetSize(self.GetBestSize())
def change_status(self, status): def change_status(self, status):
self.sb.SetStatusText(status) self.sb.SetStatusText(status)
@ -102,14 +88,6 @@ class mainWindow(wx.Frame):
except: except:
wx.AboutBox(info) wx.AboutBox(info)
def get_text(self):
t = self.text.GetValue()
self.text.ChangeValue("")
return t
def get_item(self):
return self.list.GetSelection()
def get_destination_path(self, filename): def get_destination_path(self, filename):
saveFileDialog = wx.FileDialog(self, _(u"Save this file"), "", filename, _(u"Audio Files(*.mp3)|*.mp3"), wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) saveFileDialog = wx.FileDialog(self, _(u"Save this file"), "", filename, _(u"Audio Files(*.mp3)|*.mp3"), wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
if saveFileDialog.ShowModal() == wx.ID_OK: if saveFileDialog.ShowModal() == wx.ID_OK:
@ -122,3 +100,45 @@ class mainWindow(wx.Frame):
except AttributeError: except AttributeError:
self.notification = wx.NotificationMessage(title, text) self.notification = wx.NotificationMessage(title, text)
self.notification.Show() self.notification.Show()
def get_buffer_count(self):
return self.tb.GetPageCount()
def add_buffer(self, buffer, name):
self.tb.AddPage(buffer, name)
def insert_buffer(self, buffer, name, pos):
return self.tb.InsertSubPage(pos, buffer, name)
def search(self, name_):
for i in range(0, self.tb.GetPageCount()):
if self.tb.GetPage(i).name == name_: return i
def get_current_buffer(self):
return self.tb.GetCurrentPage()
def get_current_buffer_pos(self):
return self.tb.GetSelection()
def get_buffer(self, pos):
return self.tb.GetPage(pos)
def change_buffer(self, position):
self.tb.ChangeSelection(position)
def get_buffer_text(self, pos=None):
if pos == None:
pos = self.tb.GetSelection()
return self.tb.GetPageText(pos)
def get_buffer_by_id(self, id):
return self.tb.FindWindowById(id)
def advance_selection(self, forward):
self.tb.AdvanceSelection(forward)
def remove_buffer(self, pos):
self.tb.DeletePage(pos)
def remove_buffer_from_position(self, pos):
return self.tb.RemovePage(pos)

41
src/wxUI/search.py Normal file
View File

@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
import wx
from pubsub import pub
class searchPanel(wx.Panel):
def __init__(self, services=[], *args, **kwargs):
super(searchPanel, self).__init__(*args, **kwargs)
sizer = wx.BoxSizer(wx.VERTICAL)
lbl2 = wx.StaticText(self, wx.NewId(), _("search"))
self.text = wx.TextCtrl(self, wx.NewId())
box = wx.BoxSizer(wx.HORIZONTAL)
box.Add(lbl2, 0, wx.GROW)
box.Add(self.text, 1, wx.GROW)
box.Add(wx.StaticText(self, wx.NewId(), _(u"Search in")), 0, wx.GROW)
self.service = wx.ComboBox(self, wx.NewId(), choices=services, value=services[0], style=wx.CB_READONLY)
box.Add(self.service, 1, wx.GROW)
self.search = wx.Button(self, wx.NewId(), _(u"Search"))
self.search.SetDefault()
self.search.Bind(wx.EVT_BUTTON, self.on_search)
box.Add(self.search, 0, wx.GROW)
sizer.Add(box, 0, wx.GROW)
lbl = wx.StaticText(self, wx.NewId(), _(u"Results"))
self.list = wx.ListBox(self, wx.NewId())
sizer.Add(lbl, 0, wx.GROW)
sizer.Add(self.list, 1, wx.GROW)
self.SetSizer(sizer)
def get_text(self):
t = self.text.GetValue()
self.text.ChangeValue("")
return t
def get_item(self):
return self.list.GetSelection()
def on_search(self, event, *args, **kwargs):
text = self.get_text()
service = self.service.GetValue()
pub.sendMessage("search", service=service, text=text)
event.Skip()