Changed default config path to $HOME/.youtube-dl-gui & removed startup popup

This commit is contained in:
MrS0m30n3 2014-03-27 13:41:39 +02:00
parent 69f4d1cd02
commit dbe147ab62
4 changed files with 34 additions and 66 deletions

View File

@ -4,11 +4,13 @@ from .Utils import (
get_HOME,
file_exist,
get_os_type,
fix_path
fix_path,
makedir
)
SETTINGS_FILENAME = 'settings'
LINUX_SAVEPATH = '/.config'
LINUX_FILES_PATH = get_HOME() + '/.youtube-dl-gui'
WINDOWS_FILES_PATH = get_HOME() + '\\youtube-dl-gui'
class OptionsHandler():
@ -16,11 +18,17 @@ class OptionsHandler():
def __init__(self, statusBarWrite):
self.statusBarWrite = statusBarWrite
self.load_default()
self.set_settings_path()
self.load_settings()
def load_settings(self):
if not file_exist(self.get_config_path()):
makedir(self.get_config_path())
if file_exist(self.settings_abs_path):
self.load_from_file()
else:
self.load_default()
def load_default(self):
self.ignoreErrors = True
self.idAsName = False
@ -52,16 +60,16 @@ class OptionsHandler():
self.cmdArgs = ""
self.dashAudioFormat = "NO SOUND"
self.clearDashFiles = False
self.updatePath = ""
self.updatePath = self.get_config_path()
def get_config_path(self):
if get_os_type() == 'nt':
return WINDOWS_FILES_PATH
else:
return LINUX_FILES_PATH
def set_settings_path(self):
self.settings_abs_path = get_HOME()
'''
On Linux save settings file under $HOME/LINUX_SAVEPATH/settings.
On windows save settings file under %UserProfile%/settings
'''
if get_os_type() != 'nt':
self.settings_abs_path += LINUX_SAVEPATH
self.settings_abs_path = self.get_config_path()
self.settings_abs_path = fix_path(self.settings_abs_path)
self.settings_abs_path += SETTINGS_FILENAME
@ -71,16 +79,16 @@ class OptionsHandler():
f.close()
return options
def extract_options(self):
def extract_options(self, options):
opts = []
for option in self.read_from_file():
for option in options:
opt = option.split('=')
if not len(opt) < 2:
opts.append(opt[1].rstrip('\n'))
return opts
def load_from_file(self):
opts = self.extract_options()
opts = self.extract_options(self.read_from_file())
try:
self.ignoreErrors = opts[0] in ['True']
self.idAsName = opts[1] in ['True']

View File

@ -122,29 +122,12 @@ class MainFrame(wx.Frame):
# init urlList for evt_text on self.trackList
self.urlList = []
# fix update path
self.check_update_path()
# check & update libraries (youtube-dl)
self.check_if_youtube_dl_exist()
if (self.optionsList.autoUpdate):
self.status_bar_write("Auto update enable")
self.update_youtube_dl()
def check_update_path(self):
if self.optionsList.updatePath == '':
self.pop_update_dialog()
if self.optionsList.updatePath == '':
self.optionsList.updatePath = get_HOME()
self.optionsList.updatePath = get_abs_path(self.optionsList.updatePath)
if get_os_type() == 'nt':
add_PATH(self.optionsList.updatePath)
def pop_update_dialog(self):
upDialog = UpdateDialog(self.optionsList)
upDialog.ShowModal()
upDialog.Destroy()
def check_if_youtube_dl_exist(self):
path = fix_path(self.optionsList.updatePath)+YOUTUBE_DL_FILENAME
if not file_exist(path):
@ -304,44 +287,19 @@ class ListCtrl(wx.ListCtrl):
items.append(data)
return items
class UpdateDialog(wx.Dialog):
def __init__(self, optionsList, parent=None, id=-1):
wx.Dialog.__init__(self, parent, id, 'Update Path', size=(380, 180))
self.optionsList = optionsList
self.initGUI()
def initGUI(self):
panel = wx.Panel(self)
text = '''Plase enter the path where youtube-dlG
should download latest updates (Default is $HOME)'''
wx.StaticText(panel, -1, text, (15, 10))
wx.StaticText(panel, -1, 'Update Path', (15, 60))
self.updatePathBox = wx.TextCtrl(panel, -1, pos=(10, 80), size=(360, -1))
wx.StaticText(panel, -1, '*** NEED WRITE PERMISSION', (15, 110))
saveButton = wx.Button(panel, label='Save Path', pos=(140, 140))
saveButton.Bind(wx.EVT_BUTTON, self.OnSave)
def OnSave(self, event):
self.setPath()
self.Close(True)
def setPath(self):
self.optionsList.updatePath = self.updatePathBox.GetValue()
class UpdatePanel(wx.Panel):
def __init__(self, parent, optionsList):
self.optionsList = optionsList
text = '''Enter the path where youtube-dlG should store
settings file and the latest youtube-dl.'''
wx.Panel.__init__(self, parent)
wx.StaticText(self, -1, 'Update Path (Should point where youtube-dl is)', (25, 20))
self.updatePathBox = wx.TextCtrl(self, -1, pos=(20, 40), size=(450, -1))
self.autoUpdateChk = wx.CheckBox(self, -1, 'Auto Update', (25, 80))
wx.StaticText(self, -1, text, (15, 10))
wx.StaticText(self, -1, 'Path', (25, 60))
self.updatePathBox = wx.TextCtrl(self, -1, pos=(20, 80), size=(450, -1))
self.autoUpdateChk = wx.CheckBox(self, -1, 'Auto Update', (25, 120))
def load_options(self):
self.updatePathBox.SetValue(self.optionsList.updatePath)

View File

@ -16,4 +16,5 @@ def main():
frame = MainFrame()
frame.Centre()
frame.Show()
app.MainLoop()
app.MainLoop()

View File

@ -11,4 +11,5 @@ if __package__ is None and not hasattr(sys, "frozen"):
import youtube_dl_gui
if __name__ == '__main__':
youtube_dl_gui.main()
youtube_dl_gui.main()