deemix-py/deemix/ui/MainFrame.py

68 lines
2.0 KiB
Python
Raw Normal View History

2020-02-17 15:46:18 +00:00
#!/usr/bin/env python3
import wx
2020-02-19 18:03:21 +00:00
from deemix.ui.SettingsDialog import SettingsDialog
from deemix.utils.misc import getIDFromLink, getTypeFromLink
2020-02-22 13:38:01 +00:00
from deemix.app.downloader import download_track, download_album, download_playlist
2020-02-20 14:42:12 +00:00
from deemix.app.settings import initSettings
2020-02-17 15:46:18 +00:00
2020-02-19 18:03:21 +00:00
menuIDs = {
"SETTINGS": 1
}
2020-02-17 15:46:18 +00:00
class MainFrame(wx.Frame):
2020-02-19 18:03:21 +00:00
def __init__(self, *args, **kwargs):
2020-02-17 15:46:18 +00:00
super().__init__(parent=None, title='deemix')
panel = wx.Panel(self)
2020-02-19 18:03:21 +00:00
2020-02-20 14:42:12 +00:00
self.settings = initSettings()
2020-02-19 18:03:21 +00:00
# Menubar
menubar = wx.MenuBar()
fileMenu = wx.Menu()
settingsItem = fileMenu.Append(menuIDs['SETTINGS'], 'Settings', 'Edit Settings')
fileMenu.AppendSeparator()
quitItem = fileMenu.Append(wx.ID_EXIT, 'Quit', 'Quit application')
menubar.Append(fileMenu, '&File')
self.SetMenuBar(menubar)
self.Bind(wx.EVT_MENU, self.close_app, quitItem)
self.Bind(wx.EVT_MENU, self.open_settings, settingsItem)
# Main app
2020-02-17 15:46:18 +00:00
main_sizer = wx.BoxSizer(wx.VERTICAL)
search_sizer = wx.BoxSizer(wx.HORIZONTAL)
main_sizer.Add(search_sizer, 0, wx.EXPAND, 5)
self.text_ctrl = wx.TextCtrl(panel)
search_sizer.Add(self.text_ctrl, 1, wx.ALL, 5)
my_btn = wx.Button(panel, label='Download')
my_btn.Bind(wx.EVT_BUTTON, self.download_track)
2020-02-17 15:46:18 +00:00
search_sizer.Add(my_btn, 0, wx.ALL, 5)
panel.SetSizer(main_sizer)
self.Show()
def download_track(self, event):
2020-02-17 15:46:18 +00:00
value = self.text_ctrl.GetValue()
if not value:
print("You didn't enter anything!")
return None
type = getTypeFromLink(value)
id = getIDFromLink(value, type)
2020-02-17 15:46:18 +00:00
print(type, id)
if type == "track":
2020-02-20 14:42:12 +00:00
download_track(id, self.settings)
elif type == "album":
download_album(id, self.settings)
2020-02-22 13:38:01 +00:00
elif type == "playlist":
download_playlist(id, self.settings)
2020-02-17 15:46:18 +00:00
self.text_ctrl.SetValue("")
2020-02-19 18:03:21 +00:00
def close_app(self, event):
self.Close()
def open_settings(self, event):
settings_dialog = SettingsDialog(self.settings, self)
res = settings_dialog.ShowModal()
if res == wx.ID_OK:
self.settings = settings_dialog.GetSettings()
settings_dialog.Destroy()