Merge pull request #1096 from Metallicow/aui-fixes-Dec2018

Aui fixes dec2018
This commit is contained in:
Robin Dunn
2018-12-21 14:44:18 -08:00
committed by GitHub
3 changed files with 80 additions and 43 deletions

View File

@@ -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)

View File

@@ -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):

View File

@@ -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)