Merge pull request #1021 from RobinD42/fix-issue976

Removed wx.lib.floatbar, which has been deprecated forever
This commit is contained in:
Robin Dunn
2018-09-28 11:57:37 +08:00
committed by GitHub
4 changed files with 4 additions and 445 deletions

View File

@@ -89,6 +89,10 @@ Changes in this release include the following:
positioning the Window (a small image) on the left of text in a
CustomTreeItem. (#PR886).
* Removed wx.lib.floatbar, which has been deprecated forever and probably
hasn't been working in nearly as long. (#976)

View File

@@ -1,134 +0,0 @@
#!/usr/bin/env python
# Please note that wx.lib.floatbar is not formally supported as
# part of wxPython. If it works, fine. If not, unfortunate.
# GTK users can use the wx.TB_DOCKABLE flag with a regular
# wx.ToolBar, but everyone else has to take their chances.
import wx
import wx.lib.floatbar
import images
class TestFloatBar(wx.Frame):
def __init__(self, parent, log):
wx.Frame.__init__(
self, parent, -1, 'Test ToolBar', wx.DefaultPosition, (500, 300)
)
self.log = log
win = wx.Window(self, -1)
win.SetBackgroundColour("WHITE")
wx.StaticText(
win, -1, "Drag the toolbar to float it,\n"
"Toggle the last tool to remove\nthe title.", (15,15)
)
tb = wx.lib.floatbar.FloatBar(self, -1)
self.SetToolBar(tb)
tb.SetFloatable(1)
tb.SetTitle("Floating!")
self.CreateStatusBar()
tsize = (16,16)
new_bmp = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, tsize)
open_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tsize)
copy_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR, tsize)
paste_bmp= wx.ArtProvider.GetBitmap(wx.ART_PASTE, wx.ART_TOOLBAR, tsize)
tb.AddTool(10, "New", new_bmp, "Long help for 'New'")
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=10)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=10)
tb.AddTool(20, "Open", open_bmp)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=20)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=20)
tb.AddSeparator()
tb.AddTool(30, "Copy", copy_bmp)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=30)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=30)
tb.AddTool(40, "Paste", paste_bmp)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=40)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=40)
tb.AddSeparator()
tb.AddCheckTool(60, "Check", images.Tog1.GetBitmap(), images.Tog2.GetBitmap(), "Check", "Long Help: Check", None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=60)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=60)
tb.Realize()
self.tb = tb
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseWindow(self, event):
self.Destroy()
def OnToolClick(self, event):
self.log.WriteText("tool %s clicked\n" % event.GetId())
if event.GetId() == 60:
print(event.GetExtraLong(), event.IsChecked(), event.GetInt(), self.tb.GetToolState(60))
if event.GetExtraLong():
self.tb.SetTitle("")
else:
self.tb.SetTitle("Floating!")
def OnToolRClick(self, event):
self.log.WriteText("tool %s right-clicked\n" % event.GetId())
#---------------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent, -1)
b = wx.Button(self, -1, "Show the FloatBar sample", (50,50))
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
def OnButton(self, evt):
if wx.Platform == "__WXMAC__":
dlg = wx.MessageDialog(
self, 'FloatBar does not work well on this platform.',
'Sorry', wx.OK | wx.ICON_WARNING
)
dlg.ShowModal()
dlg.Destroy()
else:
win = TestFloatBar(self, self.log)
win.Show(True)
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
#---------------------------------------------------------------------------
overview = """\
FloatBar is a subclass of wx.ToolBar, implemented in Python, which
can be detached from its frame.
Drag the toolbar with the mouse to make it float, and drag it back, or
close it to make the toolbar return to its original position.
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])

View File

@@ -174,7 +174,6 @@ _treeList = [
'ExpandoTextCtrl',
'FancyText',
'FileBrowseButton',
'FloatBar',
'FloatCanvas',
'HtmlWindow',
'HTML2_WebView',

View File

@@ -1,310 +0,0 @@
#----------------------------------------------------------------------------
# Name: floatbar.py
# Purpose: Contains floating toolbar class
#
# Author: Bryn Keller
#
# Created: 10/4/99
# Tags: phoenix-port
#----------------------------------------------------------------------------
# 12/02/2003 - Jeff Grimmett (grimmtooth@softhome.net)
#
# o 2.5 Compatibility changes
#
# 12/07/2003 - Jeff Grimmett (grimmtooth@softhome.net)
#
# o Added deprecation warning.
#
# 12/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
#
# o wxFloatBar -> FloatBar
#
"""
NOTE: This module is *not* supported in any way. Use it however you
wish, but be warned that dealing with any consequences is
entirly up to you.
--Robin
"""
import warnings
import wx
warningmsg = r"""\
################################################\
# This module is not supported in any way! |
# |
# See cource code for wx.lib.floatbar for more |
# information. |
################################################/
"""
warnings.warn(warningmsg, DeprecationWarning, stacklevel=2)
if wx.Platform == '__WXGTK__':
#
# For wxGTK all we have to do is set the wxTB_DOCKABLE flag
#
class FloatBar(wx.ToolBar):
def __init__(self, parent, ID,
pos = wx.DefaultPosition,
size = wx.DefaultSize,
style = 0,
name = 'toolbar'):
wx.ToolBar.__init__(self, parent, ID, pos, size,
style|wx.TB_DOCKABLE, name)
# these other methods just become no-ops
def SetFloatable(self, float):
pass
def IsFloating(self):
return 1
def GetTitle(self):
return ""
def SetTitle(self, title):
pass
else:
_DOCKTHRESHOLD = 25
class FloatBar(wx.ToolBar):
"""
wxToolBar subclass which can be dragged off its frame and later
replaced there. Drag on the toolbar to release it, close it like
a normal window to make it return to its original
position. Programmatically, call SetFloatable(True) and then
Float(True) to float, Float(False) to dock.
"""
def __init__(self,*_args,**_kwargs):
"""
In addition to the usual arguments, wxFloatBar accepts keyword
args of: title(string): the title that should appear on the
toolbar's frame when it is floating. floatable(bool): whether
user actions (i.e., dragging) can float the toolbar or not.
"""
wx.ToolBar.__init__(self, *_args, **_kwargs)
if 'floatable' in _kwargs:
self.floatable = _kwargs['floatable']
assert type(self.floatable) == type(0)
else:
self.floatable = 0
self.floating = 0
if 'title' in _kwargs:
self.title = _kwargs['title']
assert type(self.title) == type("")
else:
self.title = ""
self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
self.parentframe = _args[1]
def IsFloatable(self):
return self.floatable
def SetFloatable(self, float):
self.floatable = float
#Find the size of a title bar.
if not hasattr(self, 'titleheight'):
test = wx.MiniFrame(None, -1, "TEST")
test.SetClientSize((0,0))
self.titleheight = test.GetSize()[1]
test.Destroy()
def IsFloating(self):
return self.floating
def Realize(self):
wx.ToolBar.Realize(self)
def GetTitle(self):
return self.title
def SetTitle(self, title):
print('SetTitle', title)
self.title = title
if self.IsFloating():
self.floatframe.SetTitle(self.title)
## def GetHome(self):
## """
## Returns the frame which this toolbar will return to when
## docked, or the parent if currently docked.
## """
## if hasattr(self, 'parentframe'):
## return self.parentframe
## else:
## return (self.GetParent())
## def SetHome(self, frame):
## """
## Called when docked, this will remove the toolbar from its
## current frame and attach it to another. If called when
## floating, it will dock to the frame specified when the toolbar
## window is closed.
## """
## if self.IsFloating():
## self.parentframe = frame
## self.floatframe.Reparent(frame)
## else:
## parent = self.GetParent()
## self.Reparent(frame)
## parent.SetToolBar(None)
## size = parent.GetSize()
## parent.SetSize(wxSize(0,0))
## parent.SetSize(size)
## frame.SetToolBar(self)
## size = frame.GetSize()
## frame.SetSize(wxSize(0,0))
## frame.SetSize(size)
def Float(self, bool):
"Floats or docks the toolbar programmatically."
if bool:
self.parentframe = self.GetParent()
print(self.title)
if self.title:
useStyle = wx.DEFAULT_FRAME_STYLE
else:
useStyle = wx.THICK_FRAME
self.floatframe = wx.MiniFrame(self.parentframe, -1, self.title,
style = useStyle)
self.Reparent(self.floatframe)
self.parentframe.SetToolBar(None)
self.floating = 1
psize = self.parentframe.GetSize()
self.parentframe.SetSize((0,0))
self.parentframe.SetSize(psize)
self.floatframe.SetToolBar(self)
self.oldcolor = self.GetBackgroundColour()
w = psize[0]
h = self.GetSize()[1]
if self.title:
h = h + self.titleheight
self.floatframe.SetSize((w,h))
self.floatframe.SetClientSize(self.GetSize())
newpos = self.parentframe.GetPosition()
newpos.y = newpos.y + _DOCKTHRESHOLD * 2
self.floatframe.SetPosition(newpos)
self.floatframe.Show(True)
self.floatframe.Bind(wx.EVT_CLOSE, self.OnDock)
#self.floatframe.Bind(wx.EVT_MOVE, self.OnMove)
else:
self.Reparent(self.parentframe)
self.parentframe.SetToolBar(self)
self.floating = 0
self.floatframe.SetToolBar(None)
self.floatframe.Destroy()
size = self.parentframe.GetSize()
self.parentframe.SetSize((0,0))
self.parentframe.SetSize(size)
self.SetBackgroundColour(self.oldcolor)
def OnDock(self, e):
self.Float(0)
if hasattr(self, 'oldpos'):
del self.oldpos
def OnMove(self, e):
homepos = self.parentframe.ClientToScreen((0,0))
floatpos = self.floatframe.GetPosition()
if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and
abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD):
self.Float(0)
#homepos = self.parentframe.GetPosition()
#homepos = homepos[0], homepos[1] + self.titleheight
#floatpos = self.floatframe.GetPosition()
#if abs(homepos[0] - floatpos[0]) < 35 and abs(homepos[1] - floatpos[1]) < 35:
# self._SetFauxBarVisible(True)
#else:
# self._SetFauxBarVisible(False)
def OnMouse(self, e):
if not self.IsFloatable():
e.Skip()
return
if e.ButtonDClick(1) or e.ButtonDClick(2) or e.ButtonDClick(3) or e.ButtonDown() or e.ButtonUp():
e.Skip()
if e.ButtonDown():
self.CaptureMouse()
self.oldpos = (e.GetX(), e.GetY())
if e.Entering():
self.oldpos = (e.GetX(), e.GetY())
if e.ButtonUp():
self.ReleaseMouse()
if self.IsFloating():
homepos = self.parentframe.ClientToScreen((0,0))
floatpos = self.floatframe.GetPosition()
if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and
abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD):
self.Float(0)
return
if e.Dragging():
if not self.IsFloating():
self.Float(True)
self.oldpos = (e.GetX(), e.GetY())
else:
if hasattr(self, 'oldpos'):
loc = self.floatframe.GetPosition()
pt = (loc.x - (self.oldpos[0]-e.GetX()), loc.y - (self.oldpos[1]-e.GetY()))
self.floatframe.Move(pt)
def _SetFauxBarVisible(self, vis):
return
if vis:
if self.parentframe.GetToolBar() == None:
if not hasattr(self, 'nullbar'):
self.nullbar = wx.ToolBar(self.parentframe, -1)
print("Adding fauxbar.")
self.nullbar.Reparent(self.parentframe)
print("Reparented.")
self.parentframe.SetToolBar(self.nullbar)
print("Set toolbar")
col = wx.Colour("GREY")
self.nullbar.SetBackgroundColour(col)
print("Set color")
size = self.parentframe.GetSize()
self.parentframe.SetSize((0,0))
self.parentframe.SetSize(size)
print("Set size")
else:
print(self.parentframe.GetToolBar())
else:
if self.parentframe.GetToolBar() != None:
print("Removing fauxbar")
self.nullbar.Reparent(self.floatframe)
self.parentframe.SetToolBar(None)
size = self.parentframe.GetSize()
self.parentframe.SetSize((0,0))
self.parentframe.SetSize(size)