From 999bf9f92b6a62e50570d0c9d2ad4edfbf7aef9e Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 21 Dec 2018 14:44:18 -0800 Subject: [PATCH] Merge pull request #1096 from Metallicow/aui-fixes-Dec2018 Aui fixes dec2018 (cherry picked from commit d3deff2ed82d19bb2dfb32edd921047d5b9db386) --- CHANGES.rst | 5 +++ wx/lib/agw/aui/auibook.py | 74 ++++++++++++++++++++++++++++++---- wx/lib/agw/aui/framemanager.py | 44 ++++---------------- 3 files changed, 80 insertions(+), 43 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 01afc7a37..e480ec4f5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -49,6 +49,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 diff --git a/wx/lib/agw/aui/auibook.py b/wx/lib/agw/aui/auibook.py index d2928d38a..cdb39213a 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 @@ def __init__(self, parent, props): # 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 @@ def __init__(self, parent, props): 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 @@ def OnKeyUp(self, event): 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 @@ def OnItemSelected(self, event): 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): diff --git a/wx/lib/agw/aui/framemanager.py b/wx/lib/agw/aui/framemanager.py index e17a44d86..d38b1c48e 100644 --- a/wx/lib/agw/aui/framemanager.py +++ b/wx/lib/agw/aui/framemanager.py @@ -125,9 +125,6 @@ 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 @@ def OnMoveEvent(self, event): 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 @@ def OnIdle(self, event): """ 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 @@ def FlyOut(self): 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 @@ def UnInit(self): 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 @@ def DrawPaneButton(self, dc, part, pt): 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 @@ def OnMotion_DragToolbarPane(self, eventOrPt): # 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)