Added base code for settings
This commit is contained in:
parent
26f2da1e6d
commit
0447974029
@ -1,8 +1,13 @@
|
||||
[main]
|
||||
volume = integer(default=50)
|
||||
language = string(default="system")
|
||||
|
||||
[services]
|
||||
[[tidal]]
|
||||
username = string(default="")
|
||||
password = string(default="")
|
||||
quality=string(default="lossless")
|
||||
quality=string(default="lossless")
|
||||
|
||||
|
||||
[[youtube]]
|
||||
transcode = boolean(default=True)
|
30
src/controller/configuration.py
Normal file
30
src/controller/configuration.py
Normal file
@ -0,0 +1,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import config
|
||||
from utils import get_extractors
|
||||
from wxUI.configuration import configurationDialog
|
||||
|
||||
class configuration(object):
|
||||
|
||||
def __init__(self):
|
||||
self.view = configurationDialog(_("Settings"))
|
||||
self.create_config()
|
||||
self.view.get_response()
|
||||
self.save()
|
||||
|
||||
def create_config(self):
|
||||
self.view.create_general()
|
||||
extractors = get_extractors()
|
||||
for i in extractors:
|
||||
print(i)
|
||||
if hasattr(i, "settings"):
|
||||
panel = getattr(i, "settings")(self.view.notebook)
|
||||
self.view.notebook.AddPage(panel, panel.name)
|
||||
panel.load()
|
||||
self.view.realize()
|
||||
|
||||
def save(self):
|
||||
for i in range(0, self.view.notebook.GetPageCount()):
|
||||
page = self.view.notebook.GetPage(i)
|
||||
if hasattr(page, "save"):
|
||||
page.save()
|
||||
config.app.write()
|
@ -13,17 +13,11 @@ from pubsub import pub
|
||||
from issueReporter import issueReporter
|
||||
from wxUI import mainWindow, menus
|
||||
from update import updater
|
||||
from . import player
|
||||
from utils import get_extractors
|
||||
from . import player, configuration
|
||||
|
||||
log = logging.getLogger("controller.main")
|
||||
|
||||
def get_extractors():
|
||||
""" Function for importing everything wich is located in the extractors package and has a class named interface."""
|
||||
import extractors
|
||||
module_type = types.ModuleType
|
||||
classes = [m.interface for m in extractors.__dict__.values() if type(m) == module_type and hasattr(m, 'interface')]
|
||||
return sorted(classes, key=lambda c: c.name)
|
||||
|
||||
class Controller(object):
|
||||
|
||||
def __init__(self):
|
||||
@ -32,7 +26,7 @@ class Controller(object):
|
||||
# Setting up the player object
|
||||
player.setup()
|
||||
# Get main window
|
||||
self.window = mainWindow.mainWindow(extractors=[i.name for i in get_extractors()])
|
||||
self.window = mainWindow.mainWindow(extractors=[i.interface.name for i in get_extractors()])
|
||||
log.debug("Main window created")
|
||||
self.window.change_status(_(u"Ready"))
|
||||
# Here we will save results for searches as song objects.
|
||||
@ -67,6 +61,7 @@ class Controller(object):
|
||||
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_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_previous, menuitem=self.window.player_previous)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_stop, menuitem=self.window.player_stop)
|
||||
@ -95,6 +90,9 @@ class Controller(object):
|
||||
pub.subscribe(self.on_notify, "notify")
|
||||
|
||||
# Event functions. These functions will call other functions in a thread and are bound to widget events.
|
||||
def on_settings(self, *args, **kwargs):
|
||||
settings = configuration.configuration()
|
||||
|
||||
def on_search(self, *args, **kwargs):
|
||||
wx.CallAfter(self.search)
|
||||
|
||||
@ -246,8 +244,8 @@ class Controller(object):
|
||||
self.change_status(_(u"Searching {0}... ").format(text))
|
||||
extractors = get_extractors()
|
||||
for i in extractors:
|
||||
if extractor == i.name:
|
||||
self.extractor = i()
|
||||
if extractor == i.interface.name:
|
||||
self.extractor = i.interface()
|
||||
break
|
||||
log.debug("Started search for {0} (selected extractor: {1})".format(text, self.extractor.name))
|
||||
self.window.list.Clear()
|
||||
|
@ -4,4 +4,4 @@ import config
|
||||
from . import youtube, zaycev
|
||||
# conditional imports
|
||||
if config.app != None and config.app["services"]["tidal"]["username"] != "" and config.app["services"]["tidal"]["password"] != "":
|
||||
from . import tidal
|
||||
from . import tidal
|
||||
|
@ -1,6 +1,10 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: UTF-8 -*-
|
||||
from __future__ import unicode_literals # at top of module
|
||||
import logging
|
||||
import wx
|
||||
import config
|
||||
log = logging.getLogger("extractors.config")
|
||||
|
||||
class song(object):
|
||||
""" Represents a song in all services. Data will be filled by the service itself"""
|
||||
@ -20,4 +24,22 @@ class song(object):
|
||||
return self.extractor.format_track(self)
|
||||
|
||||
def get_download_url(self):
|
||||
self.download_url = self.extractor.get_download_url(self.url)
|
||||
self.download_url = self.extractor.get_download_url(self.url)
|
||||
|
||||
class baseSettings(wx.Panel):
|
||||
config_section = "base"
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(baseSettings, self).__init__(*args, **kwargs)
|
||||
self.map = []
|
||||
|
||||
def save(self):
|
||||
for i in self.map:
|
||||
config.app["services"][self.config_section][i[0]] = i[1].GetValue()
|
||||
|
||||
def load(self):
|
||||
for i in self.map:
|
||||
if i[0] in config.app["services"][self.config_section]:
|
||||
i[1].SetValue(config.app["services"][self.config_section][i[0]])
|
||||
else:
|
||||
log.error("No key available: {key} on extractor {extractor}".format(key=i[0], extractor=self.config_section))
|
@ -3,10 +3,11 @@ from __future__ import unicode_literals # at top of module
|
||||
import isodate
|
||||
import youtube_dl
|
||||
import logging
|
||||
import wx
|
||||
from googleapiclient.discovery import build
|
||||
from googleapiclient.errors import HttpError
|
||||
from .import baseFile
|
||||
from update.utils import seconds_to_string
|
||||
from .import baseFile
|
||||
|
||||
DEVELOPER_KEY = "AIzaSyCU_hvZJEjLlAGAnlscquKEkE8l0lVOfn0"
|
||||
YOUTUBE_API_SERVICE_NAME = "youtube"
|
||||
@ -101,4 +102,16 @@ class interface(object):
|
||||
return video["formats"][0]["url"]
|
||||
|
||||
def format_track(self, item):
|
||||
return "{0} {1}".format(item.title, item.duration)
|
||||
return "{0} {1}".format(item.title, item.duration)
|
||||
|
||||
class settings(baseFile.baseSettings):
|
||||
name = _("Youtube Settings")
|
||||
config_section = "youtube"
|
||||
|
||||
def __init__(self, parent):
|
||||
super(settings, self).__init__(parent=parent)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.transcode = wx.CheckBox(self, wx.NewId(), _("Enable transcode when downloading"))
|
||||
self.map.append(("transcode", self.transcode))
|
||||
sizer.Add(self.transcode, 0, wx.ALL, 5)
|
||||
self.SetSizer(sizer)
|
||||
|
@ -3,6 +3,7 @@ import os
|
||||
import requests
|
||||
import threading
|
||||
import logging
|
||||
import types
|
||||
from pubsub import pub
|
||||
|
||||
log = logging.getLogger("utils")
|
||||
@ -68,3 +69,10 @@ def download_file(url, local_filename):
|
||||
pub.sendMessage("download_finished", file=os.path.basename(local_filename))
|
||||
log.debug("Download finished successfully")
|
||||
return local_filename
|
||||
|
||||
def get_extractors():
|
||||
""" Function for importing everything wich is located in the extractors package and has a class named interface."""
|
||||
import extractors
|
||||
module_type = types.ModuleType
|
||||
classes = [m for m in extractors.__dict__.values() if type(m) == module_type and hasattr(m, 'interface')]
|
||||
return classes#sorted(classes, key=lambda c: c.name)
|
44
src/wxUI/configuration.py
Normal file
44
src/wxUI/configuration.py
Normal file
@ -0,0 +1,44 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import wx
|
||||
import widgetUtils
|
||||
|
||||
class general(wx.Panel, widgetUtils.BaseDialog):
|
||||
def __init__(self, panel):
|
||||
super(general, self).__init__(panel)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.SetSizer(sizer)
|
||||
|
||||
class configurationDialog(widgetUtils.BaseDialog):
|
||||
|
||||
def __init__(self, title):
|
||||
super(configurationDialog, self).__init__(None, -1, title=title)
|
||||
self.panel = wx.Panel(self)
|
||||
self.sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.notebook = wx.Treebook(self.panel)
|
||||
|
||||
def create_general(self):
|
||||
self.general = general(self.notebook)
|
||||
self.notebook.AddPage(self.general, _("General"))
|
||||
self.general.SetFocus()
|
||||
|
||||
def realize(self):
|
||||
self.sizer.Add(self.notebook, 0, wx.ALL, 5)
|
||||
ok_cancel_box = wx.BoxSizer(wx.HORIZONTAL)
|
||||
ok = wx.Button(self.panel, wx.ID_OK, _("Save"))
|
||||
ok.SetDefault()
|
||||
cancel = wx.Button(self.panel, wx.ID_CANCEL, _("Close"))
|
||||
self.SetEscapeId(cancel.GetId())
|
||||
ok_cancel_box.Add(ok, 0, wx.ALL, 5)
|
||||
ok_cancel_box.Add(cancel, 0, wx.ALL, 5)
|
||||
self.sizer.Add(ok_cancel_box, 0, wx.ALL, 5)
|
||||
self.panel.SetSizer(self.sizer)
|
||||
self.SetClientSize(self.sizer.CalcMin())
|
||||
|
||||
def get_value(self, panel, key):
|
||||
p = getattr(self, panel)
|
||||
return getattr(p, key).GetValue()
|
||||
|
||||
def set_value(self, panel, key, value):
|
||||
p = getattr(self, panel)
|
||||
control = getattr(p, key)
|
||||
getattr(control, "SetValue")(value)
|
@ -11,8 +11,9 @@ import widgetUtils
|
||||
class mainWindow(wx.Frame):
|
||||
def makeMenu(self):
|
||||
mb = wx.MenuBar()
|
||||
# app_ = wx.Menu()
|
||||
# mb.Append(app_, _(u"Application"))
|
||||
app_ = wx.Menu()
|
||||
self.settings = app_.Append(wx.NewId(), _("Settings"))
|
||||
mb.Append(app_, _("Application"))
|
||||
player = wx.Menu()
|
||||
self.player_play = player.Append(wx.NewId(), _(u"Play"))
|
||||
self.player_stop = player.Append(wx.NewId(), _(u"Stop"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user