From dbe147ab62d2a62d945c2cb32104187dab1f5ccb Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Thu, 27 Mar 2014 13:41:39 +0200 Subject: [PATCH] Changed default config path to $HOME/.youtube-dl-gui & removed startup popup --- youtube_dl_gui/OptionsHandler.py | 38 +++++++++++++--------- youtube_dl_gui/YoutubeDLGUI.py | 56 ++++---------------------------- youtube_dl_gui/__init__.py | 3 +- youtube_dl_gui/__main__.py | 3 +- 4 files changed, 34 insertions(+), 66 deletions(-) diff --git a/youtube_dl_gui/OptionsHandler.py b/youtube_dl_gui/OptionsHandler.py index adb01fc..ead8040 100644 --- a/youtube_dl_gui/OptionsHandler.py +++ b/youtube_dl_gui/OptionsHandler.py @@ -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'] diff --git a/youtube_dl_gui/YoutubeDLGUI.py b/youtube_dl_gui/YoutubeDLGUI.py index 1b71e87..daea3e1 100644 --- a/youtube_dl_gui/YoutubeDLGUI.py +++ b/youtube_dl_gui/YoutubeDLGUI.py @@ -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) diff --git a/youtube_dl_gui/__init__.py b/youtube_dl_gui/__init__.py index 5fe23c3..739230d 100644 --- a/youtube_dl_gui/__init__.py +++ b/youtube_dl_gui/__init__.py @@ -16,4 +16,5 @@ def main(): frame = MainFrame() frame.Centre() frame.Show() - app.MainLoop() \ No newline at end of file + app.MainLoop() + diff --git a/youtube_dl_gui/__main__.py b/youtube_dl_gui/__main__.py index 3e5bb0b..d989627 100644 --- a/youtube_dl_gui/__main__.py +++ b/youtube_dl_gui/__main__.py @@ -11,4 +11,5 @@ if __package__ is None and not hasattr(sys, "frozen"): import youtube_dl_gui if __name__ == '__main__': - youtube_dl_gui.main() \ No newline at end of file + youtube_dl_gui.main() +