From eb8abfe000c285e227088da13f1d76bc5ec987a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Thu, 2 Apr 2015 23:31:36 +0600 Subject: [PATCH 1/7] [optionsframe] Center on parent frame --- youtube_dl_gui/mainframe.py | 1 + 1 file changed, 1 insertion(+) diff --git a/youtube_dl_gui/mainframe.py b/youtube_dl_gui/mainframe.py index 38ac6ce..d2155b3 100644 --- a/youtube_dl_gui/mainframe.py +++ b/youtube_dl_gui/mainframe.py @@ -469,6 +469,7 @@ class MainFrame(wx.Frame): """ self._options_frame.load_all_options() + self._options_frame.CenterOnParent() self._options_frame.Show() def _on_close(self, event): From cb37d5c11c0c3becbf4a18b55878ff482fc34ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Sun, 5 Apr 2015 04:31:57 +0600 Subject: [PATCH 2/7] [optionswindow] Store window position and center on parent only for the first time --- youtube_dl_gui/__init__.py | 1 - youtube_dl_gui/mainframe.py | 6 +++++- youtube_dl_gui/optionsframe.py | 4 +++- youtube_dl_gui/optionsmanager.py | 7 ++++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/youtube_dl_gui/__init__.py b/youtube_dl_gui/__init__.py index b1b62b1..a6d22d9 100644 --- a/youtube_dl_gui/__init__.py +++ b/youtube_dl_gui/__init__.py @@ -75,6 +75,5 @@ def main(): """The real main. Creates and calls the main app windows. """ app = wx.App() frame = MainFrame(opt_manager, log_manager) - frame.Centre() frame.Show() app.MainLoop() diff --git a/youtube_dl_gui/mainframe.py b/youtube_dl_gui/mainframe.py index d2155b3..1eddd3c 100644 --- a/youtube_dl_gui/mainframe.py +++ b/youtube_dl_gui/mainframe.py @@ -131,6 +131,8 @@ class MainFrame(wx.Frame): self.update_thread = None self.app_icon = get_icon_file() + self.Centre() + # Create the app icon if self.app_icon is not None: self.app_icon = wx.Icon(self.app_icon, wx.BITMAP_TYPE_PNG) @@ -138,6 +140,8 @@ class MainFrame(wx.Frame): # Create options frame self._options_frame = OptionsFrame(self) + if self.opt_manager.options['opts_win_position'] == wx.Point(-1, -1): + self._options_frame.CenterOnParent() # Create components self._panel = wx.Panel(self) @@ -469,7 +473,6 @@ class MainFrame(wx.Frame): """ self._options_frame.load_all_options() - self._options_frame.CenterOnParent() self._options_frame.Show() def _on_close(self, event): @@ -490,6 +493,7 @@ class MainFrame(wx.Frame): # Store main-options frame size self.opt_manager.options['main_win_size'] = self.GetSize() self.opt_manager.options['opts_win_size'] = self._options_frame.GetSize() + self.opt_manager.options['opts_win_position'] = self._options_frame.GetPosition() self._options_frame.save_all_options() self.opt_manager.save_to_file() diff --git a/youtube_dl_gui/optionsframe.py b/youtube_dl_gui/optionsframe.py index b027c80..b3b9041 100644 --- a/youtube_dl_gui/optionsframe.py +++ b/youtube_dl_gui/optionsframe.py @@ -54,7 +54,9 @@ class OptionsFrame(wx.Frame): LOCALIZATION_TAB = _("Localization") def __init__(self, parent): - wx.Frame.__init__(self, parent, title=self.FRAME_TITLE, size=parent.opt_manager.options['opts_win_size']) + wx.Frame.__init__(self, parent, title=self.FRAME_TITLE, + pos=parent.opt_manager.options['opts_win_position'], + size=parent.opt_manager.options['opts_win_size']) self.opt_manager = parent.opt_manager self.log_manager = parent.log_manager self.app_icon = parent.app_icon diff --git a/youtube_dl_gui/optionsmanager.py b/youtube_dl_gui/optionsmanager.py index 145da10..44fca4c 100644 --- a/youtube_dl_gui/optionsmanager.py +++ b/youtube_dl_gui/optionsmanager.py @@ -196,6 +196,8 @@ class OptionsManager(object): If window becomes to small the program will reset its size. See _settings_are_valid method MIN_FRAME_SIZE. + opts_win_position (tuple): Options window position. + """ self.options = { 'save_path': os.path.expanduser('~'), @@ -241,7 +243,8 @@ class OptionsManager(object): 'workers_number': 3, 'locale_name': 'en_US', 'main_win_size': (700, 490), - 'opts_win_size': (640, 270) + 'opts_win_size': (640, 270), + 'opts_win_position': (-1, -1) } def load_from_file(self): @@ -300,6 +303,7 @@ class OptionsManager(object): # Decode string formatted tuples back to normal tuples settings_dictionary['main_win_size'] = decode_tuple(settings_dictionary['main_win_size']) settings_dictionary['opts_win_size'] = decode_tuple(settings_dictionary['opts_win_size']) + settings_dictionary['opts_win_position'] = decode_tuple(settings_dictionary['opts_win_position']) for key in self.options: if key not in settings_dictionary: @@ -349,6 +353,7 @@ class OptionsManager(object): # Encode normal tuples to string formatted tuples temp_options['main_win_size'] = encode_tuple(temp_options['main_win_size']) temp_options['opts_win_size'] = encode_tuple(temp_options['opts_win_size']) + temp_options['opts_win_position'] = encode_tuple(temp_options['opts_win_position']) return temp_options From a5329056bfbd4d9dcc053ceeb6f27f3219a3e0d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Sun, 5 Apr 2015 05:09:36 +0600 Subject: [PATCH 3/7] [optionswindow] Frame should be centered right before the first `Show` as position of parent frame may change after construction --- youtube_dl_gui/mainframe.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/youtube_dl_gui/mainframe.py b/youtube_dl_gui/mainframe.py index 1eddd3c..b384f23 100644 --- a/youtube_dl_gui/mainframe.py +++ b/youtube_dl_gui/mainframe.py @@ -140,8 +140,6 @@ class MainFrame(wx.Frame): # Create options frame self._options_frame = OptionsFrame(self) - if self.opt_manager.options['opts_win_position'] == wx.Point(-1, -1): - self._options_frame.CenterOnParent() # Create components self._panel = wx.Panel(self) @@ -473,6 +471,9 @@ class MainFrame(wx.Frame): """ self._options_frame.load_all_options() + if self.opt_manager.options['opts_win_position'] == wx.Point(-1, -1): + self._options_frame.CenterOnParent() + self.opt_manager.options['opts_win_position'] = self._options_frame.GetPosition() self._options_frame.Show() def _on_close(self, event): From ce89c839c950b05d417381e47f0f5c640b507d59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Wed, 8 Apr 2015 00:07:57 +0600 Subject: [PATCH 4/7] [optionsframe] Remove position storing --- youtube_dl_gui/mainframe.py | 4 ---- youtube_dl_gui/optionsframe.py | 4 +--- youtube_dl_gui/optionsmanager.py | 5 ----- 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/youtube_dl_gui/mainframe.py b/youtube_dl_gui/mainframe.py index b384f23..ec79f10 100644 --- a/youtube_dl_gui/mainframe.py +++ b/youtube_dl_gui/mainframe.py @@ -471,9 +471,6 @@ class MainFrame(wx.Frame): """ self._options_frame.load_all_options() - if self.opt_manager.options['opts_win_position'] == wx.Point(-1, -1): - self._options_frame.CenterOnParent() - self.opt_manager.options['opts_win_position'] = self._options_frame.GetPosition() self._options_frame.Show() def _on_close(self, event): @@ -494,7 +491,6 @@ class MainFrame(wx.Frame): # Store main-options frame size self.opt_manager.options['main_win_size'] = self.GetSize() self.opt_manager.options['opts_win_size'] = self._options_frame.GetSize() - self.opt_manager.options['opts_win_position'] = self._options_frame.GetPosition() self._options_frame.save_all_options() self.opt_manager.save_to_file() diff --git a/youtube_dl_gui/optionsframe.py b/youtube_dl_gui/optionsframe.py index b3b9041..b027c80 100644 --- a/youtube_dl_gui/optionsframe.py +++ b/youtube_dl_gui/optionsframe.py @@ -54,9 +54,7 @@ class OptionsFrame(wx.Frame): LOCALIZATION_TAB = _("Localization") def __init__(self, parent): - wx.Frame.__init__(self, parent, title=self.FRAME_TITLE, - pos=parent.opt_manager.options['opts_win_position'], - size=parent.opt_manager.options['opts_win_size']) + wx.Frame.__init__(self, parent, title=self.FRAME_TITLE, size=parent.opt_manager.options['opts_win_size']) self.opt_manager = parent.opt_manager self.log_manager = parent.log_manager self.app_icon = parent.app_icon diff --git a/youtube_dl_gui/optionsmanager.py b/youtube_dl_gui/optionsmanager.py index 44fca4c..642500c 100644 --- a/youtube_dl_gui/optionsmanager.py +++ b/youtube_dl_gui/optionsmanager.py @@ -196,8 +196,6 @@ class OptionsManager(object): If window becomes to small the program will reset its size. See _settings_are_valid method MIN_FRAME_SIZE. - opts_win_position (tuple): Options window position. - """ self.options = { 'save_path': os.path.expanduser('~'), @@ -244,7 +242,6 @@ class OptionsManager(object): 'locale_name': 'en_US', 'main_win_size': (700, 490), 'opts_win_size': (640, 270), - 'opts_win_position': (-1, -1) } def load_from_file(self): @@ -303,7 +300,6 @@ class OptionsManager(object): # Decode string formatted tuples back to normal tuples settings_dictionary['main_win_size'] = decode_tuple(settings_dictionary['main_win_size']) settings_dictionary['opts_win_size'] = decode_tuple(settings_dictionary['opts_win_size']) - settings_dictionary['opts_win_position'] = decode_tuple(settings_dictionary['opts_win_position']) for key in self.options: if key not in settings_dictionary: @@ -353,7 +349,6 @@ class OptionsManager(object): # Encode normal tuples to string formatted tuples temp_options['main_win_size'] = encode_tuple(temp_options['main_win_size']) temp_options['opts_win_size'] = encode_tuple(temp_options['opts_win_size']) - temp_options['opts_win_position'] = encode_tuple(temp_options['opts_win_position']) return temp_options From c6fb3d284c4328ddd9149eb67a628d40f1cc2f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Wed, 8 Apr 2015 00:09:35 +0600 Subject: [PATCH 5/7] [mainframe] Fixed center naming consistency and typo --- youtube_dl_gui/mainframe.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/youtube_dl_gui/mainframe.py b/youtube_dl_gui/mainframe.py index ec79f10..d3d44d7 100644 --- a/youtube_dl_gui/mainframe.py +++ b/youtube_dl_gui/mainframe.py @@ -131,7 +131,7 @@ class MainFrame(wx.Frame): self.update_thread = None self.app_icon = get_icon_file() - self.Centre() + self.Center() # Create the app icon if self.app_icon is not None: @@ -467,7 +467,7 @@ class MainFrame(wx.Frame): """Event handler of the self._options_btn widget. This method is used when the options button is pressed to show - the optios window. + the options window. """ self._options_frame.load_all_options() From 0212a42bf54b441f570996f75e8a7375f9b68d70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Wed, 8 Apr 2015 00:13:19 +0600 Subject: [PATCH 6/7] [optionsframe] Center on parent on first show only --- youtube_dl_gui/optionsframe.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/youtube_dl_gui/optionsframe.py b/youtube_dl_gui/optionsframe.py index b027c80..99408fd 100644 --- a/youtube_dl_gui/optionsframe.py +++ b/youtube_dl_gui/optionsframe.py @@ -62,6 +62,8 @@ class OptionsFrame(wx.Frame): if self.app_icon is not None: self.SetIcon(self.app_icon) + self._was_shown = False + # Create GUI panel = wx.Panel(self) notebook = wx.Notebook(panel) @@ -123,6 +125,14 @@ class OptionsFrame(wx.Frame): for tab, _ in self.tabs: tab.save_options() + def Show(self, *args, **kwargs): + # CenterOnParent can't go to main frame's __init__ as main frame may change + # own position and options frame won't be centered on main frame anymore. + if not self._was_shown: + self._was_shown = True + self.CenterOnParent() + return wx.Frame.Show(self, *args, **kwargs) + class TabPanel(wx.Panel): From 1efae6d6534cb557274bbdee766542390359dc1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Wed, 8 Apr 2015 00:17:23 +0600 Subject: [PATCH 7/7] [optionsmanager] Remove trailing comma --- youtube_dl_gui/optionsmanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl_gui/optionsmanager.py b/youtube_dl_gui/optionsmanager.py index 642500c..145da10 100644 --- a/youtube_dl_gui/optionsmanager.py +++ b/youtube_dl_gui/optionsmanager.py @@ -241,7 +241,7 @@ class OptionsManager(object): 'workers_number': 3, 'locale_name': 'en_US', 'main_win_size': (700, 490), - 'opts_win_size': (640, 270), + 'opts_win_size': (640, 270) } def load_from_file(self):