From 64dd594d72ab573abad9d4644a52e7fd5845da09 Mon Sep 17 00:00:00 2001 From: Metallicow Date: Mon, 3 Dec 2018 03:14:53 -0600 Subject: [PATCH 1/3] Remove "2.9" version check stuff According to Robin "Classic" wont be updated anymore so this isnt shouldnt be needed in "Phoenix" --- wx/lib/agw/aui/framemanager.py | 44 +++++++--------------------------- 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/wx/lib/agw/aui/framemanager.py b/wx/lib/agw/aui/framemanager.py index e17a44d8..d38b1c48 100644 --- a/wx/lib/agw/aui/framemanager.py +++ b/wx/lib/agw/aui/framemanager.py @@ -125,9 +125,6 @@ if wx.Platform == "__WXMSW__": except ImportError: pass -# wxPython version string -_VERSION_STRING = wx.VERSION_STRING - # AUI Events wxEVT_AUI_PANE_BUTTON = wx.NewEventType() wxEVT_AUI_PANE_CLOSE = wx.NewEventType() @@ -3213,12 +3210,7 @@ class AuiFloatingFrame(wx.MiniFrame): self._last2_rect = wx.Rect(*self._last_rect) self._last_rect = wx.Rect(*win_rect) - if _VERSION_STRING < "2.9": - leftDown = wx.GetMouseState().LeftDown() - else: - leftDown = wx.GetMouseState().LeftIsDown() - - if not leftDown: + if not wx.GetMouseState().LeftIsDown(): return if not self._moving: @@ -3248,12 +3240,7 @@ class AuiFloatingFrame(wx.MiniFrame): """ if self._moving: - if _VERSION_STRING < "2.9": - leftDown = wx.GetMouseState().LeftDown() - else: - leftDown = wx.GetMouseState().LeftIsDown() - - if not leftDown: + if not wx.GetMouseState().LeftIsDown(): self._moving = False self.OnMoveFinished() else: @@ -3363,12 +3350,7 @@ class AuiFloatingFrame(wx.MiniFrame): if self._fly_timer.IsRunning(): return - if _VERSION_STRING < "2.9": - leftDown = wx.GetMouseState().LeftDown() - else: - leftDown = wx.GetMouseState().LeftIsDown() - - if leftDown: + if wx.GetMouseState().LeftIsDown(): return rect = wx.Rect(*self.GetScreenRect()) @@ -4603,13 +4585,13 @@ class AuiManager(wx.EvtHandler): klass.RemoveEventHandler(handler) - def OnClose(self, ev): + def OnClose(self, event): """Called when the managed window is closed. Makes sure that :meth:`UnInit` is called. """ - ev.Skip() - if ev.GetEventObject() == self._frame: + event.Skip() + if event.GetEventObject() == self._frame: wx.CallAfter(self.UnInit) @@ -8252,12 +8234,7 @@ class AuiManager(wx.EvtHandler): if part.rect.Contains(pt): - if _VERSION_STRING < "2.9": - leftDown = wx.GetMouseState().LeftDown() - else: - leftDown = wx.GetMouseState().LeftIsDown() - - if leftDown: + if wx.GetMouseState().LeftIsDown(): state = AUI_BUTTON_STATE_PRESSED else: state = AUI_BUTTON_STATE_HOVER @@ -9924,12 +9901,7 @@ class AuiManager(wx.EvtHandler): # when release the button out of the window. # TODO: a better fix is needed. - if _VERSION_STRING < "2.9": - leftDown = wx.GetMouseState().LeftDown() - else: - leftDown = wx.GetMouseState().LeftIsDown() - - if not leftDown: + if not wx.GetMouseState().LeftIsDown(): self._action = actionNone self.OnLeftUp_DragToolbarPane(eventOrPt) From ffd286db8b9aab60af607fe5ff26def6a59874d8 Mon Sep 17 00:00:00 2001 From: Metallicow Date: Mon, 3 Dec 2018 03:17:10 -0600 Subject: [PATCH 2/3] TabNavigatorWindow Improvements Makes TabNavigatorWindow Draggable and Resizable similar to other programs that have these. Annoyance fixes mainly if having many items or long names. Also option to popup at mouse pos instead of centre. This can be demo'd in the agw aui demo as smart tabbing. --- wx/lib/agw/aui/auibook.py | 74 +++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 7 deletions(-) diff --git a/wx/lib/agw/aui/auibook.py b/wx/lib/agw/aui/auibook.py index d2928d38..cdb39213 100644 --- a/wx/lib/agw/aui/auibook.py +++ b/wx/lib/agw/aui/auibook.py @@ -606,15 +606,16 @@ class TabNavigatorWindow(wx.Dialog): similar to what you would get by hitting ``Alt`` + ``Tab`` on Windows. """ - def __init__(self, parent, props): + def __init__(self, parent, props, centreOnMouse=False): """ Default class constructor. Used internally. :param `parent`: the :class:`TabNavigatorWindow` parent; :param `props`: the :class:`TabNavigatorProps` object. + :param `centreOnMouse`: popup position of the dialog at mouse cursor. Defaults to Centre. """ - wx.Dialog.__init__(self, parent, wx.ID_ANY, "", size=props.MinSize, style=0) + wx.Dialog.__init__(self, parent, wx.ID_ANY, "", size=props.MinSize, style=wx.RESIZE_BORDER) self._selectedItem = -1 self._indexMap = [] @@ -661,6 +662,8 @@ class TabNavigatorWindow(wx.Dialog): # Connect events to the list box self._listBox.Bind(wx.EVT_KEY_UP, self.OnKeyUp) + self.Bind(wx.EVT_NAVIGATION_KEY, self.OnNavigationKey) # Process tab/shift-tab if dialog has focus also. + self._panel.Bind(wx.EVT_NAVIGATION_KEY, self.OnNavigationKey) # Process tab/shift-tab if panel has focus also. self._listBox.Bind(wx.EVT_NAVIGATION_KEY, self.OnNavigationKey) self._listBox.Bind(wx.EVT_LISTBOX_DCLICK, self.OnItemSelected) @@ -668,18 +671,73 @@ class TabNavigatorWindow(wx.Dialog): self._panel.Bind(wx.EVT_PAINT, self.OnPanelPaint) self._panel.Bind(wx.EVT_ERASE_BACKGROUND, self.OnPanelEraseBg) + # Connect mouse events to the panel + self.delta = (0, 0) + self._panel.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) + self._panel.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) + self._panel.Bind(wx.EVT_MOTION, self.OnMotion) + self.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DFACE)) self._listBox.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DFACE)) self.PopulateListControl(parent) self.SetInitialSize(props.MinSize) - self.Centre() + if centreOnMouse: + mousePosX, mousePosY = wx.GetMousePosition() + sizeW, sizeH = props.MinSize + self.SetPosition((mousePosX - sizeW // 2, mousePosY - sizeH // 2)) # CentreOnMouse + else: + self.Centre() # Set focus on the list box to avoid having to click on it to change # the tab selection under GTK. self._listBox.SetFocus() + def OnLeftDown(self, event): + """ + Handles the ``wx.EVT_LEFT_DOWN`` event for self._panel. + + :param `event`: a :class:`MouseEvent` event to be processed. + """ + + if self._panel.HasCapture(): + self._panel.ReleaseMouse() + self._panel.CaptureMouse() + x, y = self.ClientToScreen(event.GetPosition()) + originx, originy = self.GetPosition() + dx = x - originx + dy = y - originy + self.delta = ((dx, dy)) + self._panel.SetFocus() + + + def OnLeftUp(self, event): + """ + Handles the ``wx.EVT_LEFT_UP`` event for self._panel. + + :param `event`: a :class:`MouseEvent` event to be processed. + """ + + if self._panel.HasCapture(): + self._panel.ReleaseMouse() + self._listBox.SetFocus() + self.Refresh() + + + def OnMotion(self, event): + """ + Handles the ``wx.EVT_MOTION`` event for self._panel. + + :param `event`: a :class:`MouseEvent` event to be processed. + """ + + if event.Dragging() and event.LeftIsDown(): + x, y = self.ClientToScreen(event.GetPosition()) + fp = (x - self.delta[0], y - self.delta[1]) + self.Move(fp) + + def OnKeyUp(self, event): """ Handles the ``wx.EVT_KEY_UP`` for the :class:`TabNavigatorWindow`. @@ -689,7 +747,8 @@ class TabNavigatorWindow(wx.Dialog): if event.GetKeyCode() == wx.WXK_CONTROL: self.CloseDialog() - + elif event.GetKeyCode() == wx.WXK_ESCAPE: + self.CloseDialog(wx.ID_CANCEL) def OnNavigationKey(self, event): """ @@ -768,12 +827,13 @@ class TabNavigatorWindow(wx.Dialog): self.CloseDialog() - def CloseDialog(self): + def CloseDialog(self, returnId=wx.ID_OK): """ Closes the :class:`TabNavigatorWindow` dialog, setting selection in :class:`AuiNotebook`. """ - bk = self.GetParent() + if self._panel.HasCapture(): + self._panel.ReleaseMouse() self._selectedItem = self._listBox.GetSelection() - self.EndModal(wx.ID_OK) + self.EndModal(returnId) def GetSelectedPage(self): From 0fa5ae869b5e871709a5f1253239fff99a8ff795 Mon Sep 17 00:00:00 2001 From: Metallicow Date: Mon, 3 Dec 2018 03:25:11 -0600 Subject: [PATCH 3/3] Add Changes For PR #1096 --- CHANGES.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index a49ebd1b..3fc4cef9 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -18,6 +18,11 @@ Pip: ``pip install wxPython==4.0.4`` Changes in this release include the following: +* TabNavigatorWindow works similarly like other programs now. Its resizable and + draggable so if user has ton of files with long names, it isnt an irritation + anymore plastered right in the middle of the screen and cant be worked with + easily and Esc now cancels the popup with a proper returnId. (#1096) + * Fixed an issue where wx.lib.intctrl would erroneously attempt to use ``long`` on Python3. (#898)