Skip to content

Commit

Permalink
Merge pull request #1096 from Metallicow/aui-fixes-Dec2018
Browse files Browse the repository at this point in the history
Aui fixes dec2018
(cherry picked from commit d3deff2)
  • Loading branch information
RobinD42 committed Dec 21, 2018
1 parent cb1488a commit 999bf9f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 43 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Expand Up @@ -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

Expand Down
74 changes: 67 additions & 7 deletions wx/lib/agw/aui/auibook.py
Expand Up @@ -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 = []
Expand Down Expand Up @@ -661,25 +662,82 @@ 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)

# Connect paint event to the panel
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`.
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down
44 changes: 8 additions & 36 deletions wx/lib/agw/aui/framemanager.py
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 999bf9f

Please sign in to comment.