From b7d118df0f2741196b939f1382a96487cc509a94 Mon Sep 17 00:00:00 2001 From: cbeytas Date: Mon, 7 Jan 2019 00:26:28 -0500 Subject: [PATCH] Add fullscreen option to CustomTreeCtrl Drag/Drop Feature addition Add SetDragFullScreen and GetDragFullScreen methods which changes the way the simplified drag/drop works in the tree. This flag is passed to the wx.DragImage.BeginDrag() method when it is called. Also add this option to HyperTreeList. Modify the CustomTreeCtrl and HyperTreeList demos so it can be tested. --- demo/agw/CustomTreeCtrl.py | 26 ++++++++++++++++++------- demo/agw/HyperTreeList.py | 25 +++++++++++++++++------- wx/lib/agw/customtreectrl.py | 37 +++++++++++++++++++++++++++++++++++- wx/lib/agw/hypertreelist.py | 13 ++++++++++--- 4 files changed, 83 insertions(+), 18 deletions(-) diff --git a/demo/agw/CustomTreeCtrl.py b/demo/agw/CustomTreeCtrl.py index 44aaffc5..8d954ab1 100644 --- a/demo/agw/CustomTreeCtrl.py +++ b/demo/agw/CustomTreeCtrl.py @@ -979,10 +979,14 @@ class CustomTreeCtrlDemo(wx.Panel): self.checkvista = wx.CheckBox(pnl, -1, "Windows Vista Theme") self.checkvista.Bind(wx.EVT_CHECKBOX, self.OnVista) + self.dragFullScreen = wx.CheckBox(pnl, -1, "Fullscreen Drag/Drop") + self.dragFullScreen.Bind(wx.EVT_CHECKBOX, self.OnDragFullScreen) + themessizer.Add(sizera, 0, wx.EXPAND) themessizer.Add(sizerb, 0, wx.EXPAND) themessizer.Add((0, 5)) themessizer.Add(self.checkvista, 0, wx.EXPAND|wx.ALL, 3) + themessizer.Add(self.dragFullScreen, 0, wx.EXPAND|wx.ALL, 3) mainsizer.Add(stylesizer, 0, wx.EXPAND|wx.ALL, 5) mainsizer.Add(colourssizer, 0, wx.EXPAND|wx.ALL, 5) @@ -1280,6 +1284,12 @@ class CustomTreeCtrlDemo(wx.Panel): event.Skip() + def OnDragFullScreen(self, event): + + self.tree.SetDragFullScreen(event.IsChecked()) + event.Skip() + + #--------------------------------------------------------------------------- # CustomTreeCtrl Demo Implementation #--------------------------------------------------------------------------- @@ -2005,8 +2015,7 @@ class CustomTreeCtrl(CT.CustomTreeCtrl): self.item = event.GetItem() if self.item: - self.log.write("Beginning Drag..." + "\n") - + self.log.write("Beginning Drag... fullscreen=%s\n" % self.GetDragFullScreen()) event.Allow() @@ -2014,16 +2023,19 @@ class CustomTreeCtrl(CT.CustomTreeCtrl): self.item = event.GetItem() if self.item: - self.log.write("Beginning Right Drag..." + "\n") - + self.log.write("Beginning Right Drag... fullscreen=%s\n" % self.GetDragFullScreen()) event.Allow() def OnEndDrag(self, event): - self.item = event.GetItem() - if self.item: - self.log.write("Ending Drag!" + "\n") + if self.GetDragFullScreen() is True: + wnd = wx.FindWindowAtPoint(self.ClientToScreen(event.GetPoint())) + self.log.write("Ending Drag! window=%s\n" % repr(wnd)) + else: + self.item = event.GetItem() + name = self.GetItemText(self.item) if self.item else 'None' + self.log.write("Ending Drag! item=%s\n" % name) event.Skip() diff --git a/demo/agw/HyperTreeList.py b/demo/agw/HyperTreeList.py index 324079bb..f739df9e 100644 --- a/demo/agw/HyperTreeList.py +++ b/demo/agw/HyperTreeList.py @@ -1323,10 +1323,14 @@ class HyperTreeListDemo(wx.Frame): self.checkvista = wx.CheckBox(self.leftpanel, -1, "Windows Vista Theme") self.checkvista.Bind(wx.EVT_CHECKBOX, self.OnVista) + self.dragFullScreen = wx.CheckBox(self.leftpanel, -1, "Fullscreen Drag/Drop") + self.dragFullScreen.Bind(wx.EVT_CHECKBOX, self.OnDragFullScreen) + themessizer.Add(sizera, 0, wx.EXPAND) themessizer.Add(sizerb, 0, wx.EXPAND) themessizer.Add((0, 5)) themessizer.Add(self.checkvista, 0, wx.EXPAND|wx.ALL, 3) + themessizer.Add(self.dragFullScreen, 0, wx.EXPAND|wx.ALL, 3) mainsizer.Add(stylesizer, 0, wx.EXPAND|wx.ALL, 5) mainsizer.Add(columnssizer, 0, wx.EXPAND|wx.ALL, 5) @@ -1679,6 +1683,11 @@ class HyperTreeListDemo(wx.Frame): event.Skip() + def OnDragFullScreen(self, event): + + self.tree.SetDragFullScreen(event.IsChecked()) + event.Skip() + #--------------------------------------------------------------------------- # HyperTreeList Implementation @@ -2427,8 +2436,7 @@ class HyperTreeList(HTL.HyperTreeList): self.item = event.GetItem() if self.item: - self.log.write("Beginning Drag...\n") - + self.log.write("Beginning Drag... fullscreen=%s\n" % self.GetDragFullScreen()) event.Allow() @@ -2436,16 +2444,19 @@ class HyperTreeList(HTL.HyperTreeList): self.item = event.GetItem() if self.item: - self.log.write("Beginning Right Drag...\n") - + self.log.write("Beginning Right Drag... fullscreen=%s\n" % self.GetDragFullScreen()) event.Allow() def OnEndDrag(self, event): - self.item = event.GetItem() - if self.item: - self.log.write("Ending Drag!\n") + if self.GetDragFullScreen() is True: + wnd = wx.FindWindowAtPoint(self.ClientToScreen(event.GetPoint())) + self.log.write("Ending Drag! window=%s\n" % repr(wnd)) + else: + self.item = event.GetItem() + name = self.GetItemText(self.item) if self.item else 'None' + self.log.write("Ending Drag! item=%s\n" % name) event.Skip() diff --git a/wx/lib/agw/customtreectrl.py b/wx/lib/agw/customtreectrl.py index 01660c3b..86c424d7 100644 --- a/wx/lib/agw/customtreectrl.py +++ b/wx/lib/agw/customtreectrl.py @@ -2859,6 +2859,7 @@ class CustomTreeCtrl(wx.ScrolledWindow): self._isDragging = False self._dropTarget = self._oldSelection = None self._dragImage = None + self._dragFullScreen = False self._underMouse = None # EditCtrl initial settings for editable items @@ -4532,6 +4533,36 @@ class CustomTreeCtrl(wx.ScrolledWindow): self.Refresh() + def GetDragFullScreen(self): + """ + Returns whether built-in drag/drop will be full screen or not. + + :return: ``True`` if the drag/drop operation will be full screen, or + ``False`` if only within the tree. + """ + + return self._dragFullScreen + + + def SetDragFullScreen(self, fullScreen=False): + """ + Sets whether a drag operation will be performed full screen or not. + + A full screen drag allows the user to drag outside of the tree to + other controls. When the drag is finished the destination will have + to be found manually in the ``EVT_TREE_END_DRAG`` handler with + something like: + + example:: + + wnd = wx.FindWindowAtPoint(self.ClientToScreen(event.GetPoint())) + + :param bool `fullScreen`: False (default) to drag within tree only. + """ + + self._dragFullScreen = bool(fullScreen) + + # ----------------------------------------------------------------------------- # item status inquiries # ----------------------------------------------------------------------------- @@ -8071,7 +8102,7 @@ class CustomTreeCtrl(wx.ScrolledWindow): # Create the custom draw image from the icons and the text of the item self._dragImage = DragImage(self, self._current) - self._dragImage.BeginDrag(wx.Point(0,0), self) + self._dragImage.BeginDrag(wx.Point(0,0), self, fullScreen=self._dragFullScreen) self._dragImage.Show() self._dragImage.Move(self.CalcScrolledPosition(*pt)) @@ -8079,6 +8110,10 @@ class CustomTreeCtrl(wx.ScrolledWindow): self._dragImage.Move(self.CalcScrolledPosition(*pt)) + if self._dragFullScreen is True: + # Don't highlight target items if dragging full-screen. + return + if self._countDrag == 0 and item: self._oldItem = item diff --git a/wx/lib/agw/hypertreelist.py b/wx/lib/agw/hypertreelist.py index 979891a8..3c655354 100644 --- a/wx/lib/agw/hypertreelist.py +++ b/wx/lib/agw/hypertreelist.py @@ -3636,11 +3636,15 @@ class TreeListMainWindow(CustomTreeCtrl): # BeginDrag captures mouse. GTK cannot capture mouse twice. if self.HasCapture() is True: self.ReleaseMouse() - self._dragImage.BeginDrag(wx.Point(0,0), self) + self._dragImage.BeginDrag(wx.Point(0,0), self, fullScreen=self._dragFullScreen) self._dragImage.Show() self._dragImage.Move(p) + if self._dragFullScreen is True: + # Don't highlight target items if dragging full-screen. + return + if self._countDrag == 0 and item: self._oldItem = self._current self._oldSelection = self._current @@ -3694,6 +3698,7 @@ class TreeListMainWindow(CustomTreeCtrl): # we're going to drag this item self._isDragging = True + self._left_down_selection = True # Stop DoSelect on drag end. if not self.HasCapture(): self.CaptureMouse() self.RefreshSelected() @@ -4238,8 +4243,8 @@ _methods = ["GetIndent", "SetIndent", "GetSpacing", "SetSpacing", "GetImageList" "CheckChilds", "CheckSameLevel", "GetItemWindowEnabled", "SetItemWindowEnabled", "GetItemType", "IsDescendantOf", "SetItemHyperText", "IsItemHyperText", "SetItemBold", "SetItemDropHighlight", "SetItemItalic", "GetEditControl", "ShouldInheritColours", "GetItemWindow", "SetItemWindow", "DeleteItemWindow", "SetItemTextColour", - "HideItem", "DeleteAllItems", "ItemHasChildren", "ToggleItemSelection", "SetItemType", "GetCurrentItem", - "SetItem3State", "SetItem3StateValue", "GetItem3StateValue", "IsItem3State", "GetPrev", + "HideItem", "DeleteAllItems", "ItemHasChildren", "ToggleItemSelection", "SetItemType", "GetDragFullScreen", "SetDragFullScreen", + "GetCurrentItem", "SetItem3State", "SetItem3StateValue", "GetItem3StateValue", "IsItem3State", "GetPrev", "GetNextShown", "GetPrevShown"] @@ -4304,6 +4309,7 @@ class HyperTreeList(wx.Control): :meth:`~wx.lib.agw.customtreectrl.CustomTreeCtrl.GetCount` Returns the global number of items in the tree. :meth:`~wx.lib.agw.hypertreelist.TreeListMainWindow.GetCurrentItem` Returns the current item. Simply calls :meth:`~wx.lib.agw.customtreectrl.CustomTreeCtrl.GetSelection`. :meth:`~wx.lib.agw.customtreectrl.CustomTreeCtrl.GetDisabledColour` Returns the colour for items in a disabled state. + :meth:`~wx.lib.agw.customtreectrl.CustomTreeCtrl.GetDragFullScreen` Returns whether built-in drag/drop will be full screen or not. :meth:`~wx.lib.agw.customtreectrl.CustomTreeCtrl.GetEditControl` Returns a reference to the edit :class:`~wx.lib.agw.customtreectrl.TreeTextCtrl` if the item is being edited. :meth:`~wx.lib.agw.customtreectrl.CustomTreeCtrl.GetFirstChild` Returns the item's first child and an integer value 'cookie'. :meth:`~wx.lib.agw.hypertreelist.TreeListMainWindow.GetFirstExpandedItem` Returns the first item which is in the expanded state. @@ -4375,6 +4381,7 @@ class HyperTreeList(wx.Control): :meth:`~wx.lib.agw.customtreectrl.CustomTreeCtrl.SetButtonsImageList` Sets the buttons image list for :class:`TreeListMainWindow`. :meth:`~wx.lib.agw.customtreectrl.CustomTreeCtrl.SetConnectionPen` Sets the pen used to draw the connecting lines between items. :meth:`~wx.lib.agw.customtreectrl.CustomTreeCtrl.SetDisabledColour` Sets the colour for items in a disabled state. + :meth:`~wx.lib.agw.customtreectrl.CustomTreeCtrl.SetDragFullScreen` Sets whether a drag operation will be performed full screen or not. :meth:`~wx.lib.agw.hypertreelist.TreeListMainWindow.SetDragItem` Sets the specified item as member of a current drag and drop operation. :meth:`~wx.lib.agw.customtreectrl.CustomTreeCtrl.SetFirstGradientColour` Sets the first gradient colour for gradient-style selections. :meth:`~wx.lib.agw.customtreectrl.CustomTreeCtrl.SetGradientStyle` Sets the gradient style for gradient-style selections.