Lots of wx namespace updates for the wx.lib package and the demo from
Jeff Grimmett with some tweaks and changes from Robin git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24889 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -7,6 +7,10 @@
|
|||||||
# o the three libraries below all have not been hit by the
|
# o the three libraries below all have not been hit by the
|
||||||
# wx renamer.
|
# wx renamer.
|
||||||
#
|
#
|
||||||
|
# 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o A few changes to correct my own mistakes earlier :-).
|
||||||
|
#
|
||||||
|
|
||||||
import string
|
import string
|
||||||
import sys
|
import sys
|
||||||
@@ -577,9 +581,9 @@ with right-insert for ordinal:""")
|
|||||||
self.log.write(line)
|
self.log.write(line)
|
||||||
|
|
||||||
def OnParensCheck( self, event ):
|
def OnParensCheck( self, event ):
|
||||||
self.intctrl1.SetCtrlParameters(useParensForNegatives=event.Checked())
|
self.intctrl1.SetCtrlParameters(useParensForNegatives=event.IsChecked())
|
||||||
self.intctrl2.SetCtrlParameters(useParensForNegatives=event.Checked())
|
self.intctrl2.SetCtrlParameters(useParensForNegatives=event.IsChecked())
|
||||||
self.floatctrl.SetCtrlParameters(useParensForNegatives=event.Checked())
|
self.floatctrl.SetCtrlParameters(useParensForNegatives=event.IsChecked())
|
||||||
|
|
||||||
def OnIpAddrChange( self, event ):
|
def OnIpAddrChange( self, event ):
|
||||||
ipaddr = self.FindWindowById( event.GetId() )
|
ipaddr = self.FindWindowById( event.GetId() )
|
||||||
@@ -597,7 +601,7 @@ with right-insert for ordinal:""")
|
|||||||
formatcodes += 'r'
|
formatcodes += 'r'
|
||||||
mask = '###'
|
mask = '###'
|
||||||
else:
|
else:
|
||||||
choices = states
|
choices = med.states
|
||||||
mask = 'AA'
|
mask = 'AA'
|
||||||
formatcodes += '!'
|
formatcodes += '!'
|
||||||
self.dynamicbox.SetCtrlParameters( mask = mask,
|
self.dynamicbox.SetCtrlParameters( mask = mask,
|
||||||
|
|||||||
@@ -1,76 +1,87 @@
|
|||||||
|
# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Updated for wx namespace
|
||||||
|
|
||||||
|
import wx
|
||||||
|
|
||||||
from wxPython.wx import *
|
|
||||||
import images
|
import images
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
text = """\
|
text = """\
|
||||||
|
|
||||||
Right-click on the panel (or Ctrl-click on the Mac) to show a popup
|
Right-click on any bare area of this panel (or Ctrl-click on the Mac)
|
||||||
menu. Then look at the code for this sample. Notice how the
|
to show a popup menu. Then look at the code for this sample. Notice
|
||||||
PopupMenu method is similar to the ShowModal method of a wxDialog in
|
how the PopupMenu method is similar to the ShowModal method of a
|
||||||
that it doesn't return until the popup menu has been dismissed. The
|
wx.Dialog in that it doesn't return until the popup menu has been
|
||||||
event handlers for the popup menu items can either be attached to the
|
dismissed. The event handlers for the popup menu items can either be
|
||||||
menu itself, or to the window that invokes PopupMenu.
|
attached to the menu itself, or to the window that invokes PopupMenu.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
class TestPanel(wxPanel):
|
class TestPanel(wx.Panel):
|
||||||
def __init__(self, parent, log):
|
def __init__(self, parent, log):
|
||||||
self.log = log
|
self.log = log
|
||||||
wxPanel.__init__(self, parent, -1)
|
wx.Panel.__init__(self, parent, -1)
|
||||||
box = wxBoxSizer(wxVERTICAL)
|
box = wx.BoxSizer(wx.VERTICAL)
|
||||||
|
|
||||||
# Make and layout the controls
|
# Make and layout the controls
|
||||||
fs = self.GetFont().GetPointSize()
|
fs = self.GetFont().GetPointSize()
|
||||||
bf = wxFont(fs+4, wxSWISS, wxNORMAL, wxBOLD)
|
bf = wx.Font(fs+4, wx.SWISS, wx.NORMAL, wx.BOLD)
|
||||||
nf = wxFont(fs+2, wxSWISS, wxNORMAL, wxNORMAL)
|
nf = wx.Font(fs+2, wx.SWISS, wx.NORMAL, wx.NORMAL)
|
||||||
|
|
||||||
t = wxStaticText(self, -1, "PopupMenu")
|
t = wx.StaticText(self, -1, "PopupMenu")
|
||||||
t.SetFont(bf)
|
t.SetFont(bf)
|
||||||
box.Add(t, 0, wxCENTER|wxALL, 5)
|
box.Add(t, 0, wx.CENTER|wx.ALL, 5)
|
||||||
|
self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
|
||||||
|
|
||||||
box.Add(wxStaticLine(self, -1), 0, wxEXPAND)
|
|
||||||
|
box.Add(wx.StaticLine(self, -1), 0, wx.EXPAND)
|
||||||
box.Add((10,20))
|
box.Add((10,20))
|
||||||
|
|
||||||
t = wxStaticText(self, -1, text)
|
t = wx.StaticText(self, -1, text)
|
||||||
t.SetFont(nf)
|
t.SetFont(nf)
|
||||||
box.Add(t, 0, wxCENTER|wxALL, 5)
|
box.Add(t, 0, wx.CENTER|wx.ALL, 5)
|
||||||
|
|
||||||
self.SetSizer(box)
|
self.SetSizer(box)
|
||||||
|
|
||||||
EVT_RIGHT_UP(self, self.OnRightClick)
|
self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
|
||||||
|
|
||||||
|
|
||||||
def OnRightClick(self, event):
|
def OnRightClick(self, event):
|
||||||
self.log.WriteText("OnRightClick\n")
|
self.log.WriteText("OnRightClick\n")
|
||||||
|
|
||||||
# only do this part the first time so the events are only bound once
|
# only do this part the first time so the events are only bound once
|
||||||
|
#
|
||||||
|
# Yet another anternate way to do IDs. Some prefer them up top to
|
||||||
|
# avoid clutter, some prefer them close to the object of interest
|
||||||
|
# for clarity.
|
||||||
if not hasattr(self, "popupID1"):
|
if not hasattr(self, "popupID1"):
|
||||||
self.popupID1 = wxNewId()
|
self.popupID1 = wx.NewId()
|
||||||
self.popupID2 = wxNewId()
|
self.popupID2 = wx.NewId()
|
||||||
self.popupID3 = wxNewId()
|
self.popupID3 = wx.NewId()
|
||||||
self.popupID4 = wxNewId()
|
self.popupID4 = wx.NewId()
|
||||||
self.popupID5 = wxNewId()
|
self.popupID5 = wx.NewId()
|
||||||
self.popupID6 = wxNewId()
|
self.popupID6 = wx.NewId()
|
||||||
self.popupID7 = wxNewId()
|
self.popupID7 = wx.NewId()
|
||||||
self.popupID8 = wxNewId()
|
self.popupID8 = wx.NewId()
|
||||||
self.popupID9 = wxNewId()
|
self.popupID9 = wx.NewId()
|
||||||
EVT_MENU(self, self.popupID1, self.OnPopupOne)
|
|
||||||
EVT_MENU(self, self.popupID2, self.OnPopupTwo)
|
self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
|
||||||
EVT_MENU(self, self.popupID3, self.OnPopupThree)
|
self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
|
||||||
EVT_MENU(self, self.popupID4, self.OnPopupFour)
|
self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
|
||||||
EVT_MENU(self, self.popupID5, self.OnPopupFive)
|
self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
|
||||||
EVT_MENU(self, self.popupID6, self.OnPopupSix)
|
self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
|
||||||
EVT_MENU(self, self.popupID7, self.OnPopupSeven)
|
self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
|
||||||
EVT_MENU(self, self.popupID8, self.OnPopupEIght)
|
self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
|
||||||
EVT_MENU(self, self.popupID9, self.OnPopupNine)
|
self.Bind(wx.EVT_MENU, self.OnPopupEight, id=self.popupID8)
|
||||||
|
self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
|
||||||
|
|
||||||
# make a menu
|
# make a menu
|
||||||
menu = wxMenu()
|
menu = wx.Menu()
|
||||||
# Show how to put an icon in the menu
|
# Show how to put an icon in the menu
|
||||||
item = wxMenuItem(menu, self.popupID1,"One")
|
item = wx.MenuItem(menu, self.popupID1,"One")
|
||||||
item.SetBitmap(images.getSmilesBitmap())
|
item.SetBitmap(images.getSmilesBitmap())
|
||||||
menu.AppendItem(item)
|
menu.AppendItem(item)
|
||||||
# add some other items
|
# add some other items
|
||||||
@@ -80,7 +91,7 @@ class TestPanel(wxPanel):
|
|||||||
menu.Append(self.popupID5, "Five")
|
menu.Append(self.popupID5, "Five")
|
||||||
menu.Append(self.popupID6, "Six")
|
menu.Append(self.popupID6, "Six")
|
||||||
# make a submenu
|
# make a submenu
|
||||||
sm = wxMenu()
|
sm = wx.Menu()
|
||||||
sm.Append(self.popupID8, "sub item 1")
|
sm.Append(self.popupID8, "sub item 1")
|
||||||
sm.Append(self.popupID9, "sub item 1")
|
sm.Append(self.popupID9, "sub item 1")
|
||||||
menu.AppendMenu(self.popupID7, "Test Submenu", sm)
|
menu.AppendMenu(self.popupID7, "Test Submenu", sm)
|
||||||
@@ -113,7 +124,7 @@ class TestPanel(wxPanel):
|
|||||||
def OnPopupSeven(self, event):
|
def OnPopupSeven(self, event):
|
||||||
self.log.WriteText("Popup seven\n")
|
self.log.WriteText("Popup seven\n")
|
||||||
|
|
||||||
def OnPopupEIght(self, event):
|
def OnPopupEight(self, event):
|
||||||
self.log.WriteText("Popup eight\n")
|
self.log.WriteText("Popup eight\n")
|
||||||
|
|
||||||
def OnPopupNine(self, event):
|
def OnPopupNine(self, event):
|
||||||
|
|||||||
@@ -9,6 +9,10 @@
|
|||||||
# o printout.py is generating a snootful of errors all related to the
|
# o printout.py is generating a snootful of errors all related to the
|
||||||
# requirement for tuples on the base DC calls now
|
# requirement for tuples on the base DC calls now
|
||||||
#
|
#
|
||||||
|
# 12/10/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Issues corrected.
|
||||||
|
#
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
<html>
|
<html>
|
||||||
|
|
||||||
|
<!-- 12/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
|
||||||
|
o Updated for wx namespace.
|
||||||
|
-->
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>wxHTML does wxPython!</title>
|
<title>wxHTML does wxPython!</title>
|
||||||
</head>
|
</head>
|
||||||
@@ -13,18 +19,18 @@ sources and doc-string <a href="../../lib/wxpTag.py">here</a>.
|
|||||||
The button below is added to the page like this:
|
The button below is added to the page like this:
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<center><wxp class="wxButton" width="50%">
|
<center><wxp module="wx" class="Button" width="50%">
|
||||||
<param name="label" value="It works!">
|
<param name="label" value="It works!">
|
||||||
<param name="id" value="wxID_OK">
|
<param name="id" value="ID_OK">
|
||||||
</wxp></center>
|
</wxp></center>
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<center>
|
<center>
|
||||||
<wxp class="wxButton" width="50%">
|
<wxp module="wx" class="Button" width="50%">
|
||||||
<param name="label" value="It works!">
|
<param name="label" value="It works!">
|
||||||
<param name="id" value="wxID_OK">
|
<param name="id" value="ID_OK">
|
||||||
</wxp>
|
</wxp>
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
|
|||||||
@@ -117,9 +117,10 @@ if __name__ == "__main__":
|
|||||||
## sys.stdout.close()
|
## sys.stdout.close()
|
||||||
## self.Destroy()
|
## self.Destroy()
|
||||||
|
|
||||||
|
class MyApp(wx.App):
|
||||||
|
|
||||||
# Override the default output window and point it to the
|
# Override the default output window and point it to the
|
||||||
# custom class.
|
# custom class.
|
||||||
#>>Todo: wx renamer didn't get this
|
|
||||||
outputWindowClass = infoframe.wxPyInformationalMessagesFrame
|
outputWindowClass = infoframe.wxPyInformationalMessagesFrame
|
||||||
|
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
@@ -141,7 +142,6 @@ if __name__ == "__main__":
|
|||||||
self.SetTopWindow(frame)
|
self.SetTopWindow(frame)
|
||||||
|
|
||||||
# Associate the frame with stdout.
|
# Associate the frame with stdout.
|
||||||
#>>Todo: wx renamer didn't get this
|
|
||||||
if isinstance(sys.stdout, infoframe.wxPyInformationalMessagesFrame):
|
if isinstance(sys.stdout, infoframe.wxPyInformationalMessagesFrame):
|
||||||
sys.stdout.SetParent(frame)
|
sys.stdout.SetParent(frame)
|
||||||
|
|
||||||
|
|||||||
@@ -2,17 +2,20 @@
|
|||||||
#
|
#
|
||||||
# o Updated for wx namespace
|
# o Updated for wx namespace
|
||||||
#
|
#
|
||||||
|
# 12/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o got the wxpTag stuff working right.
|
||||||
|
#
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
import wx.html as html
|
import wx.html as html
|
||||||
|
import wx.lib.wxpTag
|
||||||
|
|
||||||
from Main import opj
|
from Main import opj
|
||||||
|
|
||||||
##wxTrap()
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
# This shows how to catch the OnLinkClicked non-event. (It's a virtual
|
# This shows how to catch the OnLinkClicked non-event. (It's a virtual
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
# o intctrl needs the renamer applied.
|
# o intctrl needs the renamer applied.
|
||||||
# o intctrl needs new event binders.
|
# o intctrl needs new event binders.
|
||||||
#
|
#
|
||||||
|
# 12/08/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o All issues corrected
|
||||||
|
#
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
import wx.lib.intctrl as intctrl
|
import wx.lib.intctrl as intctrl
|
||||||
@@ -70,10 +74,9 @@ class TestPanel( wx.Panel ):
|
|||||||
self.Bind(wx.EVT_CHECKBOX, self.OnSetAllowNone, self.allow_none)
|
self.Bind(wx.EVT_CHECKBOX, self.OnSetAllowNone, self.allow_none)
|
||||||
self.Bind(wx.EVT_CHECKBOX, self.OnSetAllowLong, self.allow_long)
|
self.Bind(wx.EVT_CHECKBOX, self.OnSetAllowLong, self.allow_long)
|
||||||
|
|
||||||
# Once the intctrl library is updated, this should be too.
|
self.Bind(intctrl.EVT_INT, self.SetTargetMinMax, self.min)
|
||||||
intctrl.EVT_INT(self, self.min.GetId(), self.SetTargetMinMax)
|
self.Bind(intctrl.EVT_INT, self.SetTargetMinMax, self.max)
|
||||||
intctrl.EVT_INT(self, self.max.GetId(), self.SetTargetMinMax)
|
self.Bind(intctrl.EVT_INT, self.OnTargetChange, self.target_ctl)
|
||||||
intctrl.EVT_INT(self, self.target_ctl.GetId(), self.OnTargetChange)
|
|
||||||
|
|
||||||
|
|
||||||
def OnSetMin( self, event ):
|
def OnSetMin( self, event ):
|
||||||
|
|||||||
@@ -19,6 +19,11 @@
|
|||||||
# o listctrl mixin needs wx renamer.
|
# o listctrl mixin needs wx renamer.
|
||||||
# o wx.ListItem.GetText() returns a wxString pointer, not the text.
|
# o wx.ListItem.GetText() returns a wxString pointer, not the text.
|
||||||
#
|
#
|
||||||
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o ColumnSorterMixin implementation was broke - added event.Skip()
|
||||||
|
# to column click event to allow event to fall through to mixin.
|
||||||
|
#
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
import wx.lib.mixins.listctrl as listmix
|
import wx.lib.mixins.listctrl as listmix
|
||||||
@@ -263,6 +268,7 @@ class TestListCtrlPanel(wx.Panel, listmix.wxColumnSorterMixin):
|
|||||||
|
|
||||||
def OnColClick(self, event):
|
def OnColClick(self, event):
|
||||||
self.log.WriteText("OnColClick: %d\n" % event.GetColumn())
|
self.log.WriteText("OnColClick: %d\n" % event.GetColumn())
|
||||||
|
event.Skip()
|
||||||
|
|
||||||
def OnColRightClick(self, event):
|
def OnColRightClick(self, event):
|
||||||
item = self.list.GetColumn(event.GetColumn())
|
item = self.list.GetColumn(event.GetColumn())
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
#
|
#
|
||||||
# o wx.lib.maskednumctrl needs hit up with the renamer and new binders
|
# o wx.lib.maskednumctrl needs hit up with the renamer and new binders
|
||||||
#
|
#
|
||||||
|
# 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Issues with lib corrected.
|
||||||
|
#
|
||||||
|
|
||||||
import string
|
import string
|
||||||
import sys
|
import sys
|
||||||
@@ -148,15 +152,15 @@ value entry ctrl:""")
|
|||||||
panel.Move( (50,10) )
|
panel.Move( (50,10) )
|
||||||
self.panel = panel
|
self.panel = panel
|
||||||
|
|
||||||
mnum.EVT_MASKEDNUM( self, self.integerwidth.GetId(), self.OnSetIntWidth )
|
self.Bind(mnum.EVT_MASKEDNUM, self.OnSetIntWidth, self.integerwidth )
|
||||||
mnum.EVT_MASKEDNUM( self, self.fractionwidth.GetId(), self.OnSetFractionWidth )
|
self.Bind(mnum.EVT_MASKEDNUM, self.OnSetFractionWidth, self.fractionwidth )
|
||||||
self.Bind(wx.EVT_TEXT, self.OnSetGroupChar, self.groupchar )
|
self.Bind(wx.EVT_TEXT, self.OnSetGroupChar, self.groupchar )
|
||||||
self.Bind(wx.EVT_TEXT, self.OnSetDecimalChar, self.decimalchar )
|
self.Bind(wx.EVT_TEXT, self.OnSetDecimalChar, self.decimalchar )
|
||||||
|
|
||||||
self.Bind(wx.EVT_CHECKBOX, self.OnSetMin, self.set_min )
|
self.Bind(wx.EVT_CHECKBOX, self.OnSetMin, self.set_min )
|
||||||
self.Bind(wx.EVT_CHECKBOX, self.OnSetMax, self.set_max )
|
self.Bind(wx.EVT_CHECKBOX, self.OnSetMax, self.set_max )
|
||||||
mnum.EVT_MASKEDNUM( self, self.min.GetId(), self.SetTargetMinMax )
|
self.Bind(mnum.EVT_MASKEDNUM, self.SetTargetMinMax, self.min )
|
||||||
mnum.EVT_MASKEDNUM( self, self.max.GetId(), self.SetTargetMinMax )
|
self.Bind(mnum.EVT_MASKEDNUM, self.SetTargetMinMax, self.max )
|
||||||
|
|
||||||
self.Bind(wx.EVT_CHECKBOX, self.SetTargetMinMax, self.limit_target )
|
self.Bind(wx.EVT_CHECKBOX, self.SetTargetMinMax, self.limit_target )
|
||||||
self.Bind(wx.EVT_CHECKBOX, self.OnSetAllowNone, self.allow_none )
|
self.Bind(wx.EVT_CHECKBOX, self.OnSetAllowNone, self.allow_none )
|
||||||
@@ -165,7 +169,7 @@ value entry ctrl:""")
|
|||||||
self.Bind(wx.EVT_CHECKBOX, self.OnSetUseParens, self.use_parens )
|
self.Bind(wx.EVT_CHECKBOX, self.OnSetUseParens, self.use_parens )
|
||||||
self.Bind(wx.EVT_CHECKBOX, self.OnSetSelectOnEntry, self.select_on_entry )
|
self.Bind(wx.EVT_CHECKBOX, self.OnSetSelectOnEntry, self.select_on_entry )
|
||||||
|
|
||||||
mnum.EVT_MASKEDNUM( self, self.target_ctl.GetId(), self.OnTargetChange )
|
self.Bind(mnum.EVT_MASKEDNUM, self.OnTargetChange, self.target_ctl )
|
||||||
self.Bind(wx.EVT_COMBOBOX, self.OnNumberSelect, self.numselect )
|
self.Bind(wx.EVT_COMBOBOX, self.OnNumberSelect, self.numselect )
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,10 @@
|
|||||||
# o There appears to be a problem with the image that
|
# o There appears to be a problem with the image that
|
||||||
# the library is trying to use for the alternate cursor
|
# the library is trying to use for the alternate cursor
|
||||||
#
|
#
|
||||||
|
# 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o renamer issue shelved.
|
||||||
|
#
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
import wx.lib.multisash as sash
|
import wx.lib.multisash as sash
|
||||||
@@ -38,6 +42,10 @@ returned by GetSaveData, as it is just another object in the dictionary.
|
|||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
class TestWindow(stc.StyledTextCtrl):
|
class TestWindow(stc.StyledTextCtrl):
|
||||||
|
|
||||||
|
# shared document reference
|
||||||
|
doc = None
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
stc.StyledTextCtrl.__init__(self, parent, -1, style=wx.NO_BORDER)
|
stc.StyledTextCtrl.__init__(self, parent, -1, style=wx.NO_BORDER)
|
||||||
self.SetMarginWidth(1,0)
|
self.SetMarginWidth(1,0)
|
||||||
@@ -52,17 +60,16 @@ class TestWindow(stc.StyledTextCtrl):
|
|||||||
wx.Font(fSize, wx.MODERN, wx.NORMAL, wx.NORMAL)
|
wx.Font(fSize, wx.MODERN, wx.NORMAL, wx.NORMAL)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.doc:
|
||||||
|
self.SetDocPointer(self.doc)
|
||||||
|
else:
|
||||||
self.SetText(sampleText)
|
self.SetText(sampleText)
|
||||||
|
TestWindow.doc = self.GetDocPointer()
|
||||||
|
|
||||||
class TestFrame(wx.Frame):
|
|
||||||
def __init__(self, parent, log):
|
|
||||||
wx.Frame.__init__(self, parent, -1, "Multi Sash Demo", size=(640,480))
|
|
||||||
self.multi = sash.wxMultiSash(self,-1,pos=(0,0), size=(640,480))
|
|
||||||
|
|
||||||
# Use this method to set the default class that will be created when
|
def SutdownDemo(self):
|
||||||
# a new sash is created. The class's constructor needs 1 parameter
|
# Reset doc reference in case this demo is run again
|
||||||
# which is the parent of the window
|
TestWindow.doc = None
|
||||||
self.multi.SetDefaultChildClass(TestWindow)
|
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
@@ -78,9 +85,6 @@ def runTest(frame, nb, log):
|
|||||||
|
|
||||||
return multi
|
return multi
|
||||||
|
|
||||||
# win = TestPanel(nb, log)
|
|
||||||
# return win
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
#
|
#
|
||||||
# o Updated for wx namespace
|
# o Updated for wx namespace
|
||||||
#
|
#
|
||||||
# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
#
|
#
|
||||||
# o wx renamer not applied to library.
|
# o Updated URL for SF link in overview.
|
||||||
#
|
#
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
@@ -54,7 +54,7 @@ wxPyColourChooser was written and is maintained by:
|
|||||||
Michael Gilfix <mgilfix@eecs.tufts.edu>
|
Michael Gilfix <mgilfix@eecs.tufts.edu>
|
||||||
|
|
||||||
You can find the latest wxPyColourChooser code at
|
You can find the latest wxPyColourChooser code at
|
||||||
http://www.sourceforge.net/wxcolourchooser. If you have
|
http://sourceforge.net/projects/wxcolourchooser/. If you have
|
||||||
any suggestions or want to submit a patch, please send
|
any suggestions or want to submit a patch, please send
|
||||||
it my way at: mgilfix@eecs.tufts.edu
|
it my way at: mgilfix@eecs.tufts.edu
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -6,6 +6,11 @@
|
|||||||
#
|
#
|
||||||
# o The rightalign library needs converted for this to work correctly.
|
# o The rightalign library needs converted for this to work correctly.
|
||||||
#
|
#
|
||||||
|
# 12/11/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o All issues resolved.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
############################################################################\
|
############################################################################\
|
||||||
# Note: this demo has been converted, but the control is deprecated because |
|
# Note: this demo has been converted, but the control is deprecated because |
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
#
|
#
|
||||||
# o scrolledpanel lib needs wx update
|
# o scrolledpanel lib needs wx update
|
||||||
#
|
#
|
||||||
|
# 12/11/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o lib updated, all is well.
|
||||||
|
#
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
import wx.lib.scrolledpanel as scrolled
|
import wx.lib.scrolledpanel as scrolled
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
# o wx renamer needed for timectrl lib
|
# o wx renamer needed for timectrl lib
|
||||||
# o presense of spin control causing probs (see spin ctrl demo for details)
|
# o presense of spin control causing probs (see spin ctrl demo for details)
|
||||||
#
|
#
|
||||||
|
# 12/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o New binders applied. Issues still exist.
|
||||||
|
#
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
import wx.lib.timectrl as timectl
|
import wx.lib.timectrl as timectl
|
||||||
@@ -146,17 +150,14 @@ class TestPanel( scrolled.wxScrolledPanel ):
|
|||||||
self.SetupScrolling()
|
self.SetupScrolling()
|
||||||
|
|
||||||
self.Bind(wx.EVT_BUTTON, self.OnButtonClick, buttonChange )
|
self.Bind(wx.EVT_BUTTON, self.OnButtonClick, buttonChange )
|
||||||
timectl.EVT_TIMEUPDATE( self, self.time12.GetId(), self.OnTimeChange )
|
self.Bind(timectl.EVT_TIMEUPDATE, self.OnTimeChange, self.time12 )
|
||||||
timectl.EVT_TIMEUPDATE( self, self.time24.GetId(), self.OnTimeChange )
|
self.Bind(timectl.EVT_TIMEUPDATE, self.OnTimeChange, self.time24 )
|
||||||
timectl.EVT_TIMEUPDATE( self, self.spinless_ctrl.GetId(), self.OnTimeChange )
|
self.Bind(timectl.EVT_TIMEUPDATE, self.OnTimeChange, self.spinless_ctrl )
|
||||||
|
|
||||||
|
|
||||||
self.Bind(wx.EVT_CHECKBOX, self.OnBoundsCheck, self.set_bounds )
|
self.Bind(wx.EVT_CHECKBOX, self.OnBoundsCheck, self.set_bounds )
|
||||||
self.Bind(wx.EVT_CHECKBOX, self.SetTargetMinMax, self.limit_check )
|
self.Bind(wx.EVT_CHECKBOX, self.SetTargetMinMax, self.limit_check )
|
||||||
timectl.EVT_TIMEUPDATE( self, self.min.GetId(), self.SetTargetMinMax )
|
self.Bind(timectl.EVT_TIMEUPDATE, self.SetTargetMinMax, self.min )
|
||||||
timectl.EVT_TIMEUPDATE( self, self.max.GetId(), self.SetTargetMinMax )
|
self.Bind(timectl.EVT_TIMEUPDATE, self.SetTargetMinMax, self.max )
|
||||||
timectl.EVT_TIMEUPDATE( self, self.target_ctrl.GetId(), self.OnTimeChange )
|
self.Bind(timectl.EVT_TIMEUPDATE, self.OnTimeChange, self.target_ctrl )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def OnTimeChange( self, event ):
|
def OnTimeChange( self, event ):
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
# 12/01/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Updated for wx namespace. Not tested though.
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
sorry no documentation...
|
sorry no documentation...
|
||||||
@@ -5,28 +9,27 @@ Christopher J. Fama
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
import wx
|
||||||
|
import wx.html as html
|
||||||
|
|
||||||
from wxPython.wx import *
|
class wxPyClickableHtmlWindow(html.HtmlWindow):
|
||||||
from wxPython.html import *
|
|
||||||
|
|
||||||
class wxPyClickableHtmlWindow(wxHtmlWindow):
|
|
||||||
"""
|
"""
|
||||||
Class for a wxHtmlWindow which responds to clicks on links by opening a
|
Class for a wxHtmlWindow which responds to clicks on links by opening a
|
||||||
browser pointed at that link, and to shift-clicks by copying the link
|
browser pointed at that link, and to shift-clicks by copying the link
|
||||||
to the clipboard.
|
to the clipboard.
|
||||||
"""
|
"""
|
||||||
def __init__(self,parent,ID,**kw):
|
def __init__(self,parent,ID,**kw):
|
||||||
apply(wxHtmlWindow.__init__,(self,parent,ID),kw)
|
apply(html.HtmlWindow.__init__,(self,parent,ID),kw)
|
||||||
|
|
||||||
def OnLinkClicked(self,link):
|
def OnLinkClicked(self,link):
|
||||||
self.link = wxTextDataObject(link.GetHref())
|
self.link = wx.TextDataObject(link.GetHref())
|
||||||
if link.GetEvent().ShiftDown():
|
if link.GetEvent().ShiftDown():
|
||||||
if wxTheClipboard.Open():
|
if wx.TheClipboard.Open():
|
||||||
wxTheClipboard.SetData(self.link)
|
wx.TheClipboard.SetData(self.link)
|
||||||
wxTheClipboard.Close()
|
wx.TheClipboard.Close()
|
||||||
else:
|
else:
|
||||||
dlg = wxMessageDialog(self,"Couldn't open clipboard!\n",wxOK)
|
dlg = wx.MessageDialog(self,"Couldn't open clipboard!\n",wx.OK)
|
||||||
wxBell()
|
wx.Bell()
|
||||||
dlg.ShowModal()
|
dlg.ShowModal()
|
||||||
dlg.Destroy()
|
dlg.Destroy()
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -8,8 +8,13 @@
|
|||||||
# Copyright: (c) 2000 by Total Control Software
|
# Copyright: (c) 2000 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Updated for wx namespace
|
||||||
|
# o Tested with updated demo
|
||||||
|
#
|
||||||
|
|
||||||
from wxPython.wx import *
|
import wx
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import win32ui
|
import win32ui
|
||||||
@@ -58,7 +63,7 @@ def MakeActiveXClass(CoClass, eventClass=None, eventObj=None):
|
|||||||
|
|
||||||
# determine the base classes
|
# determine the base classes
|
||||||
axEventClass = CoClass.default_source
|
axEventClass = CoClass.default_source
|
||||||
baseClasses = [wxWindow, pywin.mfc.activex.Control, CoClass, axEventClass]
|
baseClasses = [wx.Window, pywin.mfc.activex.Control, CoClass, axEventClass]
|
||||||
if eventClass:
|
if eventClass:
|
||||||
baseClasses.append(eventClass)
|
baseClasses.append(eventClass)
|
||||||
baseClasses = tuple(baseClasses)
|
baseClasses = tuple(baseClasses)
|
||||||
@@ -84,10 +89,11 @@ def MakeActiveXClass(CoClass, eventClass=None, eventObj=None):
|
|||||||
|
|
||||||
|
|
||||||
# These functions will be used as methods in the new class
|
# These functions will be used as methods in the new class
|
||||||
def axw__init__(self, parent, ID, pos=wxDefaultPosition, size=wxDefaultSize, style=0):
|
def axw__init__(self, parent, ID, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0):
|
||||||
|
|
||||||
# init base classes
|
# init base classes
|
||||||
pywin.mfc.activex.Control.__init__(self)
|
pywin.mfc.activex.Control.__init__(self)
|
||||||
wxWindow.__init__(self, parent, -1, pos, size, style|wxNO_FULL_REPAINT_ON_RESIZE)
|
wx.Window.__init__( self, parent, -1, pos, size, style|wx.NO_FULL_REPAINT_ON_RESIZE)
|
||||||
|
|
||||||
win32ui.EnableControlContainer()
|
win32ui.EnableControlContainer()
|
||||||
self._eventObj = self._eventObj # move from class to instance
|
self._eventObj = self._eventObj # move from class to instance
|
||||||
@@ -105,8 +111,7 @@ def axw__init__(self, parent, ID, pos=wxDefaultPosition, size=wxDefaultSize, sty
|
|||||||
self._eventBase.__init__(self, self._dispobj_)
|
self._eventBase.__init__(self, self._dispobj_)
|
||||||
|
|
||||||
# hook some wx events
|
# hook some wx events
|
||||||
EVT_SIZE(self, self.axw_OnSize)
|
self.Bind(wx.EVT_SIZE, self.axw_OnSize)
|
||||||
#EVT_ERASE_BACKGROUND(self, self.axw_OEB)
|
|
||||||
|
|
||||||
|
|
||||||
def axw__getattr__(self, attr):
|
def axw__getattr__(self, attr):
|
||||||
@@ -133,7 +138,6 @@ def axw_Cleanup(self):
|
|||||||
del self._wnd
|
del self._wnd
|
||||||
self.close()
|
self.close()
|
||||||
pass
|
pass
|
||||||
## anything else???
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,23 +9,31 @@
|
|||||||
# Copyright: (c) 2003 by Total Control Software
|
# Copyright: (c) 2003 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Updated for wx namespace
|
||||||
|
# o Tested with updated demo and with builtin test.
|
||||||
|
#
|
||||||
|
|
||||||
import math, sys, string, time
|
import math
|
||||||
from wxPython.wx import *
|
import string
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
import wx
|
||||||
|
|
||||||
|
class AnalogClockWindow(wx.Window):
|
||||||
class AnalogClockWindow(wxWindow):
|
|
||||||
"""A simple analog clock window"""
|
"""A simple analog clock window"""
|
||||||
|
|
||||||
TICKS_NONE = 0
|
TICKS_NONE = 0
|
||||||
TICKS_SQUARE = 1
|
TICKS_SQUARE = 1
|
||||||
TICKS_CIRCLE = 2
|
TICKS_CIRCLE = 2
|
||||||
|
|
||||||
def __init__(self, parent, ID=-1, pos=wxDefaultPosition, size=wxDefaultSize,
|
def __init__(self, parent, ID=-1, pos=wx.DefaultPosition, size=wx.DefaultSize,
|
||||||
style=0, name="clock"):
|
style=0, name="clock"):
|
||||||
|
|
||||||
# Initialize the wxWindow...
|
# Initialize the wxWindow...
|
||||||
wxWindow.__init__(self, parent, ID, pos, size, style, name)
|
wx.Window.__init__(self, parent, ID, pos, size, style, name)
|
||||||
|
|
||||||
# Initialize the default clock settings...
|
# Initialize the default clock settings...
|
||||||
self.minuteMarks = 60
|
self.minuteMarks = 60
|
||||||
@@ -37,20 +45,20 @@ class AnalogClockWindow(wxWindow):
|
|||||||
# Make an initial bitmap for the face, it will be updated and
|
# Make an initial bitmap for the face, it will be updated and
|
||||||
# painted at the first EVT_SIZE event.
|
# painted at the first EVT_SIZE event.
|
||||||
W, H = size
|
W, H = size
|
||||||
self.faceBitmap = wxEmptyBitmap(max(W,1), max(H,1))
|
self.faceBitmap = wx.EmptyBitmap(max(W,1), max(H,1))
|
||||||
|
|
||||||
# Initialize the timer that drives the update of the clock
|
# Initialize the timer that drives the update of the clock
|
||||||
# face. Update every half second to ensure that there is at
|
# face. Update every half second to ensure that there is at
|
||||||
# least one true update during each realtime second.
|
# least one true update during each realtime second.
|
||||||
self.timer = wxTimer(self)
|
self.timer = wx.Timer(self)
|
||||||
self.timer.Start(500)
|
self.timer.Start(500)
|
||||||
|
|
||||||
# Set event handlers...
|
# Set event handlers...
|
||||||
EVT_PAINT(self, self.OnPaint)
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||||
EVT_ERASE_BACKGROUND(self, lambda x: None)
|
self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None)
|
||||||
EVT_SIZE(self, self.OnSize)
|
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||||
EVT_TIMER(self, -1, self.OnTimerExpire)
|
self.Bind(wx.EVT_TIMER, self.OnTimerExpire)
|
||||||
EVT_WINDOW_DESTROY(self, self.OnQuit)
|
self.Bind(wx.EVT_WINDOW_DESTROY, self.OnQuit)
|
||||||
|
|
||||||
|
|
||||||
def SetTickMarkStyle(self, style):
|
def SetTickMarkStyle(self, style):
|
||||||
@@ -77,7 +85,6 @@ class AnalogClockWindow(wxWindow):
|
|||||||
self.SetForegroundColour(c) # the hands just use the foreground colour
|
self.SetForegroundColour(c) # the hands just use the foreground colour
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Using the current settings, render the points and line endings for the
|
# Using the current settings, render the points and line endings for the
|
||||||
# circle inside the specified device context. In this case, the DC is
|
# circle inside the specified device context. In this case, the DC is
|
||||||
# a memory based device context that will be blitted to the actual
|
# a memory based device context that will be blitted to the actual
|
||||||
@@ -86,12 +93,12 @@ class AnalogClockWindow(wxWindow):
|
|||||||
# The faceBitmap init is done here, to make sure the buffer is always
|
# The faceBitmap init is done here, to make sure the buffer is always
|
||||||
# the same size as the Window
|
# the same size as the Window
|
||||||
size = self.GetClientSize()
|
size = self.GetClientSize()
|
||||||
self.faceBitmap = wxEmptyBitmap(size.width, size.height)
|
self.faceBitmap = wx.EmptyBitmap(size.width, size.height)
|
||||||
self.DrawFace()
|
self.DrawFace()
|
||||||
|
|
||||||
|
|
||||||
def OnPaint(self, event):
|
def OnPaint(self, event):
|
||||||
self.DrawHands(wxPaintDC(self))
|
self.DrawHands(wx.PaintDC(self))
|
||||||
|
|
||||||
|
|
||||||
def OnQuit(self, event):
|
def OnQuit(self, event):
|
||||||
@@ -100,7 +107,7 @@ class AnalogClockWindow(wxWindow):
|
|||||||
|
|
||||||
|
|
||||||
def OnTimerExpire(self, event):
|
def OnTimerExpire(self, event):
|
||||||
self.DrawHands(wxClientDC(self))
|
self.DrawHands(wx.ClientDC(self))
|
||||||
|
|
||||||
|
|
||||||
def DrawHands(self, drawDC):
|
def DrawHands(self, drawDC):
|
||||||
@@ -124,23 +131,23 @@ class AnalogClockWindow(wxWindow):
|
|||||||
secondsX, secondsY = (x + centerX), (centerY - y)
|
secondsX, secondsY = (x + centerX), (centerY - y)
|
||||||
|
|
||||||
# Draw the hour hand...
|
# Draw the hour hand...
|
||||||
drawDC.SetPen(wxPen(self.GetForegroundColour(), 5, wxSOLID))
|
drawDC.SetPen(wx.Pen(self.GetForegroundColour(), 5, wx.SOLID))
|
||||||
drawDC.DrawLine((centerX, centerY), (hourX, hourY))
|
drawDC.DrawLine((centerX, centerY), (hourX, hourY))
|
||||||
|
|
||||||
# Draw the minutes hand...
|
# Draw the minutes hand...
|
||||||
drawDC.SetPen(wxPen(self.GetForegroundColour(), 3, wxSOLID))
|
drawDC.SetPen(wx.Pen(self.GetForegroundColour(), 3, wx.SOLID))
|
||||||
drawDC.DrawLine((centerX, centerY), (minutesX, minutesY))
|
drawDC.DrawLine((centerX, centerY), (minutesX, minutesY))
|
||||||
|
|
||||||
# Draw the seconds hand...
|
# Draw the seconds hand...
|
||||||
drawDC.SetPen(wxPen(self.GetForegroundColour(), 1, wxSOLID))
|
drawDC.SetPen(wx.Pen(self.GetForegroundColour(), 1, wx.SOLID))
|
||||||
drawDC.DrawLine((centerX, centerY), (secondsX, secondsY))
|
drawDC.DrawLine((centerX, centerY), (secondsX, secondsY))
|
||||||
|
|
||||||
|
|
||||||
# Draw the specified set of line marks inside the clock face for the
|
# Draw the specified set of line marks inside the clock face for the
|
||||||
# hours or minutes...
|
# hours or minutes...
|
||||||
def DrawFace(self):
|
def DrawFace(self):
|
||||||
backgroundBrush = wxBrush(self.GetBackgroundColour(), wxSOLID)
|
backgroundBrush = wx.Brush(self.GetBackgroundColour(), wx.SOLID)
|
||||||
drawDC = wxMemoryDC()
|
drawDC = wx.MemoryDC()
|
||||||
drawDC.SelectObject(self.faceBitmap)
|
drawDC.SelectObject(self.faceBitmap)
|
||||||
drawDC.SetBackground(backgroundBrush)
|
drawDC.SetBackground(backgroundBrush)
|
||||||
drawDC.Clear()
|
drawDC.Clear()
|
||||||
@@ -160,8 +167,9 @@ class AnalogClockWindow(wxWindow):
|
|||||||
scaledX = x + centerX - markSize/2
|
scaledX = x + centerX - markSize/2
|
||||||
scaledY = centerY - y - markSize/2
|
scaledY = centerY - y - markSize/2
|
||||||
|
|
||||||
drawDC.SetBrush(wxBrush(self.tickMarksBrushC, wxSOLID))
|
drawDC.SetBrush(wx.Brush(self.tickMarksBrushC, wx.SOLID))
|
||||||
drawDC.SetPen(wxPen(self.tickMarksPenC, 1, wxSOLID))
|
drawDC.SetPen(wx.Pen(self.tickMarksPenC, 1, wx.SOLID))
|
||||||
|
|
||||||
if self.tickMarkStyle != self.TICKS_NONE:
|
if self.tickMarkStyle != self.TICKS_NONE:
|
||||||
if self.tickMarkStyle == self.TICKS_CIRCLE:
|
if self.tickMarkStyle == self.TICKS_CIRCLE:
|
||||||
drawDC.DrawEllipse((scaledX - 2, scaledY), (markSize, markSize))
|
drawDC.DrawEllipse((scaledX - 2, scaledY), (markSize, markSize))
|
||||||
@@ -174,25 +182,25 @@ class AnalogClockWindow(wxWindow):
|
|||||||
radiansPerDegree = math.pi / 180
|
radiansPerDegree = math.pi / 180
|
||||||
pointX = int(round(radius * math.sin(angle * radiansPerDegree)))
|
pointX = int(round(radius * math.sin(angle * radiansPerDegree)))
|
||||||
pointY = int(round(radius * math.cos(angle * radiansPerDegree)))
|
pointY = int(round(radius * math.cos(angle * radiansPerDegree)))
|
||||||
return wxPoint(pointX, pointY)
|
return wx.Point(pointX, pointY)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
class App(wxApp):
|
class App(wx.App):
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
frame = wxFrame(None, -1, "AnalogClockWindow Test", size=(375,375))
|
frame = wx.Frame(None, -1, "AnalogClockWindow Test", size=(375,375))
|
||||||
|
|
||||||
clock = AnalogClockWindow(frame)
|
clock = AnalogClockWindow(frame)
|
||||||
clock.SetTickMarkColours("RED")
|
clock.SetTickMarkColours("RED")
|
||||||
clock.SetHandsColour("WHITE")
|
clock.SetHandsColour("WHITE")
|
||||||
clock.SetBackgroundColour("BLUE")
|
clock.SetBackgroundColour("BLUE")
|
||||||
|
|
||||||
frame.Centre(wxBOTH)
|
frame.Centre(wx.BOTH)
|
||||||
frame.Show(True)
|
frame.Show(True)
|
||||||
self.SetTopWindow(frame)
|
self.SetTopWindow(frame)
|
||||||
return true
|
return True
|
||||||
|
|
||||||
theApp = App(0)
|
theApp = App(0)
|
||||||
theApp.MainLoop()
|
theApp.MainLoop()
|
||||||
|
|||||||
@@ -10,12 +10,16 @@
|
|||||||
# Copyright: (c) 2000 by Total Control Software
|
# Copyright: (c) 2000 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Updated for wx namespace
|
||||||
|
# o Tested with updated demo
|
||||||
|
#
|
||||||
|
|
||||||
from wxPython.wx import wxLayoutConstraints, wxTop, wxLeft, wxBottom, wxRight, \
|
import wx
|
||||||
wxHeight, wxWidth
|
|
||||||
|
|
||||||
class LayoutAnchors(wxLayoutConstraints):
|
class LayoutAnchors(wx.LayoutConstraints):
|
||||||
""" A class that implements Delphi's Anchors with wxLayoutConstraints.
|
""" A class that implements Delphi's Anchors with wx.LayoutConstraints.
|
||||||
|
|
||||||
Anchored sides maintain the distance from the edge of the
|
Anchored sides maintain the distance from the edge of the
|
||||||
control to the same edge of the parent.
|
control to the same edge of the parent.
|
||||||
@@ -56,22 +60,22 @@ class LayoutAnchors(wxLayoutConstraints):
|
|||||||
+-------------------+
|
+-------------------+
|
||||||
* = anchored edge
|
* = anchored edge
|
||||||
"""
|
"""
|
||||||
def __init__(self, control, left = 1, top = 1, right = 0, bottom = 0):
|
def __init__(self, control, left=1, top=1, right=0, bottom=0):
|
||||||
wxLayoutConstraints.__init__(self)
|
wx.LayoutConstraints.__init__(self)
|
||||||
parent = control.GetParent()
|
parent = control.GetParent()
|
||||||
if not parent: return
|
if not parent: return
|
||||||
|
|
||||||
pPos, pSize = parent.GetPosition(), parent.GetClientSize()
|
pPos, pSize = parent.GetPosition(), parent.GetClientSize()
|
||||||
cPos, cSize = control.GetPosition(), control.GetSize()
|
cPos, cSize = control.GetPosition(), control.GetSize()
|
||||||
|
|
||||||
self.setConstraintSides(self.left, wxLeft, left,
|
self.setConstraintSides(self.left, wx.Left, left,
|
||||||
self.right, wxRight, right,
|
self.right, wx.Right, right,
|
||||||
self.width, wxWidth, self.centreX,
|
self.width, wx.Width, self.centreX,
|
||||||
cPos.x, cSize.width, pSize.width, parent)
|
cPos.x, cSize.width, pSize.width, parent)
|
||||||
|
|
||||||
self.setConstraintSides(self.top, wxTop, top,
|
self.setConstraintSides(self.top, wx.Top, top,
|
||||||
self.bottom, wxBottom, bottom,
|
self.bottom, wx.Bottom, bottom,
|
||||||
self.height, wxHeight, self.centreY,
|
self.height, wx.Height, self.centreY,
|
||||||
cPos.y, cSize.height, pSize.height, parent)
|
cPos.y, cSize.height, pSize.height, parent)
|
||||||
|
|
||||||
def setConstraintSides(self, side1, side1Edge, side1Anchor,
|
def setConstraintSides(self, side1, side1Edge, side1Anchor,
|
||||||
@@ -80,12 +84,16 @@ class LayoutAnchors(wxLayoutConstraints):
|
|||||||
cPos, cSize, pSize, parent):
|
cPos, cSize, pSize, parent):
|
||||||
if side2Anchor:
|
if side2Anchor:
|
||||||
side2.SameAs(parent, side2Edge, pSize - (cPos + cSize))
|
side2.SameAs(parent, side2Edge, pSize - (cPos + cSize))
|
||||||
|
|
||||||
if side1Anchor:
|
if side1Anchor:
|
||||||
side1.SameAs(parent, side1Edge, cPos)
|
side1.SameAs(parent, side1Edge, cPos)
|
||||||
|
|
||||||
if not side2Anchor:
|
if not side2Anchor:
|
||||||
size.AsIs()
|
size.AsIs()
|
||||||
else:
|
else:
|
||||||
size.AsIs()
|
size.AsIs()
|
||||||
|
|
||||||
if not side2Anchor:
|
if not side2Anchor:
|
||||||
centre.PercentOf(parent, sizeEdge,
|
centre.PercentOf(parent, sizeEdge,
|
||||||
int(((cPos + cSize / 2.0) / pSize)*100))
|
int(((cPos + cSize / 2.0) / pSize)*100))
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,11 @@
|
|||||||
# Copyright: (c) 1999 by Total Control Software
|
# Copyright: (c) 1999 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Updated for wx namespace
|
||||||
|
# o Tested with updated demo
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This module implements various forms of generic buttons, meaning that
|
This module implements various forms of generic buttons, meaning that
|
||||||
|
|||||||
@@ -9,19 +9,44 @@
|
|||||||
# Date: Nov 26, 2001
|
# Date: Nov 26, 2001
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
# 12/01/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Updated for wx namespace
|
||||||
|
# o Tested with updated demo
|
||||||
|
# o Added new event type EVT_CALENDAR. The reason for this is that the original
|
||||||
|
# library used a hardcoded ID of 2100 for generating events. This makes it
|
||||||
|
# very difficult to fathom when trying to decode the code since there's no
|
||||||
|
# published API. Creating the new event binder might seem like overkill -
|
||||||
|
# after all, you might ask, why not just use a new event ID and be done with
|
||||||
|
# it? However, a consistent interface is very useful at times; also it makes
|
||||||
|
# it clear that we're not just hunting for mouse clicks -- we're hunting
|
||||||
|
# wabbit^H^H^H^H (sorry bout that) for calender-driven mouse clicks. So
|
||||||
|
# that's my sad story. Shoot me if you must :-)
|
||||||
|
# o There's still one deprecation warning buried in here somewhere, but I
|
||||||
|
# haven't been able to find it yet. It only occurs when displaying a
|
||||||
|
# print preview, and only the first time. It *could* be an error in the
|
||||||
|
# demo, I suppose.
|
||||||
|
#
|
||||||
|
# Here's the traceback:
|
||||||
|
#
|
||||||
|
# C:\Python\lib\site-packages\wx\core.py:949: DeprecationWarning:
|
||||||
|
# integer argument expected, got float
|
||||||
|
# newobj = _core.new_Rect(*args, **kwargs)
|
||||||
|
#
|
||||||
|
|
||||||
from wxPython.wx import *
|
import wx
|
||||||
|
|
||||||
from CDate import *
|
from CDate import *
|
||||||
|
|
||||||
|
|
||||||
CalDays = [6, 0, 1, 2, 3, 4, 5]
|
CalDays = [6, 0, 1, 2, 3, 4, 5]
|
||||||
AbrWeekday = {6:"Sun", 0:"Mon", 1:"Tue", 2:"Wed", 3:"Thu", 4:"Fri", 5:"Sat"}
|
AbrWeekday = {6:"Sun", 0:"Mon", 1:"Tue", 2:"Wed", 3:"Thu", 4:"Fri", 5:"Sat"}
|
||||||
_MIDSIZE = 180
|
_MIDSIZE = 180
|
||||||
|
|
||||||
BusCalDays = [0, 1, 2, 3, 4, 5, 6]
|
BusCalDays = [0, 1, 2, 3, 4, 5, 6]
|
||||||
|
|
||||||
# calendar drawing routing
|
# Calendar click event - added 12/1/03 by jmg (see above)
|
||||||
|
wxEVT_COMMAND_PYCALENDAR_DAY_CLICKED = wx.NewEventType()
|
||||||
|
EVT_CALENDAR = wx.PyEventBinder(wxEVT_COMMAND_PYCALENDAR_DAY_CLICKED, 1)
|
||||||
|
|
||||||
def GetMonthList():
|
def GetMonthList():
|
||||||
monthlist = []
|
monthlist = []
|
||||||
@@ -31,6 +56,8 @@ def GetMonthList():
|
|||||||
monthlist.append(name)
|
monthlist.append(name)
|
||||||
return monthlist
|
return monthlist
|
||||||
|
|
||||||
|
# calendar drawing routing
|
||||||
|
|
||||||
class CalDraw:
|
class CalDraw:
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
self.pwidth = 1
|
self.pwidth = 1
|
||||||
@@ -47,8 +74,8 @@ class CalDraw:
|
|||||||
self.num_size = 12 # default size of calendar if no auto size
|
self.num_size = 12 # default size of calendar if no auto size
|
||||||
self.max_num_size = 12 # maximum size for calendar number
|
self.max_num_size = 12 # maximum size for calendar number
|
||||||
|
|
||||||
self.num_align_horz = wxALIGN_CENTRE # alignment of numbers
|
self.num_align_horz = wx.ALIGN_CENTRE # alignment of numbers
|
||||||
self.num_align_vert = wxALIGN_CENTRE
|
self.num_align_vert = wx.ALIGN_CENTRE
|
||||||
self.num_indent_horz = 0 # points indent from position, used to offset if not centered
|
self.num_indent_horz = 0 # points indent from position, used to offset if not centered
|
||||||
self.num_indent_vert = 0
|
self.num_indent_vert = 0
|
||||||
|
|
||||||
@@ -67,8 +94,8 @@ class CalDraw:
|
|||||||
self.week_font_color = 'BLACK' # font colors
|
self.week_font_color = 'BLACK' # font colors
|
||||||
self.day_font_color = 'BLACK'
|
self.day_font_color = 'BLACK'
|
||||||
|
|
||||||
self.font = wxSWISS
|
self.font = wx.SWISS
|
||||||
self.bold = wxNORMAL
|
self.bold = wx.NORMAL
|
||||||
|
|
||||||
self.hide_title = False
|
self.hide_title = False
|
||||||
self.hide_grid = False
|
self.hide_grid = False
|
||||||
@@ -84,8 +111,8 @@ class CalDraw:
|
|||||||
self.week_color = week_color
|
self.week_color = week_color
|
||||||
|
|
||||||
def SetSize(self, size):
|
def SetSize(self, size):
|
||||||
self.set_sizew = size.width
|
self.set_sizew = size[0]
|
||||||
self.set_sizeh = size.height
|
self.set_sizeh = size[1]
|
||||||
|
|
||||||
def InitValues(self): # default dimensions of various elements of the calendar
|
def InitValues(self): # default dimensions of various elements of the calendar
|
||||||
self.rg = {}
|
self.rg = {}
|
||||||
@@ -122,6 +149,7 @@ class CalDraw:
|
|||||||
self.InitScale()
|
self.InitScale()
|
||||||
|
|
||||||
self.DrawBorder()
|
self.DrawBorder()
|
||||||
|
|
||||||
if self.hide_title is False:
|
if self.hide_title is False:
|
||||||
self.DrawMonth()
|
self.DrawMonth()
|
||||||
|
|
||||||
@@ -142,19 +170,22 @@ class CalDraw:
|
|||||||
def AddSelect(self, list, cfont=None, cbackgrd = None):
|
def AddSelect(self, list, cfont=None, cbackgrd = None):
|
||||||
if cfont is None:
|
if cfont is None:
|
||||||
cfont = self.sel_color # font digit color
|
cfont = self.sel_color # font digit color
|
||||||
|
|
||||||
if cbackgrd is None:
|
if cbackgrd is None:
|
||||||
cbackgrd = self.high_color # select background color
|
cbackgrd = self.high_color # select background color
|
||||||
|
|
||||||
for val in list:
|
for val in list:
|
||||||
self.cal_sel[val] = (cfont, cbackgrd)
|
self.cal_sel[val] = (cfont, cbackgrd)
|
||||||
|
|
||||||
def DrawBorder(self): # draw border around the outside of the main display rectangle
|
# draw border around the outside of the main display rectangle
|
||||||
brush = wxBrush(wxNamedColour(self.back_color), wxSOLID)
|
def DrawBorder(self):
|
||||||
|
brush = wx.Brush(wx.NamedColour(self.back_color), wx.SOLID)
|
||||||
self.DC.SetBrush(brush)
|
self.DC.SetBrush(brush)
|
||||||
self.DC.SetPen(wxPen(wxNamedColour(self.border_color), 1))
|
self.DC.SetPen(wx.Pen(wx.NamedColour(self.border_color), 1))
|
||||||
|
|
||||||
if self.outer_border is True:
|
if self.outer_border is True:
|
||||||
rect = wxRect(self.cx_st, self.cy_st, self.sizew, self.sizeh) # full display window area
|
# full display window area
|
||||||
|
rect = wx.Rect(self.cx_st, self.cy_st, self.sizew, self.sizeh)
|
||||||
self.DC.DrawRectangleRect(rect)
|
self.DC.DrawRectangleRect(rect)
|
||||||
|
|
||||||
def DrawNumVal(self):
|
def DrawNumVal(self):
|
||||||
@@ -172,6 +203,7 @@ class CalDraw:
|
|||||||
t = Date(year, month, day)
|
t = Date(year, month, day)
|
||||||
dow = self.dow = t.day_of_week # start day in month
|
dow = self.dow = t.day_of_week # start day in month
|
||||||
dim = self.dim = t.days_in_month # number of days in month
|
dim = self.dim = t.days_in_month # number of days in month
|
||||||
|
|
||||||
if self.cal_type == "NORMAL":
|
if self.cal_type == "NORMAL":
|
||||||
start_pos = dow+1
|
start_pos = dow+1
|
||||||
else:
|
else:
|
||||||
@@ -182,17 +214,21 @@ class CalDraw:
|
|||||||
self.cal = []
|
self.cal = []
|
||||||
for i in range(start_pos):
|
for i in range(start_pos):
|
||||||
self.cal.append('')
|
self.cal.append('')
|
||||||
|
|
||||||
i = 1
|
i = 1
|
||||||
while i <= dim:
|
while i <= dim:
|
||||||
self.cal.append(str(i))
|
self.cal.append(str(i))
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
|
||||||
return start_pos
|
return start_pos
|
||||||
|
|
||||||
def SetWeekEnd(self, font_color='BLACK', backgrd = 'LIGHT GREY'):
|
def SetWeekEnd(self, font_color='BLACK', backgrd = 'LIGHT GREY'):
|
||||||
date = 6 - int(self.dow) # start day of first saturday
|
date = 6 - int(self.dow) # start day of first saturday
|
||||||
|
|
||||||
while date <= self.dim:
|
while date <= self.dim:
|
||||||
self.cal_sel[date] = (font_color, backgrd) # Saturday
|
self.cal_sel[date] = (font_color, backgrd) # Saturday
|
||||||
date = date + 1
|
date = date + 1
|
||||||
|
|
||||||
if date <= self.dim:
|
if date <= self.dim:
|
||||||
self.cal_sel[date] = (font_color, backgrd) # Sunday
|
self.cal_sel[date] = (font_color, backgrd) # Sunday
|
||||||
date = date + 6
|
date = date + 6
|
||||||
@@ -203,9 +239,10 @@ class CalDraw:
|
|||||||
cnt = 0
|
cnt = 0
|
||||||
for y in self.gridy[1:-1]:
|
for y in self.gridy[1:-1]:
|
||||||
for x in self.gridx[:-1]:
|
for x in self.gridx[:-1]:
|
||||||
rect = wxRect(x, y, self.dl_w, self.dl_h) # create rect region
|
rect = wx.Rect(x, y, self.dl_w, self.dl_h) # create rect region
|
||||||
self.rg[cnt] = rect
|
self.rg[cnt] = rect
|
||||||
cnt = cnt + 1
|
cnt = cnt + 1
|
||||||
|
|
||||||
return self.rg
|
return self.rg
|
||||||
|
|
||||||
def GetCal(self):
|
def GetCal(self):
|
||||||
@@ -221,7 +258,7 @@ class CalDraw:
|
|||||||
if self.sizeh < _MIDSIZE:
|
if self.sizeh < _MIDSIZE:
|
||||||
sizef = 10
|
sizef = 10
|
||||||
|
|
||||||
f = wxFont(sizef, self.font, wxNORMAL, self.bold)
|
f = wx.Font(sizef, self.font, wx.NORMAL, self.bold)
|
||||||
self.DC.SetFont(f)
|
self.DC.SetFont(f)
|
||||||
|
|
||||||
tw,th = self.DC.GetTextExtent(month)
|
tw,th = self.DC.GetTextExtent(month)
|
||||||
@@ -234,7 +271,7 @@ class CalDraw:
|
|||||||
|
|
||||||
self.title_offset = th * 2
|
self.title_offset = th * 2
|
||||||
|
|
||||||
f = wxFont(sizef, self.font, wxNORMAL, self.bold)
|
f = wx.Font(sizef, self.font, wx.NORMAL, self.bold)
|
||||||
self.DC.SetFont(f)
|
self.DC.SetFont(f)
|
||||||
self.DC.DrawText(year, (self.cx_st + adjust, self.cy_st + th))
|
self.DC.DrawText(year, (self.cx_st + adjust, self.cy_st + th))
|
||||||
|
|
||||||
@@ -243,7 +280,8 @@ class CalDraw:
|
|||||||
height = self.gridy[1] - self.gridy[0]
|
height = self.gridy[1] - self.gridy[0]
|
||||||
rect_w = self.gridx[7]-self.gridx[0]
|
rect_w = self.gridx[7]-self.gridx[0]
|
||||||
|
|
||||||
f = wxFont(10, self.font, wxNORMAL, self.bold) # initial font setting
|
f = wx.Font(10, self.font, wx.NORMAL, self.bold) # initial font setting
|
||||||
|
|
||||||
if self.week_auto == True:
|
if self.week_auto == True:
|
||||||
test_size = self.max_week_size # max size
|
test_size = self.max_week_size # max size
|
||||||
test_day = ' Sun '
|
test_day = ' Sun '
|
||||||
@@ -251,21 +289,23 @@ class CalDraw:
|
|||||||
f.SetPointSize(test_size)
|
f.SetPointSize(test_size)
|
||||||
self.DC.SetFont(f)
|
self.DC.SetFont(f)
|
||||||
tw,th = self.DC.GetTextExtent(test_day)
|
tw,th = self.DC.GetTextExtent(test_day)
|
||||||
|
|
||||||
if tw < width and th < height:
|
if tw < width and th < height:
|
||||||
break
|
break
|
||||||
|
|
||||||
test_size = test_size - 1
|
test_size = test_size - 1
|
||||||
else:
|
else:
|
||||||
f.SetPointSize(self.week_size) # set fixed size
|
f.SetPointSize(self.week_size) # set fixed size
|
||||||
self.DC.SetFont(f)
|
self.DC.SetFont(f)
|
||||||
|
|
||||||
self.DC.SetTextForeground(wxNamedColour(self.week_font_color))
|
self.DC.SetTextForeground(wx.NamedColour(self.week_font_color))
|
||||||
|
|
||||||
cnt_x = 0
|
cnt_x = 0
|
||||||
cnt_y = 0
|
cnt_y = 0
|
||||||
|
|
||||||
brush = wxBrush(wxNamedColour(self.week_color), wxSOLID)
|
brush = wx.Brush(wx.NamedColour(self.week_color), wx.SOLID)
|
||||||
self.DC.SetBrush(brush)
|
self.DC.SetBrush(brush)
|
||||||
# self.DC.DrawRectangle((self.gridx[0], self.gridy[0]), (rect_w+1, height))
|
self.DC.DrawRectangle((self.gridx[0], self.gridy[0]), (rect_w+1, height))
|
||||||
|
|
||||||
if self.cal_type == "NORMAL":
|
if self.cal_type == "NORMAL":
|
||||||
cal_days = CalDays
|
cal_days = CalDays
|
||||||
@@ -274,8 +314,10 @@ class CalDraw:
|
|||||||
|
|
||||||
for val in cal_days:
|
for val in cal_days:
|
||||||
day = AbrWeekday[val]
|
day = AbrWeekday[val]
|
||||||
|
|
||||||
if self.sizew < 200:
|
if self.sizew < 200:
|
||||||
day = day[0]
|
day = day[0]
|
||||||
|
|
||||||
dw,dh = self.DC.GetTextExtent(day)
|
dw,dh = self.DC.GetTextExtent(day)
|
||||||
diffx = (width-dw)/2
|
diffx = (width-dw)/2
|
||||||
diffy = (height-dh)/2
|
diffy = (height-dh)/2
|
||||||
@@ -287,14 +329,17 @@ class CalDraw:
|
|||||||
cnt_x = cnt_x + 1
|
cnt_x = cnt_x + 1
|
||||||
|
|
||||||
def DrawNum(self): # draw the day numbers
|
def DrawNum(self): # draw the day numbers
|
||||||
f = wxFont(10, self.font, wxNORMAL, self.bold) # initial font setting
|
f = wx.Font(10, self.font, wx.NORMAL, self.bold) # initial font setting
|
||||||
|
|
||||||
if self.num_auto == True:
|
if self.num_auto == True:
|
||||||
test_size = self.max_num_size # max size
|
test_size = self.max_num_size # max size
|
||||||
test_day = ' 99 '
|
test_day = ' 99 '
|
||||||
|
|
||||||
while test_size > 2:
|
while test_size > 2:
|
||||||
f.SetPointSize(test_size)
|
f.SetPointSize(test_size)
|
||||||
self.DC.SetFont(f)
|
self.DC.SetFont(f)
|
||||||
tw,th = self.DC.GetTextExtent(test_day)
|
tw,th = self.DC.GetTextExtent(test_day)
|
||||||
|
|
||||||
if tw < self.dl_w and th < self.dl_h:
|
if tw < self.dl_w and th < self.dl_h:
|
||||||
sizef = test_size
|
sizef = test_size
|
||||||
break
|
break
|
||||||
@@ -315,22 +360,23 @@ class CalDraw:
|
|||||||
except:
|
except:
|
||||||
num_color = self.day_font_color
|
num_color = self.day_font_color
|
||||||
|
|
||||||
self.DC.SetTextForeground(wxNamedColour(num_color))
|
self.DC.SetTextForeground(wx.NamedColour(num_color))
|
||||||
self.DC.SetFont(f)
|
self.DC.SetFont(f)
|
||||||
|
|
||||||
tw,th = self.DC.GetTextExtent(val)
|
tw,th = self.DC.GetTextExtent(val)
|
||||||
if self.num_align_horz == wxALIGN_CENTRE:
|
|
||||||
|
if self.num_align_horz == wx.ALIGN_CENTRE:
|
||||||
adj_h = (self.dl_w - tw)/2
|
adj_h = (self.dl_w - tw)/2
|
||||||
elif self.num_align_horz == wxALIGN_RIGHT:
|
elif self.num_align_horz == wx.ALIGN_RIGHT:
|
||||||
adj_h = self.dl_w - tw
|
adj_h = self.dl_w - tw
|
||||||
else:
|
else:
|
||||||
adj_h = 0 # left alignment
|
adj_h = 0 # left alignment
|
||||||
|
|
||||||
adj_h = adj_h + self.num_indent_horz
|
adj_h = adj_h + self.num_indent_horz
|
||||||
|
|
||||||
if self.num_align_vert == wxALIGN_CENTRE:
|
if self.num_align_vert == wx.ALIGN_CENTRE:
|
||||||
adj_v = (self.dl_h - th)/2
|
adj_v = (self.dl_h - th)/2
|
||||||
elif self.num_align_horz == wxALIGN_RIGHT:
|
elif self.num_align_horz == wx.ALIGN_RIGHT:
|
||||||
adj_v = self.dl_h - th
|
adj_v = self.dl_h - th
|
||||||
else:
|
else:
|
||||||
adj_v = 0 # left alignment
|
adj_v = 0 # left alignment
|
||||||
@@ -338,6 +384,7 @@ class CalDraw:
|
|||||||
adj_v = adj_v + self.num_indent_vert
|
adj_v = adj_v + self.num_indent_vert
|
||||||
|
|
||||||
self.DC.DrawText(val, (x+adj_h, y+adj_v))
|
self.DC.DrawText(val, (x+adj_h, y+adj_v))
|
||||||
|
|
||||||
if cnt_x < 6:
|
if cnt_x < 6:
|
||||||
cnt_x = cnt_x + 1
|
cnt_x = cnt_x + 1
|
||||||
else:
|
else:
|
||||||
@@ -358,19 +405,20 @@ class CalDraw:
|
|||||||
def DrawSel(self): # highlighted selected days
|
def DrawSel(self): # highlighted selected days
|
||||||
for key in self.cal_sel.keys():
|
for key in self.cal_sel.keys():
|
||||||
sel_color = self.cal_sel[key][1]
|
sel_color = self.cal_sel[key][1]
|
||||||
brush = wxBrush(wxNamedColour(sel_color), wxSOLID)
|
brush = wx.Brush(wx.NamedColour(sel_color), wx.SOLID)
|
||||||
self.DC.SetBrush(brush)
|
self.DC.SetBrush(brush)
|
||||||
|
|
||||||
if self.hide_grid is False:
|
if self.hide_grid is False:
|
||||||
self.DC.SetPen(wxPen(wxNamedColour(self.grid_color), 0))
|
self.DC.SetPen(wx.Pen(wx.NamedColour(self.grid_color), 0))
|
||||||
else:
|
else:
|
||||||
self.DC.SetPen(wxPen(wxNamedColour(self.back_color), 0))
|
self.DC.SetPen(wx.Pen(wx.NamedColour(self.back_color), 0))
|
||||||
|
|
||||||
nkey = key + self.st_pos -1
|
nkey = key + self.st_pos -1
|
||||||
rect = self.rg[nkey]
|
rect = self.rg[nkey]
|
||||||
self.DC.DrawRectangle((rect.x, rect.y), (rect.width+1, rect.height+1))
|
self.DC.DrawRectangle((rect.x, rect.y), (rect.width+1, rect.height+1))
|
||||||
|
|
||||||
def DrawGrid(self): # calculate and draw the grid lines
|
def DrawGrid(self): # calculate and draw the grid lines
|
||||||
self.DC.SetPen(wxPen(wxNamedColour(self.grid_color), 0))
|
self.DC.SetPen(wx.Pen(wx.NamedColour(self.grid_color), 0))
|
||||||
|
|
||||||
self.gridx = []
|
self.gridx = []
|
||||||
self.gridy = []
|
self.gridy = []
|
||||||
@@ -380,8 +428,8 @@ class CalDraw:
|
|||||||
|
|
||||||
x1 = self.x_st
|
x1 = self.x_st
|
||||||
y1 = self.y_st
|
y1 = self.y_st
|
||||||
|
|
||||||
y2 = y1 + self.cheight
|
y2 = y1 + self.cheight
|
||||||
|
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
if self.hide_grid is False:
|
if self.hide_grid is False:
|
||||||
self.DC.DrawLine((x1, y1), (x1, y2))
|
self.DC.DrawLine((x1, y1), (x1, y2))
|
||||||
@@ -390,12 +438,14 @@ class CalDraw:
|
|||||||
|
|
||||||
x1 = self.x_st
|
x1 = self.x_st
|
||||||
y1 = self.y_st
|
y1 = self.y_st
|
||||||
|
|
||||||
x2 = x1 + self.cwidth
|
x2 = x1 + self.cwidth
|
||||||
|
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
if self.hide_grid is False:
|
if self.hide_grid is False:
|
||||||
self.DC.DrawLine((x1, y1), (x2, y1))
|
self.DC.DrawLine((x1, y1), (x2, y1))
|
||||||
|
|
||||||
self.gridy.append(y1)
|
self.gridy.append(y1)
|
||||||
|
|
||||||
if i == 0:
|
if i == 0:
|
||||||
y1 = y1 + self.dl_th
|
y1 = y1 + self.dl_th
|
||||||
else:
|
else:
|
||||||
@@ -413,16 +463,17 @@ class PrtCalDraw(CalDraw):
|
|||||||
self.set_x_mrg = 0.2
|
self.set_x_mrg = 0.2
|
||||||
self.set_y_end = 0.2
|
self.set_y_end = 0.2
|
||||||
|
|
||||||
def SetPSize(self, pwidth, pheight): # calculate the dimensions in the center of the drawing area
|
# calculate the dimensions in the center of the drawing area
|
||||||
|
def SetPSize(self, pwidth, pheight):
|
||||||
self.pwidth = int(pwidth)/self.scale
|
self.pwidth = int(pwidth)/self.scale
|
||||||
self.pheight = int(pheight)/self.scale
|
self.pheight = int(pheight)/self.scale
|
||||||
|
|
||||||
def SetPreview(self, preview):
|
def SetPreview(self, preview):
|
||||||
self.preview = preview
|
self.preview = preview
|
||||||
|
|
||||||
class wxCalendar(wxWindow):
|
class wxCalendar(wx.Window):
|
||||||
def __init__(self, parent, id, pos=wxDefaultPosition, size=wxDefaultSize):
|
def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize):
|
||||||
wxWindow.__init__(self, parent, id, pos, size)
|
wx.Window.__init__(self, parent, id, pos, size)
|
||||||
|
|
||||||
# set the calendar control attributes
|
# set the calendar control attributes
|
||||||
|
|
||||||
@@ -439,11 +490,11 @@ class wxCalendar(wxWindow):
|
|||||||
|
|
||||||
self.select_list = []
|
self.select_list = []
|
||||||
|
|
||||||
self.SetBackgroundColour(wxNamedColour(self.back_color))
|
self.SetBackgroundColour(self.back_color)
|
||||||
self.Connect(-1, -1, wxEVT_LEFT_DOWN, self.OnLeftEvent)
|
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftEvent)
|
||||||
self.Connect(-1, -1, wxEVT_LEFT_DCLICK, self.OnLeftDEvent)
|
self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDEvent)
|
||||||
self.Connect(-1, -1, wxEVT_RIGHT_DOWN, self.OnRightEvent)
|
self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightEvent)
|
||||||
self.Connect(-1, -1, wxEVT_RIGHT_DCLICK, self.OnRightDEvent)
|
self.Bind(wx.EVT_RIGHT_DCLICK, self.OnRightDEvent)
|
||||||
|
|
||||||
self.sel_key = None # last used by
|
self.sel_key = None # last used by
|
||||||
self.sel_lst = [] # highlighted selected days
|
self.sel_lst = [] # highlighted selected days
|
||||||
@@ -453,8 +504,8 @@ class wxCalendar(wxWindow):
|
|||||||
self.size = None
|
self.size = None
|
||||||
self.set_day = None
|
self.set_day = None
|
||||||
|
|
||||||
EVT_PAINT(self, self.OnPaint)
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||||
EVT_SIZE(self, self.OnSize)
|
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||||
|
|
||||||
# control some of the main calendar attributes
|
# control some of the main calendar attributes
|
||||||
|
|
||||||
@@ -574,7 +625,8 @@ class wxCalendar(wxWindow):
|
|||||||
if self.day == "":
|
if self.day == "":
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
evt = wxPyCommandEvent(2100, self.GetId())
|
# Changed 12/1/03 by jmg (see above) to support 2.5 event binding
|
||||||
|
evt = wx.PyCommandEvent(wxEVT_COMMAND_PYCALENDAR_DAY_CLICKED, self.GetId())
|
||||||
evt.click, evt.day, evt.month, evt.year = self.click, self.day, self.month, self.year
|
evt.click, evt.day, evt.month, evt.year = self.click, self.day, self.month, self.year
|
||||||
evt.shiftkey = self.shiftkey
|
evt.shiftkey = self.shiftkey
|
||||||
evt.ctrlkey = self.ctrlkey
|
evt.ctrlkey = self.ctrlkey
|
||||||
@@ -588,10 +640,11 @@ class wxCalendar(wxWindow):
|
|||||||
def GetDayHit(self, mx, my):
|
def GetDayHit(self, mx, my):
|
||||||
for key in self.rg.keys():
|
for key in self.rg.keys():
|
||||||
val = self.rg[key]
|
val = self.rg[key]
|
||||||
ms_rect = wxRect(mx, my, 1, 1)
|
ms_rect = wx.Rect(mx, my, 1, 1)
|
||||||
if wxIntersectRect(ms_rect, val) is not None:
|
if wx.IntersectRect(ms_rect, val) is not None:
|
||||||
result = self.TestDay(key)
|
result = self.TestDay(key)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# calendar drawing
|
# calendar drawing
|
||||||
@@ -615,11 +668,11 @@ class wxCalendar(wxWindow):
|
|||||||
evt.Skip()
|
evt.Skip()
|
||||||
|
|
||||||
def OnPaint(self, event):
|
def OnPaint(self, event):
|
||||||
DC = wxPaintDC(self)
|
DC = wx.PaintDC(self)
|
||||||
self.DoDrawing(DC)
|
self.DoDrawing(DC)
|
||||||
|
|
||||||
def DoDrawing(self, DC):
|
def DoDrawing(self, DC):
|
||||||
DC = wxPaintDC(self)
|
DC = wx.PaintDC(self)
|
||||||
DC.BeginDrawing()
|
DC.BeginDrawing()
|
||||||
|
|
||||||
self.cal = cal = CalDraw(self)
|
self.cal = cal = CalDraw(self)
|
||||||
@@ -644,6 +697,7 @@ class wxCalendar(wxWindow):
|
|||||||
|
|
||||||
cal.SetSize(size)
|
cal.SetSize(size)
|
||||||
cal.SetCal(self.year, self.month)
|
cal.SetCal(self.year, self.month)
|
||||||
|
|
||||||
for val in self.select_list:
|
for val in self.select_list:
|
||||||
cal.AddSelect(val[0], val[1], val[2])
|
cal.AddSelect(val[0], val[1], val[2])
|
||||||
|
|
||||||
@@ -656,6 +710,7 @@ class wxCalendar(wxWindow):
|
|||||||
|
|
||||||
if self.set_day != None:
|
if self.set_day != None:
|
||||||
self.SetDay(self.set_day)
|
self.SetDay(self.set_day)
|
||||||
|
|
||||||
DC.EndDrawing()
|
DC.EndDrawing()
|
||||||
|
|
||||||
# draw the selection rectangle
|
# draw the selection rectangle
|
||||||
@@ -663,12 +718,13 @@ class wxCalendar(wxWindow):
|
|||||||
def DrawRect(self, key, color = 'BLACK', width = 0):
|
def DrawRect(self, key, color = 'BLACK', width = 0):
|
||||||
if key == None:
|
if key == None:
|
||||||
return
|
return
|
||||||
DC = wxClientDC(self)
|
|
||||||
|
DC = wx.ClientDC(self)
|
||||||
DC.BeginDrawing()
|
DC.BeginDrawing()
|
||||||
|
|
||||||
brush = wxBrush(wxColour(0, 0xFF, 0x80), wxTRANSPARENT)
|
brush = wx.Brush(wx.Colour(0, 0xFF, 0x80), wx.TRANSPARENT)
|
||||||
DC.SetBrush(brush)
|
DC.SetBrush(brush)
|
||||||
DC.SetPen(wxPen(wxNamedColour(color), width))
|
DC.SetPen(wx.Pen(wx.NamedColour(color), width))
|
||||||
|
|
||||||
rect = self.rg[key]
|
rect = self.rg[key]
|
||||||
DC.DrawRectangle((rect.x, rect.y), (rect.width+1, rect.height+1))
|
DC.DrawRectangle((rect.x, rect.y), (rect.width+1, rect.height+1))
|
||||||
@@ -684,6 +740,7 @@ class wxCalendar(wxWindow):
|
|||||||
def SelectDay(self, key):
|
def SelectDay(self, key):
|
||||||
sel_size = 1
|
sel_size = 1
|
||||||
self.DrawRect(self.sel_key, self.back_color, sel_size) # clear large selection
|
self.DrawRect(self.sel_key, self.back_color, sel_size) # clear large selection
|
||||||
|
|
||||||
if self.hide_grid is False:
|
if self.hide_grid is False:
|
||||||
self.DrawRect(self.sel_key, self.grid_color)
|
self.DrawRect(self.sel_key, self.grid_color)
|
||||||
|
|
||||||
@@ -694,12 +751,13 @@ class wxCalendar(wxWindow):
|
|||||||
def ClearDsp(self):
|
def ClearDsp(self):
|
||||||
self.Clear()
|
self.Clear()
|
||||||
|
|
||||||
class CalenDlg(wxDialog):
|
class CalenDlg(wx.Dialog):
|
||||||
def __init__(self, parent, month=None, day = None, year=None):
|
def __init__(self, parent, month=None, day = None, year=None):
|
||||||
wxDialog.__init__(self, parent, -1, "Event Calendar", wxDefaultPosition, wxSize(280, 360))
|
wx.Dialog.__init__(self, parent, -1, "Event Calendar", wx.DefaultPosition, (280, 360))
|
||||||
|
|
||||||
# set the calendar and attributes
|
# set the calendar and attributes
|
||||||
self.calend = wxCalendar(self, -1, wxPoint(20, 60), wxSize(240, 200))
|
self.calend = wxCalendar(self, -1, (20, 60), (240, 200))
|
||||||
|
|
||||||
if month == None:
|
if month == None:
|
||||||
self.calend.SetCurrentDay()
|
self.calend.SetCurrentDay()
|
||||||
start_month = self.calend.GetMonth()
|
start_month = self.calend.GetMonth()
|
||||||
@@ -716,49 +774,43 @@ class CalenDlg(wxDialog):
|
|||||||
monthlist = GetMonthList()
|
monthlist = GetMonthList()
|
||||||
|
|
||||||
# select the month
|
# select the month
|
||||||
mID = wxNewId()
|
self.date = wx.ComboBox(self, -1, Month[start_month], (20, 20), (90, -1),
|
||||||
self.date = wxComboBox(self, mID, Month[start_month], wxPoint(20, 20), wxSize(90, -1), monthlist, wxCB_DROPDOWN)
|
monthlist, wx.CB_DROPDOWN)
|
||||||
EVT_COMBOBOX(self, mID, self.EvtComboBox)
|
self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, self.date)
|
||||||
|
|
||||||
# alternate spin button to control the month
|
# alternate spin button to control the month
|
||||||
mID = wxNewId()
|
|
||||||
h = self.date.GetSize().height
|
h = self.date.GetSize().height
|
||||||
self.m_spin = wxSpinButton(self, mID, wxPoint(130, 20), wxSize(h*2, h), wxSP_VERTICAL)
|
self.m_spin = wx.SpinButton(self, -1, (130, 20), (h*2, h), wx.SP_VERTICAL)
|
||||||
self.m_spin.SetRange(1, 12)
|
self.m_spin.SetRange(1, 12)
|
||||||
self.m_spin.SetValue(start_month)
|
self.m_spin.SetValue(start_month)
|
||||||
|
self.Bind(wx.EVT_SPIN, self.OnMonthSpin, self.m_spin)
|
||||||
EVT_SPIN(self, mID, self.OnMonthSpin)
|
|
||||||
|
|
||||||
# spin button to control the year
|
# spin button to control the year
|
||||||
mID = wxNewId()
|
self.dtext = wx.TextCtrl(self, -1, str(start_year), (160, 20), (60, -1))
|
||||||
self.dtext = wxTextCtrl(self, -1, str(start_year), wxPoint(160, 20), wxSize(60, -1))
|
|
||||||
h = self.dtext.GetSize().height
|
h = self.dtext.GetSize().height
|
||||||
|
|
||||||
self.y_spin = wxSpinButton(self, mID, wxPoint(220, 20), wxSize(h*2, h), wxSP_VERTICAL)
|
self.y_spin = wx.SpinButton(self, -1, (220, 20), (h*2, h), wx.SP_VERTICAL)
|
||||||
self.y_spin.SetRange(1980, 2010)
|
self.y_spin.SetRange(1980, 2010)
|
||||||
self.y_spin.SetValue(start_year)
|
self.y_spin.SetValue(start_year)
|
||||||
|
|
||||||
EVT_SPIN(self, mID, self.OnYrSpin)
|
self.Bind(wx.EVT_SPIN, self.OnYrSpin, self.y_spin)
|
||||||
|
self.Bind(EVT_CALENDAR, self.MouseClick, self.calend)
|
||||||
self.Connect(self.calend.GetId(), -1, 2100, self.MouseClick)
|
|
||||||
|
|
||||||
x_pos = 50
|
x_pos = 50
|
||||||
y_pos = 280
|
y_pos = 280
|
||||||
but_size = wxSize(60, 25)
|
but_size = (60, 25)
|
||||||
|
|
||||||
mID = wxNewId()
|
btn = wx.Button(self, -1, ' Ok ', (x_pos, y_pos), but_size)
|
||||||
wxButton(self, mID, ' Ok ', wxPoint(x_pos, y_pos), but_size)
|
self.Bind(wx.EVT_BUTTON, self.OnOk, btn)
|
||||||
EVT_BUTTON(self, mID, self.OnOk)
|
|
||||||
|
|
||||||
mID = wxNewId()
|
btn = wx.Button(self, mID, ' Close ', (x_pos + 120, y_pos), but_size)
|
||||||
wxButton(self, mID, ' Close ', wxPoint(x_pos + 120, y_pos), but_size)
|
self.Bind(wx.EVT_BUTTON, self.OnCancel, btn)
|
||||||
EVT_BUTTON(self, mID, self.OnCancel)
|
|
||||||
|
|
||||||
def OnOk(self, event):
|
def OnOk(self, event):
|
||||||
self.EndModal(wxID_OK)
|
self.EndModal(wx.ID_OK)
|
||||||
|
|
||||||
def OnCancel(self, event):
|
def OnCancel(self, event):
|
||||||
self.EndModal(wxID_CANCEL)
|
self.EndModal(wx.ID_CANCEL)
|
||||||
|
|
||||||
# log the mouse clicks
|
# log the mouse clicks
|
||||||
def MouseClick(self, evt):
|
def MouseClick(self, evt):
|
||||||
@@ -766,7 +818,7 @@ class CalenDlg(wxDialog):
|
|||||||
self.result = [evt.click, str(evt.day), Month[evt.month], str(evt.year)] # result click type and date
|
self.result = [evt.click, str(evt.day), Month[evt.month], str(evt.year)] # result click type and date
|
||||||
|
|
||||||
if evt.click == 'DLEFT':
|
if evt.click == 'DLEFT':
|
||||||
self.EndModal(wxID_OK)
|
self.EndModal(wx.ID_OK)
|
||||||
|
|
||||||
# month and year spin selection routines
|
# month and year spin selection routines
|
||||||
def OnMonthSpin(self, event):
|
def OnMonthSpin(self, event):
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
#
|
||||||
|
|
||||||
from pycolourchooser import *
|
from pycolourchooser import *
|
||||||
|
|
||||||
# For the American in you
|
# For the American in you
|
||||||
|
|||||||
@@ -12,9 +12,14 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from wxPython.wx import *
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
#
|
||||||
|
|
||||||
class BitmapBuffer(wxMemoryDC):
|
import wx
|
||||||
|
|
||||||
|
class BitmapBuffer(wx.MemoryDC):
|
||||||
"""A screen buffer class.
|
"""A screen buffer class.
|
||||||
|
|
||||||
This class implements a screen output buffer. Data is meant to
|
This class implements a screen output buffer. Data is meant to
|
||||||
@@ -23,27 +28,27 @@ class BitmapBuffer(wxMemoryDC):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, width, height, colour):
|
def __init__(self, width, height, colour):
|
||||||
"""Initialize the empty buffer object."""
|
"""Initialize the empty buffer object."""
|
||||||
wxMemoryDC.__init__(self)
|
wx.MemoryDC.__init__(self)
|
||||||
|
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
self.colour = colour
|
self.colour = colour
|
||||||
|
|
||||||
self.bitmap = wxEmptyBitmap(self.width, self.height)
|
self.bitmap = wx.EmptyBitmap(self.width, self.height)
|
||||||
self.SelectObject(self.bitmap)
|
self.SelectObject(self.bitmap)
|
||||||
|
|
||||||
# Initialize the buffer to the background colour
|
# Initialize the buffer to the background colour
|
||||||
self.SetBackground(wxBrush(self.colour, wxSOLID))
|
self.SetBackground(wx.Brush(self.colour, wx.SOLID))
|
||||||
self.Clear()
|
self.Clear()
|
||||||
|
|
||||||
# Make each logical unit of the buffer equal to 1 pixel
|
# Make each logical unit of the buffer equal to 1 pixel
|
||||||
self.SetMapMode(wxMM_TEXT)
|
self.SetMapMode(wx.MM_TEXT)
|
||||||
|
|
||||||
def GetBitmap(self):
|
def GetBitmap(self):
|
||||||
"""Returns the internal bitmap for direct drawing."""
|
"""Returns the internal bitmap for direct drawing."""
|
||||||
return self.bitmap
|
return self.bitmap
|
||||||
|
|
||||||
class Canvas(wxWindow):
|
class Canvas(wx.Window):
|
||||||
"""A canvas class for arbitrary drawing.
|
"""A canvas class for arbitrary drawing.
|
||||||
|
|
||||||
The Canvas class implements a window that allows for drawing
|
The Canvas class implements a window that allows for drawing
|
||||||
@@ -55,24 +60,24 @@ class Canvas(wxWindow):
|
|||||||
are also provided.
|
are also provided.
|
||||||
"""
|
"""
|
||||||
def __init__(self, parent, id,
|
def __init__(self, parent, id,
|
||||||
pos=wxDefaultPosition,
|
pos=wx.DefaultPosition,
|
||||||
size=wxDefaultSize,
|
size=wx.DefaultSize,
|
||||||
style=wxSIMPLE_BORDER):
|
style=wx.SIMPLE_BORDER):
|
||||||
"""Creates a canvas instance and initializes the off-screen
|
"""Creates a canvas instance and initializes the off-screen
|
||||||
buffer. Also sets the handler for rendering the canvas
|
buffer. Also sets the handler for rendering the canvas
|
||||||
automatically via size and paint calls from the windowing
|
automatically via size and paint calls from the windowing
|
||||||
system."""
|
system."""
|
||||||
wxWindow.__init__(self, parent, id, pos, size, style)
|
wx.Window.__init__(self, parent, id, pos, size, style)
|
||||||
|
|
||||||
# Perform an intial sizing
|
# Perform an intial sizing
|
||||||
self.ReDraw()
|
self.ReDraw()
|
||||||
|
|
||||||
# Register event handlers
|
# Register event handlers
|
||||||
EVT_SIZE(self, self.onSize)
|
self.Bind(wx.EVT_SIZE, self.onSize)
|
||||||
EVT_PAINT(self, self.onPaint)
|
self.Bind(wx.EVT_PAINT, self.onPaint)
|
||||||
|
|
||||||
def MakeNewBuffer(self):
|
def MakeNewBuffer(self):
|
||||||
size = self.GetSizeTuple()
|
size = self.GetSize()
|
||||||
self.buffer = BitmapBuffer(size[0], size[1],
|
self.buffer = BitmapBuffer(size[0], size[1],
|
||||||
self.GetBackgroundColour())
|
self.GetBackgroundColour())
|
||||||
|
|
||||||
@@ -91,12 +96,12 @@ class Canvas(wxWindow):
|
|||||||
|
|
||||||
def Refresh(self):
|
def Refresh(self):
|
||||||
"""Re-draws the buffer contents on-screen."""
|
"""Re-draws the buffer contents on-screen."""
|
||||||
dc = wxClientDC(self)
|
dc = wx.ClientDC(self)
|
||||||
self.Blit(dc)
|
self.Blit(dc)
|
||||||
|
|
||||||
def onPaint(self, event):
|
def onPaint(self, event):
|
||||||
"""Renders the off-screen buffer on-screen."""
|
"""Renders the off-screen buffer on-screen."""
|
||||||
dc = wxPaintDC(self)
|
dc = wx.PaintDC(self)
|
||||||
self.Blit(dc)
|
self.Blit(dc)
|
||||||
|
|
||||||
def Blit(self, dc):
|
def Blit(self, dc):
|
||||||
@@ -109,7 +114,7 @@ class Canvas(wxWindow):
|
|||||||
def GetBoundingRect(self):
|
def GetBoundingRect(self):
|
||||||
"""Returns a tuple that contains the co-ordinates of the
|
"""Returns a tuple that contains the co-ordinates of the
|
||||||
top-left and bottom-right corners of the canvas."""
|
top-left and bottom-right corners of the canvas."""
|
||||||
x, y = self.GetPositionTuple()
|
x, y = self.GetPosition()
|
||||||
w, h = self.GetSize()
|
w, h = self.GetSize()
|
||||||
return(x, y + h, x + w, y)
|
return(x, y + h, x + w, y)
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,14 @@ This program is distributed in the hope that it will be useful,
|
|||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
"""
|
"""
|
||||||
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
#
|
||||||
|
|
||||||
from wxPython.wx import *
|
import wx
|
||||||
|
|
||||||
class PyColourBox(wxPanel):
|
class PyColourBox(wx.Panel):
|
||||||
"""A Colour Selection Box
|
"""A Colour Selection Box
|
||||||
|
|
||||||
The Colour selection box implements button like behavior but contains
|
The Colour selection box implements button like behavior but contains
|
||||||
@@ -24,13 +28,12 @@ class PyColourBox(wxPanel):
|
|||||||
def __init__(self, parent, id, colour=(0, 0, 0), size=(25, 20)):
|
def __init__(self, parent, id, colour=(0, 0, 0), size=(25, 20)):
|
||||||
"""Creates a new colour box instance and initializes the colour
|
"""Creates a new colour box instance and initializes the colour
|
||||||
content."""
|
content."""
|
||||||
wxPanel.__init__(self, parent, id,
|
wx.Panel.__init__(self, parent, id, size=size)
|
||||||
size=wxSize(size[0], size[1]))
|
|
||||||
|
|
||||||
self.colour_box = wxPanel(self, -1, style=wxSIMPLE_BORDER)
|
self.colour_box = wx.Panel(self, -1, style=wx.SIMPLE_BORDER)
|
||||||
|
|
||||||
sizer = wxGridSizer(1, 1)
|
sizer = wx.GridSizer(1, 1)
|
||||||
sizer.Add(self.colour_box, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL)
|
sizer.Add(self.colour_box, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL)
|
||||||
sizer.SetItemMinSize(self.colour_box, size[0] - 5, size[1] - 5)
|
sizer.SetItemMinSize(self.colour_box, size[0] - 5, size[1] - 5)
|
||||||
self.SetAutoLayout(True)
|
self.SetAutoLayout(True)
|
||||||
self.SetSizer(sizer)
|
self.SetSizer(sizer)
|
||||||
@@ -57,10 +60,10 @@ class PyColourBox(wxPanel):
|
|||||||
def SetColourTuple(self, colour):
|
def SetColourTuple(self, colour):
|
||||||
"""Sets the box's current couple to the given tuple."""
|
"""Sets the box's current couple to the given tuple."""
|
||||||
self.colour = colour
|
self.colour = colour
|
||||||
self.colour_box.SetBackgroundColour(wxColour(*self.colour))
|
self.colour_box.SetBackgroundColour(wx.Colour(*self.colour))
|
||||||
|
|
||||||
def Update(self):
|
def Update(self):
|
||||||
wxPanel.Update(self)
|
wx.Panel.Update(self)
|
||||||
self.colour_box.Update()
|
self.colour_box.Update()
|
||||||
|
|
||||||
def SetHighlight(self, val):
|
def SetHighlight(self, val):
|
||||||
@@ -72,7 +75,7 @@ class PyColourBox(wxPanel):
|
|||||||
red =(self.real_bg.Red() - 45) % 255
|
red =(self.real_bg.Red() - 45) % 255
|
||||||
green =(self.real_bg.Green() - 45) % 255
|
green =(self.real_bg.Green() - 45) % 255
|
||||||
blue =(self.real_bg.Blue() - 45) % 255
|
blue =(self.real_bg.Blue() - 45) % 255
|
||||||
new_colour = wxColour(red, green, blue)
|
new_colour = wx.Colour(red, green, blue)
|
||||||
self.SetBackgroundColour(new_colour)
|
self.SetBackgroundColour(new_colour)
|
||||||
else:
|
else:
|
||||||
self.SetBackgroundColour(self.real_bg)
|
self.SetBackgroundColour(self.real_bg)
|
||||||
|
|||||||
@@ -12,14 +12,22 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
#
|
||||||
|
|
||||||
|
import wx
|
||||||
|
|
||||||
import pycolourbox
|
import pycolourbox
|
||||||
import pypalette
|
import pypalette
|
||||||
import pycolourslider
|
import pycolourslider
|
||||||
import colorsys
|
import colorsys
|
||||||
from intl import _
|
import intl
|
||||||
from wxPython.wx import *
|
|
||||||
|
|
||||||
class wxPyColourChooser(wxPanel):
|
from intl import _ # _
|
||||||
|
|
||||||
|
class wxPyColourChooser(wx.Panel):
|
||||||
"""A Pure-Python implementation of the colour chooser dialog.
|
"""A Pure-Python implementation of the colour chooser dialog.
|
||||||
|
|
||||||
The PyColourChooser is a pure python implementation of the colour
|
The PyColourChooser is a pure python implementation of the colour
|
||||||
@@ -88,140 +96,147 @@ class wxPyColourChooser(wxPanel):
|
|||||||
# Generate the custom colours. These colours are shared across
|
# Generate the custom colours. These colours are shared across
|
||||||
# all instances of the colour chooser
|
# all instances of the colour chooser
|
||||||
NO_CUSTOM_COLOURS = 16
|
NO_CUSTOM_COLOURS = 16
|
||||||
custom_colours = [ (wxColour(255, 255, 255),
|
custom_colours = [ (wx.Colour(255, 255, 255),
|
||||||
pycolourslider.PyColourSlider.HEIGHT / 2)
|
pycolourslider.PyColourSlider.HEIGHT / 2)
|
||||||
] * NO_CUSTOM_COLOURS
|
] * NO_CUSTOM_COLOURS
|
||||||
last_custom = 0
|
last_custom = 0
|
||||||
|
|
||||||
idADD_CUSTOM = wxNewId()
|
idADD_CUSTOM = wx.NewId()
|
||||||
idSCROLL = wxNewId()
|
idSCROLL = wx.NewId()
|
||||||
|
|
||||||
def __init__(self, parent, id):
|
def __init__(self, parent, id):
|
||||||
"""Creates an instance of the colour chooser. Note that it is best to
|
"""Creates an instance of the colour chooser. Note that it is best to
|
||||||
accept the given size of the colour chooser as it is currently not
|
accept the given size of the colour chooser as it is currently not
|
||||||
resizeable."""
|
resizeable."""
|
||||||
wxPanel.__init__(self, parent, id)
|
wx.Panel.__init__(self, parent, id)
|
||||||
|
|
||||||
self.basic_label = wxStaticText(self, -1, _("Basic Colours:"))
|
self.basic_label = wx.StaticText(self, -1, _("Basic Colours:"))
|
||||||
self.custom_label = wxStaticText(self, -1, _("Custom Colours:"))
|
self.custom_label = wx.StaticText(self, -1, _("Custom Colours:"))
|
||||||
self.add_button = wxButton(self, self.idADD_CUSTOM, _("Add to Custom Colours"))
|
self.add_button = wx.Button(self, self.idADD_CUSTOM, _("Add to Custom Colours"))
|
||||||
|
|
||||||
EVT_BUTTON(self, self.idADD_CUSTOM, self.onAddCustom)
|
self.Bind(wx.EVT_BUTTON, self.onAddCustom, self.add_button)
|
||||||
|
|
||||||
# Since we're going to be constructing widgets that require some serious
|
# Since we're going to be constructing widgets that require some serious
|
||||||
# computation, let's process any events (like redraws) right now
|
# computation, let's process any events (like redraws) right now
|
||||||
wxYield()
|
wx.Yield()
|
||||||
|
|
||||||
# Create the basic colours palette
|
# Create the basic colours palette
|
||||||
self.colour_boxs = [ ]
|
self.colour_boxs = [ ]
|
||||||
colour_grid = wxGridSizer(6, 8)
|
colour_grid = wx.GridSizer(6, 8)
|
||||||
for name in self.colour_names:
|
for name in self.colour_names:
|
||||||
new_id = wxNewId()
|
new_id = wx.NewId()
|
||||||
box = pycolourbox.PyColourBox(self, new_id)
|
box = pycolourbox.PyColourBox(self, new_id)
|
||||||
EVT_LEFT_DOWN(box.GetColourBox(), lambda x, b=box: self.onBasicClick(x, b))
|
|
||||||
|
box.GetColourBox().Bind(wx.EVT_LEFT_DOWN, lambda x, b=box: self.onBasicClick(x, b))
|
||||||
|
|
||||||
self.colour_boxs.append(box)
|
self.colour_boxs.append(box)
|
||||||
colour_grid.Add(box, 0, wxEXPAND)
|
colour_grid.Add(box, 0, wx.EXPAND)
|
||||||
|
|
||||||
# Create the custom colours palette
|
# Create the custom colours palette
|
||||||
self.custom_boxs = [ ]
|
self.custom_boxs = [ ]
|
||||||
custom_grid = wxGridSizer(2, 8)
|
custom_grid = wx.GridSizer(2, 8)
|
||||||
for wxcolour, slidepos in self.custom_colours:
|
for wxcolour, slidepos in self.custom_colours:
|
||||||
new_id = wxNewId()
|
new_id = wx.NewId()
|
||||||
custom = pycolourbox.PyColourBox(self, new_id)
|
custom = pycolourbox.PyColourBox(self, new_id)
|
||||||
EVT_LEFT_DOWN(custom.GetColourBox(), lambda x, b=custom: self.onCustomClick(x, b))
|
|
||||||
|
custom.GetColourBox().Bind(wx.EVT_LEFT_DOWN, lambda x, b=custom: self.onCustomClick(x, b))
|
||||||
|
|
||||||
custom.SetColour(wxcolour)
|
custom.SetColour(wxcolour)
|
||||||
custom_grid.Add(custom, 0, wxEXPAND)
|
custom_grid.Add(custom, 0, wx.EXPAND)
|
||||||
self.custom_boxs.append(custom)
|
self.custom_boxs.append(custom)
|
||||||
|
|
||||||
csizer = wxBoxSizer(wxVERTICAL)
|
csizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
csizer.Add((1, 25))
|
csizer.Add((1, 25))
|
||||||
csizer.Add(self.basic_label, 0, wxEXPAND)
|
csizer.Add(self.basic_label, 0, wx.EXPAND)
|
||||||
csizer.Add((1, 5))
|
csizer.Add((1, 5))
|
||||||
csizer.Add(colour_grid, 0, wxEXPAND)
|
csizer.Add(colour_grid, 0, wx.EXPAND)
|
||||||
csizer.Add((1, 25))
|
csizer.Add((1, 25))
|
||||||
csizer.Add(self.custom_label, 0, wxEXPAND)
|
csizer.Add(self.custom_label, 0, wx.EXPAND)
|
||||||
csizer.Add((1, 5))
|
csizer.Add((1, 5))
|
||||||
csizer.Add(custom_grid, 0, wxEXPAND)
|
csizer.Add(custom_grid, 0, wx.EXPAND)
|
||||||
csizer.Add((1, 5))
|
csizer.Add((1, 5))
|
||||||
csizer.Add(self.add_button, 0, wxEXPAND)
|
csizer.Add(self.add_button, 0, wx.EXPAND)
|
||||||
|
|
||||||
self.palette = pypalette.PyPalette(self, -1)
|
self.palette = pypalette.PyPalette(self, -1)
|
||||||
self.colour_slider = pycolourslider.PyColourSlider(self, -1)
|
self.colour_slider = pycolourslider.PyColourSlider(self, -1)
|
||||||
self.slider = wxSlider(self, self.idSCROLL, 86, 0, self.colour_slider.HEIGHT - 1,
|
self.slider = wx.Slider(
|
||||||
style=wxSL_VERTICAL, size=wxSize(15, self.colour_slider.HEIGHT))
|
self, self.idSCROLL, 86, 0, self.colour_slider.HEIGHT - 1,
|
||||||
EVT_COMMAND_SCROLL(self, self.idSCROLL, self.onScroll)
|
style=wx.SL_VERTICAL, size=(15, self.colour_slider.HEIGHT)
|
||||||
psizer = wxBoxSizer(wxHORIZONTAL)
|
)
|
||||||
|
|
||||||
|
self.Bind(wx.EVT_COMMAND_SCROLL, self.onScroll, self.slider)
|
||||||
|
psizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
psizer.Add(self.palette, 0, 0)
|
psizer.Add(self.palette, 0, 0)
|
||||||
psizer.Add((10, 1))
|
psizer.Add((10, 1))
|
||||||
psizer.Add(self.colour_slider, 0, wxALIGN_CENTER_VERTICAL)
|
psizer.Add(self.colour_slider, 0, wx.ALIGN_CENTER_VERTICAL)
|
||||||
psizer.Add(self.slider, 0, wxALIGN_CENTER_VERTICAL)
|
psizer.Add(self.slider, 0, wx.ALIGN_CENTER_VERTICAL)
|
||||||
|
|
||||||
# Register mouse events for dragging across the palette
|
# Register mouse events for dragging across the palette
|
||||||
EVT_LEFT_DOWN(self.palette, self.onPaletteDown)
|
self.palette.Bind(wx.EVT_LEFT_DOWN, self.onPaletteDown)
|
||||||
EVT_LEFT_UP(self.palette, self.onPaletteUp)
|
self.palette.Bind(wx.EVT_LEFT_UP, self.onPaletteUp)
|
||||||
EVT_MOTION(self.palette, self.onPaletteMotion)
|
self.palette.Bind(wx.EVT_MOTION, self.onPaletteMotion)
|
||||||
self.mouse_down = False
|
self.mouse_down = False
|
||||||
|
|
||||||
self.solid = pycolourbox.PyColourBox(self, -1, size=wxSize(75, 50))
|
self.solid = pycolourbox.PyColourBox(self, -1, size=(75, 50))
|
||||||
slabel = wxStaticText(self, -1, _("Solid Colour"))
|
slabel = wx.StaticText(self, -1, _("Solid Colour"))
|
||||||
ssizer = wxBoxSizer(wxVERTICAL)
|
ssizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
ssizer.Add(self.solid, 0, 0)
|
ssizer.Add(self.solid, 0, 0)
|
||||||
ssizer.Add((1, 2))
|
ssizer.Add((1, 2))
|
||||||
ssizer.Add(slabel, 0, wxALIGN_CENTER_HORIZONTAL)
|
ssizer.Add(slabel, 0, wx.ALIGN_CENTER_HORIZONTAL)
|
||||||
|
|
||||||
hlabel = wxStaticText(self, -1, _("H:"))
|
hlabel = wx.StaticText(self, -1, _("H:"))
|
||||||
self.hentry = wxTextCtrl(self, -1)
|
self.hentry = wx.TextCtrl(self, -1)
|
||||||
self.hentry.SetSize((40, -1))
|
self.hentry.SetSize((40, -1))
|
||||||
slabel = wxStaticText(self, -1, _("S:"))
|
slabel = wx.StaticText(self, -1, _("S:"))
|
||||||
self.sentry = wxTextCtrl(self, -1)
|
self.sentry = wx.TextCtrl(self, -1)
|
||||||
self.sentry.SetSize((40, -1))
|
self.sentry.SetSize((40, -1))
|
||||||
vlabel = wxStaticText(self, -1, _("V:"))
|
vlabel = wx.StaticText(self, -1, _("V:"))
|
||||||
self.ventry = wxTextCtrl(self, -1)
|
self.ventry = wx.TextCtrl(self, -1)
|
||||||
self.ventry.SetSize((40, -1))
|
self.ventry.SetSize((40, -1))
|
||||||
hsvgrid = wxFlexGridSizer(1, 6, 2, 2)
|
hsvgrid = wx.FlexGridSizer(1, 6, 2, 2)
|
||||||
hsvgrid.AddMany ([
|
hsvgrid.AddMany ([
|
||||||
(hlabel, 0, wxALIGN_CENTER_VERTICAL), (self.hentry, 0, 0),
|
(hlabel, 0, wx.ALIGN_CENTER_VERTICAL), (self.hentry, 0, 0),
|
||||||
(slabel, 0, wxALIGN_CENTER_VERTICAL), (self.sentry, 0, 0),
|
(slabel, 0, wx.ALIGN_CENTER_VERTICAL), (self.sentry, 0, 0),
|
||||||
(vlabel, 0, wxALIGN_CENTER_VERTICAL), (self.ventry, 0, 0),
|
(vlabel, 0, wx.ALIGN_CENTER_VERTICAL), (self.ventry, 0, 0),
|
||||||
])
|
])
|
||||||
|
|
||||||
rlabel = wxStaticText(self, -1, _("R:"))
|
rlabel = wx.StaticText(self, -1, _("R:"))
|
||||||
self.rentry = wxTextCtrl(self, -1)
|
self.rentry = wx.TextCtrl(self, -1)
|
||||||
self.rentry.SetSize((40, -1))
|
self.rentry.SetSize((40, -1))
|
||||||
glabel = wxStaticText(self, -1, _("G:"))
|
glabel = wx.StaticText(self, -1, _("G:"))
|
||||||
self.gentry = wxTextCtrl(self, -1)
|
self.gentry = wx.TextCtrl(self, -1)
|
||||||
self.gentry.SetSize((40, -1))
|
self.gentry.SetSize((40, -1))
|
||||||
blabel = wxStaticText(self, -1, _("B:"))
|
blabel = wx.StaticText(self, -1, _("B:"))
|
||||||
self.bentry = wxTextCtrl(self, -1)
|
self.bentry = wx.TextCtrl(self, -1)
|
||||||
self.bentry.SetSize((40, -1))
|
self.bentry.SetSize((40, -1))
|
||||||
lgrid = wxFlexGridSizer(1, 6, 2, 2)
|
lgrid = wx.FlexGridSizer(1, 6, 2, 2)
|
||||||
lgrid.AddMany([
|
lgrid.AddMany([
|
||||||
(rlabel, 0, wxALIGN_CENTER_VERTICAL), (self.rentry, 0, 0),
|
(rlabel, 0, wx.ALIGN_CENTER_VERTICAL), (self.rentry, 0, 0),
|
||||||
(glabel, 0, wxALIGN_CENTER_VERTICAL), (self.gentry, 0, 0),
|
(glabel, 0, wx.ALIGN_CENTER_VERTICAL), (self.gentry, 0, 0),
|
||||||
(blabel, 0, wxALIGN_CENTER_VERTICAL), (self.bentry, 0, 0),
|
(blabel, 0, wx.ALIGN_CENTER_VERTICAL), (self.bentry, 0, 0),
|
||||||
])
|
])
|
||||||
|
|
||||||
gsizer = wxGridSizer(2, 1)
|
gsizer = wx.GridSizer(2, 1)
|
||||||
gsizer.SetVGap (10)
|
gsizer.SetVGap (10)
|
||||||
gsizer.SetHGap (2)
|
gsizer.SetHGap (2)
|
||||||
gsizer.Add(hsvgrid, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL)
|
gsizer.Add(hsvgrid, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL)
|
||||||
gsizer.Add(lgrid, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL)
|
gsizer.Add(lgrid, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL)
|
||||||
|
|
||||||
hsizer = wxBoxSizer(wxHORIZONTAL)
|
hsizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
hsizer.Add(ssizer, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL)
|
hsizer.Add(ssizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL)
|
||||||
hsizer.Add(gsizer, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL)
|
hsizer.Add(gsizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL)
|
||||||
|
|
||||||
vsizer = wxBoxSizer(wxVERTICAL)
|
vsizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
vsizer.Add((1, 5))
|
vsizer.Add((1, 5))
|
||||||
vsizer.Add(psizer, 0, 0)
|
vsizer.Add(psizer, 0, 0)
|
||||||
vsizer.Add((1, 15))
|
vsizer.Add((1, 15))
|
||||||
vsizer.Add(hsizer, 0, wxEXPAND)
|
vsizer.Add(hsizer, 0, wx.EXPAND)
|
||||||
|
|
||||||
sizer = wxBoxSizer(wxHORIZONTAL)
|
sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
sizer.Add((5, 1))
|
sizer.Add((5, 1))
|
||||||
sizer.Add(csizer, 0, wxEXPAND)
|
sizer.Add(csizer, 0, wx.EXPAND)
|
||||||
sizer.Add((10, 1))
|
sizer.Add((10, 1))
|
||||||
sizer.Add(vsizer, 0, wxEXPAND)
|
sizer.Add(vsizer, 0, wx.EXPAND)
|
||||||
self.SetAutoLayout(True)
|
self.SetAutoLayout(True)
|
||||||
self.SetSizer(sizer)
|
self.SetSizer(sizer)
|
||||||
sizer.Fit(self)
|
sizer.Fit(self)
|
||||||
@@ -232,7 +247,7 @@ class wxPyColourChooser(wxPanel):
|
|||||||
def InitColours(self):
|
def InitColours(self):
|
||||||
"""Initializes the pre-set palette colours."""
|
"""Initializes the pre-set palette colours."""
|
||||||
for i in range(len(self.colour_names)):
|
for i in range(len(self.colour_names)):
|
||||||
colour = wxTheColourDatabase.FindColour(self.colour_names[i])
|
colour = wx.TheColourDatabase.FindColour(self.colour_names[i])
|
||||||
self.colour_boxs[i].SetColourTuple((colour.Red(),
|
self.colour_boxs[i].SetColourTuple((colour.Red(),
|
||||||
colour.Green(),
|
colour.Green(),
|
||||||
colour.Blue()))
|
colour.Blue()))
|
||||||
@@ -364,12 +379,12 @@ class wxPyColourChooser(wxPanel):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Simple test display."""
|
"""Simple test display."""
|
||||||
class App(wxApp):
|
class App(wx.App):
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
frame = wxFrame(NULL, -1, 'PyColourChooser Test')
|
frame = wx.Frame(None, -1, 'PyColourChooser Test')
|
||||||
|
|
||||||
chooser = wxPyColourChooser(frame, -1)
|
chooser = wxPyColourChooser(frame, -1)
|
||||||
sizer = wxBoxSizer(wxVERTICAL)
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
sizer.Add(chooser, 0, 0)
|
sizer.Add(chooser, 0, 0)
|
||||||
frame.SetAutoLayout(True)
|
frame.SetAutoLayout(True)
|
||||||
frame.SetSizer(sizer)
|
frame.SetSizer(sizer)
|
||||||
@@ -378,7 +393,7 @@ def main():
|
|||||||
frame.Show(True)
|
frame.Show(True)
|
||||||
self.SetTopWindow(frame)
|
self.SetTopWindow(frame)
|
||||||
return True
|
return True
|
||||||
app = App()
|
app = App(False)
|
||||||
app.MainLoop()
|
app.MainLoop()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -16,9 +16,15 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
#
|
||||||
|
|
||||||
|
import wx
|
||||||
|
|
||||||
import canvas
|
import canvas
|
||||||
import colorsys
|
import colorsys
|
||||||
from wxPython.wx import *
|
|
||||||
|
|
||||||
class PyColourSlider(canvas.Canvas):
|
class PyColourSlider(canvas.Canvas):
|
||||||
"""A Pure-Python Colour Slider
|
"""A Pure-Python Colour Slider
|
||||||
@@ -41,8 +47,7 @@ class PyColourSlider(canvas.Canvas):
|
|||||||
# drawing function
|
# drawing function
|
||||||
self.SetBaseColour(colour)
|
self.SetBaseColour(colour)
|
||||||
|
|
||||||
canvas.Canvas.__init__(self, parent, id,
|
canvas.Canvas.__init__(self, parent, id, size=(self.WIDTH, self.HEIGHT))
|
||||||
size=wxSize(self.WIDTH, self.HEIGHT))
|
|
||||||
|
|
||||||
def SetBaseColour(self, colour):
|
def SetBaseColour(self, colour):
|
||||||
"""Sets the base, or target colour, to use as the central colour
|
"""Sets the base, or target colour, to use as the central colour
|
||||||
@@ -76,7 +81,7 @@ class PyColourSlider(canvas.Canvas):
|
|||||||
vstep = 1.0 / self.HEIGHT
|
vstep = 1.0 / self.HEIGHT
|
||||||
for y_pos in range(0, self.HEIGHT):
|
for y_pos in range(0, self.HEIGHT):
|
||||||
r,g,b = [c * 255.0 for c in colorsys.hsv_to_rgb(h,s,v)]
|
r,g,b = [c * 255.0 for c in colorsys.hsv_to_rgb(h,s,v)]
|
||||||
colour = wxColour(int(r), int(g), int(b))
|
colour = wx.Colour(int(r), int(g), int(b))
|
||||||
self.buffer.SetPen(wxPen(colour, 1, wxSOLID))
|
self.buffer.SetPen(wx.Pen(colour, 1, wx.SOLID))
|
||||||
self.buffer.DrawRectangle((0, y_pos), (15, 1))
|
self.buffer.DrawRectangle((0, y_pos), (15, 1))
|
||||||
v = v - vstep
|
v = v - vstep
|
||||||
|
|||||||
@@ -15,11 +15,19 @@ This program is distributed in the hope that it will be useful,
|
|||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
"""
|
"""
|
||||||
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
#
|
||||||
|
|
||||||
|
import cStringIO
|
||||||
|
import zlib
|
||||||
|
|
||||||
|
import wx
|
||||||
|
|
||||||
import canvas
|
import canvas
|
||||||
import colorsys
|
import colorsys
|
||||||
import cStringIO, zlib
|
|
||||||
from wxPython.wx import *
|
|
||||||
|
|
||||||
# Bitmap functions generated from img2py
|
# Bitmap functions generated from img2py
|
||||||
def getData():
|
def getData():
|
||||||
@@ -128,11 +136,11 @@ L\x1a\xc5\x9c\x88U\xde\xc7\x9d\xd04\x04\x8en\x11\x8112\xbd\xf6J\x96wP\x06\
|
|||||||
\xc5\x8e\x1a\xd5\x84\x8b\x7f\x8f\x01\x0e6\x8e\xd6eV~W\xff\x01[x\x1b=' )
|
\xc5\x8e\x1a\xd5\x84\x8b\x7f\x8f\x01\x0e6\x8e\xd6eV~W\xff\x01[x\x1b=' )
|
||||||
|
|
||||||
def getBitmap():
|
def getBitmap():
|
||||||
return wxBitmapFromImage(getImage())
|
return wx.BitmapFromImage(getImage())
|
||||||
|
|
||||||
def getImage():
|
def getImage():
|
||||||
stream = cStringIO.StringIO(getData())
|
stream = cStringIO.StringIO(getData())
|
||||||
return wxImageFromStream(stream)
|
return wx.ImageFromStream(stream)
|
||||||
|
|
||||||
class PyPalette(canvas.Canvas):
|
class PyPalette(canvas.Canvas):
|
||||||
"""The Pure-Python Palette
|
"""The Pure-Python Palette
|
||||||
@@ -156,8 +164,9 @@ class PyPalette(canvas.Canvas):
|
|||||||
def __init__(self, parent, id):
|
def __init__(self, parent, id):
|
||||||
"""Creates a palette object."""
|
"""Creates a palette object."""
|
||||||
# Load the pre-generated palette XPM
|
# Load the pre-generated palette XPM
|
||||||
|
wx.InitAllImageHandlers()
|
||||||
self.palette = getBitmap ()
|
self.palette = getBitmap ()
|
||||||
canvas.Canvas.__init__ (self, parent, id, size=wxSize(200, 192))
|
canvas.Canvas.__init__ (self, parent, id, size=(200, 192))
|
||||||
|
|
||||||
def GetValue(self, x, y):
|
def GetValue(self, x, y):
|
||||||
"""Returns a colour value at a specific x, y coordinate pair. This
|
"""Returns a colour value at a specific x, y coordinate pair. This
|
||||||
@@ -173,9 +182,9 @@ class PyPalette(canvas.Canvas):
|
|||||||
def HighlightPoint(self, x, y):
|
def HighlightPoint(self, x, y):
|
||||||
"""Highlights an area of the palette with a little circle around
|
"""Highlights an area of the palette with a little circle around
|
||||||
the coordinate point"""
|
the coordinate point"""
|
||||||
colour = wxColour(0, 0, 0)
|
colour = wx.Colour(0, 0, 0)
|
||||||
self.buffer.SetPen(wxPen(colour, 1, wxSOLID))
|
self.buffer.SetPen(wx.Pen(colour, 1, wx.SOLID))
|
||||||
self.buffer.SetBrush(wxBrush(colour, wxTRANSPARENT))
|
self.buffer.SetBrush(wx.Brush(colour, wx.TRANSPARENT))
|
||||||
self.buffer.DrawCircle((x, y), 3)
|
self.buffer.DrawCircle((x, y), 3)
|
||||||
self.Refresh()
|
self.Refresh()
|
||||||
|
|
||||||
@@ -201,13 +210,13 @@ class PyPalette(canvas.Canvas):
|
|||||||
for x in range(0, width, self.HORIZONTAL_STEP):
|
for x in range(0, width, self.HORIZONTAL_STEP):
|
||||||
hue = float(x) / float(width)
|
hue = float(x) / float(width)
|
||||||
r,g,b = colorsys.hsv_to_rgb(hue, saturation, value)
|
r,g,b = colorsys.hsv_to_rgb(hue, saturation, value)
|
||||||
colour = wxColour(int(r * 255.0), int(g * 255.0), int(b * 255.0))
|
colour = wx.Colour(int(r * 255.0), int(g * 255.0), int(b * 255.0))
|
||||||
self.buffer.SetPen(wxPen(colour, 1, wxSOLID))
|
self.buffer.SetPen(wx.Pen(colour, 1, wx.SOLID))
|
||||||
self.buffer.SetBrush(wxBrush(colour, wxSOLID))
|
self.buffer.SetBrush(wx.Brush(colour, wx.SOLID))
|
||||||
self.buffer.DrawRectangle((x, y),
|
self.buffer.DrawRectangle((x, y),
|
||||||
(self.HORIZONTAL_STEP, self.vertical_step))
|
(self.HORIZONTAL_STEP, self.vertical_step))
|
||||||
|
|
||||||
# this code is now simpler (and works)
|
# this code is now simpler (and works)
|
||||||
bitmap = self.buffer.GetBitmap()
|
bitmap = self.buffer.GetBitmap()
|
||||||
image = wxImageFromBitmap(bitmap)
|
image = wx.ImageFromBitmap(bitmap)
|
||||||
image.SaveFile (file_name, wxBITMAP_TYPE_XPM)
|
image.SaveFile (file_name, wx.BITMAP_TYPE_XPM)
|
||||||
|
|||||||
@@ -664,7 +664,9 @@ def updateColourDB():
|
|||||||
import wx
|
import wx
|
||||||
assert wx.GetApp() is not None, "You must have a wx.App object before you can use the colour database."
|
assert wx.GetApp() is not None, "You must have a wx.App object before you can use the colour database."
|
||||||
cl = getColourInfoList()
|
cl = getColourInfoList()
|
||||||
|
|
||||||
for info in cl:
|
for info in cl:
|
||||||
wx.TheColourDatabase.Append(*info)
|
wx.TheColourDatabase.Append(*info)
|
||||||
|
|
||||||
|
_haveUpdated = True
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
from wxPython.wx import *
|
|
||||||
|
|
||||||
# creates a colour wxButton with selectable color
|
# creates a colour wxButton with selectable color
|
||||||
# button click provides a colour selection box
|
# button click provides a colour selection box
|
||||||
# button colour will change to new colour
|
# button colour will change to new colour
|
||||||
@@ -29,26 +27,35 @@ from wxPython.wx import *
|
|||||||
# Cliff Wells, 2002/02/07
|
# Cliff Wells, 2002/02/07
|
||||||
# - Added ColourSelect Event
|
# - Added ColourSelect Event
|
||||||
|
|
||||||
EVT_COMMAND_COLOURSELECT = wxNewId()
|
# 12/01/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Updated for 2.5 compatability.
|
||||||
|
#
|
||||||
|
|
||||||
class ColourSelectEvent(wxPyCommandEvent):
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
import wx
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxEVT_COMMAND_COLOURSELECT = wx.NewEventType()
|
||||||
|
|
||||||
|
class ColourSelectEvent(wx.PyCommandEvent):
|
||||||
def __init__(self, id, value):
|
def __init__(self, id, value):
|
||||||
wxPyCommandEvent.__init__(self, id = id)
|
wx.PyCommandEvent.__init__(self, id = id)
|
||||||
self.SetEventType(EVT_COMMAND_COLOURSELECT)
|
self.SetEventType(wxEVT_COMMAND_COLOURSELECT)
|
||||||
self.value = value
|
self.value = value
|
||||||
|
|
||||||
def GetValue(self):
|
def GetValue(self):
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
def EVT_COLOURSELECT(win, id, func):
|
EVT_COLOURSELECT = wx.PyEventBinder(wxEVT_COMMAND_COLOURSELECT, 1)
|
||||||
win.Connect(id, -1, EVT_COMMAND_COLOURSELECT, func)
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class ColourSelect(wx.BitmapButton):
|
||||||
|
def __init__(self, parent, id, label="", colour=wx.BLACK,
|
||||||
class ColourSelect(wxBitmapButton):
|
pos=wx.DefaultPosition, size=wx.DefaultSize,
|
||||||
def __init__(self, parent, id, label="", colour=wxBLACK,
|
|
||||||
pos=wxDefaultPosition, size=wxDefaultSize,
|
|
||||||
callback=None, style=0):
|
callback=None, style=0):
|
||||||
if label:
|
if label:
|
||||||
w, h = parent.GetTextExtent(label)
|
w, h = parent.GetTextExtent(label)
|
||||||
@@ -56,33 +63,32 @@ class ColourSelect(wxBitmapButton):
|
|||||||
h += 6
|
h += 6
|
||||||
else:
|
else:
|
||||||
w, h = 20, 20
|
w, h = 20, 20
|
||||||
wxBitmapButton.__init__(self, parent, id, wxEmptyBitmap(w,h),
|
wx.BitmapButton.__init__(self, parent, id, wx.EmptyBitmap(w,h),
|
||||||
pos=pos, size=size, style=style|wxBU_AUTODRAW)
|
pos=pos, size=size, style=style|wx.BU_AUTODRAW)
|
||||||
|
|
||||||
if type(colour) == type( () ):
|
if type(colour) == type( () ):
|
||||||
colour = wxColour(*colour)
|
colour = wx.Colour(*colour)
|
||||||
self.colour = colour
|
self.colour = colour
|
||||||
self.SetLabel(label)
|
self.SetLabel(label)
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
bmp = self.MakeBitmap()
|
bmp = self.MakeBitmap()
|
||||||
self.SetBitmap(bmp)
|
self.SetBitmap(bmp)
|
||||||
EVT_BUTTON(parent, self.GetId(), self.OnClick)
|
parent.Bind(wx.EVT_BUTTON, self.OnClick, self)
|
||||||
|
|
||||||
|
|
||||||
def GetColour(self):
|
def GetColour(self):
|
||||||
return self.colour
|
return self.colour
|
||||||
|
|
||||||
|
|
||||||
def GetValue(self):
|
def GetValue(self):
|
||||||
return self.colour
|
return self.colour
|
||||||
|
|
||||||
|
|
||||||
def SetValue(self, colour):
|
def SetValue(self, colour):
|
||||||
self.SetColour(colour)
|
self.SetColour(colour)
|
||||||
|
|
||||||
|
|
||||||
def SetColour(self, colour):
|
def SetColour(self, colour):
|
||||||
if type(colour) == type( () ):
|
if type(colour) == type( () ):
|
||||||
colour = wxColour(*colour)
|
colour = wxColour(*colour)
|
||||||
|
|
||||||
self.colour = colour
|
self.colour = colour
|
||||||
bmp = self.MakeBitmap()
|
bmp = self.MakeBitmap()
|
||||||
self.SetBitmap(bmp)
|
self.SetBitmap(bmp)
|
||||||
@@ -90,23 +96,24 @@ class ColourSelect(wxBitmapButton):
|
|||||||
|
|
||||||
def MakeBitmap(self):
|
def MakeBitmap(self):
|
||||||
bdr = 10
|
bdr = 10
|
||||||
sz = self.GetSize()
|
width, height = self.GetSize()
|
||||||
bmp = wxEmptyBitmap(sz.width-bdr, sz.height-bdr)
|
bmp = wx.EmptyBitmap(width-bdr, height-bdr)
|
||||||
dc = wxMemoryDC()
|
dc = wx.MemoryDC()
|
||||||
dc.SelectObject(bmp)
|
dc.SelectObject(bmp)
|
||||||
label = self.GetLabel()
|
label = self.GetLabel()
|
||||||
# Just make a little colored bitmap
|
# Just make a little colored bitmap
|
||||||
dc.SetBackground(wxBrush(self.colour))
|
dc.SetBackground(wx.Brush(self.colour))
|
||||||
dc.Clear()
|
dc.Clear()
|
||||||
|
|
||||||
if label:
|
if label:
|
||||||
# Add a label to it
|
# Add a label to it
|
||||||
avg = reduce(lambda a, b: a + b, self.colour.Get()) / 3
|
avg = reduce(lambda a, b: a + b, self.colour.Get()) / 3
|
||||||
fcolour = avg > 128 and wxBLACK or wxWHITE
|
fcolour = avg > 128 and wx.BLACK or wx.WHITE
|
||||||
dc.SetTextForeground(fcolour)
|
dc.SetTextForeground(fcolour)
|
||||||
dc.DrawLabel(label, (0,0, sz.width-bdr, sz.height-bdr),
|
dc.DrawLabel(label, (0,0, width-bdr, height-bdr),
|
||||||
wxALIGN_CENTER)
|
wx.ALIGN_CENTER)
|
||||||
|
|
||||||
dc.SelectObject(wxNullBitmap)
|
dc.SelectObject(wx.NullBitmap)
|
||||||
return bmp
|
return bmp
|
||||||
|
|
||||||
|
|
||||||
@@ -119,21 +126,24 @@ class ColourSelect(wxBitmapButton):
|
|||||||
|
|
||||||
|
|
||||||
def OnChange(self):
|
def OnChange(self):
|
||||||
wxPostEvent(self, ColourSelectEvent(self.GetId(), self.GetValue()))
|
wx.PostEvent(self, ColourSelectEvent(self.GetId(), self.GetValue()))
|
||||||
if self.callback is not None:
|
if self.callback is not None:
|
||||||
self.callback()
|
self.callback()
|
||||||
|
|
||||||
def OnClick(self, event):
|
def OnClick(self, event):
|
||||||
data = wxColourData()
|
data = wx.ColourData()
|
||||||
data.SetChooseFull(True)
|
data.SetChooseFull(True)
|
||||||
data.SetColour(self.colour)
|
data.SetColour(self.colour)
|
||||||
dlg = wxColourDialog(self.GetParent(), data)
|
dlg = wx.ColourDialog(self.GetParent(), data)
|
||||||
changed = dlg.ShowModal() == wxID_OK
|
changed = dlg.ShowModal() == wx.ID_OK
|
||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
data = dlg.GetColourData()
|
data = dlg.GetColourData()
|
||||||
self.SetColour(data.GetColour())
|
self.SetColour(data.GetColour())
|
||||||
|
|
||||||
dlg.Destroy()
|
dlg.Destroy()
|
||||||
|
|
||||||
|
# moved after dlg.Destroy, since who knows what the callback will do...
|
||||||
if changed:
|
if changed:
|
||||||
self.OnChange() # moved after dlg.Destroy, since who knows what the callback will do...
|
self.OnChange()
|
||||||
|
|
||||||
|
|||||||
@@ -10,50 +10,69 @@
|
|||||||
# Copyright: (c) 2002 by Total Control Software
|
# Copyright: (c) 2002 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 12/01/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Updated for 2.5 compatability.
|
||||||
|
#
|
||||||
|
|
||||||
from wxPython import wx
|
import wx
|
||||||
from layoutf import Layoutf
|
import layoutf
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
class wxScrolledMessageDialog(wx.wxDialog):
|
class wxScrolledMessageDialog(wx.Dialog):
|
||||||
def __init__(self, parent, msg, caption, pos = wx.wxDefaultPosition, size = (500,300)):
|
def __init__(self, parent, msg, caption, pos = wx.DefaultPosition,
|
||||||
wx.wxDialog.__init__(self, parent, -1, caption, pos, size)
|
size = (500,300)):
|
||||||
|
wx.Dialog.__init__(self, parent, -1, caption, pos, size)
|
||||||
x, y = pos
|
x, y = pos
|
||||||
if x == -1 and y == -1:
|
if x == -1 and y == -1:
|
||||||
self.CenterOnScreen(wx.wxBOTH)
|
self.CenterOnScreen(wx.BOTH)
|
||||||
text = wx.wxTextCtrl(self, -1, msg, wx.wxDefaultPosition,
|
|
||||||
wx.wxDefaultSize,
|
text = wx.TextCtrl(self, -1, msg, wx.DefaultPosition, wx.DefaultSize,
|
||||||
wx.wxTE_MULTILINE | wx.wxTE_READONLY)
|
wx.TE_MULTILINE | wx.TE_READONLY)
|
||||||
ok = wx.wxButton(self, wx.wxID_OK, "OK")
|
|
||||||
text.SetConstraints(Layoutf('t=t5#1;b=t5#2;l=l5#1;r=r5#1', (self,ok)))
|
ok = wx.Button(self, wx.ID_OK, "OK")
|
||||||
ok.SetConstraints(Layoutf('b=b5#1;x%w50#1;w!80;h!25', (self,)))
|
lc = layoutf.Layoutf('t=t5#1;b=t5#2;l=l5#1;r=r5#1', (self,ok))
|
||||||
|
text.SetConstraints(lc)
|
||||||
|
|
||||||
|
lc = layoutf.Layoutf('b=b5#1;x%w50#1;w!80;h!25', (self,))
|
||||||
|
ok.SetConstraints(lc)
|
||||||
self.SetAutoLayout(1)
|
self.SetAutoLayout(1)
|
||||||
self.Layout()
|
self.Layout()
|
||||||
|
|
||||||
|
|
||||||
class wxMultipleChoiceDialog(wx.wxDialog):
|
class wxMultipleChoiceDialog(wx.Dialog):
|
||||||
def __init__(self, parent, msg, title, lst, pos = wx.wxDefaultPosition,
|
def __init__(self, parent, msg, title, lst, pos = wx.DefaultPosition,
|
||||||
size = (200,200), style = wx.wxDEFAULT_DIALOG_STYLE):
|
size = (200,200), style = wx.DEFAULT_DIALOG_STYLE):
|
||||||
wx.wxDialog.__init__(self, parent, -1, title, pos, size, style)
|
wx.Dialog.__init__(self, parent, -1, title, pos, size, style)
|
||||||
|
|
||||||
x, y = pos
|
x, y = pos
|
||||||
if x == -1 and y == -1:
|
if x == -1 and y == -1:
|
||||||
self.CenterOnScreen(wx.wxBOTH)
|
self.CenterOnScreen(wx.BOTH)
|
||||||
dc = wx.wxClientDC(self)
|
|
||||||
|
dc = wx.ClientDC(self)
|
||||||
height = 0
|
height = 0
|
||||||
for line in msg.splitlines():
|
for line in msg.splitlines():
|
||||||
height = height + dc.GetTextExtent(line)[1] + 2
|
height = height + dc.GetTextExtent(line)[1] + 2
|
||||||
stat = wx.wxStaticText(self, -1, msg)
|
|
||||||
self.lbox = wx.wxListBox(self, 100, wx.wxDefaultPosition,
|
stat = wx.StaticText(self, -1, msg)
|
||||||
wx.wxDefaultSize, lst, wx.wxLB_MULTIPLE)
|
self.lbox = wx.ListBox(self, 100, wx.DefaultPosition, wx.DefaultSize,
|
||||||
ok = wx.wxButton(self, wx.wxID_OK, "OK")
|
lst, wx.LB_MULTIPLE)
|
||||||
cancel = wx.wxButton(self, wx.wxID_CANCEL, "Cancel")
|
|
||||||
stat.SetConstraints(Layoutf('t=t10#1;l=l5#1;r=r5#1;h!%d' % (height,),
|
ok = wx.Button(self, wx.ID_OK, "OK")
|
||||||
(self,)))
|
cancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
|
||||||
self.lbox.SetConstraints(Layoutf('t=b10#2;l=l5#1;r=r5#1;b=t5#3',
|
lc = layoutf.Layoutf('t=t10#1;l=l5#1;r=r5#1;h!%d' % (height,), (self,))
|
||||||
(self, stat, ok)))
|
stat.SetConstraints(lc)
|
||||||
ok.SetConstraints(Layoutf('b=b5#1;x%w25#1;w!80;h!25', (self,)))
|
|
||||||
cancel.SetConstraints(Layoutf('b=b5#1;x%w75#1;w!80;h!25', (self,)))
|
lc = layoutf.Layoutf('t=b10#2;l=l5#1;r=r5#1;b=t5#3', (self, stat, ok))
|
||||||
|
self.lbox.SetConstraints(lc)
|
||||||
|
|
||||||
|
lc = layoutf.Layoutf('b=b5#1;x%w25#1;w!80;h!25', (self,))
|
||||||
|
ok.SetConstraints(lc)
|
||||||
|
|
||||||
|
lc = layoutf.Layoutf('b=b5#1;x%w75#1;w!80;h!25', (self,))
|
||||||
|
cancel.SetConstraints(lc)
|
||||||
|
|
||||||
self.SetAutoLayout(1)
|
self.SetAutoLayout(1)
|
||||||
self.lst = lst
|
self.lst = lst
|
||||||
self.Layout()
|
self.Layout()
|
||||||
@@ -64,10 +83,11 @@ class wxMultipleChoiceDialog(wx.wxDialog):
|
|||||||
def GetValueString(self):
|
def GetValueString(self):
|
||||||
sel = self.lbox.GetSelections()
|
sel = self.lbox.GetSelections()
|
||||||
val = []
|
val = []
|
||||||
|
|
||||||
for i in sel:
|
for i in sel:
|
||||||
val.append(self.lst[i])
|
val.append(self.lst[i])
|
||||||
return tuple(val)
|
|
||||||
|
|
||||||
|
return tuple(val)
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
@@ -102,45 +122,47 @@ rev 2:
|
|||||||
class DialogResults:
|
class DialogResults:
|
||||||
def __init__(self, returned):
|
def __init__(self, returned):
|
||||||
self.returned = returned
|
self.returned = returned
|
||||||
self.accepted = returned in (wx.wxID_OK, wx.wxID_YES)
|
self.accepted = returned in (wx.ID_OK, wx.ID_YES)
|
||||||
self.returnedString = returnedString(returned)
|
self.returnedString = returnedString(returned)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return str(self.__dict__)
|
return str(self.__dict__)
|
||||||
|
|
||||||
def returnedString(ret):
|
def returnedString(ret):
|
||||||
if ret == wx.wxID_OK:
|
if ret == wx.ID_OK:
|
||||||
return "Ok"
|
return "Ok"
|
||||||
elif ret == wx.wxID_CANCEL:
|
elif ret == wx.ID_CANCEL:
|
||||||
return "Cancel"
|
return "Cancel"
|
||||||
elif ret == wx.wxID_YES:
|
elif ret == wx.ID_YES:
|
||||||
return "Yes"
|
return "Yes"
|
||||||
elif ret == wx.wxID_NO:
|
elif ret == wx.ID_NO:
|
||||||
return "No"
|
return "No"
|
||||||
|
|
||||||
|
|
||||||
# findDialog was created before wxPython got a Find/Replace dialog
|
## findDialog was created before wxPython got a Find/Replace dialog
|
||||||
# but it may be instructive as to how a function wrapper can
|
## but it may be instructive as to how a function wrapper can
|
||||||
# be added for your own custom dialogs
|
## be added for your own custom dialogs
|
||||||
# this dialog is always modal, while wxFindReplaceDialog is
|
## this dialog is always modal, while wxFindReplaceDialog is
|
||||||
# modeless and so doesn't lend itself to a function wrapper
|
## modeless and so doesn't lend itself to a function wrapper
|
||||||
def findDialog(parent=None, searchText='', wholeWordsOnly=0, caseSensitive=0):
|
def findDialog(parent=None, searchText='', wholeWordsOnly=0, caseSensitive=0):
|
||||||
dlg = wx.wxDialog(parent, -1, "Find", wx.wxDefaultPosition, wx.wxSize(370, 120))
|
dlg = wx.Dialog(parent, -1, "Find", wx.DefaultPosition, (370, 120))
|
||||||
|
|
||||||
wx.wxStaticText(dlg, -1, 'Find what:', wx.wxPoint(7, 10))
|
wx.StaticText(dlg, -1, 'Find what:', (7, 10))
|
||||||
wSearchText = wx.wxTextCtrl(dlg, -1, searchText,
|
wSearchText = wx.TextCtrl(dlg, -1, searchText, (70, 7), (195, -1))
|
||||||
wx.wxPoint(70, 7), wx.wxSize(195, -1))
|
|
||||||
wSearchText.SetValue(searchText)
|
wSearchText.SetValue(searchText)
|
||||||
wx.wxButton(dlg, wx.wxID_OK, "Find Next", wx.wxPoint(280, 5), wx.wxDefaultSize).SetDefault()
|
wx.wxButton(dlg, wx.ID_OK, "Find Next", (280, 5), wx.DefaultSize).SetDefault()
|
||||||
wx.wxButton(dlg, wx.wxID_CANCEL, "Cancel", wx.wxPoint(280, 35), wx.wxDefaultSize)
|
wx.wxButton(dlg, wx.ID_CANCEL, "Cancel", (280, 35), wx.DefaultSize)
|
||||||
wWholeWord = wx.wxCheckBox(dlg, -1, 'Match whole word only',
|
wWholeWord = wx.CheckBox(dlg, -1, 'Match whole word only',
|
||||||
wx.wxPoint(7, 35), wx.wxDefaultSize, wx.wxNO_BORDER)
|
(7, 35), wx.DefaultSize, wx.NO_BORDER)
|
||||||
|
|
||||||
if wholeWordsOnly:
|
if wholeWordsOnly:
|
||||||
wWholeWord.SetValue(1)
|
wWholeWord.SetValue(1)
|
||||||
wCase = wx.wxCheckBox(dlg, -1, 'Match case',
|
|
||||||
wx.wxPoint(7, 55), wx.wxDefaultSize, wx.wxNO_BORDER)
|
wCase = wx.CheckBox(dlg, -1, 'Match case', (7, 55), wx.DefaultSize, wx.NO_BORDER)
|
||||||
|
|
||||||
if caseSensitive:
|
if caseSensitive:
|
||||||
wCase.SetValue(1)
|
wCase.SetValue(1)
|
||||||
|
|
||||||
wSearchText.SetSelection(0, len(wSearchText.GetValue()))
|
wSearchText.SetSelection(0, len(wSearchText.GetValue()))
|
||||||
wSearchText.SetFocus()
|
wSearchText.SetFocus()
|
||||||
|
|
||||||
@@ -154,28 +176,33 @@ def findDialog(parent=None, searchText='', wholeWordsOnly=0, caseSensitive=0):
|
|||||||
|
|
||||||
def colorDialog(parent=None, colorData=None, color=None):
|
def colorDialog(parent=None, colorData=None, color=None):
|
||||||
if colorData:
|
if colorData:
|
||||||
dialog = wx.wxColourDialog(parent, colorData)
|
dialog = wx.ColourDialog(parent, colorData)
|
||||||
else:
|
else:
|
||||||
dialog = wx.wxColourDialog(parent)
|
dialog = wx.ColourDialog(parent)
|
||||||
dialog.GetColourData().SetChooseFull(1)
|
dialog.GetColourData().SetChooseFull(1)
|
||||||
|
|
||||||
if color is not None:
|
if color is not None:
|
||||||
dialog.GetColourData().SetColour(color)
|
dialog.GetColourData().SetColour(color)
|
||||||
|
|
||||||
result = DialogResults(dialog.ShowModal())
|
result = DialogResults(dialog.ShowModal())
|
||||||
result.colorData = dialog.GetColourData()
|
result.colorData = dialog.GetColourData()
|
||||||
result.color = result.colorData.GetColour().Get()
|
result.color = result.colorData.GetColour().Get()
|
||||||
dialog.Destroy()
|
dialog.Destroy()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# it is easier to just duplicate the code than
|
|
||||||
# try and replace color with colour in the result
|
## it is easier to just duplicate the code than
|
||||||
|
## try and replace color with colour in the result
|
||||||
def colourDialog(parent=None, colourData=None, colour=None):
|
def colourDialog(parent=None, colourData=None, colour=None):
|
||||||
if colourData:
|
if colourData:
|
||||||
dialog = wx.wxColourDialog(parent, colourData)
|
dialog = wx.ColourDialog(parent, colourData)
|
||||||
else:
|
else:
|
||||||
dialog = wx.wxColourDialog(parent)
|
dialog = wx.ColourDialog(parent)
|
||||||
dialog.GetColourData().SetChooseFull(1)
|
dialog.GetColourData().SetChooseFull(1)
|
||||||
|
|
||||||
if colour is not None:
|
if colour is not None:
|
||||||
dialog.GetColourData().SetColour(color)
|
dialog.GetColourData().SetColour(color)
|
||||||
|
|
||||||
result = DialogResults(dialog.ShowModal())
|
result = DialogResults(dialog.ShowModal())
|
||||||
result.colourData = dialog.GetColourData()
|
result.colourData = dialog.GetColourData()
|
||||||
result.colour = result.colourData.GetColour().Get()
|
result.colour = result.colourData.GetColour().Get()
|
||||||
@@ -185,11 +212,14 @@ def colourDialog(parent=None, colourData=None, colour=None):
|
|||||||
|
|
||||||
def fontDialog(parent=None, fontData=None, font=None):
|
def fontDialog(parent=None, fontData=None, font=None):
|
||||||
if fontData is None:
|
if fontData is None:
|
||||||
fontData = wx.wxFontData()
|
fontData = wx.FontData()
|
||||||
|
|
||||||
if font is not None:
|
if font is not None:
|
||||||
aFontData.SetInitialFont(font)
|
aFontData.SetInitialFont(font)
|
||||||
dialog = wx.wxFontDialog(parent, fontData)
|
|
||||||
|
dialog = wx.FontDialog(parent, fontData)
|
||||||
result = DialogResults(dialog.ShowModal())
|
result = DialogResults(dialog.ShowModal())
|
||||||
|
|
||||||
if result.accepted:
|
if result.accepted:
|
||||||
fontData = dialog.GetFontData()
|
fontData = dialog.GetFontData()
|
||||||
result.fontData = fontData
|
result.fontData = fontData
|
||||||
@@ -200,12 +230,14 @@ def fontDialog(parent=None, fontData=None, font=None):
|
|||||||
result.color = None
|
result.color = None
|
||||||
result.colour = None
|
result.colour = None
|
||||||
result.font = None
|
result.font = None
|
||||||
|
|
||||||
dialog.Destroy()
|
dialog.Destroy()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def textEntryDialog(parent=None, message='', title='', defaultText='', style=wx.wxOK | wx.wxCANCEL):
|
def textEntryDialog(parent=None, message='', title='', defaultText='',
|
||||||
dialog = wx.wxTextEntryDialog(parent, message, title, defaultText, style)
|
style=wx.OK | wx.CANCEL):
|
||||||
|
dialog = wx.TextEntryDialog(parent, message, title, defaultText, style)
|
||||||
result = DialogResults(dialog.ShowModal())
|
result = DialogResults(dialog.ShowModal())
|
||||||
result.text = dialog.GetValue()
|
result.text = dialog.GetValue()
|
||||||
dialog.Destroy()
|
dialog.Destroy()
|
||||||
@@ -213,22 +245,24 @@ def textEntryDialog(parent=None, message='', title='', defaultText='', style=wx.
|
|||||||
|
|
||||||
|
|
||||||
def messageDialog(parent=None, message='', title='Message box',
|
def messageDialog(parent=None, message='', title='Message box',
|
||||||
aStyle = wx.wxOK | wx.wxCANCEL | wx.wxCENTRE,
|
aStyle = wx.OK | wx.CANCEL | wx.CENTRE,
|
||||||
pos=wx.wxDefaultPosition):
|
pos=wx.DefaultPosition):
|
||||||
dialog = wx.wxMessageDialog(parent, message, title, aStyle, pos)
|
dialog = wx.MessageDialog(parent, message, title, aStyle, pos)
|
||||||
result = DialogResults(dialog.ShowModal())
|
result = DialogResults(dialog.ShowModal())
|
||||||
dialog.Destroy()
|
dialog.Destroy()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
# KEA alerts are common, so I'm providing a class rather than
|
## KEA: alerts are common, so I'm providing a class rather than
|
||||||
# requiring the user code to set up the right icons and buttons
|
## requiring the user code to set up the right icons and buttons
|
||||||
# the with messageDialog function
|
## the with messageDialog function
|
||||||
def alertDialog(parent=None, message='', title='Alert', pos=wx.wxDefaultPosition):
|
def alertDialog(parent=None, message='', title='Alert', pos=wx.DefaultPosition):
|
||||||
return messageDialog(parent, message, title, wx.wxICON_EXCLAMATION | wx.wxOK, pos)
|
return messageDialog(parent, message, title, wx.ICON_EXCLAMATION | wx.OK, pos)
|
||||||
|
|
||||||
|
|
||||||
def scrolledMessageDialog(parent=None, message='', title='', pos=wx.wxDefaultPosition, size=(500,300)):
|
def scrolledMessageDialog(parent=None, message='', title='', pos=wx.DefaultPosition,
|
||||||
|
size=(500,300)):
|
||||||
|
|
||||||
dialog = wxScrolledMessageDialog(parent, message, title, pos, size)
|
dialog = wxScrolledMessageDialog(parent, message, title, pos, size)
|
||||||
result = DialogResults(dialog.ShowModal())
|
result = DialogResults(dialog.ShowModal())
|
||||||
dialog.Destroy()
|
dialog.Destroy()
|
||||||
@@ -236,8 +270,9 @@ def scrolledMessageDialog(parent=None, message='', title='', pos=wx.wxDefaultPos
|
|||||||
|
|
||||||
|
|
||||||
def fileDialog(parent=None, title='Open', directory='', filename='', wildcard='*.*',
|
def fileDialog(parent=None, title='Open', directory='', filename='', wildcard='*.*',
|
||||||
style=wx.wxOPEN | wx.wxMULTIPLE):
|
style=wx.OPEN | wx.MULTIPLE):
|
||||||
dialog = wx.wxFileDialog(parent, title, directory, filename, wildcard, style)
|
|
||||||
|
dialog = wx.FileDialog(parent, title, directory, filename, wildcard, style)
|
||||||
result = DialogResults(dialog.ShowModal())
|
result = DialogResults(dialog.ShowModal())
|
||||||
if result.accepted:
|
if result.accepted:
|
||||||
result.paths = dialog.GetPaths()
|
result.paths = dialog.GetPaths()
|
||||||
@@ -247,24 +282,25 @@ def fileDialog(parent=None, title='Open', directory='', filename='', wildcard='*
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
# openFileDialog and saveFileDialog are convenience functions
|
## openFileDialog and saveFileDialog are convenience functions
|
||||||
# they represent the most common usages of the fileDialog
|
## they represent the most common usages of the fileDialog
|
||||||
# with the most common style options
|
## with the most common style options
|
||||||
def openFileDialog(parent=None, title='Open', directory='', filename='',
|
def openFileDialog(parent=None, title='Open', directory='', filename='',
|
||||||
wildcard='All Files (*.*)|*.*',
|
wildcard='All Files (*.*)|*.*',
|
||||||
style=wx.wxOPEN | wx.wxMULTIPLE):
|
style=wx.OPEN | wx.MULTIPLE):
|
||||||
return fileDialog(parent, title, directory, filename, wildcard, style)
|
return fileDialog(parent, title, directory, filename, wildcard, style)
|
||||||
|
|
||||||
|
|
||||||
def saveFileDialog(parent=None, title='Save', directory='', filename='',
|
def saveFileDialog(parent=None, title='Save', directory='', filename='',
|
||||||
wildcard='All Files (*.*)|*.*',
|
wildcard='All Files (*.*)|*.*',
|
||||||
style=wx.wxSAVE | wx.wxHIDE_READONLY | wx.wxOVERWRITE_PROMPT):
|
style=wx.SAVE | wx.HIDE_READONLY | wx.OVERWRITE_PROMPT):
|
||||||
return fileDialog(parent, title, directory, filename, wildcard, style)
|
return fileDialog(parent, title, directory, filename, wildcard, style)
|
||||||
|
|
||||||
|
|
||||||
def dirDialog(parent=None, message='Choose a directory', path='', style=0,
|
def dirDialog(parent=None, message='Choose a directory', path='', style=0,
|
||||||
pos=wx.wxDefaultPosition, size=wx.wxDefaultSize):
|
pos=wx.DefaultPosition, size=wx.DefaultSize):
|
||||||
dialog = wx.wxDirDialog(parent, message, path, style, pos, size)
|
|
||||||
|
dialog = wx.DirDialog(parent, message, path, style, pos, size)
|
||||||
result = DialogResults(dialog.ShowModal())
|
result = DialogResults(dialog.ShowModal())
|
||||||
if result.accepted:
|
if result.accepted:
|
||||||
result.path = dialog.GetPath()
|
result.path = dialog.GetPath()
|
||||||
@@ -277,19 +313,17 @@ directoryDialog = dirDialog
|
|||||||
|
|
||||||
|
|
||||||
def singleChoiceDialog(parent=None, message='', title='', lst=[],
|
def singleChoiceDialog(parent=None, message='', title='', lst=[],
|
||||||
style=wx.wxOK | wx.wxCANCEL | wx.wxCENTRE):
|
style=wx.OK | wx.CANCEL | wx.CENTRE):
|
||||||
dialog = wx.wxSingleChoiceDialog(parent,
|
dialog = wx.SingleChoiceDialog(parent, message, title, lst, style)
|
||||||
message,
|
|
||||||
title,
|
|
||||||
lst,
|
|
||||||
style)
|
|
||||||
result = DialogResults(dialog.ShowModal())
|
result = DialogResults(dialog.ShowModal())
|
||||||
result.selection = dialog.GetStringSelection()
|
result.selection = dialog.GetStringSelection()
|
||||||
dialog.Destroy()
|
dialog.Destroy()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def multipleChoiceDialog(parent=None, message='', title='', lst=[], pos=wx.wxDefaultPosition, size=(200,200)):
|
def multipleChoiceDialog(parent=None, message='', title='', lst=[], pos=wx.DefaultPosition,
|
||||||
|
size=(200,200)):
|
||||||
|
|
||||||
dialog = wxMultipleChoiceDialog(parent, message, title, lst, pos, size)
|
dialog = wxMultipleChoiceDialog(parent, message, title, lst, pos, size)
|
||||||
result = DialogResults(dialog.ShowModal())
|
result = DialogResults(dialog.ShowModal())
|
||||||
result.selection = dialog.GetValueString()
|
result.selection = dialog.GetValueString()
|
||||||
@@ -298,11 +332,11 @@ def multipleChoiceDialog(parent=None, message='', title='', lst=[], pos=wx.wxDef
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
class MyApp(wx.wxApp):
|
class MyApp(wx.App):
|
||||||
|
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
frame = wx.wxFrame(wx.NULL, -1, "Dialogs", size=(400, 200))
|
frame = wx.Frame(None, -1, "Dialogs", size=(400, 200))
|
||||||
panel = wx.wxPanel(frame, -1)
|
panel = wx.Panel(frame, -1)
|
||||||
self.panel = panel
|
self.panel = panel
|
||||||
|
|
||||||
frame.Show(1)
|
frame.Show(1)
|
||||||
@@ -322,11 +356,11 @@ if __name__ == '__main__':
|
|||||||
'singleChoiceDialog',
|
'singleChoiceDialog',
|
||||||
'textEntryDialog',
|
'textEntryDialog',
|
||||||
]
|
]
|
||||||
self.nameList = wx.wxListBox(panel, -1, (0, 0), (130, 180), dialogNames, style=wx.wxLB_SINGLE)
|
self.nameList = wx.ListBox(panel, -1, (0, 0), (130, 180), dialogNames, style=wx.LB_SINGLE)
|
||||||
wx.EVT_LISTBOX(panel, self.nameList.GetId(), self.OnNameListSelected)
|
self.Bind(wx.EVT_LISTBOX, self.OnNameListSelected, id=self.nameList.GetId())
|
||||||
|
|
||||||
tstyle = wx.wxTE_RICH2 | wx.wxTE_PROCESS_TAB | wx.wxTE_MULTILINE
|
tstyle = wx.TE_RICH2 | wx.TE_PROCESS_TAB | wx.TE_MULTILINE
|
||||||
self.text1 = wx.wxTextCtrl(panel, -1, pos=(150, 0), size=(200, 180), style=tstyle)
|
self.text1 = wx.TextCtrl(panel, -1, pos=(150, 0), size=(200, 180), style=tstyle)
|
||||||
|
|
||||||
self.SetTopWindow(frame)
|
self.SetTopWindow(frame)
|
||||||
|
|
||||||
@@ -381,5 +415,7 @@ if __name__ == '__main__':
|
|||||||
#self.text1.SetValue(pprint.pformat(result.__dict__))
|
#self.text1.SetValue(pprint.pformat(result.__dict__))
|
||||||
self.text1.SetValue(str(result))
|
self.text1.SetValue(str(result))
|
||||||
|
|
||||||
app = MyApp(0)
|
app = MyApp(True)
|
||||||
app.MainLoop()
|
app.MainLoop()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,10 @@
|
|||||||
# Copyright: (c) 1999 by Total Control Software
|
# Copyright: (c) 1999 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
#
|
||||||
|
|
||||||
# This file makes this directory into a Python package
|
# This file makes this directory into a Python package
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,15 @@
|
|||||||
# Copyright: (c) 1999 by Dirk Holtwick, 1999
|
# Copyright: (c) 1999 by Dirk Holtwick, 1999
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
#
|
||||||
|
|
||||||
import os, time
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
from wxPython.wx import *
|
import wx
|
||||||
|
|
||||||
import selection
|
import selection
|
||||||
import images
|
import images
|
||||||
@@ -70,14 +75,14 @@ class Scroller:
|
|||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
class wxEditor(wxScrolledWindow):
|
class wxEditor(wx.ScrolledWindow):
|
||||||
|
|
||||||
def __init__(self, parent, id,
|
def __init__(self, parent, id,
|
||||||
pos=wxDefaultPosition, size=wxDefaultSize, style=0):
|
pos=wx.DefaultPosition, size=wx.DefaultSize, style=0):
|
||||||
|
|
||||||
wxScrolledWindow.__init__(self, parent, id,
|
wx.ScrolledWindow.__init__(self, parent, id,
|
||||||
pos, size,
|
pos, size,
|
||||||
style|wxWANTS_CHARS)
|
style|wx.WANTS_CHARS)
|
||||||
|
|
||||||
self.isDrawing = False
|
self.isDrawing = False
|
||||||
|
|
||||||
@@ -108,26 +113,33 @@ class wxEditor(wxScrolledWindow):
|
|||||||
self.sco_y = 0
|
self.sco_y = 0
|
||||||
|
|
||||||
def MapEvents(self):
|
def MapEvents(self):
|
||||||
EVT_LEFT_DOWN(self, self.OnLeftDown)
|
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
|
||||||
EVT_LEFT_UP(self, self.OnLeftUp)
|
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
|
||||||
EVT_MOTION(self, self.OnMotion)
|
self.Bind(wx.EVT_MOTION, self.OnMotion)
|
||||||
EVT_SCROLLWIN(self, self.OnScroll)
|
self.Bind(wx.EVT_SCROLLWIN, self.OnScroll)
|
||||||
EVT_CHAR(self, self.OnChar)
|
self.Bind(wx.EVT_CHAR, self.OnChar)
|
||||||
EVT_PAINT(self, self.OnPaint)
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||||
EVT_SIZE(self, self.OnSize)
|
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||||
EVT_WINDOW_DESTROY(self, self.OnDestroy)
|
self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
|
||||||
EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
|
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
|
||||||
|
|
||||||
##------------------- Platform-specific stuff
|
##------------------- Platform-specific stuff
|
||||||
|
|
||||||
def NiceFontForPlatform(self):
|
def NiceFontForPlatform(self):
|
||||||
if wxPlatform == "__WXMSW__":
|
if wx.Platform == "__WXMSW__":
|
||||||
return wxFont(10, wxMODERN, wxNORMAL, wxNORMAL)
|
return wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL)
|
||||||
else:
|
else:
|
||||||
return wxFont(12, wxMODERN, wxNORMAL, wxNORMAL, False)
|
return wx.Font(12, wx.MODERN, wx.NORMAL, wx.NORMAL, False)
|
||||||
|
|
||||||
def UnixKeyHack(self, key):
|
def UnixKeyHack(self, key):
|
||||||
|
#
|
||||||
# this will be obsolete when we get the new wxWindows patch
|
# this will be obsolete when we get the new wxWindows patch
|
||||||
|
#
|
||||||
|
# 12/14/03 - jmg
|
||||||
|
#
|
||||||
|
# Which patch? I don't know if this is needed, but I don't know
|
||||||
|
# why it's here either. Play it safe; leave it in.
|
||||||
|
#
|
||||||
if key <= 26:
|
if key <= 26:
|
||||||
key += ord('a') - 1
|
key += ord('a') - 1
|
||||||
return key
|
return key
|
||||||
@@ -141,39 +153,39 @@ class wxEditor(wxScrolledWindow):
|
|||||||
def SetCharDimensions(self):
|
def SetCharDimensions(self):
|
||||||
# TODO: We need a code review on this. It appears that Linux
|
# TODO: We need a code review on this. It appears that Linux
|
||||||
# improperly reports window dimensions when the scrollbar's there.
|
# improperly reports window dimensions when the scrollbar's there.
|
||||||
self.bw, self.bh = self.GetClientSizeTuple()
|
self.bw, self.bh = self.GetClientSize()
|
||||||
|
|
||||||
if wxPlatform == "__WXMSW__":
|
if wx.Platform == "__WXMSW__":
|
||||||
self.sh = self.bh / self.fh
|
self.sh = self.bh / self.fh
|
||||||
self.sw = (self.bw / self.fw) - 1
|
self.sw = (self.bw / self.fw) - 1
|
||||||
else:
|
else:
|
||||||
self.sh = self.bh / self.fh
|
self.sh = self.bh / self.fh
|
||||||
if self.LinesInFile() >= self.sh:
|
if self.LinesInFile() >= self.sh:
|
||||||
self.bw = self.bw - wxSystemSettings_GetMetric(wxSYS_VSCROLL_X)
|
self.bw = self.bw - wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
|
||||||
self.sw = (self.bw / self.fw) - 1
|
self.sw = (self.bw / self.fw) - 1
|
||||||
|
|
||||||
self.sw = (self.bw / self.fw) - 1
|
self.sw = (self.bw / self.fw) - 1
|
||||||
if self.CalcMaxLineLen() >= self.sw:
|
if self.CalcMaxLineLen() >= self.sw:
|
||||||
self.bh = self.bh - wxSystemSettings_GetMetric(wxSYS_HSCROLL_Y)
|
self.bh = self.bh - wx.SystemSettings_GetMetric(wx.SYS_HSCROLL_Y)
|
||||||
self.sh = self.bh / self.fh
|
self.sh = self.bh / self.fh
|
||||||
|
|
||||||
|
|
||||||
def UpdateView(self, dc = None):
|
def UpdateView(self, dc = None):
|
||||||
if dc is None:
|
if dc is None:
|
||||||
dc = wxClientDC(self)
|
dc = wx.ClientDC(self)
|
||||||
if dc.Ok():
|
if dc.Ok():
|
||||||
self.SetCharDimensions()
|
self.SetCharDimensions()
|
||||||
self.KeepCursorOnScreen()
|
self.KeepCursorOnScreen()
|
||||||
self.DrawSimpleCursor(0,0,dc, True)
|
self.DrawSimpleCursor(0,0, dc, True)
|
||||||
self.Draw(dc)
|
self.Draw(dc)
|
||||||
|
|
||||||
def OnPaint(self, event):
|
def OnPaint(self, event):
|
||||||
dc = wxPaintDC(self)
|
dc = wx.PaintDC(self)
|
||||||
if self.isDrawing:
|
if self.isDrawing:
|
||||||
return
|
return
|
||||||
self.isDrawing = True
|
self.isDrawing = True
|
||||||
self.UpdateView(dc)
|
self.UpdateView(dc)
|
||||||
wxCallAfter(self.AdjustScrollbars)
|
wx.CallAfter(self.AdjustScrollbars)
|
||||||
self.isDrawing = False
|
self.isDrawing = False
|
||||||
|
|
||||||
def OnEraseBackground(self, evt):
|
def OnEraseBackground(self, evt):
|
||||||
@@ -182,16 +194,16 @@ class wxEditor(wxScrolledWindow):
|
|||||||
##-------------------- Drawing code
|
##-------------------- Drawing code
|
||||||
|
|
||||||
def InitFonts(self):
|
def InitFonts(self):
|
||||||
dc = wxClientDC(self)
|
dc = wx.ClientDC(self)
|
||||||
self.font = self.NiceFontForPlatform()
|
self.font = self.NiceFontForPlatform()
|
||||||
dc.SetFont(self.font)
|
dc.SetFont(self.font)
|
||||||
self.fw = dc.GetCharWidth()
|
self.fw = dc.GetCharWidth()
|
||||||
self.fh = dc.GetCharHeight()
|
self.fh = dc.GetCharHeight()
|
||||||
|
|
||||||
def SetColors(self):
|
def SetColors(self):
|
||||||
self.fgColor = wxNamedColour('black')
|
self.fgColor = wx.NamedColour('black')
|
||||||
self.bgColor = wxNamedColour('white')
|
self.bgColor = wx.NamedColour('white')
|
||||||
self.selectColor = wxColour(238, 220, 120) # r, g, b = emacsOrange
|
self.selectColor = wx.Colour(238, 220, 120) # r, g, b = emacsOrange
|
||||||
|
|
||||||
def InitDoubleBuffering(self):
|
def InitDoubleBuffering(self):
|
||||||
pass
|
pass
|
||||||
@@ -220,13 +232,13 @@ class wxEditor(wxScrolledWindow):
|
|||||||
|
|
||||||
def Draw(self, odc=None):
|
def Draw(self, odc=None):
|
||||||
if not odc:
|
if not odc:
|
||||||
odc = wxClientDC(self)
|
odc = wx.ClientDC(self)
|
||||||
|
|
||||||
bmp = wxEmptyBitmap(max(1,self.bw), max(1,self.bh))
|
bmp = wx.EmptyBitmap(max(1,self.bw), max(1,self.bh))
|
||||||
dc = wxBufferedDC(odc, bmp)
|
dc = wx.BufferedDC(odc, bmp)
|
||||||
if dc.Ok():
|
if dc.Ok():
|
||||||
dc.SetFont(self.font)
|
dc.SetFont(self.font)
|
||||||
dc.SetBackgroundMode(wxSOLID)
|
dc.SetBackgroundMode(wx.SOLID)
|
||||||
dc.SetTextBackground(self.bgColor)
|
dc.SetTextBackground(self.bgColor)
|
||||||
dc.SetTextForeground(self.fgColor)
|
dc.SetTextForeground(self.fgColor)
|
||||||
dc.Clear()
|
dc.Clear()
|
||||||
@@ -251,7 +263,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
|
|
||||||
def DrawCursor(self, dc = None):
|
def DrawCursor(self, dc = None):
|
||||||
if not dc:
|
if not dc:
|
||||||
dc = wxClientDC(self)
|
dc = wx.ClientDC(self)
|
||||||
|
|
||||||
if (self.LinesInFile())<self.cy: #-1 ?
|
if (self.LinesInFile())<self.cy: #-1 ?
|
||||||
self.cy = self.LinesInFile()-1
|
self.cy = self.LinesInFile()-1
|
||||||
@@ -264,7 +276,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
|
|
||||||
def DrawSimpleCursor(self, xp, yp, dc = None, old=False):
|
def DrawSimpleCursor(self, xp, yp, dc = None, old=False):
|
||||||
if not dc:
|
if not dc:
|
||||||
dc = wxClientDC(self)
|
dc = wx.ClientDC(self)
|
||||||
|
|
||||||
if old:
|
if old:
|
||||||
xp = self.sco_x
|
xp = self.sco_x
|
||||||
@@ -274,7 +286,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
szy = self.fh
|
szy = self.fh
|
||||||
x = xp * szx
|
x = xp * szx
|
||||||
y = yp * szy
|
y = yp * szy
|
||||||
dc.Blit((x,y), (szx,szy), dc, (x,y), wxSRC_INVERT)
|
dc.Blit((x,y), (szx,szy), dc, (x,y), wx.SRC_INVERT)
|
||||||
self.sco_x = xp
|
self.sco_x = xp
|
||||||
self.sco_y = yp
|
self.sco_y = yp
|
||||||
|
|
||||||
@@ -376,7 +388,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
self.EnableScrolling(False, False)
|
self.EnableScrolling(False, False)
|
||||||
self.nextScrollTime = 0
|
self.nextScrollTime = 0
|
||||||
self.SCROLLDELAY = 0.050 # seconds
|
self.SCROLLDELAY = 0.050 # seconds
|
||||||
self.scrollTimer = wxTimer(self)
|
self.scrollTimer = wx.Timer(self)
|
||||||
self.scroller = Scroller(self)
|
self.scroller = Scroller(self)
|
||||||
|
|
||||||
def CanScroll(self):
|
def CanScroll(self):
|
||||||
@@ -389,10 +401,10 @@ class wxEditor(wxScrolledWindow):
|
|||||||
def SetScrollTimer(self):
|
def SetScrollTimer(self):
|
||||||
oneShot = True
|
oneShot = True
|
||||||
self.scrollTimer.Start(1000*self.SCROLLDELAY/2, oneShot)
|
self.scrollTimer.Start(1000*self.SCROLLDELAY/2, oneShot)
|
||||||
EVT_TIMER(self, -1, self.OnTimer)
|
self.Bind(wx.EVT_TIMER, self.OnTimer)
|
||||||
|
|
||||||
def OnTimer(self, event):
|
def OnTimer(self, event):
|
||||||
screenX, screenY = wxGetMousePosition()
|
screenX, screenY = wx.GetMousePosition()
|
||||||
x, y = self.ScreenToClientXY(screenX, screenY)
|
x, y = self.ScreenToClientXY(screenX, screenY)
|
||||||
self.MouseToRow(y)
|
self.MouseToRow(y)
|
||||||
self.MouseToCol(x)
|
self.MouseToCol(x)
|
||||||
@@ -484,17 +496,17 @@ class wxEditor(wxScrolledWindow):
|
|||||||
def HorizScroll(self, event, eventType):
|
def HorizScroll(self, event, eventType):
|
||||||
maxLineLen = self.CalcMaxLineLen()
|
maxLineLen = self.CalcMaxLineLen()
|
||||||
|
|
||||||
if eventType == wxEVT_SCROLLWIN_LINEUP:
|
if eventType == wx.EVT_SCROLLWIN_LINEUP:
|
||||||
self.sx -= 1
|
self.sx -= 1
|
||||||
elif eventType == wxEVT_SCROLLWIN_LINEDOWN:
|
elif eventType == wx.EVT_SCROLLWIN_LINEDOWN:
|
||||||
self.sx += 1
|
self.sx += 1
|
||||||
elif eventType == wxEVT_SCROLLWIN_PAGEUP:
|
elif eventType == wx.EVT_SCROLLWIN_PAGEUP:
|
||||||
self.sx -= self.sw
|
self.sx -= self.sw
|
||||||
elif eventType == wxEVT_SCROLLWIN_PAGEDOWN:
|
elif eventType == wx.EVT_SCROLLWIN_PAGEDOWN:
|
||||||
self.sx += self.sw
|
self.sx += self.sw
|
||||||
elif eventType == wxEVT_SCROLLWIN_TOP:
|
elif eventType == wx.EVT_SCROLLWIN_TOP:
|
||||||
self.sx = self.cx = 0
|
self.sx = self.cx = 0
|
||||||
elif eventType == wxEVT_SCROLLWIN_BOTTOM:
|
elif eventType == wx.EVT_SCROLLWIN_BOTTOM:
|
||||||
self.sx = maxLineLen - self.sw
|
self.sx = maxLineLen - self.sw
|
||||||
self.cx = maxLineLen
|
self.cx = maxLineLen
|
||||||
else:
|
else:
|
||||||
@@ -503,17 +515,17 @@ class wxEditor(wxScrolledWindow):
|
|||||||
self.HorizBoundaries()
|
self.HorizBoundaries()
|
||||||
|
|
||||||
def VertScroll(self, event, eventType):
|
def VertScroll(self, event, eventType):
|
||||||
if eventType == wxEVT_SCROLLWIN_LINEUP:
|
if eventType == wx.EVT_SCROLLWIN_LINEUP:
|
||||||
self.sy -= 1
|
self.sy -= 1
|
||||||
elif eventType == wxEVT_SCROLLWIN_LINEDOWN:
|
elif eventType == wx.EVT_SCROLLWIN_LINEDOWN:
|
||||||
self.sy += 1
|
self.sy += 1
|
||||||
elif eventType == wxEVT_SCROLLWIN_PAGEUP:
|
elif eventType == wx.EVT_SCROLLWIN_PAGEUP:
|
||||||
self.sy -= self.sh
|
self.sy -= self.sh
|
||||||
elif eventType == wxEVT_SCROLLWIN_PAGEDOWN:
|
elif eventType == wx.EVT_SCROLLWIN_PAGEDOWN:
|
||||||
self.sy += self.sh
|
self.sy += self.sh
|
||||||
elif eventType == wxEVT_SCROLLWIN_TOP:
|
elif eventType == wx.EVT_SCROLLWIN_TOP:
|
||||||
self.sy = self.cy = 0
|
self.sy = self.cy = 0
|
||||||
elif eventType == wxEVT_SCROLLWIN_BOTTOM:
|
elif eventType == wx.EVT_SCROLLWIN_BOTTOM:
|
||||||
self.sy = self.LinesInFile() - self.sh
|
self.sy = self.LinesInFile() - self.sh
|
||||||
self.cy = self.LinesInFile()
|
self.cy = self.LinesInFile()
|
||||||
else:
|
else:
|
||||||
@@ -524,7 +536,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
def OnScroll(self, event):
|
def OnScroll(self, event):
|
||||||
dir = event.GetOrientation()
|
dir = event.GetOrientation()
|
||||||
eventType = event.GetEventType()
|
eventType = event.GetEventType()
|
||||||
if dir == wxHORIZONTAL:
|
if dir == wx.HORIZONTAL:
|
||||||
self.HorizScroll(event, eventType)
|
self.HorizScroll(event, eventType)
|
||||||
else:
|
else:
|
||||||
self.VertScroll(event, eventType)
|
self.VertScroll(event, eventType)
|
||||||
@@ -583,7 +595,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
self.JoinLines()
|
self.JoinLines()
|
||||||
self.TouchBuffer()
|
self.TouchBuffer()
|
||||||
else:
|
else:
|
||||||
wxBell()
|
wx.Bell()
|
||||||
|
|
||||||
def Delete(self, event):
|
def Delete(self, event):
|
||||||
t = self.GetTextLine(self.cy)
|
t = self.GetTextLine(self.cy)
|
||||||
@@ -625,7 +637,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
|
|
||||||
def FindSelection(self):
|
def FindSelection(self):
|
||||||
if self.SelectEnd is None or self.SelectBegin is None:
|
if self.SelectEnd is None or self.SelectBegin is None:
|
||||||
wxBell()
|
wx.Bell()
|
||||||
return None
|
return None
|
||||||
(begin, end) = self.NormalizedSelect()
|
(begin, end) = self.NormalizedSelect()
|
||||||
(bRow, bCol) = begin
|
(bRow, bCol) = begin
|
||||||
@@ -654,11 +666,11 @@ class wxEditor(wxScrolledWindow):
|
|||||||
self.SelectOff()
|
self.SelectOff()
|
||||||
|
|
||||||
def CopyToClipboard(self, linesOfText):
|
def CopyToClipboard(self, linesOfText):
|
||||||
do = wxTextDataObject()
|
do = wx.TextDataObject()
|
||||||
do.SetText(os.linesep.join(linesOfText))
|
do.SetText(os.linesep.join(linesOfText))
|
||||||
wxTheClipboard.Open()
|
wx.TheClipboard.Open()
|
||||||
wxTheClipboard.SetData(do)
|
wx.TheClipboard.SetData(do)
|
||||||
wxTheClipboard.Close()
|
wx.TheClipboard.Close()
|
||||||
|
|
||||||
def SingleLineCopy(self, Row, bCol, eCol):
|
def SingleLineCopy(self, Row, bCol, eCol):
|
||||||
Line = self.GetTextLine(Row)
|
Line = self.GetTextLine(Row)
|
||||||
@@ -700,17 +712,17 @@ class wxEditor(wxScrolledWindow):
|
|||||||
self.lines[bRow:eRow + 1] = [ModLine]
|
self.lines[bRow:eRow + 1] = [ModLine]
|
||||||
|
|
||||||
def OnPaste(self, event):
|
def OnPaste(self, event):
|
||||||
do = wxTextDataObject()
|
do = wx.TextDataObject()
|
||||||
wxTheClipboard.Open()
|
wx.TheClipboard.Open()
|
||||||
success = wxTheClipboard.GetData(do)
|
success = wx.TheClipboard.GetData(do)
|
||||||
wxTheClipboard.Close()
|
wx.TheClipboard.Close()
|
||||||
if success:
|
if success:
|
||||||
pastedLines = LineSplitter(do.GetText())
|
pastedLines = LineSplitter(do.GetText())
|
||||||
else:
|
else:
|
||||||
wxBell()
|
wx.Bell()
|
||||||
return
|
return
|
||||||
if len(pastedLines) == 0:
|
if len(pastedLines) == 0:
|
||||||
wxBell()
|
wx.Bell()
|
||||||
return
|
return
|
||||||
elif len(pastedLines) == 1:
|
elif len(pastedLines) == 1:
|
||||||
self.SingleLineInsert(pastedLines[0])
|
self.SingleLineInsert(pastedLines[0])
|
||||||
@@ -797,18 +809,18 @@ class wxEditor(wxScrolledWindow):
|
|||||||
#-------------- Key handler mapping tables
|
#-------------- Key handler mapping tables
|
||||||
|
|
||||||
def SetMoveSpecialFuncs(self, action):
|
def SetMoveSpecialFuncs(self, action):
|
||||||
action[WXK_DOWN] = self.MoveDown
|
action[wx.WXK_DOWN] = self.MoveDown
|
||||||
action[WXK_UP] = self.MoveUp
|
action[wx.WXK_UP] = self.MoveUp
|
||||||
action[WXK_LEFT] = self.MoveLeft
|
action[wx.WXK_LEFT] = self.MoveLeft
|
||||||
action[WXK_RIGHT] = self.MoveRight
|
action[wx.WXK_RIGHT] = self.MoveRight
|
||||||
action[WXK_NEXT] = self.MovePageDown
|
action[wx.WXK_NEXT] = self.MovePageDown
|
||||||
action[WXK_PRIOR] = self.MovePageUp
|
action[wx.WXK_PRIOR] = self.MovePageUp
|
||||||
action[WXK_HOME] = self.MoveHome
|
action[wx.WXK_HOME] = self.MoveHome
|
||||||
action[WXK_END] = self.MoveEnd
|
action[wx.WXK_END] = self.MoveEnd
|
||||||
|
|
||||||
def SetMoveSpecialControlFuncs(self, action):
|
def SetMoveSpecialControlFuncs(self, action):
|
||||||
action[WXK_HOME] = self.MoveStartOfFile
|
action[wx.WXK_HOME] = self.MoveStartOfFile
|
||||||
action[WXK_END] = self.MoveEndOfFile
|
action[wx.WXK_END] = self.MoveEndOfFile
|
||||||
|
|
||||||
def SetAltFuncs(self, action):
|
def SetAltFuncs(self, action):
|
||||||
# subclass implements
|
# subclass implements
|
||||||
@@ -821,18 +833,18 @@ class wxEditor(wxScrolledWindow):
|
|||||||
action['x'] = self.OnCutSelection
|
action['x'] = self.OnCutSelection
|
||||||
|
|
||||||
def SetSpecialControlFuncs(self, action):
|
def SetSpecialControlFuncs(self, action):
|
||||||
action[WXK_INSERT] = self.OnCopySelection
|
action[wx.WXK_INSERT] = self.OnCopySelection
|
||||||
|
|
||||||
def SetShiftFuncs(self, action):
|
def SetShiftFuncs(self, action):
|
||||||
action[WXK_DELETE] = self.OnCutSelection
|
action[wx.WXK_DELETE] = self.OnCutSelection
|
||||||
action[WXK_INSERT] = self.OnPaste
|
action[wx.WXK_INSERT] = self.OnPaste
|
||||||
|
|
||||||
def SetSpecialFuncs(self, action):
|
def SetSpecialFuncs(self, action):
|
||||||
action[WXK_BACK] = self.BackSpace
|
action[wx.WXK_BACK] = self.BackSpace
|
||||||
action[WXK_DELETE] = self.Delete
|
action[wx.WXK_DELETE] = self.Delete
|
||||||
action[WXK_RETURN] = self.BreakLine
|
action[wx.WXK_RETURN] = self.BreakLine
|
||||||
action[WXK_ESCAPE] = self.Escape
|
action[wx.WXK_ESCAPE] = self.Escape
|
||||||
action[WXK_TAB] = self.TabKey
|
action[wx.WXK_TAB] = self.TabKey
|
||||||
|
|
||||||
##-------------- Logic for key handlers
|
##-------------- Logic for key handlers
|
||||||
|
|
||||||
@@ -886,7 +898,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
if not self.Dispatch(MappingFunc, key, event):
|
if not self.Dispatch(MappingFunc, key, event):
|
||||||
wxBell()
|
wx.Bell()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def ControlKey(self, event, key):
|
def ControlKey(self, event, key):
|
||||||
@@ -899,7 +911,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
if not event.ControlDown():
|
if not event.ControlDown():
|
||||||
return False
|
return False
|
||||||
if not self.Dispatch(self.SetSpecialControlFuncs, key, event):
|
if not self.Dispatch(self.SetSpecialControlFuncs, key, event):
|
||||||
wxBell()
|
wx.Bell()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def ShiftKey(self, event, key):
|
def ShiftKey(self, event, key):
|
||||||
@@ -915,7 +927,7 @@ class wxEditor(wxScrolledWindow):
|
|||||||
if (key>31) and (key<256):
|
if (key>31) and (key<256):
|
||||||
self.InsertChar(chr(key))
|
self.InsertChar(chr(key))
|
||||||
else:
|
else:
|
||||||
wxBell()
|
wx.Bell()
|
||||||
return
|
return
|
||||||
self.UpdateView()
|
self.UpdateView()
|
||||||
self.AdjustScrollbars()
|
self.AdjustScrollbars()
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
|
|
||||||
# images converted with wxPython's img2py.py tool
|
# images converted with wxPython's img2py.py tool
|
||||||
|
|
||||||
from wxPython.wx import wxImageFromStream, wxBitmapFromImage
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
#
|
||||||
|
|
||||||
import cStringIO
|
import cStringIO
|
||||||
|
import wx
|
||||||
|
|
||||||
##----------- Common Functions
|
##----------- Common Functions
|
||||||
|
|
||||||
def GetBitmap(ImageData):
|
def GetBitmap(ImageData):
|
||||||
return wxBitmapFromImage(GetImage(ImageData))
|
return wx.BitmapFromImage(GetImage(ImageData))
|
||||||
|
|
||||||
def GetImage(ImageData):
|
def GetImage(ImageData):
|
||||||
stream = cStringIO.StringIO(ImageData)
|
stream = cStringIO.StringIO(ImageData)
|
||||||
return wxImageFromStream(stream)
|
return wx.ImageFromStream(stream)
|
||||||
|
|
||||||
##----------- Image Data
|
##----------- Image Data
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
True = 1
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
False = 0
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
#
|
||||||
|
|
||||||
def RestOfLine(sx, width, data, bool):
|
def RestOfLine(sx, width, data, bool):
|
||||||
if len(data) == 0 and sx == 0:
|
if len(data) == 0 and sx == 0:
|
||||||
|
|||||||
@@ -11,6 +11,10 @@
|
|||||||
# Copyright: (c) 2003 by db-X Corporation
|
# Copyright: (c) 2003 by db-X Corporation
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
# 12/02/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Updated for 2.5 compatability.
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
A module that allows multiple handlers to respond to single wxWindows
|
A module that allows multiple handlers to respond to single wxWindows
|
||||||
@@ -33,8 +37,8 @@ programmer to declare or track control ids or parent containers:
|
|||||||
This module is Python 2.1+ compatible.
|
This module is Python 2.1+ compatible.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from wxPython import wx
|
import wx
|
||||||
import pubsub
|
import pubsub # publish / subscribe library
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -84,9 +88,11 @@ class EventManager:
|
|||||||
# the natural way of doing things.)
|
# the natural way of doing things.)
|
||||||
if source is not None:
|
if source is not None:
|
||||||
id = source.GetId()
|
id = source.GetId()
|
||||||
|
|
||||||
if win is None:
|
if win is None:
|
||||||
# Some widgets do not function as their own windows.
|
# Some widgets do not function as their own windows.
|
||||||
win = self._determineWindow(source)
|
win = self._determineWindow(source)
|
||||||
|
|
||||||
topic = (event, win, id)
|
topic = (event, win, id)
|
||||||
|
|
||||||
# Create an adapter from the PS system back to wxEvents, and
|
# Create an adapter from the PS system back to wxEvents, and
|
||||||
@@ -143,9 +149,11 @@ class EventManager:
|
|||||||
"""
|
"""
|
||||||
win = self._determineWindow(win)
|
win = self._determineWindow(win)
|
||||||
topics = self.__getTopics(win)
|
topics = self.__getTopics(win)
|
||||||
|
|
||||||
if topics:
|
if topics:
|
||||||
for aTopic in topics:
|
for aTopic in topics:
|
||||||
self.__deregisterTopic(aTopic)
|
self.__deregisterTopic(aTopic)
|
||||||
|
|
||||||
del self.windowTopicLookup[win]
|
del self.windowTopicLookup[win]
|
||||||
|
|
||||||
|
|
||||||
@@ -160,13 +168,16 @@ class EventManager:
|
|||||||
|
|
||||||
for topic in topicList:
|
for topic in topicList:
|
||||||
topicDict = self.messageAdapterDict[topic]
|
topicDict = self.messageAdapterDict[topic]
|
||||||
|
|
||||||
if topicDict.has_key(listener):
|
if topicDict.has_key(listener):
|
||||||
topicDict[listener].Destroy()
|
topicDict[listener].Destroy()
|
||||||
del topicDict[listener]
|
del topicDict[listener]
|
||||||
|
|
||||||
if len(topicDict) == 0:
|
if len(topicDict) == 0:
|
||||||
self.eventAdapterDict[topic].Destroy()
|
self.eventAdapterDict[topic].Destroy()
|
||||||
del self.eventAdapterDict[topic]
|
del self.eventAdapterDict[topic]
|
||||||
del self.messageAdapterDict[topic]
|
del self.messageAdapterDict[topic]
|
||||||
|
|
||||||
del self.listenerTopicLookup[listener]
|
del self.listenerTopicLookup[listener]
|
||||||
|
|
||||||
|
|
||||||
@@ -211,8 +222,8 @@ class EventManager:
|
|||||||
name = aWin.GetClassName()
|
name = aWin.GetClassName()
|
||||||
i = id(aWin)
|
i = id(aWin)
|
||||||
return '%s #%d' % (name, i)
|
return '%s #%d' % (name, i)
|
||||||
except wx.wxPyDeadObjectError:
|
except wx.PyDeadObjectError:
|
||||||
return '(dead wxObject)'
|
return '(dead wx.Object)'
|
||||||
|
|
||||||
|
|
||||||
def __topicString(self, aTopic):
|
def __topicString(self, aTopic):
|
||||||
@@ -239,8 +250,10 @@ class EventManager:
|
|||||||
# This topic isn't valid. Probably because it was deleted
|
# This topic isn't valid. Probably because it was deleted
|
||||||
# by listener.
|
# by listener.
|
||||||
return
|
return
|
||||||
|
|
||||||
for messageAdapter in messageAdapterList:
|
for messageAdapter in messageAdapterList:
|
||||||
messageAdapter.Destroy()
|
messageAdapter.Destroy()
|
||||||
|
|
||||||
self.eventAdapterDict[aTopic].Destroy()
|
self.eventAdapterDict[aTopic].Destroy()
|
||||||
del self.messageAdapterDict[aTopic]
|
del self.messageAdapterDict[aTopic]
|
||||||
del self.eventAdapterDict[aTopic]
|
del self.eventAdapterDict[aTopic]
|
||||||
@@ -249,6 +262,7 @@ class EventManager:
|
|||||||
def __getTopics(self, win=None):
|
def __getTopics(self, win=None):
|
||||||
if win is None:
|
if win is None:
|
||||||
return self.messageAdapterDict.keys()
|
return self.messageAdapterDict.keys()
|
||||||
|
|
||||||
if win is not None:
|
if win is not None:
|
||||||
try:
|
try:
|
||||||
return self.windowTopicLookup[win]
|
return self.windowTopicLookup[win]
|
||||||
@@ -284,7 +298,7 @@ class EventManager:
|
|||||||
discovered, the implementation can be changed to a dictionary
|
discovered, the implementation can be changed to a dictionary
|
||||||
lookup along the lines of class : function-to-get-window.
|
lookup along the lines of class : function-to-get-window.
|
||||||
"""
|
"""
|
||||||
if isinstance(aComponent, wx.wxMenuItem):
|
if isinstance(aComponent, wx.MenuItem):
|
||||||
return aComponent.GetMenu()
|
return aComponent.GetMenu()
|
||||||
else:
|
else:
|
||||||
return aComponent
|
return aComponent
|
||||||
@@ -429,7 +443,7 @@ class EventAdapter:
|
|||||||
try:
|
try:
|
||||||
if not self.disconnect():
|
if not self.disconnect():
|
||||||
print 'disconnect failed'
|
print 'disconnect failed'
|
||||||
except wx.wxPyDeadObjectError:
|
except wx.PyDeadObjectError:
|
||||||
print 'disconnect failed: dead object' ##????
|
print 'disconnect failed: dead object' ##????
|
||||||
|
|
||||||
|
|
||||||
@@ -481,12 +495,11 @@ eventManager = EventManager()
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from wxPython.wx import wxPySimpleApp, wxFrame, wxToggleButton, wxBoxSizer, wxHORIZONTAL, EVT_MOTION, EVT_LEFT_DOWN, EVT_TOGGLEBUTTON, wxALL
|
app = wx.PySimpleApp()
|
||||||
app = wxPySimpleApp()
|
frame = wx.Frame(None, -1, 'Event Test', size=(300,300))
|
||||||
frame = wxFrame(None, -1, 'Event Test', size=(300,300))
|
button = wx.ToggleButton(frame, -1, 'Listen for Mouse Events')
|
||||||
button = wxToggleButton(frame, -1, 'Listen for Mouse Events')
|
sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
sizer = wxBoxSizer(wxHORIZONTAL)
|
sizer.Add(button, 0, 0 | wx.ALL, 10)
|
||||||
sizer.Add(button, 0, 0 | wxALL, 10)
|
|
||||||
frame.SetAutoLayout(1)
|
frame.SetAutoLayout(1)
|
||||||
frame.SetSizer(sizer)
|
frame.SetSizer(sizer)
|
||||||
|
|
||||||
@@ -502,16 +515,16 @@ if __name__ == '__main__':
|
|||||||
# Turn the output of mouse events on and off
|
# Turn the output of mouse events on and off
|
||||||
if event.IsChecked():
|
if event.IsChecked():
|
||||||
print '\nEnabling mouse events...'
|
print '\nEnabling mouse events...'
|
||||||
eventManager.Register(printEvent, EVT_MOTION, frame)
|
eventManager.Register(printEvent, wx.EVT_MOTION, frame)
|
||||||
eventManager.Register(printEvent, EVT_LEFT_DOWN, frame)
|
eventManager.Register(printEvent, wx.EVT_LEFT_DOWN, frame)
|
||||||
else:
|
else:
|
||||||
print '\nDisabling mouse events...'
|
print '\nDisabling mouse events...'
|
||||||
eventManager.DeregisterWindow(frame)
|
eventManager.DeregisterWindow(frame)
|
||||||
|
|
||||||
# Send togglebutton events to both the on/off code as well
|
# Send togglebutton events to both the on/off code as well
|
||||||
# as the function that prints to stdout.
|
# as the function that prints to stdout.
|
||||||
eventManager.Register(printEvent, EVT_TOGGLEBUTTON, button)
|
eventManager.Register(printEvent, wx.EVT_TOGGLEBUTTON, button)
|
||||||
eventManager.Register(enableFrameEvents, EVT_TOGGLEBUTTON, button)
|
eventManager.Register(enableFrameEvents, wx.EVT_TOGGLEBUTTON, button)
|
||||||
|
|
||||||
frame.CenterOnScreen()
|
frame.CenterOnScreen()
|
||||||
frame.Show(1)
|
frame.Show(1)
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
# 12/02/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Updated for 2.5 compatability.
|
||||||
|
#
|
||||||
|
|
||||||
"""<font weight="bold" size="16">FancyText</font> -- <font style="italic" size="16">methods for rendering XML specified text</font>
|
"""<font weight="bold" size="16">FancyText</font> -- <font style="italic" size="16">methods for rendering XML specified text</font>
|
||||||
<font family="swiss" size="12">
|
<font family="swiss" size="12">
|
||||||
This module exports four main methods::
|
This module exports four main methods::
|
||||||
@@ -34,11 +39,14 @@ We can use doctest/guitest to display this string in all its marked up glory.
|
|||||||
|
|
||||||
</font></font>
|
</font></font>
|
||||||
The End"""
|
The End"""
|
||||||
|
|
||||||
# Copyright 2001-2003 Timothy Hochberg
|
# Copyright 2001-2003 Timothy Hochberg
|
||||||
# Use as you see fit. No warantees, I cannot be help responsible, etc.
|
# Use as you see fit. No warantees, I cannot be held responsible, etc.
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import math
|
import math
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
import xml.parsers.expat
|
import xml.parsers.expat
|
||||||
|
|
||||||
@@ -395,9 +403,9 @@ renderToDC = RenderToDC
|
|||||||
# Test Driver
|
# Test Driver
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
app = wx.PyApp()
|
app = wx.PySimpleApp()
|
||||||
box = wx.BoxSizer(wx.VERTICAL)
|
box = wx.BoxSizer(wx.VERTICAL)
|
||||||
frame = wx.Frame(wx.NULL, -1, "FancyText demo", wx.DefaultPosition)
|
frame = wx.Frame(None, -1, "FancyText demo", wx.DefaultPosition)
|
||||||
frame.SetBackgroundColour("light grey")
|
frame.SetBackgroundColour("light grey")
|
||||||
sft = StaticFancyText(frame, -1, __doc__)
|
sft = StaticFancyText(frame, -1, __doc__)
|
||||||
box.Add(sft, 1, wx.EXPAND)
|
box.Add(sft, 1, wx.EXPAND)
|
||||||
|
|||||||
@@ -11,13 +11,19 @@
|
|||||||
# Copyright: (c) 2000 by Total Control Software
|
# Copyright: (c) 2000 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 12/02/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 Compatability changes
|
||||||
|
#
|
||||||
|
|
||||||
from wxPython.wx import *
|
import os
|
||||||
import os, types
|
import types
|
||||||
|
|
||||||
|
import wx
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
class FileBrowseButton(wxPanel):
|
class FileBrowseButton(wx.Panel):
|
||||||
""" A control to allow the user to type in a filename
|
""" A control to allow the user to type in a filename
|
||||||
or browse with the standard file dialog to select file
|
or browse with the standard file dialog to select file
|
||||||
|
|
||||||
@@ -40,8 +46,8 @@ class FileBrowseButton(wxPanel):
|
|||||||
browseButton -- pointer to button
|
browseButton -- pointer to button
|
||||||
"""
|
"""
|
||||||
def __init__ (self, parent, id= -1,
|
def __init__ (self, parent, id= -1,
|
||||||
pos = wxDefaultPosition, size = wxDefaultSize,
|
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||||
style = wxTAB_TRAVERSAL,
|
style = wx.TAB_TRAVERSAL,
|
||||||
labelText= "File Entry:",
|
labelText= "File Entry:",
|
||||||
buttonText= "Browse",
|
buttonText= "Browse",
|
||||||
toolTip= "Type filename or click browse to choose file",
|
toolTip= "Type filename or click browse to choose file",
|
||||||
@@ -50,7 +56,7 @@ class FileBrowseButton(wxPanel):
|
|||||||
startDirectory = ".",
|
startDirectory = ".",
|
||||||
initialValue = "",
|
initialValue = "",
|
||||||
fileMask = "*.*",
|
fileMask = "*.*",
|
||||||
fileMode = wxOPEN,
|
fileMode = wx.OPEN,
|
||||||
# callback for when value changes (optional)
|
# callback for when value changes (optional)
|
||||||
changeCallback= lambda x:x
|
changeCallback= lambda x:x
|
||||||
):
|
):
|
||||||
@@ -84,58 +90,57 @@ class FileBrowseButton(wxPanel):
|
|||||||
|
|
||||||
def createDialog( self, parent, id, pos, size, style ):
|
def createDialog( self, parent, id, pos, size, style ):
|
||||||
"""Setup the graphic representation of the dialog"""
|
"""Setup the graphic representation of the dialog"""
|
||||||
wxPanel.__init__ (self, parent, id, pos, size, style)
|
wx.Panel.__init__ (self, parent, id, pos, size, style)
|
||||||
# try to set the background colour
|
# try to set the background colour
|
||||||
try:
|
try:
|
||||||
self.SetBackgroundColour(self._bc)
|
self.SetBackgroundColour(self._bc)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
box = wxBoxSizer(wxHORIZONTAL)
|
box = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
|
|
||||||
self.label = self.createLabel( )
|
self.label = self.createLabel( )
|
||||||
box.Add( self.label, 0, wxCENTER )
|
box.Add( self.label, 0, wx.CENTER )
|
||||||
|
|
||||||
self.textControl = self.createTextControl()
|
self.textControl = self.createTextControl()
|
||||||
box.Add( self.textControl, 1, wxLEFT|wxCENTER, 5)
|
box.Add( self.textControl, 1, wx.LEFT|wx.CENTER, 5)
|
||||||
|
|
||||||
self.browseButton = self.createBrowseButton()
|
self.browseButton = self.createBrowseButton()
|
||||||
box.Add( self.browseButton, 0, wxLEFT|wxCENTER, 5)
|
box.Add( self.browseButton, 0, wx.LEFT|wx.CENTER, 5)
|
||||||
|
|
||||||
# add a border around the whole thing and resize the panel to fit
|
# add a border around the whole thing and resize the panel to fit
|
||||||
outsidebox = wxBoxSizer(wxVERTICAL)
|
outsidebox = wx.BoxSizer(wx.VERTICAL)
|
||||||
outsidebox.Add(box, 1, wxEXPAND|wxALL, 3)
|
outsidebox.Add(box, 1, wx.EXPAND|wx.ALL, 3)
|
||||||
outsidebox.Fit(self)
|
outsidebox.Fit(self)
|
||||||
|
|
||||||
self.SetAutoLayout(True)
|
self.SetAutoLayout(True)
|
||||||
self.SetSizer( outsidebox )
|
self.SetSizer( outsidebox )
|
||||||
self.Layout()
|
self.Layout()
|
||||||
if type( size ) == types.TupleType:
|
if type( size ) == types.TupleType:
|
||||||
size = apply( wxSize, size)
|
size = apply( wx.Size, size)
|
||||||
self.SetDimensions(-1, -1, size.width, size.height, wxSIZE_USE_EXISTING)
|
self.SetDimensions(-1, -1, size.width, size.height, wx.SIZE_USE_EXISTING)
|
||||||
|
|
||||||
# if size.width != -1 or size.height != -1:
|
# if size.width != -1 or size.height != -1:
|
||||||
# self.SetSize(size)
|
# self.SetSize(size)
|
||||||
|
|
||||||
def SetBackgroundColour(self,color):
|
def SetBackgroundColour(self,color):
|
||||||
wxPanel.SetBackgroundColour(self,color)
|
wx.Panel.SetBackgroundColour(self,color)
|
||||||
self.label.SetBackgroundColour(color)
|
self.label.SetBackgroundColour(color)
|
||||||
|
|
||||||
def createLabel( self ):
|
def createLabel( self ):
|
||||||
"""Create the label/caption"""
|
"""Create the label/caption"""
|
||||||
label = wxStaticText(self, -1, self.labelText, style =wxALIGN_RIGHT )
|
label = wx.StaticText(self, -1, self.labelText, style =wx.ALIGN_RIGHT )
|
||||||
font = label.GetFont()
|
font = label.GetFont()
|
||||||
w, h, d, e = self.GetFullTextExtent(self.labelText, font)
|
w, h, d, e = self.GetFullTextExtent(self.labelText, font)
|
||||||
label.SetSize(wxSize(w+5, h))
|
label.SetSize((w+5, h))
|
||||||
return label
|
return label
|
||||||
|
|
||||||
def createTextControl( self):
|
def createTextControl( self):
|
||||||
"""Create the text control"""
|
"""Create the text control"""
|
||||||
ID = wxNewId()
|
textControl = wx.TextCtrl(self, -1)
|
||||||
textControl = wxTextCtrl(self, ID)
|
|
||||||
textControl.SetToolTipString( self.toolTip )
|
textControl.SetToolTipString( self.toolTip )
|
||||||
if self.changeCallback:
|
if self.changeCallback:
|
||||||
EVT_TEXT(textControl, ID, self.OnChanged)
|
textControl.Bind(wx.EVT_TEXT, self.OnChanged)
|
||||||
EVT_COMBOBOX(textControl, ID, self.OnChanged)
|
textControl.Bind(wx.EVT_COMBOBOX, self.OnChanged)
|
||||||
return textControl
|
return textControl
|
||||||
|
|
||||||
def OnChanged(self, evt):
|
def OnChanged(self, evt):
|
||||||
@@ -144,10 +149,9 @@ class FileBrowseButton(wxPanel):
|
|||||||
|
|
||||||
def createBrowseButton( self):
|
def createBrowseButton( self):
|
||||||
"""Create the browse-button control"""
|
"""Create the browse-button control"""
|
||||||
ID = wxNewId()
|
button =wx.Button(self, -1, self.buttonText)
|
||||||
button =wxButton(self, ID, self.buttonText)
|
|
||||||
button.SetToolTipString( self.toolTip )
|
button.SetToolTipString( self.toolTip )
|
||||||
EVT_BUTTON(button, ID, self.OnBrowse)
|
button.Bind(wx.EVT_BUTTON, self.OnBrowse)
|
||||||
return button
|
return button
|
||||||
|
|
||||||
|
|
||||||
@@ -163,9 +167,10 @@ class FileBrowseButton(wxPanel):
|
|||||||
directory = directory [0]
|
directory = directory [0]
|
||||||
else:
|
else:
|
||||||
directory = self.startDirectory
|
directory = self.startDirectory
|
||||||
dlg = wxFileDialog(self, self.dialogTitle, directory, current, self.fileMask, self.fileMode)
|
dlg = wx.FileDialog(self, self.dialogTitle, directory, current,
|
||||||
|
self.fileMask, self.fileMode)
|
||||||
|
|
||||||
if dlg.ShowModal() == wxID_OK:
|
if dlg.ShowModal() == wx.ID_OK:
|
||||||
self.SetValue(dlg.GetPath())
|
self.SetValue(dlg.GetPath())
|
||||||
dlg.Destroy()
|
dlg.Destroy()
|
||||||
|
|
||||||
@@ -210,7 +215,7 @@ class FileBrowseButtonWithHistory( FileBrowseButton ):
|
|||||||
If history is callable it will must return a list used
|
If history is callable it will must return a list used
|
||||||
for the history drop-down
|
for the history drop-down
|
||||||
changeCallback -- as for FileBrowseButton, but with a work-around
|
changeCallback -- as for FileBrowseButton, but with a work-around
|
||||||
for win32 systems which don't appear to create EVT_COMBOBOX
|
for win32 systems which don't appear to create wx.EVT_COMBOBOX
|
||||||
events properly. There is a (slight) chance that this work-around
|
events properly. There is a (slight) chance that this work-around
|
||||||
will cause some systems to create two events for each Combobox
|
will cause some systems to create two events for each Combobox
|
||||||
selection. If you discover this condition, please report it!
|
selection. If you discover this condition, please report it!
|
||||||
@@ -238,13 +243,12 @@ class FileBrowseButtonWithHistory( FileBrowseButton ):
|
|||||||
|
|
||||||
def createTextControl( self):
|
def createTextControl( self):
|
||||||
"""Create the text control"""
|
"""Create the text control"""
|
||||||
ID = wxNewId()
|
textControl = wx.ComboBox(self, -1, style = wx.CB_DROPDOWN )
|
||||||
textControl = wxComboBox(self, ID, style = wxCB_DROPDOWN )
|
|
||||||
textControl.SetToolTipString( self.toolTip )
|
textControl.SetToolTipString( self.toolTip )
|
||||||
EVT_SET_FOCUS(textControl, self.OnSetFocus)
|
textControl.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
|
||||||
if self.changeCallback:
|
if self.changeCallback:
|
||||||
EVT_TEXT(textControl, ID, self.changeCallback)
|
textControl.Bind(wx.EVT_TEXT, self.changeCallback)
|
||||||
EVT_COMBOBOX(textControl, ID, self.changeCallback)
|
textControl.Bind(wx.EVT_COMBOBOX, self.changeCallback)
|
||||||
if self.history:
|
if self.history:
|
||||||
history=self.history
|
history=self.history
|
||||||
self.history=None
|
self.history=None
|
||||||
@@ -298,10 +302,10 @@ class FileBrowseButtonWithHistory( FileBrowseButton ):
|
|||||||
event.Skip()
|
event.Skip()
|
||||||
|
|
||||||
|
|
||||||
if wxPlatform == "__WXMSW__":
|
if wx.Platform == "__WXMSW__":
|
||||||
def SetValue (self, value, callBack=1):
|
def SetValue (self, value, callBack=1):
|
||||||
""" Convenient setting of text control value, works
|
""" Convenient setting of text control value, works
|
||||||
around limitation of wxComboBox """
|
around limitation of wx.ComboBox """
|
||||||
save = self.callCallback
|
save = self.callCallback
|
||||||
self.callCallback = callBack
|
self.callCallback = callBack
|
||||||
self.textControl.SetValue(value)
|
self.textControl.SetValue(value)
|
||||||
@@ -321,15 +325,15 @@ class FileBrowseButtonWithHistory( FileBrowseButton ):
|
|||||||
|
|
||||||
class DirBrowseButton(FileBrowseButton):
|
class DirBrowseButton(FileBrowseButton):
|
||||||
def __init__(self, parent, id = -1,
|
def __init__(self, parent, id = -1,
|
||||||
pos = wxDefaultPosition, size = wxDefaultSize,
|
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||||
style = wxTAB_TRAVERSAL,
|
style = wx.TAB_TRAVERSAL,
|
||||||
labelText = 'Select a directory:',
|
labelText = 'Select a directory:',
|
||||||
buttonText = 'Browse',
|
buttonText = 'Browse',
|
||||||
toolTip = 'Type directory name or browse to select',
|
toolTip = 'Type directory name or browse to select',
|
||||||
dialogTitle = '',
|
dialogTitle = '',
|
||||||
startDirectory = '.',
|
startDirectory = '.',
|
||||||
changeCallback = None,
|
changeCallback = None,
|
||||||
dialogClass = wxDirDialog):
|
dialogClass = wx.DirDialog):
|
||||||
FileBrowseButton.__init__(self, parent, id, pos, size, style,
|
FileBrowseButton.__init__(self, parent, id, pos, size, style,
|
||||||
labelText, buttonText, toolTip,
|
labelText, buttonText, toolTip,
|
||||||
dialogTitle, startDirectory,
|
dialogTitle, startDirectory,
|
||||||
@@ -341,7 +345,7 @@ class DirBrowseButton(FileBrowseButton):
|
|||||||
#
|
#
|
||||||
def OnBrowse(self, ev = None):
|
def OnBrowse(self, ev = None):
|
||||||
dialog = self._dirDialog
|
dialog = self._dirDialog
|
||||||
if dialog.ShowModal() == wxID_OK:
|
if dialog.ShowModal() == wx.ID_OK:
|
||||||
self.SetValue(dialog.GetPath())
|
self.SetValue(dialog.GetPath())
|
||||||
#
|
#
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
@@ -359,17 +363,17 @@ if __name__ == "__main__":
|
|||||||
self.tag = tag
|
self.tag = tag
|
||||||
def __call__( self, event ):
|
def __call__( self, event ):
|
||||||
print self.tag, event.GetString()
|
print self.tag, event.GetString()
|
||||||
class DemoFrame( wxFrame ):
|
class DemoFrame( wx.Frame ):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
wxFrame.__init__(self, parent, 2400, "File entry with browse", size=(500,260) )
|
wx.Frame.__init__(self, parent, -1, "File entry with browse", size=(500,260))
|
||||||
EVT_CLOSE(self, self.OnCloseWindow)
|
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
||||||
panel = wxPanel (self,-1)
|
panel = wx.Panel (self,-1)
|
||||||
innerbox = wxBoxSizer(wxVERTICAL)
|
innerbox = wx.BoxSizer(wx.VERTICAL)
|
||||||
control = FileBrowseButton(
|
control = FileBrowseButton(
|
||||||
panel,
|
panel,
|
||||||
initialValue = "z:\\temp",
|
initialValue = "z:\\temp",
|
||||||
)
|
)
|
||||||
innerbox.Add( control, 0, wxEXPAND )
|
innerbox.Add( control, 0, wx.EXPAND )
|
||||||
middlecontrol = FileBrowseButtonWithHistory(
|
middlecontrol = FileBrowseButtonWithHistory(
|
||||||
panel,
|
panel,
|
||||||
labelText = "With History",
|
labelText = "With History",
|
||||||
@@ -377,7 +381,7 @@ if __name__ == "__main__":
|
|||||||
history = ["c:\\temp", "c:\\tmp", "r:\\temp","z:\\temp"],
|
history = ["c:\\temp", "c:\\tmp", "r:\\temp","z:\\temp"],
|
||||||
changeCallback= SimpleCallback( "With History" ),
|
changeCallback= SimpleCallback( "With History" ),
|
||||||
)
|
)
|
||||||
innerbox.Add( middlecontrol, 0, wxEXPAND )
|
innerbox.Add( middlecontrol, 0, wx.EXPAND )
|
||||||
middlecontrol = FileBrowseButtonWithHistory(
|
middlecontrol = FileBrowseButtonWithHistory(
|
||||||
panel,
|
panel,
|
||||||
labelText = "History callback",
|
labelText = "History callback",
|
||||||
@@ -385,25 +389,25 @@ if __name__ == "__main__":
|
|||||||
history = self.historyCallBack,
|
history = self.historyCallBack,
|
||||||
changeCallback= SimpleCallback( "History callback" ),
|
changeCallback= SimpleCallback( "History callback" ),
|
||||||
)
|
)
|
||||||
innerbox.Add( middlecontrol, 0, wxEXPAND )
|
innerbox.Add( middlecontrol, 0, wx.EXPAND )
|
||||||
self.bottomcontrol = control = FileBrowseButton(
|
self.bottomcontrol = control = FileBrowseButton(
|
||||||
panel,
|
panel,
|
||||||
labelText = "With Callback",
|
labelText = "With Callback",
|
||||||
style = wxSUNKEN_BORDER|wxCLIP_CHILDREN ,
|
style = wx.SUNKEN_BORDER|wx.CLIP_CHILDREN ,
|
||||||
changeCallback= SimpleCallback( "With Callback" ),
|
changeCallback= SimpleCallback( "With Callback" ),
|
||||||
)
|
)
|
||||||
innerbox.Add( control, 0, wxEXPAND)
|
innerbox.Add( control, 0, wx.EXPAND)
|
||||||
self.bottommostcontrol = control = DirBrowseButton(
|
self.bottommostcontrol = control = DirBrowseButton(
|
||||||
panel,
|
panel,
|
||||||
labelText = "Simple dir browse button",
|
labelText = "Simple dir browse button",
|
||||||
style = wxSUNKEN_BORDER|wxCLIP_CHILDREN)
|
style = wx.SUNKEN_BORDER|wx.CLIP_CHILDREN)
|
||||||
innerbox.Add( control, 0, wxEXPAND)
|
innerbox.Add( control, 0, wx.EXPAND)
|
||||||
ID = wxNewId()
|
ID = wx.NewId()
|
||||||
innerbox.Add( wxButton( panel, ID,"Change Label", ), 1, wxEXPAND)
|
innerbox.Add( wx.Button( panel, ID,"Change Label", ), 1, wx.EXPAND)
|
||||||
EVT_BUTTON( self, ID, self.OnChangeLabel )
|
self.Bind(wx.EVT_BUTTON, self.OnChangeLabel , id=ID)
|
||||||
ID = wxNewId()
|
ID = wx.NewId()
|
||||||
innerbox.Add( wxButton( panel, ID,"Change Value", ), 1, wxEXPAND)
|
innerbox.Add( wx.Button( panel, ID,"Change Value", ), 1, wx.EXPAND)
|
||||||
EVT_BUTTON( self, ID, self.OnChangeValue )
|
self.Bind(wx.EVT_BUTTON, self.OnChangeValue, id=ID )
|
||||||
panel.SetAutoLayout(True)
|
panel.SetAutoLayout(True)
|
||||||
panel.SetSizer( innerbox )
|
panel.SetSizer( innerbox )
|
||||||
self.history={"c:\\temp":1, "c:\\tmp":1, "r:\\temp":1,"z:\\temp":1}
|
self.history={"c:\\temp":1, "c:\\tmp":1, "r:\\temp":1,"z:\\temp":1}
|
||||||
@@ -426,13 +430,10 @@ if __name__ == "__main__":
|
|||||||
def OnCloseWindow(self, event):
|
def OnCloseWindow(self, event):
|
||||||
self.Destroy()
|
self.Destroy()
|
||||||
|
|
||||||
class DemoApp(wxApp):
|
class DemoApp(wx.App):
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
wxImage_AddHandler(wxJPEGHandler())
|
wx.InitAllImageHandlers()
|
||||||
wxImage_AddHandler(wxPNGHandler())
|
frame = DemoFrame(None)
|
||||||
wxImage_AddHandler(wxGIFHandler())
|
|
||||||
frame = DemoFrame(NULL)
|
|
||||||
#frame = RulesPanel(NULL )
|
|
||||||
frame.Show(True)
|
frame.Show(True)
|
||||||
self.SetTopWindow(frame)
|
self.SetTopWindow(frame)
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -6,6 +6,15 @@
|
|||||||
#
|
#
|
||||||
# Created: 10/4/99
|
# Created: 10/4/99
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
# 12/02/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 Compatability changes
|
||||||
|
#
|
||||||
|
# 12/07/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Added deprecation warning.
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
NOTE: This module is *not* supported in any way. Use it however you
|
NOTE: This module is *not* supported in any way. Use it however you
|
||||||
wish, but be warned that dealing with any consequences is
|
wish, but be warned that dealing with any consequences is
|
||||||
@@ -13,20 +22,34 @@ NOTE: This module is *not* supported in any way. Use it however you
|
|||||||
--Robin
|
--Robin
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from wxPython.wx import *
|
import warnings
|
||||||
|
import wx
|
||||||
|
|
||||||
if wxPlatform == '__WXGTK__':
|
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
|
# For wxGTK all we have to do is set the wxTB_DOCKABLE flag
|
||||||
#
|
#
|
||||||
class wxFloatBar(wxToolBar):
|
class wxFloatBar(wx.ToolBar):
|
||||||
def __init__(self, parent, ID,
|
def __init__(self, parent, ID,
|
||||||
pos = wxDefaultPosition,
|
pos = wx.DefaultPosition,
|
||||||
size = wxDefaultSize,
|
size = wx.DefaultSize,
|
||||||
style = 0,
|
style = 0,
|
||||||
name = 'toolbar'):
|
name = 'toolbar'):
|
||||||
wxToolBar.__init__(self, parent, ID, pos, size,
|
wx.ToolBar.__init__(self, parent, ID, pos, size,
|
||||||
style|wxTB_DOCKABLE, name)
|
style|wx.TB_DOCKABLE, name)
|
||||||
|
|
||||||
# these other methods just become no-ops
|
# these other methods just become no-ops
|
||||||
def SetFloatable(self, float):
|
def SetFloatable(self, float):
|
||||||
@@ -45,7 +68,7 @@ if wxPlatform == '__WXGTK__':
|
|||||||
else:
|
else:
|
||||||
_DOCKTHRESHOLD = 25
|
_DOCKTHRESHOLD = 25
|
||||||
|
|
||||||
class wxFloatBar(wxToolBar):
|
class wxFloatBar(wx.ToolBar):
|
||||||
"""
|
"""
|
||||||
wxToolBar subclass which can be dragged off its frame and later
|
wxToolBar subclass which can be dragged off its frame and later
|
||||||
replaced there. Drag on the toolbar to release it, close it like
|
replaced there. Drag on the toolbar to release it, close it like
|
||||||
@@ -62,7 +85,7 @@ else:
|
|||||||
user actions (i.e., dragging) can float the toolbar or not.
|
user actions (i.e., dragging) can float the toolbar or not.
|
||||||
"""
|
"""
|
||||||
args = (self,) + _args
|
args = (self,) + _args
|
||||||
apply(wxToolBar.__init__, args, _kwargs)
|
apply(wx.ToolBar.__init__, args, _kwargs)
|
||||||
if _kwargs.has_key('floatable'):
|
if _kwargs.has_key('floatable'):
|
||||||
self.floatable = _kwargs['floatable']
|
self.floatable = _kwargs['floatable']
|
||||||
assert type(self.floatable) == type(0)
|
assert type(self.floatable) == type(0)
|
||||||
@@ -74,8 +97,8 @@ else:
|
|||||||
assert type(self.title) == type("")
|
assert type(self.title) == type("")
|
||||||
else:
|
else:
|
||||||
self.title = ""
|
self.title = ""
|
||||||
EVT_MOUSE_EVENTS(self, self.OnMouse)
|
self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
|
||||||
self.parentframe = wxPyTypeCast(args[1], 'wxFrame')
|
self.parentframe = args[1]
|
||||||
|
|
||||||
|
|
||||||
def IsFloatable(self):
|
def IsFloatable(self):
|
||||||
@@ -86,9 +109,9 @@ else:
|
|||||||
self.floatable = float
|
self.floatable = float
|
||||||
#Find the size of a title bar.
|
#Find the size of a title bar.
|
||||||
if not hasattr(self, 'titleheight'):
|
if not hasattr(self, 'titleheight'):
|
||||||
test = wxMiniFrame(NULL, -1, "TEST")
|
test = wx.MiniFrame(None, -1, "TEST")
|
||||||
test.SetClientSize(wxSize(0,0))
|
test.SetClientSize((0,0))
|
||||||
self.titleheight = test.GetSizeTuple()[1]
|
self.titleheight = test.GetSize()[1]
|
||||||
test.Destroy()
|
test.Destroy()
|
||||||
|
|
||||||
|
|
||||||
@@ -97,7 +120,7 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
def Realize(self):
|
def Realize(self):
|
||||||
wxToolBar.Realize(self)
|
wx.ToolBar.Realize(self)
|
||||||
|
|
||||||
|
|
||||||
def GetTitle(self):
|
def GetTitle(self):
|
||||||
@@ -119,7 +142,7 @@ else:
|
|||||||
## if hasattr(self, 'parentframe'):
|
## if hasattr(self, 'parentframe'):
|
||||||
## return self.parentframe
|
## return self.parentframe
|
||||||
## else:
|
## else:
|
||||||
## return wxPyTypeCast(self.GetParent(), 'wxFrame')
|
## return (self.GetParent())
|
||||||
|
|
||||||
|
|
||||||
## def SetHome(self, frame):
|
## def SetHome(self, frame):
|
||||||
@@ -133,7 +156,7 @@ else:
|
|||||||
## self.parentframe = frame
|
## self.parentframe = frame
|
||||||
## self.floatframe.Reparent(frame)
|
## self.floatframe.Reparent(frame)
|
||||||
## else:
|
## else:
|
||||||
## parent = wxPyTypeCast(self.GetParent(), 'wxFrame')
|
## parent = self.GetParent()
|
||||||
## self.Reparent(frame)
|
## self.Reparent(frame)
|
||||||
## parent.SetToolBar(None)
|
## parent.SetToolBar(None)
|
||||||
## size = parent.GetSize()
|
## size = parent.GetSize()
|
||||||
@@ -148,37 +171,37 @@ else:
|
|||||||
def Float(self, bool):
|
def Float(self, bool):
|
||||||
"Floats or docks the toolbar programmatically."
|
"Floats or docks the toolbar programmatically."
|
||||||
if bool:
|
if bool:
|
||||||
self.parentframe = wxPyTypeCast(self.GetParent(), 'wxFrame')
|
self.parentframe = self.GetParent()
|
||||||
print self.title
|
print self.title
|
||||||
if self.title:
|
if self.title:
|
||||||
useStyle = wxDEFAULT_FRAME_STYLE
|
useStyle = wx.DEFAULT_FRAME_STYLE
|
||||||
else:
|
else:
|
||||||
useStyle = wxTHICK_FRAME
|
useStyle = wx.THICK_FRAME
|
||||||
self.floatframe = wxMiniFrame(self.parentframe, -1, self.title,
|
self.floatframe = wx.MiniFrame(self.parentframe, -1, self.title,
|
||||||
style = useStyle)
|
style = useStyle)
|
||||||
|
|
||||||
self.Reparent(self.floatframe)
|
self.Reparent(self.floatframe)
|
||||||
self.parentframe.SetToolBar(None)
|
self.parentframe.SetToolBar(None)
|
||||||
self.floating = 1
|
self.floating = 1
|
||||||
psize = self.parentframe.GetSize()
|
psize = self.parentframe.GetSize()
|
||||||
self.parentframe.SetSize(wxSize(0,0))
|
self.parentframe.SetSize((0,0))
|
||||||
self.parentframe.SetSize(psize)
|
self.parentframe.SetSize(psize)
|
||||||
self.floatframe.SetToolBar(self)
|
self.floatframe.SetToolBar(self)
|
||||||
self.oldcolor = self.GetBackgroundColour()
|
self.oldcolor = self.GetBackgroundColour()
|
||||||
|
|
||||||
w = psize.width
|
w = psize[0]
|
||||||
h = self.GetSize().height
|
h = self.GetSize()[1]
|
||||||
if self.title:
|
if self.title:
|
||||||
h = h + self.titleheight
|
h = h + self.titleheight
|
||||||
self.floatframe.SetSize(wxSize(w,h))
|
self.floatframe.SetSize((w,h))
|
||||||
self.floatframe.SetClientSize(self.GetSize())
|
self.floatframe.SetClientSize(self.GetSize())
|
||||||
newpos = self.parentframe.GetPosition()
|
newpos = self.parentframe.GetPosition()
|
||||||
newpos.y = newpos.y + _DOCKTHRESHOLD * 2
|
newpos.y = newpos.y + _DOCKTHRESHOLD * 2
|
||||||
self.floatframe.SetPosition(newpos)
|
self.floatframe.SetPosition(newpos)
|
||||||
self.floatframe.Show(True)
|
self.floatframe.Show(True)
|
||||||
|
|
||||||
EVT_CLOSE(self.floatframe, self.OnDock)
|
self.floatframe.Bind(wx.EVT_CLOSE, self.OnDock)
|
||||||
#EVT_MOVE(self.floatframe, self.OnMove)
|
#self.floatframe.Bind(wx.EVT_MOVE, self.OnMove)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.Reparent(self.parentframe)
|
self.Reparent(self.parentframe)
|
||||||
@@ -187,7 +210,7 @@ else:
|
|||||||
self.floatframe.SetToolBar(None)
|
self.floatframe.SetToolBar(None)
|
||||||
self.floatframe.Destroy()
|
self.floatframe.Destroy()
|
||||||
size = self.parentframe.GetSize()
|
size = self.parentframe.GetSize()
|
||||||
self.parentframe.SetSize(wxSize(0,0))
|
self.parentframe.SetSize((0,0))
|
||||||
self.parentframe.SetSize(size)
|
self.parentframe.SetSize(size)
|
||||||
self.SetBackgroundColour(self.oldcolor)
|
self.SetBackgroundColour(self.oldcolor)
|
||||||
|
|
||||||
@@ -199,7 +222,7 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
def OnMove(self, e):
|
def OnMove(self, e):
|
||||||
homepos = self.parentframe.ClientToScreen(wxPoint(0,0))
|
homepos = self.parentframe.ClientToScreen((0,0))
|
||||||
floatpos = self.floatframe.GetPosition()
|
floatpos = self.floatframe.GetPosition()
|
||||||
if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and
|
if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and
|
||||||
abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD):
|
abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD):
|
||||||
@@ -231,7 +254,7 @@ else:
|
|||||||
if e.ButtonUp():
|
if e.ButtonUp():
|
||||||
self.ReleaseMouse()
|
self.ReleaseMouse()
|
||||||
if self.IsFloating():
|
if self.IsFloating():
|
||||||
homepos = self.parentframe.ClientToScreen(wxPoint(0,0))
|
homepos = self.parentframe.ClientToScreen((0,0))
|
||||||
floatpos = self.floatframe.GetPosition()
|
floatpos = self.floatframe.GetPosition()
|
||||||
if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and
|
if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and
|
||||||
abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD):
|
abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD):
|
||||||
@@ -245,7 +268,7 @@ else:
|
|||||||
else:
|
else:
|
||||||
if hasattr(self, 'oldpos'):
|
if hasattr(self, 'oldpos'):
|
||||||
loc = self.floatframe.GetPosition()
|
loc = self.floatframe.GetPosition()
|
||||||
pt = wxPoint(loc.x - (self.oldpos[0]-e.GetX()), loc.y - (self.oldpos[1]-e.GetY()))
|
pt = (loc.x - (self.oldpos[0]-e.GetX()), loc.y - (self.oldpos[1]-e.GetY()))
|
||||||
self.floatframe.Move(pt)
|
self.floatframe.Move(pt)
|
||||||
|
|
||||||
|
|
||||||
@@ -255,17 +278,17 @@ else:
|
|||||||
if vis:
|
if vis:
|
||||||
if self.parentframe.GetToolBar() == None:
|
if self.parentframe.GetToolBar() == None:
|
||||||
if not hasattr(self, 'nullbar'):
|
if not hasattr(self, 'nullbar'):
|
||||||
self.nullbar = wxToolBar(self.parentframe, -1)
|
self.nullbar = wx.ToolBar(self.parentframe, -1)
|
||||||
print "Adding fauxbar."
|
print "Adding fauxbar."
|
||||||
self.nullbar.Reparent(self.parentframe)
|
self.nullbar.Reparent(self.parentframe)
|
||||||
print "Reparented."
|
print "Reparented."
|
||||||
self.parentframe.SetToolBar(self.nullbar)
|
self.parentframe.SetToolBar(self.nullbar)
|
||||||
print "Set toolbar"
|
print "Set toolbar"
|
||||||
col = wxNamedColour("GREY")
|
col = wx.NamedColour("GREY")
|
||||||
self.nullbar.SetBackgroundColour(col)
|
self.nullbar.SetBackgroundColour(col)
|
||||||
print "Set color"
|
print "Set color"
|
||||||
size = self.parentframe.GetSize()
|
size = self.parentframe.GetSize()
|
||||||
self.parentframe.SetSize(wxSize(0,0))
|
self.parentframe.SetSize((0,0))
|
||||||
self.parentframe.SetSize(size)
|
self.parentframe.SetSize(size)
|
||||||
print "Set size"
|
print "Set size"
|
||||||
else:
|
else:
|
||||||
@@ -276,7 +299,7 @@ else:
|
|||||||
self.nullbar.Reparent(self.floatframe)
|
self.nullbar.Reparent(self.floatframe)
|
||||||
self.parentframe.SetToolBar(None)
|
self.parentframe.SetToolBar(None)
|
||||||
size = self.parentframe.GetSize()
|
size = self.parentframe.GetSize()
|
||||||
self.parentframe.SetSize(wxSize(0,0))
|
self.parentframe.SetSize((0,0))
|
||||||
self.parentframe.SetSize(size)
|
self.parentframe.SetSize(size)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
# 12/07/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 Compatability changes
|
||||||
|
#
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
from wx.lib.evtmgr import eventManager
|
from wx.lib.evtmgr import eventManager
|
||||||
@@ -11,8 +15,8 @@ class FoldOutWindow(wx.PopupWindow):
|
|||||||
self.handlers={}
|
self.handlers={}
|
||||||
self.InitColors()
|
self.InitColors()
|
||||||
self.inWindow=False
|
self.inWindow=False
|
||||||
wx.EVT_ENTER_WINDOW(self,self.evEnter)
|
self.Bind(wx.EVT_ENTER_WINDOW, self.evEnter)
|
||||||
wx.EVT_LEAVE_WINDOW(self,self.evLeave)
|
self.Bind(wx.EVT_LEAVE_WINDOW, self.evLeave)
|
||||||
|
|
||||||
def InitColors(self):
|
def InitColors(self):
|
||||||
faceClr = wx.SystemSettings_GetSystemColour(wx.SYS_COLOUR_WINDOW)
|
faceClr = wx.SystemSettings_GetSystemColour(wx.SYS_COLOUR_WINDOW)
|
||||||
@@ -22,11 +26,13 @@ class FoldOutWindow(wx.PopupWindow):
|
|||||||
id=wx.NewId()
|
id=wx.NewId()
|
||||||
btn=wx.BitmapButton(self,id,bitmap)
|
btn=wx.BitmapButton(self,id,bitmap)
|
||||||
self.sizer.Add(btn, 1, wx.ALIGN_CENTER|wx.ALL|wx.EXPAND, 2)
|
self.sizer.Add(btn, 1, wx.ALIGN_CENTER|wx.ALL|wx.EXPAND, 2)
|
||||||
wx.EVT_BUTTON(self,id,self.OnBtnClick)
|
self.Bind(wx.EVT_BUTTON, self.OnBtnClick, btn)
|
||||||
self.sizer.Fit(self)
|
self.sizer.Fit(self)
|
||||||
self.Layout()
|
self.Layout()
|
||||||
|
|
||||||
if handler:
|
if handler:
|
||||||
self.handlers[id]=handler
|
self.handlers[id]=handler
|
||||||
|
|
||||||
return id
|
return id
|
||||||
|
|
||||||
def Popup(self):
|
def Popup(self):
|
||||||
@@ -35,8 +41,10 @@ class FoldOutWindow(wx.PopupWindow):
|
|||||||
|
|
||||||
def OnBtnClick(self,event):
|
def OnBtnClick(self,event):
|
||||||
id=event.GetEventObject().GetId()
|
id=event.GetEventObject().GetId()
|
||||||
|
|
||||||
if self.handlers.has_key(id):
|
if self.handlers.has_key(id):
|
||||||
self.handlers[id](event)
|
self.handlers[id](event)
|
||||||
|
|
||||||
self.Hide()
|
self.Hide()
|
||||||
self.inWindow=False
|
self.inWindow=False
|
||||||
event.Skip()
|
event.Skip()
|
||||||
@@ -50,6 +58,7 @@ class FoldOutWindow(wx.PopupWindow):
|
|||||||
if self.inWindow:
|
if self.inWindow:
|
||||||
if not self.rect.Inside(self.ClientToScreen(event.GetPosition())):
|
if not self.rect.Inside(self.ClientToScreen(event.GetPosition())):
|
||||||
self.Hide()
|
self.Hide()
|
||||||
|
|
||||||
event.Skip()
|
event.Skip()
|
||||||
|
|
||||||
|
|
||||||
@@ -60,10 +69,12 @@ class FoldOutMenu(wx.BitmapButton):
|
|||||||
def __init__(self,parent,id,bitmap,pos = wx.DefaultPosition,
|
def __init__(self,parent,id,bitmap,pos = wx.DefaultPosition,
|
||||||
size = wx.DefaultSize, style = wx.BU_AUTODRAW,
|
size = wx.DefaultSize, style = wx.BU_AUTODRAW,
|
||||||
validator = wx.DefaultValidator, name = "button"):
|
validator = wx.DefaultValidator, name = "button"):
|
||||||
|
|
||||||
wx.BitmapButton.__init__(self, parent, id, bitmap, pos, size, style,
|
wx.BitmapButton.__init__(self, parent, id, bitmap, pos, size, style,
|
||||||
validator, name)
|
validator, name)
|
||||||
|
|
||||||
self.parent=parent
|
self.parent=parent
|
||||||
wx.EVT_BUTTON(self.parent, self.GetId(), self.click)
|
self.parent.Bind(wx.EVT_BUTTON, self.click, self)
|
||||||
self.popwin=FoldOutWindow(self.parent)
|
self.popwin=FoldOutWindow(self.parent)
|
||||||
|
|
||||||
def AddButton(self,bitmap,handler=None):
|
def AddButton(self,bitmap,handler=None):
|
||||||
|
|||||||
@@ -9,27 +9,31 @@
|
|||||||
# RCS-ID: $Id$
|
# RCS-ID: $Id$
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
# 12/07/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 Compatability changes
|
||||||
|
#
|
||||||
|
|
||||||
from wxPython.wx import *
|
import wx
|
||||||
from wxPython.grid import wxGrid
|
import wx.grid
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# event class and macors
|
# event class and macros
|
||||||
|
#
|
||||||
|
# New style 12/7/03
|
||||||
|
#
|
||||||
|
|
||||||
|
wxEVT_COMMAND_GRID_COL_MOVE = wx.NewEventType()
|
||||||
|
wxEVT_COMMAND_GRID_ROW_MOVE = wx.NewEventType()
|
||||||
|
|
||||||
wxEVT_COMMAND_GRID_COL_MOVE = wxNewEventType()
|
EVT_GRID_COL_MOVE = wx.PyEventBinder(wxEVT_COMMAND_GRID_COL_MOVE, 1)
|
||||||
wxEVT_COMMAND_GRID_ROW_MOVE = wxNewEventType()
|
EVT_GRID_ROW_MOVE = wx.PyEventBinder(wxEVT_COMMAND_GRID_ROW_MOVE, 1)
|
||||||
|
|
||||||
def EVT_GRID_COL_MOVE(win, id, func):
|
#----------------------------------------------------------------------------
|
||||||
win.Connect(id, -1, wxEVT_COMMAND_GRID_COL_MOVE, func)
|
|
||||||
|
|
||||||
def EVT_GRID_ROW_MOVE(win,id,func):
|
class wxGridColMoveEvent(wx.PyCommandEvent):
|
||||||
win.Connect(id, -1, wxEVT_COMMAND_GRID_ROW_MOVE, func)
|
|
||||||
|
|
||||||
|
|
||||||
class wxGridColMoveEvent(wxPyCommandEvent):
|
|
||||||
def __init__(self, id, dCol, bCol):
|
def __init__(self, id, dCol, bCol):
|
||||||
wxPyCommandEvent.__init__(self, id = id)
|
wx.PyCommandEvent.__init__(self, id = id)
|
||||||
self.SetEventType(wxEVT_COMMAND_GRID_COL_MOVE)
|
self.SetEventType(wxEVT_COMMAND_GRID_COL_MOVE)
|
||||||
self.moveColumn = dCol
|
self.moveColumn = dCol
|
||||||
self.beforeColumn = bCol
|
self.beforeColumn = bCol
|
||||||
@@ -41,9 +45,9 @@ class wxGridColMoveEvent(wxPyCommandEvent):
|
|||||||
return self.beforeColumn
|
return self.beforeColumn
|
||||||
|
|
||||||
|
|
||||||
class wxGridRowMoveEvent(wxPyCommandEvent):
|
class wxGridRowMoveEvent(wx.PyCommandEvent):
|
||||||
def __init__(self, id, dRow, bRow):
|
def __init__(self, id, dRow, bRow):
|
||||||
wxPyCommandEvent.__init__(self,id = id)
|
wx.PyCommandEvent.__init__(self,id = id)
|
||||||
self.SetEventType(wxEVT_COMMAND_GRID_ROW_MOVE)
|
self.SetEventType(wxEVT_COMMAND_GRID_ROW_MOVE)
|
||||||
self.moveRow = dRow
|
self.moveRow = dRow
|
||||||
self.beforeRow = bRow
|
self.beforeRow = bRow
|
||||||
@@ -65,12 +69,14 @@ def _ColToRect(self,col):
|
|||||||
rect = wxRect()
|
rect = wxRect()
|
||||||
rect.height = self.GetColLabelSize()
|
rect.height = self.GetColLabelSize()
|
||||||
rect.width = self.GetColSize(col)
|
rect.width = self.GetColSize(col)
|
||||||
|
|
||||||
for cCol in range(0,col):
|
for cCol in range(0,col):
|
||||||
rect.x += self.GetColSize(cCol)
|
rect.x += self.GetColSize(cCol)
|
||||||
|
|
||||||
rect.y = self.GetGridColLabelWindow().GetPosition()[1]
|
rect.y = self.GetGridColLabelWindow().GetPosition()[1]
|
||||||
return rect
|
return rect
|
||||||
|
|
||||||
wxGrid.ColToRect = _ColToRect
|
wx.grid.Grid.ColToRect = _ColToRect
|
||||||
|
|
||||||
|
|
||||||
def _RowToRect(self,row):
|
def _RowToRect(self,row):
|
||||||
@@ -80,25 +86,27 @@ def _RowToRect(self,row):
|
|||||||
rect = wxRect()
|
rect = wxRect()
|
||||||
rect.width = self.GetRowLabelSize()
|
rect.width = self.GetRowLabelSize()
|
||||||
rect.height = self.GetRowSize(row)
|
rect.height = self.GetRowSize(row)
|
||||||
|
|
||||||
for cRow in range(0,row):
|
for cRow in range(0,row):
|
||||||
rect.y += self.GetRowSize(cRow)
|
rect.y += self.GetRowSize(cRow)
|
||||||
|
|
||||||
rect.x = self.GetGridRowLabelWindow().GetPosition()[0]
|
rect.x = self.GetGridRowLabelWindow().GetPosition()[0]
|
||||||
return rect
|
return rect
|
||||||
|
|
||||||
wxGrid.RowToRect = _RowToRect
|
wx.grid.Grid.RowToRect = _RowToRect
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
class ColDragWindow(wxWindow):
|
class ColDragWindow(wx.Window):
|
||||||
def __init__(self,parent,image,dragCol):
|
def __init__(self,parent,image,dragCol):
|
||||||
wxWindow.__init__(self,parent,-1, style=wxSIMPLE_BORDER)
|
wx.Window.__init__(self,parent,-1, style=wx.SIMPLE_BORDER)
|
||||||
self.image = image
|
self.image = image
|
||||||
self.SetSize((self.image.GetWidth(),self.image.GetHeight()))
|
self.SetSize((self.image.GetWidth(),self.image.GetHeight()))
|
||||||
self.ux = parent.GetScrollPixelsPerUnit()[0]
|
self.ux = parent.GetScrollPixelsPerUnit()[0]
|
||||||
self.moveColumn = dragCol
|
self.moveColumn = dragCol
|
||||||
|
|
||||||
EVT_PAINT(self,self.OnPaint)
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||||
|
|
||||||
def DisplayAt(self,pos,y):
|
def DisplayAt(self,pos,y):
|
||||||
x = self.GetPositionTuple()[0]
|
x = self.GetPositionTuple()[0]
|
||||||
@@ -114,20 +122,24 @@ class ColDragWindow(wxWindow):
|
|||||||
parent = self.GetParent()
|
parent = self.GetParent()
|
||||||
sx = parent.GetViewStart()[0] * self.ux
|
sx = parent.GetViewStart()[0] * self.ux
|
||||||
sx -= parent._rlSize
|
sx -= parent._rlSize
|
||||||
x = self.GetPositionTuple()[0]
|
x = self.GetPosition()[0]
|
||||||
w = self.GetSizeTuple()[0]
|
w = self.GetSize()[0]
|
||||||
sCol = parent.XToCol(x + sx)
|
sCol = parent.XToCol(x + sx)
|
||||||
eCol = parent.XToCol(x + w + sx)
|
eCol = parent.XToCol(x + w + sx)
|
||||||
iPos = xPos = xCol = 99999
|
iPos = xPos = xCol = 99999
|
||||||
centerPos = x + sx + (w / 2)
|
centerPos = x + sx + (w / 2)
|
||||||
|
|
||||||
for col in range(sCol,eCol + 1):
|
for col in range(sCol,eCol + 1):
|
||||||
cx = parent.ColToRect(col)[0]
|
cx = parent.ColToRect(col)[0]
|
||||||
|
|
||||||
if abs(cx - centerPos) < iPos:
|
if abs(cx - centerPos) < iPos:
|
||||||
iPos = abs(cx - centerPos)
|
iPos = abs(cx - centerPos)
|
||||||
xCol = col
|
xCol = col
|
||||||
xPos = cx
|
xPos = cx
|
||||||
|
|
||||||
if xCol < 0 or xCol > parent.GetNumberCols():
|
if xCol < 0 or xCol > parent.GetNumberCols():
|
||||||
xCol = parent.GetNumberCols()
|
xCol = parent.GetNumberCols()
|
||||||
|
|
||||||
return (xPos - sx - x,xCol)
|
return (xPos - sx - x,xCol)
|
||||||
|
|
||||||
def GetInsertionColumn(self):
|
def GetInsertionColumn(self):
|
||||||
@@ -137,11 +149,11 @@ class ColDragWindow(wxWindow):
|
|||||||
return self._GetInsertionInfo()[0]
|
return self._GetInsertionInfo()[0]
|
||||||
|
|
||||||
def OnPaint(self,evt):
|
def OnPaint(self,evt):
|
||||||
dc = wxPaintDC(self)
|
dc = wx.PaintDC(self)
|
||||||
w,h = self.GetSize()
|
w,h = self.GetSize()
|
||||||
dc.DrawBitmap(self.image, (0,0))
|
dc.DrawBitmap(self.image, (0,0))
|
||||||
dc.SetPen(wxPen(wxBLACK,1,wxSOLID))
|
dc.SetPen(wx.Pen(wx.BLACK,1,wx.SOLID))
|
||||||
dc.SetBrush(wxTRANSPARENT_BRUSH)
|
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
||||||
dc.DrawRectangle((0,0), (w,h))
|
dc.DrawRectangle((0,0), (w,h))
|
||||||
iPos = self.GetInsertionPos()
|
iPos = self.GetInsertionPos()
|
||||||
dc.DrawLine((iPos,h - 10), (iPos,h))
|
dc.DrawLine((iPos,h - 10), (iPos,h))
|
||||||
@@ -149,18 +161,18 @@ class ColDragWindow(wxWindow):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RowDragWindow(wxWindow):
|
class RowDragWindow(wx.Window):
|
||||||
def __init__(self,parent,image,dragRow):
|
def __init__(self,parent,image,dragRow):
|
||||||
wxWindow.__init__(self,parent,-1, style=wxSIMPLE_BORDER)
|
wx.Window.__init__(self,parent,-1, style=wx.SIMPLE_BORDER)
|
||||||
self.image = image
|
self.image = image
|
||||||
self.SetSize((self.image.GetWidth(),self.image.GetHeight()))
|
self.SetSize((self.image.GetWidth(),self.image.GetHeight()))
|
||||||
self.uy = parent.GetScrollPixelsPerUnit()[1]
|
self.uy = parent.GetScrollPixelsPerUnit()[1]
|
||||||
self.moveRow = dragRow
|
self.moveRow = dragRow
|
||||||
|
|
||||||
EVT_PAINT(self,self.OnPaint)
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||||
|
|
||||||
def DisplayAt(self,x,pos):
|
def DisplayAt(self,x,pos):
|
||||||
y = self.GetPositionTuple()[1]
|
y = self.GetPosition()[1]
|
||||||
if y == pos:
|
if y == pos:
|
||||||
self.Refresh() # Need to display insertion point
|
self.Refresh() # Need to display insertion point
|
||||||
else:
|
else:
|
||||||
@@ -173,20 +185,24 @@ class RowDragWindow(wxWindow):
|
|||||||
parent = self.GetParent()
|
parent = self.GetParent()
|
||||||
sy = parent.GetViewStart()[1] * self.uy
|
sy = parent.GetViewStart()[1] * self.uy
|
||||||
sy -= parent._clSize
|
sy -= parent._clSize
|
||||||
y = self.GetPositionTuple()[1]
|
y = self.GetPosition()[1]
|
||||||
h = self.GetSizeTuple()[1]
|
h = self.GetSize()[1]
|
||||||
sRow = parent.YToRow(y + sy)
|
sRow = parent.YToRow(y + sy)
|
||||||
eRow = parent.YToRow(y + h + sy)
|
eRow = parent.YToRow(y + h + sy)
|
||||||
iPos = yPos = yRow = 99999
|
iPos = yPos = yRow = 99999
|
||||||
centerPos = y + sy + (h / 2)
|
centerPos = y + sy + (h / 2)
|
||||||
|
|
||||||
for row in range(sRow,eRow + 1):
|
for row in range(sRow,eRow + 1):
|
||||||
cy = parent.RowToRect(row)[1]
|
cy = parent.RowToRect(row)[1]
|
||||||
|
|
||||||
if abs(cy - centerPos) < iPos:
|
if abs(cy - centerPos) < iPos:
|
||||||
iPos = abs(cy - centerPos)
|
iPos = abs(cy - centerPos)
|
||||||
yRow = row
|
yRow = row
|
||||||
yPos = cy
|
yPos = cy
|
||||||
|
|
||||||
if yRow < 0 or yRow > parent.GetNumberRows():
|
if yRow < 0 or yRow > parent.GetNumberRows():
|
||||||
yRow = parent.GetNumberRows()
|
yRow = parent.GetNumberRows()
|
||||||
|
|
||||||
return (yPos - sy - y,yRow)
|
return (yPos - sy - y,yRow)
|
||||||
|
|
||||||
def GetInsertionRow(self):
|
def GetInsertionRow(self):
|
||||||
@@ -196,20 +212,20 @@ class RowDragWindow(wxWindow):
|
|||||||
return self._GetInsertionInfo()[0]
|
return self._GetInsertionInfo()[0]
|
||||||
|
|
||||||
def OnPaint(self,evt):
|
def OnPaint(self,evt):
|
||||||
dc = wxPaintDC(self)
|
dc = wx.PaintDC(self)
|
||||||
w,h = self.GetSize()
|
w,h = self.GetSize()
|
||||||
dc.DrawBitmap(self.image, (0,0))
|
dc.DrawBitmap(self.image, (0,0))
|
||||||
dc.SetPen(wxPen(wxBLACK,1,wxSOLID))
|
dc.SetPen(wx.Pen(wx.BLACK,1,wx.SOLID))
|
||||||
dc.SetBrush(wxTRANSPARENT_BRUSH)
|
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
||||||
dc.DrawRectangle((0,0), (w,h))
|
dc.DrawRectangle((0,0), (w,h))
|
||||||
iPos = self.GetInsertionPos()
|
iPos = self.GetInsertionPos()
|
||||||
dc.DrawLine((w - 10,iPos), (w,iPos))
|
dc.DrawLine((w - 10,iPos), (w,iPos))
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxGridColMover(wxEvtHandler):
|
class wxGridColMover(wx.EvtHandler):
|
||||||
def __init__(self,grid):
|
def __init__(self,grid):
|
||||||
wxEvtHandler.__init__(self)
|
wx.EvtHandler.__init__(self)
|
||||||
|
|
||||||
self.grid = grid
|
self.grid = grid
|
||||||
self.grid._rlSize = self.grid.GetRowLabelSize()
|
self.grid._rlSize = self.grid.GetRowLabelSize()
|
||||||
@@ -222,37 +238,48 @@ class wxGridColMover(wxEvtHandler):
|
|||||||
self.didMove = False
|
self.didMove = False
|
||||||
self.isDragging = False
|
self.isDragging = False
|
||||||
|
|
||||||
EVT_MOTION(self,self.OnMouseMove)
|
self.Bind(wx.EVT_MOTION, self.OnMouseMove)
|
||||||
EVT_LEFT_DOWN(self,self.OnPress)
|
self.Bind(wx.EVT_LEFT_DOWN, self.OnPress)
|
||||||
EVT_LEFT_UP(self,self.OnRelease)
|
self.Bind(wx.EVT_LEFT_UP, self.OnRelease)
|
||||||
|
|
||||||
def OnMouseMove(self,evt):
|
def OnMouseMove(self,evt):
|
||||||
if self.isDragging:
|
if self.isDragging:
|
||||||
if abs(self.startX - evt.m_x) >= 3:
|
if abs(self.startX - evt.m_x) >= 3:
|
||||||
self.didMove = True
|
self.didMove = True
|
||||||
sx,y = self.grid.GetViewStart()
|
sx,y = self.grid.GetViewStart()
|
||||||
w,h = self.lwin.GetClientSizeTuple()
|
w,h = self.lwin.GetClientSize()
|
||||||
x = sx * self.ux
|
x = sx * self.ux
|
||||||
|
|
||||||
if (evt.m_x + x) < x:
|
if (evt.m_x + x) < x:
|
||||||
x = evt.m_x + x
|
x = evt.m_x + x
|
||||||
elif evt.m_x > w:
|
elif evt.m_x > w:
|
||||||
x += evt.m_x - w
|
x += evt.m_x - w
|
||||||
|
|
||||||
if x < 1: x = 0
|
if x < 1: x = 0
|
||||||
else: x /= self.ux
|
else: x /= self.ux
|
||||||
|
|
||||||
if x != sx:
|
if x != sx:
|
||||||
if wxPlatform == '__WXMSW__':
|
if wx.Platform == '__WXMSW__':
|
||||||
self.colWin.Show(False)
|
self.colWin.Show(False)
|
||||||
|
|
||||||
self.grid.Scroll(x,y)
|
self.grid.Scroll(x,y)
|
||||||
|
|
||||||
x,y = self.lwin.ClientToScreenXY(evt.m_x,0)
|
x,y = self.lwin.ClientToScreenXY(evt.m_x,0)
|
||||||
x,y = self.grid.ScreenToClientXY(x,y)
|
x,y = self.grid.ScreenToClientXY(x,y)
|
||||||
|
|
||||||
if not self.colWin.IsShown():
|
if not self.colWin.IsShown():
|
||||||
self.colWin.Show(True)
|
self.colWin.Show(True)
|
||||||
|
|
||||||
px = x - self.cellX
|
px = x - self.cellX
|
||||||
|
|
||||||
if px < 0 + self.grid._rlSize: px = 0 + self.grid._rlSize
|
if px < 0 + self.grid._rlSize: px = 0 + self.grid._rlSize
|
||||||
if px > w - self.colWin.GetSizeTuple()[0] + self.grid._rlSize:
|
|
||||||
px = w - self.colWin.GetSizeTuple()[0] + self.grid._rlSize
|
if px > w - self.colWin.GetSize()[0] + self.grid._rlSize:
|
||||||
|
px = w - self.colWin.GetSize()[0] + self.grid._rlSize
|
||||||
|
|
||||||
self.colWin.DisplayAt(px,y)
|
self.colWin.DisplayAt(px,y)
|
||||||
return
|
return
|
||||||
|
|
||||||
evt.Skip()
|
evt.Skip()
|
||||||
|
|
||||||
def OnPress(self,evt):
|
def OnPress(self,evt):
|
||||||
@@ -261,7 +288,8 @@ class wxGridColMover(wxEvtHandler):
|
|||||||
sx -= self.grid._rlSize
|
sx -= self.grid._rlSize
|
||||||
px,py = self.lwin.ClientToScreenXY(evt.m_x,evt.m_y)
|
px,py = self.lwin.ClientToScreenXY(evt.m_x,evt.m_y)
|
||||||
px,py = self.grid.ScreenToClientXY(px,py)
|
px,py = self.grid.ScreenToClientXY(px,py)
|
||||||
if self.grid.XToEdgeOfCol(px + sx) != wxNOT_FOUND:
|
|
||||||
|
if self.grid.XToEdgeOfCol(px + sx) != wx.NOT_FOUND:
|
||||||
evt.Skip()
|
evt.Skip()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -270,7 +298,7 @@ class wxGridColMover(wxEvtHandler):
|
|||||||
col = self.grid.XToCol(px + sx)
|
col = self.grid.XToCol(px + sx)
|
||||||
rect = self.grid.ColToRect(col)
|
rect = self.grid.ColToRect(col)
|
||||||
self.cellX = px + sx - rect.x
|
self.cellX = px + sx - rect.x
|
||||||
size = self.lwin.GetSizeTuple()
|
size = self.lwin.GetSize()
|
||||||
rect.y = 0
|
rect.y = 0
|
||||||
rect.x -= sx + self.grid._rlSize
|
rect.x -= sx + self.grid._rlSize
|
||||||
rect.height = size[1]
|
rect.height = size[1]
|
||||||
@@ -284,37 +312,40 @@ class wxGridColMover(wxEvtHandler):
|
|||||||
self.lwin.ReleaseMouse()
|
self.lwin.ReleaseMouse()
|
||||||
self.colWin.Show(False)
|
self.colWin.Show(False)
|
||||||
self.isDragging = False
|
self.isDragging = False
|
||||||
|
|
||||||
if not self.didMove:
|
if not self.didMove:
|
||||||
px = self.lwin.ClientToScreenXY(self.startX,0)[0]
|
px = self.lwin.ClientToScreenXY(self.startX,0)[0]
|
||||||
px = self.grid.ScreenToClientXY(px,0)[0]
|
px = self.grid.ScreenToClientXY(px,0)[0]
|
||||||
sx = self.grid.GetViewStart()[0] * self.ux
|
sx = self.grid.GetViewStart()[0] * self.ux
|
||||||
sx -= self.grid._rlSize
|
sx -= self.grid._rlSize
|
||||||
col = self.grid.XToCol(px+sx)
|
col = self.grid.XToCol(px+sx)
|
||||||
if col != wxNOT_FOUND:
|
|
||||||
|
if col != wx.NOT_FOUND:
|
||||||
self.grid.SelectCol(col,evt.m_controlDown)
|
self.grid.SelectCol(col,evt.m_controlDown)
|
||||||
|
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
bCol = self.colWin.GetInsertionColumn()
|
bCol = self.colWin.GetInsertionColumn()
|
||||||
dCol = self.colWin.GetMoveColumn()
|
dCol = self.colWin.GetMoveColumn()
|
||||||
wxPostEvent(self,wxGridColMoveEvent(self.grid.GetId(),
|
wx.PostEvent(self,
|
||||||
dCol,bCol))
|
wxGridColMoveEvent(self.grid.GetId(), dCol, bCol))
|
||||||
|
|
||||||
self.colWin.Destroy()
|
self.colWin.Destroy()
|
||||||
evt.Skip()
|
evt.Skip()
|
||||||
|
|
||||||
def _CaptureImage(self,rect):
|
def _CaptureImage(self,rect):
|
||||||
bmp = wxEmptyBitmap(rect.width,rect.height)
|
bmp = wx.EmptyBitmap(rect.width,rect.height)
|
||||||
memdc = wxMemoryDC()
|
memdc = wx.MemoryDC()
|
||||||
memdc.SelectObject(bmp)
|
memdc.SelectObject(bmp)
|
||||||
dc = wxWindowDC(self.lwin)
|
dc = wx.WindowDC(self.lwin)
|
||||||
memdc.Blit((0,0), rect.GetSize(), dc, rect.GetPosition())
|
memdc.Blit((0,0), rect.GetSize(), dc, rect.GetPosition())
|
||||||
memdc.SelectObject(wxNullBitmap)
|
memdc.SelectObject(wx.NullBitmap)
|
||||||
return bmp
|
return bmp
|
||||||
|
|
||||||
|
|
||||||
|
class wxGridRowMover(wx.EvtHandler):
|
||||||
class wxGridRowMover(wxEvtHandler):
|
|
||||||
def __init__(self,grid):
|
def __init__(self,grid):
|
||||||
wxEvtHandler.__init__(self)
|
wx.EvtHandler.__init__(self)
|
||||||
|
|
||||||
self.grid = grid
|
self.grid = grid
|
||||||
self.grid._clSize = self.grid.GetColLabelSize()
|
self.grid._clSize = self.grid.GetColLabelSize()
|
||||||
@@ -327,9 +358,9 @@ class wxGridRowMover(wxEvtHandler):
|
|||||||
self.didMove = False
|
self.didMove = False
|
||||||
self.isDragging = False
|
self.isDragging = False
|
||||||
|
|
||||||
EVT_MOTION(self,self.OnMouseMove)
|
self.Bind(wx.EVT_MOTION, self.OnMouseMove)
|
||||||
EVT_LEFT_DOWN(self,self.OnPress)
|
self.Bind(wx.EVT_LEFT_DOWN, self.OnPress)
|
||||||
EVT_LEFT_UP(self,self.OnRelease)
|
self.Bind(wx.EVT_LEFT_UP, self.OnRelease)
|
||||||
|
|
||||||
def OnMouseMove(self,evt):
|
def OnMouseMove(self,evt):
|
||||||
if self.isDragging:
|
if self.isDragging:
|
||||||
@@ -338,26 +369,40 @@ class wxGridRowMover(wxEvtHandler):
|
|||||||
x,sy = self.grid.GetViewStart()
|
x,sy = self.grid.GetViewStart()
|
||||||
w,h = self.lwin.GetClientSizeTuple()
|
w,h = self.lwin.GetClientSizeTuple()
|
||||||
y = sy * self.uy
|
y = sy * self.uy
|
||||||
|
|
||||||
if (evt.m_y + y) < y:
|
if (evt.m_y + y) < y:
|
||||||
y = evt.m_y + y
|
y = evt.m_y + y
|
||||||
elif evt.m_y > h:
|
elif evt.m_y > h:
|
||||||
y += evt.m_y - h
|
y += evt.m_y - h
|
||||||
if y < 1: y = 0
|
|
||||||
else: y /= self.uy
|
if y < 1:
|
||||||
|
y = 0
|
||||||
|
else:
|
||||||
|
y /= self.uy
|
||||||
|
|
||||||
if y != sy:
|
if y != sy:
|
||||||
if wxPlatform == '__WXMSW__':
|
if wx.Platform == '__WXMSW__':
|
||||||
self.rowWin.Show(False)
|
self.rowWin.Show(False)
|
||||||
|
|
||||||
self.grid.Scroll(x,y)
|
self.grid.Scroll(x,y)
|
||||||
|
|
||||||
x,y = self.lwin.ClientToScreenXY(0,evt.m_y)
|
x,y = self.lwin.ClientToScreenXY(0,evt.m_y)
|
||||||
x,y = self.grid.ScreenToClientXY(x,y)
|
x,y = self.grid.ScreenToClientXY(x,y)
|
||||||
|
|
||||||
if not self.rowWin.IsShown():
|
if not self.rowWin.IsShown():
|
||||||
self.rowWin.Show(True)
|
self.rowWin.Show(True)
|
||||||
|
|
||||||
py = y - self.cellY
|
py = y - self.cellY
|
||||||
if py < 0 + self.grid._clSize: py = 0 + self.grid._clSize
|
|
||||||
if py > h - self.rowWin.GetSizeTuple()[1] + self.grid._clSize:
|
if py < 0 + self.grid._clSize:
|
||||||
py = h - self.rowWin.GetSizeTuple()[1] + self.grid._clSize
|
py = 0 + self.grid._clSize
|
||||||
|
|
||||||
|
if py > h - self.rowWin.GetSize()[1] + self.grid._clSize:
|
||||||
|
py = h - self.rowWin.GetSize()[1] + self.grid._clSize
|
||||||
|
|
||||||
self.rowWin.DisplayAt(x,py)
|
self.rowWin.DisplayAt(x,py)
|
||||||
return
|
return
|
||||||
|
|
||||||
evt.Skip()
|
evt.Skip()
|
||||||
|
|
||||||
def OnPress(self,evt):
|
def OnPress(self,evt):
|
||||||
@@ -366,7 +411,8 @@ class wxGridRowMover(wxEvtHandler):
|
|||||||
sy -= self.grid._clSize
|
sy -= self.grid._clSize
|
||||||
px,py = self.lwin.ClientToScreenXY(evt.m_x,evt.m_y)
|
px,py = self.lwin.ClientToScreenXY(evt.m_x,evt.m_y)
|
||||||
px,py = self.grid.ScreenToClientXY(px,py)
|
px,py = self.grid.ScreenToClientXY(px,py)
|
||||||
if self.grid.YToEdgeOfRow(py + sy) != wxNOT_FOUND:
|
|
||||||
|
if self.grid.YToEdgeOfRow(py + sy) != wx.NOT_FOUND:
|
||||||
evt.Skip()
|
evt.Skip()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -375,7 +421,7 @@ class wxGridRowMover(wxEvtHandler):
|
|||||||
row = self.grid.YToRow(py + sy)
|
row = self.grid.YToRow(py + sy)
|
||||||
rect = self.grid.RowToRect(row)
|
rect = self.grid.RowToRect(row)
|
||||||
self.cellY = py + sy - rect.y
|
self.cellY = py + sy - rect.y
|
||||||
size = self.lwin.GetSizeTuple()
|
size = self.lwin.GetSize()
|
||||||
rect.x = 0
|
rect.x = 0
|
||||||
rect.y -= sy + self.grid._clSize
|
rect.y -= sy + self.grid._clSize
|
||||||
rect.width = size[0]
|
rect.width = size[0]
|
||||||
@@ -389,30 +435,34 @@ class wxGridRowMover(wxEvtHandler):
|
|||||||
self.lwin.ReleaseMouse()
|
self.lwin.ReleaseMouse()
|
||||||
self.rowWin.Show(False)
|
self.rowWin.Show(False)
|
||||||
self.isDragging = False
|
self.isDragging = False
|
||||||
|
|
||||||
if not self.didMove:
|
if not self.didMove:
|
||||||
py = self.lwin.ClientToScreenXY(0,self.startY)[1]
|
py = self.lwin.ClientToScreenXY(0,self.startY)[1]
|
||||||
py = self.grid.ScreenToClientXY(0,py)[1]
|
py = self.grid.ScreenToClientXY(0,py)[1]
|
||||||
sy = self.grid.GetViewStart()[1] * self.uy
|
sy = self.grid.GetViewStart()[1] * self.uy
|
||||||
sy -= self.grid._clSize
|
sy -= self.grid._clSize
|
||||||
row = self.grid.YToRow(py + sy)
|
row = self.grid.YToRow(py + sy)
|
||||||
if row != wxNOT_FOUND:
|
|
||||||
|
if row != wx.NOT_FOUND:
|
||||||
self.grid.SelectRow(row,evt.m_controlDown)
|
self.grid.SelectRow(row,evt.m_controlDown)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
bRow = self.rowWin.GetInsertionRow()
|
bRow = self.rowWin.GetInsertionRow()
|
||||||
dRow = self.rowWin.GetMoveRow()
|
dRow = self.rowWin.GetMoveRow()
|
||||||
wxPostEvent(self,wxGridRowMoveEvent(self.grid.GetId(),
|
|
||||||
dRow,bRow))
|
wx.PostEvent(self,
|
||||||
|
wxGridRowMoveEvent(self.grid.GetId(), dRow, bRow))
|
||||||
|
|
||||||
self.rowWin.Destroy()
|
self.rowWin.Destroy()
|
||||||
evt.Skip()
|
evt.Skip()
|
||||||
|
|
||||||
def _CaptureImage(self,rect):
|
def _CaptureImage(self,rect):
|
||||||
bmp = wxEmptyBitmap(rect.width,rect.height)
|
bmp = wx.EmptyBitmap(rect.width,rect.height)
|
||||||
memdc = wxMemoryDC()
|
memdc = wx.MemoryDC()
|
||||||
memdc.SelectObject(bmp)
|
memdc.SelectObject(bmp)
|
||||||
dc = wxWindowDC(self.lwin)
|
dc = wx.WindowDC(self.lwin)
|
||||||
memdc.Blit((0,0), rect.GetSize(), dc, rect.GetPosition())
|
memdc.Blit((0,0), rect.GetSize(), dc, rect.GetPosition())
|
||||||
memdc.SelectObject(wxNullBitmap)
|
memdc.SelectObject(wx.NullBitmap)
|
||||||
return bmp
|
return bmp
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,10 @@
|
|||||||
# Copyright: (c) 1999 by Total Control Software
|
# Copyright: (c) 1999 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 12/07/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 Compatability changes
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
In this module you will find wxGridSizer and wxFlexGridSizer. Please
|
In this module you will find wxGridSizer and wxFlexGridSizer. Please
|
||||||
@@ -33,20 +37,17 @@ wxFlexGridSizer: Derives from wxGridSizer and adds the ability for
|
|||||||
particular rows and/or columns to be marked as growable. This means
|
particular rows and/or columns to be marked as growable. This means
|
||||||
that when the sizer changes size, the growable rows and colums are the
|
that when the sizer changes size, the growable rows and colums are the
|
||||||
ones that stretch. The others remain at their initial size.
|
ones that stretch. The others remain at their initial size.
|
||||||
|
|
||||||
See the demo for a couple examples for how to use them.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from wxPython.wx import *
|
|
||||||
|
|
||||||
import operator
|
import operator
|
||||||
|
import wx
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
class wxGridSizer(wxPySizer):
|
class wxGridSizer(wx.PySizer):
|
||||||
def __init__(self, rows=0, cols=0, hgap=0, vgap=0):
|
def __init__(self, rows=0, cols=0, hgap=0, vgap=0):
|
||||||
wxPySizer.__init__(self)
|
wx.PySizer.__init__(self)
|
||||||
if rows == 0 and cols == 0:
|
if rows == 0 and cols == 0:
|
||||||
raise ValueError, "rows and cols cannot both be zero"
|
raise ValueError, "rows and cols cannot both be zero"
|
||||||
|
|
||||||
@@ -104,7 +105,7 @@ class wxGridSizer(wxPySizer):
|
|||||||
w = max(w, size.width)
|
w = max(w, size.width)
|
||||||
h = max(h, size.height)
|
h = max(h, size.height)
|
||||||
|
|
||||||
return wxSize(ncols * w + (ncols-1) * self.hgap,
|
return wx.Size(ncols * w + (ncols-1) * self.hgap,
|
||||||
nrows * h + (nrows-1) * self.vgap)
|
nrows * h + (nrows-1) * self.vgap)
|
||||||
|
|
||||||
|
|
||||||
@@ -136,7 +137,9 @@ class wxGridSizer(wxPySizer):
|
|||||||
i = r * ncols + c
|
i = r * ncols + c
|
||||||
if i < nitems:
|
if i < nitems:
|
||||||
self.SetItemBounds(items[i], x, y, w, h)
|
self.SetItemBounds(items[i], x, y, w, h)
|
||||||
|
|
||||||
y = y + h + self.vgap
|
y = y + h + self.vgap
|
||||||
|
|
||||||
x = x + w + self.hgap
|
x = x + w + self.hgap
|
||||||
|
|
||||||
|
|
||||||
@@ -144,21 +147,21 @@ class wxGridSizer(wxPySizer):
|
|||||||
def SetItemBounds(self, item, x, y, w, h):
|
def SetItemBounds(self, item, x, y, w, h):
|
||||||
# calculate the item's size and position within
|
# calculate the item's size and position within
|
||||||
# its grid cell
|
# its grid cell
|
||||||
ipt = wxPoint(x, y)
|
ipt = wx.Point(x, y)
|
||||||
isz = item.CalcMin()
|
isz = item.CalcMin()
|
||||||
flag = item.GetFlag()
|
flag = item.GetFlag()
|
||||||
|
|
||||||
if flag & wxEXPAND or flag & wxSHAPED:
|
if flag & wx.EXPAND or flag & wx.SHAPED:
|
||||||
isz = wxSize(w, h)
|
isz = (w, h)
|
||||||
else:
|
else:
|
||||||
if flag & wxALIGN_CENTER_HORIZONTAL:
|
if flag & wx.ALIGN_CENTER_HORIZONTAL:
|
||||||
ipt.x = x + (w - isz.width) / 2
|
ipt.x = x + (w - isz.width) / 2
|
||||||
elif flag & wxALIGN_RIGHT:
|
elif flag & wx.ALIGN_RIGHT:
|
||||||
ipt.x = x + (w - isz.width)
|
ipt.x = x + (w - isz.width)
|
||||||
|
|
||||||
if flag & wxALIGN_CENTER_VERTICAL:
|
if flag & wx.ALIGN_CENTER_VERTICAL:
|
||||||
ipt.y = y + (h - isz.height) / 2
|
ipt.y = y + (h - isz.height) / 2
|
||||||
elif flag & wxALIGN_BOTTOM:
|
elif flag & wx.ALIGN_BOTTOM:
|
||||||
ipt.y = y + (h - isz.height)
|
ipt.y = y + (h - isz.height)
|
||||||
|
|
||||||
item.SetDimension(ipt, isz)
|
item.SetDimension(ipt, isz)
|
||||||
@@ -197,6 +200,7 @@ class wxFlexGridSizer(wxGridSizer):
|
|||||||
# Find the max width and height for any component.
|
# Find the max width and height for any component.
|
||||||
self.rowHeights = [0] * nrows
|
self.rowHeights = [0] * nrows
|
||||||
self.colWidths = [0] * ncols
|
self.colWidths = [0] * ncols
|
||||||
|
|
||||||
for i in range(len(items)):
|
for i in range(len(items)):
|
||||||
size = items[i].CalcMin()
|
size = items[i].CalcMin()
|
||||||
row = i / ncols
|
row = i / ncols
|
||||||
@@ -208,7 +212,7 @@ class wxFlexGridSizer(wxGridSizer):
|
|||||||
cellsWidth = reduce(operator.__add__, self.colWidths)
|
cellsWidth = reduce(operator.__add__, self.colWidths)
|
||||||
cellHeight = reduce(operator.__add__, self.rowHeights)
|
cellHeight = reduce(operator.__add__, self.rowHeights)
|
||||||
|
|
||||||
return wxSize(cellsWidth + (ncols-1) * self.hgap,
|
return wx.Size(cellsWidth + (ncols-1) * self.hgap,
|
||||||
cellHeight + (nrows-1) * self.vgap)
|
cellHeight + (nrows-1) * self.vgap)
|
||||||
|
|
||||||
|
|
||||||
@@ -243,7 +247,7 @@ class wxFlexGridSizer(wxGridSizer):
|
|||||||
self.colWidths[idx] = self.colWidths[idx] + delta
|
self.colWidths[idx] = self.colWidths[idx] + delta
|
||||||
|
|
||||||
# bottom right corner
|
# bottom right corner
|
||||||
sz = wxSize(pt.x + sz.width, pt.y + sz.height)
|
sz = wx.Size(pt.x + sz.width, pt.y + sz.height)
|
||||||
|
|
||||||
# Layout each cell
|
# Layout each cell
|
||||||
x = pt.x
|
x = pt.x
|
||||||
@@ -251,11 +255,14 @@ class wxFlexGridSizer(wxGridSizer):
|
|||||||
y = pt.y
|
y = pt.y
|
||||||
for r in range(nrows):
|
for r in range(nrows):
|
||||||
i = r * ncols + c
|
i = r * ncols + c
|
||||||
|
|
||||||
if i < nitems:
|
if i < nitems:
|
||||||
w = max(0, min(self.colWidths[c], sz.width - x))
|
w = max(0, min(self.colWidths[c], sz.width - x))
|
||||||
h = max(0, min(self.rowHeights[r], sz.height - y))
|
h = max(0, min(self.rowHeights[r], sz.height - y))
|
||||||
self.SetItemBounds(items[i], x, y, w, h)
|
self.SetItemBounds(items[i], x, y, w, h)
|
||||||
|
|
||||||
y = y + self.rowHeights[r] + self.vgap
|
y = y + self.rowHeights[r] + self.vgap
|
||||||
|
|
||||||
x = x + self.colWidths[c] + self.hgap
|
x = x + self.colWidths[c] + self.hgap
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|||||||
@@ -8,17 +8,28 @@
|
|||||||
# Date: January 29, 2002
|
# Date: January 29, 2002
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
# 1.0 Release
|
# 1.0 Release
|
||||||
# Create list of all available image file types
|
# Create list of all available image file types
|
||||||
# View "All Image" File Types as default filter
|
# View "All Image" File Types as default filter
|
||||||
# Sort the file list
|
# Sort the file list
|
||||||
# Use newer "re" function for patterns
|
# Use newer "re" function for patterns
|
||||||
|
#
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# 12/08/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Updated for wx namespace
|
||||||
|
# o Corrected a nasty bug or two - see comments below.
|
||||||
|
# o There was a duplicate ImageView.DrawImage() method. Que?
|
||||||
|
#
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
import os, sys
|
import os
|
||||||
from wxPython.wx import *
|
import sys
|
||||||
|
|
||||||
|
import wx
|
||||||
|
|
||||||
dir_path = os.getcwd()
|
dir_path = os.getcwd()
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
@@ -30,55 +41,37 @@ def ConvertBMP(file_nm):
|
|||||||
fl_fld = os.path.splitext(file_nm)
|
fl_fld = os.path.splitext(file_nm)
|
||||||
ext = fl_fld[1]
|
ext = fl_fld[1]
|
||||||
ext = ext[1:].lower()
|
ext = ext[1:].lower()
|
||||||
if ext == 'bmp':
|
|
||||||
image = wxImage(file_nm, wxBITMAP_TYPE_BMP)
|
|
||||||
elif ext == 'gif':
|
|
||||||
image = wxImage(file_nm, wxBITMAP_TYPE_GIF)
|
|
||||||
elif ext == 'png':
|
|
||||||
image = wxImage(file_nm, wxBITMAP_TYPE_PNG)
|
|
||||||
elif ext == 'jpg':
|
|
||||||
image = wxImage(file_nm, wxBITMAP_TYPE_JPEG)
|
|
||||||
elif ext == 'pcx':
|
|
||||||
image = wxImage(file_nm, wxBITMAP_TYPE_PCX)
|
|
||||||
elif ext == 'tif':
|
|
||||||
image = wxImage(file_nm, wxBITMAP_TYPE_TIF)
|
|
||||||
elif ext == 'pnm':
|
|
||||||
image = wxImage(file_nm, wxBITMAP_TYPE_PNM)
|
|
||||||
else:
|
|
||||||
image = wxImage(file_nm, wxBITMAP_TYPE_ANY)
|
|
||||||
|
|
||||||
|
image = wx.Image(file_nm, wx.BITMAP_TYPE_ANY)
|
||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
||||||
def GetSize(file_nm): # for scaling image values
|
def GetSize(file_nm): # for scaling image values
|
||||||
image = ConvertBMP(file_nm)
|
image = ConvertBMP(file_nm)
|
||||||
bmp = image.ConvertToBitmap()
|
bmp = image.ConvertToBitmap()
|
||||||
size = bmp.GetWidth(), bmp.GetHeight()
|
size = bmp.GetWidth(), bmp.GetHeight()
|
||||||
return size
|
return size
|
||||||
|
|
||||||
class ImageView(wxWindow):
|
|
||||||
def __init__(self, parent, id=-1, pos=wxDefaultPosition, size=wxDefaultSize):
|
class ImageView(wx.Window):
|
||||||
wxWindow.__init__(self, parent, id, pos, size)
|
def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize):
|
||||||
|
wx.Window.__init__(self, parent, id, pos, size)
|
||||||
self.win = parent
|
self.win = parent
|
||||||
self.image = None
|
self.image = None
|
||||||
self.back_color = 'WHITE'
|
self.back_color = 'WHITE'
|
||||||
self.border_color = 'BLACK'
|
self.border_color = 'BLACK'
|
||||||
|
|
||||||
self.image_sizex = size.width
|
# Changed API of wx uses tuples for size and pos now.
|
||||||
self.image_sizey = size.height
|
self.image_sizex = size[0]
|
||||||
self.image_posx = pos.x
|
self.image_sizey = size[1]
|
||||||
self.image_posy = pos.y
|
self.image_posx = pos[0]
|
||||||
EVT_PAINT(self, self.OnPaint)
|
self.image_posy = pos[1]
|
||||||
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||||
wxInitAllImageHandlers()
|
|
||||||
|
|
||||||
def OnPaint(self, event):
|
def OnPaint(self, event):
|
||||||
dc = wxPaintDC(self)
|
dc = wx.PaintDC(self)
|
||||||
self.DrawImage(dc)
|
self.DrawImage(dc)
|
||||||
|
|
||||||
def DrawImage(self, dc):
|
|
||||||
dc.BeginDrawing()
|
|
||||||
self.DrawImage(dc)
|
|
||||||
dc.EndDrawing()
|
|
||||||
|
|
||||||
def SetValue(self, file_nm): # display the selected file in the panel
|
def SetValue(self, file_nm): # display the selected file in the panel
|
||||||
image = ConvertBMP(file_nm)
|
image = ConvertBMP(file_nm)
|
||||||
@@ -86,10 +79,10 @@ class ImageView(wxWindow):
|
|||||||
self.Refresh()
|
self.Refresh()
|
||||||
|
|
||||||
def DrawBorder(self, dc):
|
def DrawBorder(self, dc):
|
||||||
brush = wxBrush(wxNamedColour(self.back_color), wxSOLID)
|
brush = wx.Brush(wx.NamedColour(self.back_color), wx.SOLID)
|
||||||
dc.SetBrush(brush)
|
dc.SetBrush(brush)
|
||||||
dc.SetPen(wxPen(wxNamedColour(self.border_color), 1))
|
dc.SetPen(wx.Pen(wx.NamedColour(self.border_color), 1))
|
||||||
dc.DrawRectangle(0, 0, self.image_sizex, self.image_sizey)
|
dc.DrawRectangle((0, 0), (self.image_sizex, self.image_sizey))
|
||||||
|
|
||||||
def DrawImage(self, dc):
|
def DrawImage(self, dc):
|
||||||
try:
|
try:
|
||||||
@@ -98,6 +91,7 @@ class ImageView(wxWindow):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self.DrawBorder(dc)
|
self.DrawBorder(dc)
|
||||||
|
|
||||||
if image is None:
|
if image is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -119,12 +113,12 @@ class ImageView(wxWindow):
|
|||||||
image.Rescale(iwidth, iheight) # rescale to fit the window
|
image.Rescale(iwidth, iheight) # rescale to fit the window
|
||||||
image.ConvertToBitmap()
|
image.ConvertToBitmap()
|
||||||
bmp = image.ConvertToBitmap()
|
bmp = image.ConvertToBitmap()
|
||||||
dc.DrawBitmap(bmp, diffx, diffy) # draw the image to window
|
dc.DrawBitmap(bmp, (diffx, diffy)) # draw the image to window
|
||||||
|
|
||||||
|
|
||||||
class ImageDialog(wxDialog):
|
class ImageDialog(wx.Dialog):
|
||||||
def __init__(self, parent, set_dir = None):
|
def __init__(self, parent, set_dir = None):
|
||||||
wxDialog.__init__(self, parent, -1, "Image Browser", wxPyDefaultPosition, wxSize(400, 400))
|
wx.Dialog.__init__(self, parent, -1, "Image Browser", wx.DefaultPosition, (400, 400))
|
||||||
|
|
||||||
self.x_pos = 30 # initial display positions
|
self.x_pos = 30 # initial display positions
|
||||||
self.y_pos = 20
|
self.y_pos = 20
|
||||||
@@ -145,9 +139,8 @@ class ImageDialog(wxDialog):
|
|||||||
|
|
||||||
self.y_pos = self.y_pos + self.delta
|
self.y_pos = self.y_pos + self.delta
|
||||||
|
|
||||||
mID = wxNewId()
|
btn = wx.Button(self, -1, ' Set Directory ', (self.x_pos, self.y_pos), size).SetDefault()
|
||||||
wxButton(self, mID, ' Set Directory ', wxPoint(self.x_pos, self.y_pos), size).SetDefault()
|
self.Bind(wx.EVT_BUTTON, self.SetDirect, btn)
|
||||||
EVT_BUTTON(self, mID, self.SetDirect)
|
|
||||||
|
|
||||||
self.type_posy = self.y_pos # save the y position for the image type combo
|
self.type_posy = self.y_pos # save the y position for the image type combo
|
||||||
|
|
||||||
@@ -159,40 +152,55 @@ class ImageDialog(wxDialog):
|
|||||||
self.list_height = 150
|
self.list_height = 150
|
||||||
|
|
||||||
# List of Labels
|
# List of Labels
|
||||||
mID = wxNewId()
|
self.tb = tb = wx.ListBox(self, -1, (self.x_pos, self.y_pos),
|
||||||
self.tb = tb = wxListBox(self, mID, wxPoint(self.x_pos, self.y_pos), wxSize(160, self.list_height), self.fl_list, wxLB_SINGLE)
|
(160, self.list_height), self.fl_list,
|
||||||
EVT_LISTBOX(self, mID, self.OnListClick)
|
wx.LB_SINGLE )
|
||||||
EVT_LISTBOX_DCLICK(self, mID, self.OnListDClick)
|
self.Bind(wx.EVT_LISTBOX, self.OnListClick, tb)
|
||||||
|
self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnListDClick, tb)
|
||||||
|
|
||||||
width, height = self.tb.GetSizeTuple()
|
width, height = self.tb.GetSize()
|
||||||
image_posx = self.x_pos + width + 20 # positions for setting the image window
|
image_posx = self.x_pos + width + 20 # positions for setting the image window
|
||||||
image_posy = self.y_pos
|
image_posy = self.y_pos
|
||||||
image_sizex = 150
|
image_sizex = 150
|
||||||
image_sizey = self.list_height
|
image_sizey = self.list_height
|
||||||
|
|
||||||
self.fl_types = ["All Images", "Bmp", "Gif", "Png", "Jpg", "Ico", "Pnm", "Pcx", "Tif", "All Files"]
|
self.fl_types = [
|
||||||
self.fl_ext_types = { "All Images": "All", "Bmp": "*.bmp", "Gif": "*.gif", "Png": "*.png", "Jpg": "*.jpg",
|
"All Images", "Bmp", "Gif", "Png", "Jpg", "Ico", "Pnm",
|
||||||
"Ico": "*.ico", "Pnm": "*.pnm", "Pcx": "*.pcx", "Tif": "*.tif", "All Files": "*.*" }
|
"Pcx", "Tif", "All Files"
|
||||||
|
]
|
||||||
|
|
||||||
|
self.fl_ext_types = {
|
||||||
|
"All Images": "All",
|
||||||
|
"Bmp": "*.bmp",
|
||||||
|
"Gif": "*.gif",
|
||||||
|
"Png": "*.png",
|
||||||
|
"Jpg": "*.jpg",
|
||||||
|
"Ico": "*.ico",
|
||||||
|
"Pnm": "*.pnm",
|
||||||
|
"Pcx": "*.pcx",
|
||||||
|
"Tif": "*.tif",
|
||||||
|
"All Files": "*.*"
|
||||||
|
}
|
||||||
|
|
||||||
self.set_type = self.fl_types[0] # initial file filter setting
|
self.set_type = self.fl_types[0] # initial file filter setting
|
||||||
self.fl_ext = self.fl_ext_types[self.set_type]
|
self.fl_ext = self.fl_ext_types[self.set_type]
|
||||||
|
|
||||||
mID = wxNewId()
|
self.sel_type = wx.ComboBox(self, -1, self.set_type, (image_posx , self.type_posy),
|
||||||
self.sel_type = wxComboBox(self, mID, self.set_type, wxPoint(image_posx , self.type_posy), wxSize(150, -1), self.fl_types, wxCB_DROPDOWN)
|
(150, -1), self.fl_types, wx.CB_DROPDOWN)
|
||||||
EVT_COMBOBOX(self, mID, self.OnSetType)
|
self.Bind(wx.EVT_COMBOBOX, self.OnSetType, self.sel_type)
|
||||||
|
|
||||||
self.image_view = ImageView(self, pos=wxPoint(image_posx, image_posy), size=wxSize(image_sizex, image_sizey))
|
self.image_view = ImageView( self, pos=(image_posx, image_posy),
|
||||||
|
size=(image_sizex, image_sizey))
|
||||||
|
|
||||||
self.y_pos = self.y_pos + height + 20
|
self.y_pos = self.y_pos + height + 20
|
||||||
|
|
||||||
mID = wxNewId()
|
btn = wx.Button(self, -1, ' Select ', (100, self.y_pos), size).SetDefault()
|
||||||
wxButton(self, mID, ' Select ', wxPoint(100, self.y_pos), size).SetDefault()
|
self.Bind(wx.EVT_BUTTON, self.OnOk, btn)
|
||||||
EVT_BUTTON(self, mID, self.OnOk)
|
|
||||||
|
|
||||||
wxButton(self, wxID_CANCEL, 'Cancel', wxPoint(250, self.y_pos), size)
|
wx.Button(self, wx.ID_CANCEL, 'Cancel', (250, self.y_pos), size)
|
||||||
|
|
||||||
self.y_pos = self.y_pos + self.delta
|
self.y_pos = self.y_pos + self.delta
|
||||||
fsize = wxSize(400, self.y_pos + 50) # resize dialog for final vertical position
|
fsize = (400, self.y_pos + 50) # resize dialog for final vertical position
|
||||||
self.SetSize(fsize)
|
self.SetSize(fsize)
|
||||||
|
|
||||||
self.ResetFiles()
|
self.ResetFiles()
|
||||||
@@ -200,11 +208,13 @@ class ImageDialog(wxDialog):
|
|||||||
def GetFiles(self): # get the file list using directory and extension values
|
def GetFiles(self): # get the file list using directory and extension values
|
||||||
if self.fl_ext == "All":
|
if self.fl_ext == "All":
|
||||||
all_files = []
|
all_files = []
|
||||||
|
|
||||||
for ftypes in self.fl_types[1:-1]: # get list of all available image types
|
for ftypes in self.fl_types[1:-1]: # get list of all available image types
|
||||||
filter = self.fl_ext_types[ftypes]
|
filter = self.fl_ext_types[ftypes]
|
||||||
print "filter = ", filter
|
#print "filter = ", filter
|
||||||
self.fl_val = FindFiles(self, self.set_dir, filter)
|
self.fl_val = FindFiles(self, self.set_dir, filter)
|
||||||
all_files = all_files + self.fl_val.files # add to list of files
|
all_files = all_files + self.fl_val.files # add to list of files
|
||||||
|
|
||||||
self.fl_list = all_files
|
self.fl_list = all_files
|
||||||
else:
|
else:
|
||||||
self.fl_val = FindFiles(self, self.set_dir, self.fl_ext)
|
self.fl_val = FindFiles(self, self.set_dir, self.fl_ext)
|
||||||
@@ -213,7 +223,7 @@ class ImageDialog(wxDialog):
|
|||||||
self.fl_list.sort() # sort the file list
|
self.fl_list.sort() # sort the file list
|
||||||
|
|
||||||
def DisplayDir(self): # display the working directory
|
def DisplayDir(self): # display the working directory
|
||||||
wxStaticText(self, -1, self.set_dir, wxPoint(self.dir_x, self.dir_y), wxSize(250, -1))
|
wx.StaticText(self, -1, self.set_dir, (self.dir_x, self.dir_y), (250, -1))
|
||||||
|
|
||||||
def OnSetType(self, event):
|
def OnSetType(self, event):
|
||||||
val = event.GetString() # get file type value
|
val = event.GetString() # get file type value
|
||||||
@@ -233,22 +243,45 @@ class ImageDialog(wxDialog):
|
|||||||
self.image_view.SetValue(file_val)
|
self.image_view.SetValue(file_val)
|
||||||
|
|
||||||
def SetDirect(self, event): # set the new directory
|
def SetDirect(self, event): # set the new directory
|
||||||
dlg = wxDirDialog(self)
|
dlg = wx.DirDialog(self)
|
||||||
dlg.SetPath(self.set_dir)
|
dlg.SetPath(self.set_dir)
|
||||||
if dlg.ShowModal() == wxID_OK:
|
|
||||||
|
if dlg.ShowModal() == wx.ID_OK:
|
||||||
self.set_dir = dlg.GetPath()
|
self.set_dir = dlg.GetPath()
|
||||||
self.ResetFiles()
|
self.ResetFiles()
|
||||||
|
|
||||||
dlg.Destroy()
|
dlg.Destroy()
|
||||||
|
|
||||||
def ResetFiles(self): # refresh the display with files and initial image
|
def ResetFiles(self): # refresh the display with files and initial image
|
||||||
self.DisplayDir()
|
self.DisplayDir()
|
||||||
self.GetFiles()
|
self.GetFiles()
|
||||||
|
|
||||||
|
# Changed 12/8/03 jmg
|
||||||
|
#
|
||||||
|
# o Clear listbox first
|
||||||
|
# o THEN check to see if there are any valid files of the selected
|
||||||
|
# type,
|
||||||
|
# o THEN if we have any files to display, set the listbox up,
|
||||||
|
#
|
||||||
|
# OTHERWISE
|
||||||
|
#
|
||||||
|
# o Leave it cleared
|
||||||
|
# o Clear the image viewer.
|
||||||
|
#
|
||||||
|
# This avoids a nasty assert error.
|
||||||
|
#
|
||||||
|
self.tb.Clear()
|
||||||
|
|
||||||
|
if len(self.fl_list):
|
||||||
self.tb.Set(self.fl_list)
|
self.tb.Set(self.fl_list)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.tb.SetSelection(0)
|
self.tb.SetSelection(0)
|
||||||
self.SetListValue(0)
|
self.SetListValue(0)
|
||||||
except:
|
except:
|
||||||
self.image_view.SetValue(None)
|
self.image_view.SetValue(None)
|
||||||
|
else:
|
||||||
|
self.image_view.SetValue(None)
|
||||||
|
|
||||||
def GetFile(self):
|
def GetFile(self):
|
||||||
return self.set_file
|
return self.set_file
|
||||||
@@ -258,19 +291,22 @@ class ImageDialog(wxDialog):
|
|||||||
|
|
||||||
def OnCancel(self, event):
|
def OnCancel(self, event):
|
||||||
self.result = None
|
self.result = None
|
||||||
self.EndModal(wxID_CANCEL)
|
self.EndModal(wx.ID_CANCEL)
|
||||||
|
|
||||||
def OnOk(self, event):
|
def OnOk(self, event):
|
||||||
self.result = self.set_file
|
self.result = self.set_file
|
||||||
self.EndModal(wxID_OK)
|
self.EndModal(wx.ID_OK)
|
||||||
|
|
||||||
|
|
||||||
def OnFileDlg(self):
|
def OnFileDlg(self):
|
||||||
dlg = wxFileDialog(self, "Choose an Image File", ".", "", "Bmp (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg", wxOPEN)
|
dlg = wx.FileDialog(self, "Choose an Image File", ".", "",
|
||||||
if dlg.ShowModal() == wxID_OK:
|
"Bmp (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg", wx.OPEN)
|
||||||
|
|
||||||
|
if dlg.ShowModal() == wx.ID_OK:
|
||||||
path = dlg.GetPath()
|
path = dlg.GetPath()
|
||||||
else:
|
else:
|
||||||
path = None
|
path = None
|
||||||
|
|
||||||
dlg.Destroy()
|
dlg.Destroy()
|
||||||
return path
|
return path
|
||||||
|
|
||||||
@@ -282,9 +318,11 @@ class FindFiles:
|
|||||||
self.file = ""
|
self.file = ""
|
||||||
mask = mask.upper()
|
mask = mask.upper()
|
||||||
pattern = self.MakeRegex(mask)
|
pattern = self.MakeRegex(mask)
|
||||||
|
|
||||||
for i in os.listdir(dir):
|
for i in os.listdir(dir):
|
||||||
if i == "." or i == "..":
|
if i == "." or i == "..":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
path = os.path.join(dir, i)
|
path = os.path.join(dir, i)
|
||||||
path = path.upper()
|
path = path.upper()
|
||||||
value = i.upper()
|
value = i.upper()
|
||||||
@@ -297,6 +335,7 @@ class FindFiles:
|
|||||||
def MakeRegex(self, pattern):
|
def MakeRegex(self, pattern):
|
||||||
import re
|
import re
|
||||||
f = "" # Set up a regex for file names
|
f = "" # Set up a regex for file names
|
||||||
|
|
||||||
for ch in pattern:
|
for ch in pattern:
|
||||||
if ch == "*":
|
if ch == "*":
|
||||||
f = f + ".*"
|
f = f + ".*"
|
||||||
@@ -306,6 +345,7 @@ class FindFiles:
|
|||||||
f = f + "."
|
f = f + "."
|
||||||
else:
|
else:
|
||||||
f = f + ch
|
f = f + ch
|
||||||
|
|
||||||
return re.compile(f+'$')
|
return re.compile(f+'$')
|
||||||
|
|
||||||
def StripExt(self, file_nm):
|
def StripExt(self, file_nm):
|
||||||
|
|||||||
@@ -120,58 +120,57 @@ see the appropriate "stub" file in the wxPython demo.
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from wxPython.wx import *
|
import os
|
||||||
import sys, tempfile, os
|
import sys
|
||||||
|
import tempfile
|
||||||
|
|
||||||
class _MyStatusBar(wxStatusBar):
|
import wx
|
||||||
def __init__(self, parent,callbacks=None,useopenbutton=0):
|
|
||||||
wxStatusBar.__init__(self, parent, -1, style=wxTAB_TRAVERSAL)
|
class _MyStatusBar(wx.StatusBar):
|
||||||
|
def __init__(self, parent, callbacks=None, useopenbutton=0):
|
||||||
|
wx.StatusBar.__init__(self, parent, -1, style=wx.TAB_TRAVERSAL)
|
||||||
self.SetFieldsCount(3)
|
self.SetFieldsCount(3)
|
||||||
|
|
||||||
self.SetStatusText("",0)
|
self.SetStatusText("",0)
|
||||||
|
|
||||||
ID = wxNewId()
|
self.button1 = wx.Button(self, -1, "Dismiss", style=wx.TAB_TRAVERSAL)
|
||||||
self.button1 = wxButton(self,ID,"Dismiss",
|
self.Bind(wx.EVT_BUTTON, self.OnButton1, self.button1)
|
||||||
style=wxTAB_TRAVERSAL)
|
|
||||||
EVT_BUTTON(self,ID,self.OnButton1)
|
|
||||||
|
|
||||||
ID = wxNewId()
|
|
||||||
if not useopenbutton:
|
if not useopenbutton:
|
||||||
self.button2 = wxButton(self,ID,"Close File",
|
self.button2 = wx.Button(self, -1, "Close File", style=wx.TAB_TRAVERSAL)
|
||||||
style=wxTAB_TRAVERSAL)
|
|
||||||
else:
|
else:
|
||||||
self.button2 = wxButton(self,ID,"Open New File",
|
self.button2 = wx.Button(self, -1, "Open New File", style=wx.TAB_TRAVERSAL)
|
||||||
style=wxTAB_TRAVERSAL)
|
|
||||||
EVT_BUTTON(self,ID,self.OnButton2)
|
self.Bind(wx.EVT_BUTTON, self.OnButton2, self.button2)
|
||||||
self.useopenbutton = useopenbutton
|
self.useopenbutton = useopenbutton
|
||||||
self.callbacks = callbacks
|
self.callbacks = callbacks
|
||||||
|
|
||||||
# figure out how tall to make the status bar
|
# figure out how tall to make the status bar
|
||||||
dc = wxClientDC(self)
|
dc = wx.ClientDC(self)
|
||||||
dc.SetFont(self.GetFont())
|
dc.SetFont(self.GetFont())
|
||||||
(w,h) = dc.GetTextExtent('X')
|
(w,h) = dc.GetTextExtent('X')
|
||||||
h = int(h * 1.8)
|
h = int(h * 1.8)
|
||||||
self.SetSize(wxSize(100, h))
|
self.SetSize((100, h))
|
||||||
self.OnSize("dummy")
|
self.OnSize("dummy")
|
||||||
EVT_SIZE(self,self.OnSize)
|
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||||
|
|
||||||
# reposition things...
|
# reposition things...
|
||||||
def OnSize(self, event):
|
def OnSize(self, event):
|
||||||
self.CalculateSizes()
|
self.CalculateSizes()
|
||||||
rect = self.GetFieldRect(1)
|
rect = self.GetFieldRect(1)
|
||||||
self.button1.SetPosition(wxPoint(rect.x+5, rect.y+2))
|
self.button1.SetPosition((rect.x+5, rect.y+2))
|
||||||
self.button1.SetSize(wxSize(rect.width-10, rect.height-4))
|
self.button1.SetSize((rect.width-10, rect.height-4))
|
||||||
rect = self.GetFieldRect(2)
|
rect = self.GetFieldRect(2)
|
||||||
self.button2.SetPosition(wxPoint(rect.x+5, rect.y+2))
|
self.button2.SetPosition((rect.x+5, rect.y+2))
|
||||||
self.button2.SetSize(wxSize(rect.width-10, rect.height-4))
|
self.button2.SetSize((rect.width-10, rect.height-4))
|
||||||
|
|
||||||
# widths........
|
# widths........
|
||||||
def CalculateSizes(self):
|
def CalculateSizes(self):
|
||||||
dc = wxClientDC(self.button1)
|
dc = wx.ClientDC(self.button1)
|
||||||
dc.SetFont(self.button1.GetFont())
|
dc.SetFont(self.button1.GetFont())
|
||||||
(w1,h) = dc.GetTextExtent(self.button1.GetLabel())
|
(w1,h) = dc.GetTextExtent(self.button1.GetLabel())
|
||||||
|
|
||||||
dc = wxClientDC(self.button2)
|
dc = wx.ClientDC(self.button2)
|
||||||
dc.SetFont(self.button2.GetFont())
|
dc.SetFont(self.button2.GetFont())
|
||||||
(w2,h) = dc.GetTextExtent(self.button2.GetLabel())
|
(w2,h) = dc.GetTextExtent(self.button2.GetLabel())
|
||||||
|
|
||||||
@@ -185,6 +184,7 @@ class _MyStatusBar(wxStatusBar):
|
|||||||
self.button2.SetLabel ("Close File")
|
self.button2.SetLabel ("Close File")
|
||||||
elif self.callbacks[1] ():
|
elif self.callbacks[1] ():
|
||||||
self.button2.SetLabel ("Open New File")
|
self.button2.SetLabel ("Open New File")
|
||||||
|
|
||||||
self.useopenbutton = 1 - self.useopenbutton
|
self.useopenbutton = 1 - self.useopenbutton
|
||||||
self.OnSize("")
|
self.OnSize("")
|
||||||
self.button2.Refresh(True)
|
self.button2.Refresh(True)
|
||||||
@@ -217,6 +217,7 @@ class wxPyInformationalMessagesFrame:
|
|||||||
self.title = "%s %s" % (progname,text)
|
self.title = "%s %s" % (progname,text)
|
||||||
self.parent = None # use the SetParent method if desired...
|
self.parent = None # use the SetParent method if desired...
|
||||||
self.softspace = 1 # of rather limited use
|
self.softspace = 1 # of rather limited use
|
||||||
|
|
||||||
if dir:
|
if dir:
|
||||||
self.SetOutputDirectory(dir)
|
self.SetOutputDirectory(dir)
|
||||||
|
|
||||||
@@ -239,11 +240,15 @@ class wxPyInformationalMessagesFrame:
|
|||||||
f = None
|
f = None
|
||||||
|
|
||||||
|
|
||||||
def write(self,string):
|
def write(self, string):
|
||||||
if not wxThread_IsMain():
|
if not wx.Thread_IsMain():
|
||||||
# Aquire the GUI mutex before making GUI calls. Mutex is released
|
# Aquire the GUI mutex before making GUI calls. Mutex is released
|
||||||
# when locker is deleted at the end of this function.
|
# when locker is deleted at the end of this function.
|
||||||
locker = wxMutexGuiLocker()
|
#
|
||||||
|
# TODO: This should be updated to use wx.CallAfter similarly to how
|
||||||
|
# PyOnDemandOutputWindow.write was so it is not necessary
|
||||||
|
# to get the gui mutex
|
||||||
|
locker = wx.MutexGuiLocker()
|
||||||
|
|
||||||
if self.Enabled:
|
if self.Enabled:
|
||||||
if self.f:
|
if self.f:
|
||||||
@@ -257,10 +262,11 @@ class wxPyInformationalMessagesFrame:
|
|||||||
move = 0
|
move = 0
|
||||||
|
|
||||||
if not self.frame:
|
if not self.frame:
|
||||||
self.frame = wxFrame(self.parent, -1, self.title, size=(450, 300),
|
self.frame = wx.Frame(self.parent, -1, self.title, size=(450, 300),
|
||||||
style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
|
style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
|
||||||
self.text = wxTextCtrl(self.frame, -1, "",
|
|
||||||
style = wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH)
|
self.text = wx.TextCtrl(self.frame, -1, "",
|
||||||
|
style = wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_RICH)
|
||||||
|
|
||||||
self.frame.sb = _MyStatusBar(self.frame,
|
self.frame.sb = _MyStatusBar(self.frame,
|
||||||
callbacks=[self.DisableOutput,
|
callbacks=[self.DisableOutput,
|
||||||
@@ -270,7 +276,7 @@ class wxPyInformationalMessagesFrame:
|
|||||||
"nofile"))
|
"nofile"))
|
||||||
self.frame.SetStatusBar(self.frame.sb)
|
self.frame.SetStatusBar(self.frame.sb)
|
||||||
self.frame.Show(True)
|
self.frame.Show(True)
|
||||||
EVT_CLOSE(self.frame, self.OnCloseWindow)
|
self.frame.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
||||||
|
|
||||||
if hasattr(self,"nofile"):
|
if hasattr(self,"nofile"):
|
||||||
self.text.AppendText(
|
self.text.AppendText(
|
||||||
@@ -284,6 +290,7 @@ class wxPyInformationalMessagesFrame:
|
|||||||
else:
|
else:
|
||||||
tempfile.tempdir = self.dir
|
tempfile.tempdir = self.dir
|
||||||
filename = os.path.abspath(tempfile.mktemp ())
|
filename = os.path.abspath(tempfile.mktemp ())
|
||||||
|
|
||||||
self.text.AppendText(
|
self.text.AppendText(
|
||||||
"Please close this window (or select the "
|
"Please close this window (or select the "
|
||||||
"'Dismiss' button below) when desired. By "
|
"'Dismiss' button below) when desired. By "
|
||||||
@@ -389,10 +396,10 @@ class wxPyInformationalMessagesFrame:
|
|||||||
|
|
||||||
def OpenNewFile(self):
|
def OpenNewFile(self):
|
||||||
self.CloseFile()
|
self.CloseFile()
|
||||||
dlg = wxFileDialog(self.frame,
|
dlg = wx.FileDialog(self.frame,
|
||||||
"Choose a new log file", self.dir,"","*",
|
"Choose a new log file", self.dir,"","*",
|
||||||
wxSAVE | wxHIDE_READONLY | wxOVERWRITE_PROMPT)
|
wx.SAVE | wx.HIDE_READONLY | wx.OVERWRITE_PROMPT)
|
||||||
if dlg.ShowModal() == wxID_CANCEL:
|
if dlg.ShowModal() == wx.ID_CANCEL:
|
||||||
dlg.Destroy()
|
dlg.Destroy()
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
@@ -434,7 +441,7 @@ class wxPyInformationalMessagesFrame:
|
|||||||
def flush(self):
|
def flush(self):
|
||||||
if self.text:
|
if self.text:
|
||||||
self.text.SetInsertionPointEnd()
|
self.text.SetInsertionPointEnd()
|
||||||
wxYield()
|
wx.Yield()
|
||||||
|
|
||||||
|
|
||||||
def __call__(self,* args):
|
def __call__(self,* args):
|
||||||
|
|||||||
@@ -24,16 +24,31 @@
|
|||||||
# wxIntCtrl also supports range limits, with the option of either
|
# wxIntCtrl also supports range limits, with the option of either
|
||||||
# enforcing them or simply coloring the text of the control if the limits
|
# enforcing them or simply coloring the text of the control if the limits
|
||||||
# are exceeded.
|
# are exceeded.
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# 12/08/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 Compatability changes
|
||||||
|
#
|
||||||
|
|
||||||
|
import string
|
||||||
|
import types
|
||||||
|
|
||||||
|
import wx
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
from wxPython.wx import *
|
|
||||||
import types, string
|
|
||||||
from sys import maxint
|
from sys import maxint
|
||||||
MAXINT = maxint # (constants should be in upper case)
|
MAXINT = maxint # (constants should be in upper case)
|
||||||
MININT = -maxint-1
|
MININT = -maxint-1
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxEVT_COMMAND_INT_UPDATED = wxNewEventType()
|
# Used to trap events indicating that the current
|
||||||
|
# integer value of the control has been changed.
|
||||||
|
wxEVT_COMMAND_INT_UPDATED = wx.NewEventType()
|
||||||
|
EVT_INT = wx.PyEventBinder(wxEVT_COMMAND_INT_UPDATED, 1)
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
# wxWindows' wxTextCtrl translates Composite "control key"
|
# wxWindows' wxTextCtrl translates Composite "control key"
|
||||||
# events into single events before returning them to its OnChar
|
# events into single events before returning them to its OnChar
|
||||||
@@ -44,16 +59,9 @@ wxEVT_COMMAND_INT_UPDATED = wxNewEventType()
|
|||||||
WXK_CTRL_X = (ord('X')+1) - ord('A')
|
WXK_CTRL_X = (ord('X')+1) - ord('A')
|
||||||
WXK_CTRL_V = (ord('V')+1) - ord('A')
|
WXK_CTRL_V = (ord('V')+1) - ord('A')
|
||||||
|
|
||||||
|
class wxIntUpdatedEvent(wx.PyCommandEvent):
|
||||||
def EVT_INT(win, id, func):
|
|
||||||
"""Used to trap events indicating that the current
|
|
||||||
integer value of the control has been changed."""
|
|
||||||
win.Connect(id, -1, wxEVT_COMMAND_INT_UPDATED, func)
|
|
||||||
|
|
||||||
|
|
||||||
class wxIntUpdatedEvent(wxPyCommandEvent):
|
|
||||||
def __init__(self, id, value = 0, object=None):
|
def __init__(self, id, value = 0, object=None):
|
||||||
wxPyCommandEvent.__init__(self, wxEVT_COMMAND_INT_UPDATED, id)
|
wx.PyCommandEvent.__init__(self, wxEVT_COMMAND_INT_UPDATED, id)
|
||||||
|
|
||||||
self.__value = value
|
self.__value = value
|
||||||
self.SetEventObject(object)
|
self.SetEventObject(object)
|
||||||
@@ -66,14 +74,14 @@ class wxIntUpdatedEvent(wxPyCommandEvent):
|
|||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxIntValidator( wxPyValidator ):
|
class wxIntValidator( wx.PyValidator ):
|
||||||
"""
|
"""
|
||||||
Validator class used with wxIntCtrl; handles all validation of input
|
Validator class used with wxIntCtrl; handles all validation of input
|
||||||
prior to changing the value of the underlying wxTextCtrl.
|
prior to changing the value of the underlying wx.TextCtrl.
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
wxPyValidator.__init__(self)
|
wx.PyValidator.__init__(self)
|
||||||
EVT_CHAR(self, self.OnChar)
|
self.Bind(wx.EVT_CHAR, self.OnChar)
|
||||||
|
|
||||||
def Clone (self):
|
def Clone (self):
|
||||||
return self.__class__()
|
return self.__class__()
|
||||||
@@ -100,7 +108,7 @@ class wxIntValidator( wxPyValidator ):
|
|||||||
|
|
||||||
|
|
||||||
value = ctrl.GetValue()
|
value = ctrl.GetValue()
|
||||||
textval = wxTextCtrl.GetValue(ctrl)
|
textval = wx.TextCtrl.GetValue(ctrl)
|
||||||
allow_none = ctrl.IsNoneAllowed()
|
allow_none = ctrl.IsNoneAllowed()
|
||||||
|
|
||||||
pos = ctrl.GetInsertionPoint()
|
pos = ctrl.GetInsertionPoint()
|
||||||
@@ -129,12 +137,12 @@ class wxIntValidator( wxPyValidator ):
|
|||||||
# Validate action, and predict resulting value, so we can
|
# Validate action, and predict resulting value, so we can
|
||||||
# range check the result and validate that too.
|
# range check the result and validate that too.
|
||||||
|
|
||||||
if key in (WXK_DELETE, WXK_BACK, WXK_CTRL_X):
|
if key in (wx.WXK_DELETE, wx.WXK_BACK, WXK_CTRL_X):
|
||||||
if select_len:
|
if select_len:
|
||||||
new_text = textval[:sel_start] + textval[sel_to:]
|
new_text = textval[:sel_start] + textval[sel_to:]
|
||||||
elif key == WXK_DELETE and pos < len(textval):
|
elif key == wx.WXK_DELETE and pos < len(textval):
|
||||||
new_text = textval[:pos] + textval[pos+1:]
|
new_text = textval[:pos] + textval[pos+1:]
|
||||||
elif key == WXK_BACK and pos > 0:
|
elif key == wx.WXK_BACK and pos > 0:
|
||||||
new_text = textval[:pos-1] + textval[pos:]
|
new_text = textval[:pos-1] + textval[pos:]
|
||||||
# (else value shouldn't change)
|
# (else value shouldn't change)
|
||||||
|
|
||||||
@@ -167,10 +175,12 @@ class wxIntValidator( wxPyValidator ):
|
|||||||
# size if ctrl limited to int. (if not,
|
# size if ctrl limited to int. (if not,
|
||||||
# disallow event.)
|
# disallow event.)
|
||||||
new_value = ctrl._fromGUI(new_text)
|
new_value = ctrl._fromGUI(new_text)
|
||||||
|
|
||||||
if paste_text:
|
if paste_text:
|
||||||
paste_value = ctrl._fromGUI(paste_text)
|
paste_value = ctrl._fromGUI(paste_text)
|
||||||
else:
|
else:
|
||||||
paste_value = 0
|
paste_value = 0
|
||||||
|
|
||||||
new_pos = sel_start + len(str(paste_value))
|
new_pos = sel_start + len(str(paste_value))
|
||||||
|
|
||||||
# if resulting value is 0, truncate and highlight value:
|
# if resulting value is 0, truncate and highlight value:
|
||||||
@@ -184,13 +194,14 @@ class wxIntValidator( wxPyValidator ):
|
|||||||
and ( (value >= 0 and pos == 0)
|
and ( (value >= 0 and pos == 0)
|
||||||
or (value < 0 and pos in [0,1]) ) ):
|
or (value < 0 and pos in [0,1]) ) ):
|
||||||
allow_event = 0
|
allow_event = 0
|
||||||
|
|
||||||
paste = 1
|
paste = 1
|
||||||
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
allow_event = 0
|
allow_event = 0
|
||||||
|
|
||||||
|
|
||||||
elif key < WXK_SPACE or key > 255:
|
elif key < wx.WXK_SPACE or key > 255:
|
||||||
pass # event ok
|
pass # event ok
|
||||||
|
|
||||||
|
|
||||||
@@ -254,19 +265,19 @@ class wxIntValidator( wxPyValidator ):
|
|||||||
# making this like "remove leading digits"
|
# making this like "remove leading digits"
|
||||||
|
|
||||||
# Account for leading zero when positioning cursor:
|
# Account for leading zero when positioning cursor:
|
||||||
if( key == WXK_BACK
|
if( key == wx.WXK_BACK
|
||||||
or (paste and paste_value == 0 and new_pos > 0) ):
|
or (paste and paste_value == 0 and new_pos > 0) ):
|
||||||
new_pos = new_pos - 1
|
new_pos = new_pos - 1
|
||||||
|
|
||||||
wxCallAfter(ctrl.SetValue, new_value)
|
wx.CallAfter(ctrl.SetValue, new_value)
|
||||||
wxCallAfter(ctrl.SetInsertionPoint, new_pos)
|
wx.CallAfter(ctrl.SetInsertionPoint, new_pos)
|
||||||
internally_set = 1
|
internally_set = 1
|
||||||
|
|
||||||
elif paste:
|
elif paste:
|
||||||
# Always do paste numerically, to remove
|
# Always do paste numerically, to remove
|
||||||
# leading/trailing spaces
|
# leading/trailing spaces
|
||||||
wxCallAfter(ctrl.SetValue, new_value)
|
wx.CallAfter(ctrl.SetValue, new_value)
|
||||||
wxCallAfter(ctrl.SetInsertionPoint, new_pos)
|
wx.CallAfter(ctrl.SetInsertionPoint, new_pos)
|
||||||
internally_set = 1
|
internally_set = 1
|
||||||
|
|
||||||
elif (new_value == 0 and len(new_text) > 1 ):
|
elif (new_value == 0 and len(new_text) > 1 ):
|
||||||
@@ -290,24 +301,24 @@ class wxIntValidator( wxPyValidator ):
|
|||||||
|
|
||||||
if allow_event:
|
if allow_event:
|
||||||
if set_to_none:
|
if set_to_none:
|
||||||
wxCallAfter(ctrl.SetValue, new_value)
|
wx.CallAfter(ctrl.SetValue, new_value)
|
||||||
|
|
||||||
elif set_to_zero:
|
elif set_to_zero:
|
||||||
# select to "empty" numeric value
|
# select to "empty" numeric value
|
||||||
wxCallAfter(ctrl.SetValue, new_value)
|
wx.CallAfter(ctrl.SetValue, new_value)
|
||||||
wxCallAfter(ctrl.SetInsertionPoint, 0)
|
wx.CallAfter(ctrl.SetInsertionPoint, 0)
|
||||||
wxCallAfter(ctrl.SetSelection, 0, 1)
|
wx.CallAfter(ctrl.SetSelection, 0, 1)
|
||||||
|
|
||||||
elif set_to_minus_one:
|
elif set_to_minus_one:
|
||||||
wxCallAfter(ctrl.SetValue, new_value)
|
wx.CallAfter(ctrl.SetValue, new_value)
|
||||||
wxCallAfter(ctrl.SetInsertionPoint, 1)
|
wx.CallAfter(ctrl.SetInsertionPoint, 1)
|
||||||
wxCallAfter(ctrl.SetSelection, 1, 2)
|
wx.CallAfter(ctrl.SetSelection, 1, 2)
|
||||||
|
|
||||||
elif not internally_set:
|
elif not internally_set:
|
||||||
event.Skip() # allow base wxTextCtrl to finish processing
|
event.Skip() # allow base wxTextCtrl to finish processing
|
||||||
|
|
||||||
elif not wxValidator_IsSilent():
|
elif not wx.Validator_IsSilent():
|
||||||
wxBell()
|
wx.Bell()
|
||||||
|
|
||||||
|
|
||||||
def TransferToWindow(self):
|
def TransferToWindow(self):
|
||||||
@@ -316,7 +327,7 @@ class wxIntValidator( wxPyValidator ):
|
|||||||
The default implementation returns False, indicating that an error
|
The default implementation returns False, indicating that an error
|
||||||
occurred. We simply return True, as we don't do any data transfer.
|
occurred. We simply return True, as we don't do any data transfer.
|
||||||
"""
|
"""
|
||||||
return True # Prevent wxDialog from complaining.
|
return True # Prevent wx.Dialog from complaining.
|
||||||
|
|
||||||
|
|
||||||
def TransferFromWindow(self):
|
def TransferFromWindow(self):
|
||||||
@@ -325,12 +336,12 @@ class wxIntValidator( wxPyValidator ):
|
|||||||
The default implementation returns False, indicating that an error
|
The default implementation returns False, indicating that an error
|
||||||
occurred. We simply return True, as we don't do any data transfer.
|
occurred. We simply return True, as we don't do any data transfer.
|
||||||
"""
|
"""
|
||||||
return True # Prevent wxDialog from complaining.
|
return True # Prevent wx.Dialog from complaining.
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxIntCtrl(wxTextCtrl):
|
class wxIntCtrl(wx.TextCtrl):
|
||||||
"""
|
"""
|
||||||
This class provides a control that takes and returns integers as
|
This class provides a control that takes and returns integers as
|
||||||
value, and provides bounds support and optional value limiting.
|
value, and provides bounds support and optional value limiting.
|
||||||
@@ -401,33 +412,33 @@ class wxIntCtrl(wxTextCtrl):
|
|||||||
|
|
||||||
def __init__ (
|
def __init__ (
|
||||||
self, parent, id=-1, value = 0,
|
self, parent, id=-1, value = 0,
|
||||||
pos = wxDefaultPosition, size = wxDefaultSize,
|
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||||
style = 0, validator = wxDefaultValidator,
|
style = 0, validator = wx.DefaultValidator,
|
||||||
name = "integer",
|
name = "integer",
|
||||||
min=None, max=None,
|
min=None, max=None,
|
||||||
limited = 0, allow_none = 0, allow_long = 0,
|
limited = 0, allow_none = 0, allow_long = 0,
|
||||||
default_color = wxBLACK, oob_color = wxRED,
|
default_color = wx.BLACK, oob_color = wx.RED,
|
||||||
):
|
):
|
||||||
|
|
||||||
# Establish attrs required for any operation on value:
|
# Establish attrs required for any operation on value:
|
||||||
self.__min = None
|
self.__min = None
|
||||||
self.__max = None
|
self.__max = None
|
||||||
self.__limited = 0
|
self.__limited = 0
|
||||||
self.__default_color = wxBLACK
|
self.__default_color = wx.BLACK
|
||||||
self.__oob_color = wxRED
|
self.__oob_color = wx.RED
|
||||||
self.__allow_none = 0
|
self.__allow_none = 0
|
||||||
self.__allow_long = 0
|
self.__allow_long = 0
|
||||||
self.__oldvalue = None
|
self.__oldvalue = None
|
||||||
|
|
||||||
if validator == wxDefaultValidator:
|
if validator == wx.DefaultValidator:
|
||||||
validator = wxIntValidator()
|
validator = wxIntValidator()
|
||||||
|
|
||||||
wxTextCtrl.__init__(
|
wx.TextCtrl.__init__(
|
||||||
self, parent, id, self._toGUI(0),
|
self, parent, id, self._toGUI(0),
|
||||||
pos, size, style, validator, name )
|
pos, size, style, validator, name )
|
||||||
|
|
||||||
# The following lets us set out our "integer update" events:
|
# The following lets us set out our "integer update" events:
|
||||||
EVT_TEXT( self, self.GetId(), self.OnText )
|
self.Bind(wx.EVT_TEXT, self.OnText )
|
||||||
|
|
||||||
# Establish parameters, with appropriate error checking
|
# Establish parameters, with appropriate error checking
|
||||||
|
|
||||||
@@ -444,8 +455,8 @@ class wxIntCtrl(wxTextCtrl):
|
|||||||
"""
|
"""
|
||||||
Handles an event indicating that the text control's value
|
Handles an event indicating that the text control's value
|
||||||
has changed, and issue EVT_INT event.
|
has changed, and issue EVT_INT event.
|
||||||
NOTE: using wxTextCtrl.SetValue() to change the control's
|
NOTE: using wx.TextCtrl.SetValue() to change the control's
|
||||||
contents from within a EVT_CHAR handler can cause double
|
contents from within a wx.EVT_CHAR handler can cause double
|
||||||
text events. So we check for actual changes to the text
|
text events. So we check for actual changes to the text
|
||||||
before passing the events on.
|
before passing the events on.
|
||||||
"""
|
"""
|
||||||
@@ -465,7 +476,7 @@ class wxIntCtrl(wxTextCtrl):
|
|||||||
"""
|
"""
|
||||||
Returns the current integer (long) value of the control.
|
Returns the current integer (long) value of the control.
|
||||||
"""
|
"""
|
||||||
return self._fromGUI( wxTextCtrl.GetValue(self) )
|
return self._fromGUI( wx.TextCtrl.GetValue(self) )
|
||||||
|
|
||||||
def SetValue(self, value):
|
def SetValue(self, value):
|
||||||
"""
|
"""
|
||||||
@@ -476,7 +487,7 @@ class wxIntCtrl(wxTextCtrl):
|
|||||||
A ValueError exception will be raised if an invalid value
|
A ValueError exception will be raised if an invalid value
|
||||||
is specified.
|
is specified.
|
||||||
"""
|
"""
|
||||||
wxTextCtrl.SetValue( self, self._toGUI(value) )
|
wx.TextCtrl.SetValue( self, self._toGUI(value) )
|
||||||
self._colorValue()
|
self._colorValue()
|
||||||
|
|
||||||
|
|
||||||
@@ -677,7 +688,7 @@ class wxIntCtrl(wxTextCtrl):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def SetColors(self, default_color=wxBLACK, oob_color=wxRED):
|
def SetColors(self, default_color=wx.BLACK, oob_color=wx.RED):
|
||||||
"""
|
"""
|
||||||
Tells the control what colors to use for normal and out-of-bounds
|
Tells the control what colors to use for normal and out-of-bounds
|
||||||
values. If the value currently exceeds the bounds, it will be
|
values. If the value currently exceeds the bounds, it will be
|
||||||
@@ -770,13 +781,13 @@ class wxIntCtrl(wxTextCtrl):
|
|||||||
"""
|
"""
|
||||||
sel_start, sel_to = self.GetSelection()
|
sel_start, sel_to = self.GetSelection()
|
||||||
select_len = sel_to - sel_start
|
select_len = sel_to - sel_start
|
||||||
textval = wxTextCtrl.GetValue(self)
|
textval = wx.TextCtrl.GetValue(self)
|
||||||
|
|
||||||
do = wxTextDataObject()
|
do = wx.TextDataObject()
|
||||||
do.SetText(textval[sel_start:sel_to])
|
do.SetText(textval[sel_start:sel_to])
|
||||||
wxTheClipboard.Open()
|
wx.TheClipboard.Open()
|
||||||
wxTheClipboard.SetData(do)
|
wx.TheClipboard.SetData(do)
|
||||||
wxTheClipboard.Close()
|
wx.TheClipboard.Close()
|
||||||
if select_len == len(wxTextCtrl.GetValue(self)):
|
if select_len == len(wxTextCtrl.GetValue(self)):
|
||||||
if not self.IsNoneAllowed():
|
if not self.IsNoneAllowed():
|
||||||
self.SetValue(0)
|
self.SetValue(0)
|
||||||
@@ -793,10 +804,10 @@ class wxIntCtrl(wxTextCtrl):
|
|||||||
"""
|
"""
|
||||||
Subroutine for getting the current contents of the clipboard.
|
Subroutine for getting the current contents of the clipboard.
|
||||||
"""
|
"""
|
||||||
do = wxTextDataObject()
|
do = wx.TextDataObject()
|
||||||
wxTheClipboard.Open()
|
wx.TheClipboard.Open()
|
||||||
success = wxTheClipboard.GetData(do)
|
success = wx.TheClipboard.GetData(do)
|
||||||
wxTheClipboard.Close()
|
wx.TheClipboard.Close()
|
||||||
|
|
||||||
if not success:
|
if not success:
|
||||||
return None
|
return None
|
||||||
@@ -815,7 +826,7 @@ class wxIntCtrl(wxTextCtrl):
|
|||||||
if paste_text:
|
if paste_text:
|
||||||
# (conversion will raise ValueError if paste isn't legal)
|
# (conversion will raise ValueError if paste isn't legal)
|
||||||
sel_start, sel_to = self.GetSelection()
|
sel_start, sel_to = self.GetSelection()
|
||||||
text = wxTextCtrl.GetValue( self )
|
text = wx.TextCtrl.GetValue( self )
|
||||||
new_text = text[:sel_start] + paste_text + text[sel_to:]
|
new_text = text[:sel_start] + paste_text + text[sel_to:]
|
||||||
if new_text == '' and self.IsNoneAllowed():
|
if new_text == '' and self.IsNoneAllowed():
|
||||||
self.SetValue(None)
|
self.SetValue(None)
|
||||||
@@ -823,7 +834,7 @@ class wxIntCtrl(wxTextCtrl):
|
|||||||
value = self._fromGUI(new_text)
|
value = self._fromGUI(new_text)
|
||||||
self.SetValue(value)
|
self.SetValue(value)
|
||||||
new_pos = sel_start + len(paste_text)
|
new_pos = sel_start + len(paste_text)
|
||||||
wxCallAfter(self.SetInsertionPoint, new_pos)
|
wx.CallAfter(self.SetInsertionPoint, new_pos)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -833,41 +844,39 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
class myDialog(wxDialog):
|
class myDialog(wx.Dialog):
|
||||||
def __init__(self, parent, id, title,
|
def __init__(self, parent, id, title,
|
||||||
pos = wxPyDefaultPosition, size = wxPyDefaultSize,
|
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||||
style = wxDEFAULT_DIALOG_STYLE ):
|
style = wx.DEFAULT_DIALOG_STYLE ):
|
||||||
wxDialog.__init__(self, parent, id, title, pos, size, style)
|
wx.Dialog.__init__(self, parent, id, title, pos, size, style)
|
||||||
|
|
||||||
self.int_ctrl = wxIntCtrl(self, wxNewId(), size=(55,20))
|
self.int_ctrl = wxIntCtrl(self, wx.NewId(), size=(55,20))
|
||||||
self.OK = wxButton( self, wxID_OK, "OK")
|
self.OK = wx.Button( self, wx.ID_OK, "OK")
|
||||||
self.Cancel = wxButton( self, wxID_CANCEL, "Cancel")
|
self.Cancel = wx.Button( self, wx.ID_CANCEL, "Cancel")
|
||||||
|
|
||||||
vs = wxBoxSizer( wxVERTICAL )
|
vs = wx.BoxSizer( wx.VERTICAL )
|
||||||
vs.AddWindow( self.int_ctrl, 0, wxALIGN_CENTRE|wxALL, 5 )
|
vs.Add( self.int_ctrl, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
||||||
hs = wxBoxSizer( wxHORIZONTAL )
|
hs = wx.BoxSizer( wx.HORIZONTAL )
|
||||||
hs.AddWindow( self.OK, 0, wxALIGN_CENTRE|wxALL, 5 )
|
hs.Add( self.OK, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
||||||
hs.AddWindow( self.Cancel, 0, wxALIGN_CENTRE|wxALL, 5 )
|
hs.Add( self.Cancel, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
||||||
vs.AddSizer(hs, 0, wxALIGN_CENTRE|wxALL, 5 )
|
vs.Add(hs, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
||||||
|
|
||||||
self.SetAutoLayout( True )
|
self.SetAutoLayout( True )
|
||||||
self.SetSizer( vs )
|
self.SetSizer( vs )
|
||||||
vs.Fit( self )
|
vs.Fit( self )
|
||||||
vs.SetSizeHints( self )
|
vs.SetSizeHints( self )
|
||||||
EVT_INT(self, self.int_ctrl.GetId(), self.OnInt)
|
self.Bind(EVT_INT, self.OnInt, self.int_ctrl)
|
||||||
|
|
||||||
def OnInt(self, event):
|
def OnInt(self, event):
|
||||||
print 'int now', event.GetValue()
|
print 'int now', event.GetValue()
|
||||||
|
|
||||||
class TestApp(wxApp):
|
class TestApp(wx.App):
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
try:
|
try:
|
||||||
self.frame = wxFrame(NULL, -1, "Test",
|
self.frame = wx.Frame(None, -1, "Test", (20,20), (120,100) )
|
||||||
wxPoint(20,20), wxSize(120,100) )
|
self.panel = wx.Panel(self.frame, -1)
|
||||||
self.panel = wxPanel(self.frame, -1)
|
button = wx.Button(self.panel, 10, "Push Me", (20, 20))
|
||||||
button = wxButton(self.panel, 10, "Push Me",
|
self.Bind(wx.EVT_BUTTON, self.OnClick, button)
|
||||||
wxPoint(20, 20))
|
|
||||||
EVT_BUTTON(self, 10, self.OnClick)
|
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
from wxPython.wx import wxLayoutConstraints,\
|
# 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
wxTop, wxLeft, wxBottom, wxRight, \
|
#
|
||||||
wxHeight, wxWidth, wxCentreX, wxCentreY
|
# o Updated for wx namespace
|
||||||
import re
|
#
|
||||||
|
|
||||||
class Layoutf(wxLayoutConstraints):
|
import re
|
||||||
|
import wx
|
||||||
|
|
||||||
|
class Layoutf(wx.LayoutConstraints):
|
||||||
"""
|
"""
|
||||||
The class Layoutf(wxLayoutConstraints) presents a simplification
|
The class Layoutf(wxLayoutConstraints) presents a simplification
|
||||||
of the wxLayoutConstraints syntax. The name Layoutf is choosen
|
of the wxLayoutConstraints syntax. The name Layoutf is choosen
|
||||||
@@ -117,15 +120,15 @@ time of this writing not documented.
|
|||||||
op_d = { '=': 'SameAs', '%': 'PercentOf', '<': 'LeftOf',
|
op_d = { '=': 'SameAs', '%': 'PercentOf', '<': 'LeftOf',
|
||||||
'>': 'RightOf', '^': 'Above', '_': 'Below',
|
'>': 'RightOf', '^': 'Above', '_': 'Below',
|
||||||
'!': 'Absolute', '?': 'Unconstrained', '*': 'AsIs' }
|
'!': 'Absolute', '?': 'Unconstrained', '*': 'AsIs' }
|
||||||
cmp_d = { 't': 'wxTop', 'l': 'wxLeft', 'b': 'wxBottom',
|
cmp_d = { 't': 'wx.Top', 'l': 'wx.Left', 'b': 'wx.Bottom',
|
||||||
'r': 'wxRight', 'h': 'wxHeight', 'w': 'wxWidth',
|
'r': 'wx.Right', 'h': 'wx.Height', 'w': 'wx.Width',
|
||||||
'x': 'wxCentreX', 'y': 'wxCentreY' }
|
'x': 'wx.CentreX', 'y': 'wx.CentreY' }
|
||||||
|
|
||||||
rexp1 = re.compile('^\s*([tlrbhwxy])\s*([!\?\*])\s*(\d*)\s*$')
|
rexp1 = re.compile('^\s*([tlrbhwxy])\s*([!\?\*])\s*(\d*)\s*$')
|
||||||
rexp2 = re.compile('^\s*([tlrbhwxy])\s*([=%<>^_])\s*([tlrbhwxy]?)\s*(\d*)\s*#(\d+)\s*$')
|
rexp2 = re.compile('^\s*([tlrbhwxy])\s*([=%<>^_])\s*([tlrbhwxy]?)\s*(\d*)\s*#(\d+)\s*$')
|
||||||
|
|
||||||
def __init__(self,pstr=None,winlist=None):
|
def __init__(self,pstr=None,winlist=None):
|
||||||
wxLayoutConstraints.__init__(self)
|
wx.LayoutConstraints.__init__(self)
|
||||||
if pstr:
|
if pstr:
|
||||||
self.pack(pstr,winlist)
|
self.pack(pstr,winlist)
|
||||||
|
|
||||||
@@ -194,62 +197,59 @@ time of this writing not documented.
|
|||||||
self.cmp_d[g[2]])
|
self.cmp_d[g[2]])
|
||||||
|
|
||||||
if __name__=='__main__':
|
if __name__=='__main__':
|
||||||
from wxPython.wx import *
|
|
||||||
|
|
||||||
class TestLayoutf(wxFrame):
|
class TestLayoutf(wx.Frame):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
wxFrame.__init__(self, parent, -1, 'Test Layout Constraints',
|
wx.Frame.__init__(self, parent, -1, 'Test Layout Constraints',
|
||||||
wxPyDefaultPosition, wxSize(500, 300))
|
wx.DefaultPosition, (500, 300))
|
||||||
EVT_CLOSE(self, self.OnCloseWindow)
|
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
||||||
|
|
||||||
self.SetAutoLayout(True)
|
self.SetAutoLayout(True)
|
||||||
EVT_BUTTON(self, 100, self.OnButton)
|
|
||||||
EVT_BUTTON(self, 101, self.OnAbout)
|
|
||||||
|
|
||||||
self.panelA = wxWindow(self, -1, wxPyDefaultPosition, wxPyDefaultSize, wxSIMPLE_BORDER)
|
self.panelA = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
|
||||||
self.panelA.SetBackgroundColour(wxBLUE)
|
self.panelA.SetBackgroundColour(wx.BLUE)
|
||||||
self.panelA.SetConstraints(Layoutf('t=t10#1;l=l10#1;b=b10#1;r%r50#1',(self,)))
|
self.panelA.SetConstraints(Layoutf('t=t10#1;l=l10#1;b=b10#1;r%r50#1',(self,)))
|
||||||
|
|
||||||
self.panelB = wxWindow(self, -1, wxPyDefaultPosition, wxPyDefaultSize, wxSIMPLE_BORDER)
|
self.panelB = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
|
||||||
self.panelB.SetBackgroundColour(wxRED)
|
self.panelB.SetBackgroundColour(wx.RED)
|
||||||
self.panelB.SetConstraints(Layoutf('t=t10#1;r=r10#1;b%b30#1;l>10#2', (self,self.panelA)))
|
self.panelB.SetConstraints(Layoutf('t=t10#1;r=r10#1;b%b30#1;l>10#2', (self,self.panelA)))
|
||||||
|
|
||||||
self.panelC = wxWindow(self, -1, wxPyDefaultPosition, wxPyDefaultSize, wxSIMPLE_BORDER)
|
self.panelC = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
|
||||||
self.panelC.SetBackgroundColour(wxWHITE)
|
self.panelC.SetBackgroundColour(wx.WHITE)
|
||||||
self.panelC.SetConstraints(Layoutf('t_10#3;r=r10#1;b=b10#1;l>10#2', (self,self.panelA,self.panelB)))
|
self.panelC.SetConstraints(Layoutf('t_10#3;r=r10#1;b=b10#1;l>10#2', (self,self.panelA,self.panelB)))
|
||||||
|
|
||||||
b = wxButton(self.panelA, 101, ' About: ')
|
b = wx.Button(self.panelA, -1, ' About: ')
|
||||||
b.SetConstraints(Layoutf('X=X#1;Y=Y#1;h*;w%w50#1', (self.panelA,)))
|
b.SetConstraints(Layoutf('X=X#1;Y=Y#1;h*;w%w50#1', (self.panelA,)))
|
||||||
|
self.Bind(wx.EVT_BUTTON, self.OnAbout, b)
|
||||||
|
|
||||||
b = wxButton(self.panelB, 100, ' Panel B ')
|
b = wx.Button(self.panelB, 100, ' Panel B ')
|
||||||
b.SetConstraints(Layoutf('t=t2#1;r=r4#1;h*;w*', (self.panelB,)))
|
b.SetConstraints(Layoutf('t=t2#1;r=r4#1;h*;w*', (self.panelB,)))
|
||||||
|
|
||||||
self.panelD = wxWindow(self.panelC, -1, wxPyDefaultPosition, wxPyDefaultSize, wxSIMPLE_BORDER)
|
self.panelD = wx.Window(self.panelC, -1, style=wx.SIMPLE_BORDER)
|
||||||
self.panelD.SetBackgroundColour(wxGREEN)
|
self.panelD.SetBackgroundColour(wx.GREEN)
|
||||||
self.panelD.SetConstraints(Layoutf('b%h50#1;r%w50#1;h=h#2;w=w#2', (self.panelC, b)))
|
self.panelD.SetConstraints(Layoutf('b%h50#1;r%w50#1;h=h#2;w=w#2', (self.panelC, b)))
|
||||||
|
|
||||||
b = wxButton(self.panelC, 100, ' Panel C ')
|
b = wx.Button(self.panelC, -1, ' Panel C ')
|
||||||
b.SetConstraints(Layoutf('t_#1;l>#1;h*;w*', (self.panelD,)))
|
b.SetConstraints(Layoutf('t_#1;l>#1;h*;w*', (self.panelD,)))
|
||||||
|
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
|
||||||
|
|
||||||
wxStaticText(self.panelD, -1, "Panel D", wxPoint(4, 4)).SetBackgroundColour(wxGREEN)
|
wx.StaticText(self.panelD, -1, "Panel D", (4, 4)).SetBackgroundColour(wx.GREEN)
|
||||||
|
|
||||||
def OnButton(self, event):
|
def OnButton(self, event):
|
||||||
self.Close(True)
|
self.Close(True)
|
||||||
|
|
||||||
def OnAbout(self, event):
|
def OnAbout(self, event):
|
||||||
try:
|
import wx.lib.dialogs
|
||||||
from dialogs import wxScrolledMessageDialog
|
msg = wx.lib.dialogs.wxScrolledMessageDialog(self, Layoutf.__doc__, "about")
|
||||||
msg = wxScrolledMessageDialog(self, Layoutf.__doc__, "about")
|
|
||||||
msg.ShowModal()
|
msg.ShowModal()
|
||||||
except:
|
msg.Destroy()
|
||||||
print msg
|
|
||||||
|
|
||||||
def OnCloseWindow(self, event):
|
def OnCloseWindow(self, event):
|
||||||
self.Destroy()
|
self.Destroy()
|
||||||
|
|
||||||
class TestApp(wxApp):
|
class TestApp(wx.App):
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
frame = TestLayoutf(NULL)
|
frame = TestLayoutf(None)
|
||||||
frame.Show(1)
|
frame.Show(1)
|
||||||
self.SetTopWindow(frame)
|
self.SetTopWindow(frame)
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
# RCS-ID: $Id$
|
# RCS-ID: $Id$
|
||||||
# License: wxWindows license
|
# License: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
# 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Updated for wx namespace (minor)
|
||||||
|
#
|
||||||
|
|
||||||
"""<html><body>
|
"""<html><body>
|
||||||
<P>
|
<P>
|
||||||
@@ -47,9 +51,9 @@ their own demo pages and interface descriptions.
|
|||||||
</body></html>
|
</body></html>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from wxPython.lib.maskededit import wxMaskedTextCtrl, wxMaskedComboBox, wxIpAddrCtrl
|
from wx.lib.maskededit import wxMaskedTextCtrl, wxMaskedComboBox, wxIpAddrCtrl
|
||||||
from wxPython.lib.maskednumctrl import wxMaskedNumCtrl
|
from wx.lib.maskednumctrl import wxMaskedNumCtrl
|
||||||
from wxPython.lib.timectrl import wxTimeCtrl
|
from wx.lib.timectrl import wxTimeCtrl
|
||||||
|
|
||||||
|
|
||||||
# "type" enumeration for class instance factory function
|
# "type" enumeration for class instance factory function
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -31,6 +31,12 @@
|
|||||||
# wxMaskedNumCtrl is intended to support fixed-point numeric entry, and
|
# wxMaskedNumCtrl is intended to support fixed-point numeric entry, and
|
||||||
# is derived from wxMaskedTextCtrl. As such, it supports a limited range
|
# is derived from wxMaskedTextCtrl. As such, it supports a limited range
|
||||||
# of values to comply with a fixed-width entry mask.
|
# of values to comply with a fixed-width entry mask.
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Updated for wx namespace
|
||||||
|
#
|
||||||
|
|
||||||
"""<html><body>
|
"""<html><body>
|
||||||
<P>
|
<P>
|
||||||
<B>wxMaskedNumCtrl:</B>
|
<B>wxMaskedNumCtrl:</B>
|
||||||
@@ -344,32 +350,32 @@ the field values on entry.
|
|||||||
</body></html>
|
</body></html>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from wxPython.wx import *
|
import copy
|
||||||
import types, string, copy
|
import string
|
||||||
|
import types
|
||||||
|
|
||||||
|
import wx
|
||||||
|
|
||||||
from sys import maxint
|
from sys import maxint
|
||||||
MAXINT = maxint # (constants should be in upper case)
|
MAXINT = maxint # (constants should be in upper case)
|
||||||
MININT = -maxint-1
|
MININT = -maxint-1
|
||||||
|
|
||||||
from wxPython.tools.dbg import Logger
|
from wx.tools.dbg import Logger
|
||||||
from wxPython.lib.maskededit import wxMaskedEditMixin, wxMaskedTextCtrl, Field
|
from wx.lib.maskededit import wxMaskedEditMixin, wxMaskedTextCtrl, Field
|
||||||
|
|
||||||
dbg = Logger()
|
dbg = Logger()
|
||||||
dbg(enable=0)
|
dbg(enable=0)
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxEVT_COMMAND_MASKED_NUMBER_UPDATED = wxNewEventType()
|
wxEVT_COMMAND_MASKED_NUMBER_UPDATED = wx.NewEventType()
|
||||||
|
EVT_MASKEDNUM = wx.PyEventBinder(wxEVT_COMMAND_MASKED_NUMBER_UPDATED, 1)
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
def EVT_MASKEDNUM(win, id, func):
|
class wxMaskedNumNumberUpdatedEvent(wx.PyCommandEvent):
|
||||||
"""Used to trap events indicating that the current
|
|
||||||
integer value of the control has been changed."""
|
|
||||||
win.Connect(id, -1, wxEVT_COMMAND_MASKED_NUMBER_UPDATED, func)
|
|
||||||
|
|
||||||
|
|
||||||
class wxMaskedNumNumberUpdatedEvent(wxPyCommandEvent):
|
|
||||||
def __init__(self, id, value = 0, object=None):
|
def __init__(self, id, value = 0, object=None):
|
||||||
wxPyCommandEvent.__init__(self, wxEVT_COMMAND_MASKED_NUMBER_UPDATED, id)
|
wx.PyCommandEvent.__init__(self, wxEVT_COMMAND_MASKED_NUMBER_UPDATED, id)
|
||||||
|
|
||||||
self.__value = value
|
self.__value = value
|
||||||
self.SetEventObject(object)
|
self.SetEventObject(object)
|
||||||
@@ -408,8 +414,8 @@ class wxMaskedNumCtrl(wxMaskedTextCtrl):
|
|||||||
|
|
||||||
def __init__ (
|
def __init__ (
|
||||||
self, parent, id=-1, value = 0,
|
self, parent, id=-1, value = 0,
|
||||||
pos = wxDefaultPosition, size = wxDefaultSize,
|
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||||
style = wxTE_PROCESS_TAB, validator = wxDefaultValidator,
|
style = wx.TE_PROCESS_TAB, validator = wx.DefaultValidator,
|
||||||
name = "maskednum",
|
name = "maskednum",
|
||||||
**kwargs ):
|
**kwargs ):
|
||||||
|
|
||||||
@@ -493,13 +499,13 @@ class wxMaskedNumCtrl(wxMaskedTextCtrl):
|
|||||||
validFunc=self.IsInBounds,
|
validFunc=self.IsInBounds,
|
||||||
setupEventHandling = False)
|
setupEventHandling = False)
|
||||||
|
|
||||||
EVT_SET_FOCUS( self, self._OnFocus ) ## defeat automatic full selection
|
self.Bind(wx.EVT_SET_FOCUS, self._OnFocus ) ## defeat automatic full selection
|
||||||
EVT_KILL_FOCUS( self, self._OnKillFocus ) ## run internal validator
|
self.Bind(wx.EVT_KILL_FOCUS, self._OnKillFocus ) ## run internal validator
|
||||||
EVT_LEFT_DCLICK(self, self._OnDoubleClick) ## select field under cursor on dclick
|
self.Bind(wx.EVT_LEFT_DCLICK, self._OnDoubleClick) ## select field under cursor on dclick
|
||||||
EVT_RIGHT_UP(self, self._OnContextMenu ) ## bring up an appropriate context menu
|
self.Bind(wx.EVT_RIGHT_UP, self._OnContextMenu ) ## bring up an appropriate context menu
|
||||||
EVT_KEY_DOWN( self, self._OnKeyDown ) ## capture control events not normally seen, eg ctrl-tab.
|
self.Bind(wx.EVT_KEY_DOWN, self._OnKeyDown ) ## capture control events not normally seen, eg ctrl-tab.
|
||||||
EVT_CHAR( self, self._OnChar ) ## handle each keypress
|
self.Bind(wx.EVT_CHAR, self._OnChar ) ## handle each keypress
|
||||||
EVT_TEXT( self, self.GetId(), self.OnTextChange ) ## color control appropriately & keep
|
self.Bind(wx.EVT_TEXT, self.OnTextChange ) ## color control appropriately & keep
|
||||||
## track of previous value for undo
|
## track of previous value for undo
|
||||||
|
|
||||||
# Establish any additional parameters, with appropriate error checking
|
# Establish any additional parameters, with appropriate error checking
|
||||||
@@ -710,7 +716,7 @@ class wxMaskedNumCtrl(wxMaskedTextCtrl):
|
|||||||
if kwargs.has_key('decimalChar') and text.find(old_decimalchar) != -1:
|
if kwargs.has_key('decimalChar') and text.find(old_decimalchar) != -1:
|
||||||
text = text.replace(old_decimalchar, self._decimalChar)
|
text = text.replace(old_decimalchar, self._decimalChar)
|
||||||
if text != self._GetValue():
|
if text != self._GetValue():
|
||||||
wxTextCtrl.SetValue(self, text)
|
wx.TextCtrl.SetValue(self, text)
|
||||||
|
|
||||||
value = self.GetValue()
|
value = self.GetValue()
|
||||||
|
|
||||||
@@ -783,12 +789,12 @@ class wxMaskedNumCtrl(wxMaskedTextCtrl):
|
|||||||
# limited and -1 is out of bounds
|
# limited and -1 is out of bounds
|
||||||
if self._typedSign:
|
if self._typedSign:
|
||||||
self._isNeg = False
|
self._isNeg = False
|
||||||
if not wxValidator_IsSilent():
|
if not wx.Validator_IsSilent():
|
||||||
wxBell()
|
wx.Bell()
|
||||||
sel_start, sel_to = self._GetSelection()
|
sel_start, sel_to = self._GetSelection()
|
||||||
dbg('queuing reselection of (%d, %d)' % (sel_start, sel_to))
|
dbg('queuing reselection of (%d, %d)' % (sel_start, sel_to))
|
||||||
wxCallAfter(self.SetInsertionPoint, sel_start) # preserve current selection/position
|
wx.CallAfter(self.SetInsertionPoint, sel_start) # preserve current selection/position
|
||||||
wxCallAfter(self.SetSelection, sel_start, sel_to)
|
wx.CallAfter(self.SetSelection, sel_start, sel_to)
|
||||||
|
|
||||||
def _SetValue(self, value):
|
def _SetValue(self, value):
|
||||||
"""
|
"""
|
||||||
@@ -888,12 +894,12 @@ class wxMaskedNumCtrl(wxMaskedTextCtrl):
|
|||||||
# is attempting to insert a digit in the middle of the control
|
# is attempting to insert a digit in the middle of the control
|
||||||
# resulting in something like " 3 45". Disallow such actions:
|
# resulting in something like " 3 45". Disallow such actions:
|
||||||
dbg('>>>>>>>>>>>>>>>> "%s" does not convert to a long!' % int)
|
dbg('>>>>>>>>>>>>>>>> "%s" does not convert to a long!' % int)
|
||||||
if not wxValidator_IsSilent():
|
if not wx.Validator_IsSilent():
|
||||||
wxBell()
|
wx.Bell()
|
||||||
sel_start, sel_to = self._GetSelection()
|
sel_start, sel_to = self._GetSelection()
|
||||||
dbg('queuing reselection of (%d, %d)' % (sel_start, sel_to))
|
dbg('queuing reselection of (%d, %d)' % (sel_start, sel_to))
|
||||||
wxCallAfter(self.SetInsertionPoint, sel_start) # preserve current selection/position
|
wx.CallAfter(self.SetInsertionPoint, sel_start) # preserve current selection/position
|
||||||
wxCallAfter(self.SetSelection, sel_start, sel_to)
|
wx.CallAfter(self.SetSelection, sel_start, sel_to)
|
||||||
dbg(indent=0)
|
dbg(indent=0)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -915,8 +921,8 @@ class wxMaskedNumCtrl(wxMaskedTextCtrl):
|
|||||||
sel_start = wxMaskedTextCtrl.GetValue(self).find(str(abs(replacement))) # find where it put the 1, so we can select it
|
sel_start = wxMaskedTextCtrl.GetValue(self).find(str(abs(replacement))) # find where it put the 1, so we can select it
|
||||||
sel_to = sel_start + len(str(abs(replacement)))
|
sel_to = sel_start + len(str(abs(replacement)))
|
||||||
dbg('queuing selection of (%d, %d)' %(sel_start, sel_to))
|
dbg('queuing selection of (%d, %d)' %(sel_start, sel_to))
|
||||||
wxCallAfter(self.SetInsertionPoint, sel_start)
|
wx.CallAfter(self.SetInsertionPoint, sel_start)
|
||||||
wxCallAfter(self.SetSelection, sel_start, sel_to)
|
wx.CallAfter(self.SetSelection, sel_start, sel_to)
|
||||||
dbg(indent=0)
|
dbg(indent=0)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -942,7 +948,7 @@ class wxMaskedNumCtrl(wxMaskedTextCtrl):
|
|||||||
wxMaskedTextCtrl._SetValue(self, adjvalue)
|
wxMaskedTextCtrl._SetValue(self, adjvalue)
|
||||||
# After all actions so far scheduled, check that resulting cursor
|
# After all actions so far scheduled, check that resulting cursor
|
||||||
# position is appropriate, and move if not:
|
# position is appropriate, and move if not:
|
||||||
wxCallAfter(self._CheckInsertionPoint)
|
wx.CallAfter(self._CheckInsertionPoint)
|
||||||
|
|
||||||
dbg('finished wxMaskedNumCtrl::_SetValue', indent=0)
|
dbg('finished wxMaskedNumCtrl::_SetValue', indent=0)
|
||||||
|
|
||||||
@@ -975,7 +981,7 @@ class wxMaskedNumCtrl(wxMaskedTextCtrl):
|
|||||||
value = wxMaskedTextCtrl.GetValue(self)
|
value = wxMaskedTextCtrl.GetValue(self)
|
||||||
sel_start, sel_to = self._GetSelection()
|
sel_start, sel_to = self._GetSelection()
|
||||||
|
|
||||||
if key == WXK_BACK:
|
if key == wx.WXK_BACK:
|
||||||
# if 1st selected char is group char, select to previous digit
|
# if 1st selected char is group char, select to previous digit
|
||||||
if sel_start > 0 and sel_start < len(self._mask) and value[sel_start:sel_to] == self._groupChar:
|
if sel_start > 0 and sel_start < len(self._mask) and value[sel_start:sel_to] == self._groupChar:
|
||||||
self.SetInsertionPoint(sel_start-1)
|
self.SetInsertionPoint(sel_start-1)
|
||||||
@@ -986,7 +992,7 @@ class wxMaskedNumCtrl(wxMaskedTextCtrl):
|
|||||||
self.SetInsertionPoint(sel_start-2)
|
self.SetInsertionPoint(sel_start-2)
|
||||||
self.SetSelection(sel_start-2, sel_to)
|
self.SetSelection(sel_start-2, sel_to)
|
||||||
|
|
||||||
elif key == WXK_DELETE:
|
elif key == wx.WXK_DELETE:
|
||||||
if( sel_to < len(self._mask) - 2 + (1 *self._useParens)
|
if( sel_to < len(self._mask) - 2 + (1 *self._useParens)
|
||||||
and sel_start == sel_to
|
and sel_start == sel_to
|
||||||
and value[sel_to] == self._groupChar ):
|
and value[sel_to] == self._groupChar ):
|
||||||
@@ -1036,7 +1042,7 @@ class wxMaskedNumCtrl(wxMaskedTextCtrl):
|
|||||||
Override of wxMaskedTextCtrl to allow amixin to get the raw text value of the
|
Override of wxMaskedTextCtrl to allow amixin to get the raw text value of the
|
||||||
control with this function.
|
control with this function.
|
||||||
"""
|
"""
|
||||||
return wxTextCtrl.GetValue(self)
|
return wx.TextCtrl.GetValue(self)
|
||||||
|
|
||||||
|
|
||||||
def GetValue(self):
|
def GetValue(self):
|
||||||
@@ -1438,41 +1444,39 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
class myDialog(wxDialog):
|
class myDialog(wx.Dialog):
|
||||||
def __init__(self, parent, id, title,
|
def __init__(self, parent, id, title,
|
||||||
pos = wxPyDefaultPosition, size = wxPyDefaultSize,
|
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||||
style = wxDEFAULT_DIALOG_STYLE ):
|
style = wx.DEFAULT_DIALOG_STYLE ):
|
||||||
wxDialog.__init__(self, parent, id, title, pos, size, style)
|
wx.Dialog.__init__(self, parent, id, title, pos, size, style)
|
||||||
|
|
||||||
self.int_ctrl = wxMaskedNumCtrl(self, wxNewId(), size=(55,20))
|
self.int_ctrl = wxMaskedNumCtrl(self, wx.NewId(), size=(55,20))
|
||||||
self.OK = wxButton( self, wxID_OK, "OK")
|
self.OK = wx.Button( self, wx.ID_OK, "OK")
|
||||||
self.Cancel = wxButton( self, wxID_CANCEL, "Cancel")
|
self.Cancel = wx.Button( self, wx.ID_CANCEL, "Cancel")
|
||||||
|
|
||||||
vs = wxBoxSizer( wxVERTICAL )
|
vs = wx.BoxSizer( wx.VERTICAL )
|
||||||
vs.AddWindow( self.int_ctrl, 0, wxALIGN_CENTRE|wxALL, 5 )
|
vs.Add( self.int_ctrl, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
||||||
hs = wxBoxSizer( wxHORIZONTAL )
|
hs = wx.BoxSizer( wx.HORIZONTAL )
|
||||||
hs.AddWindow( self.OK, 0, wxALIGN_CENTRE|wxALL, 5 )
|
hs.Add( self.OK, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
||||||
hs.AddWindow( self.Cancel, 0, wxALIGN_CENTRE|wxALL, 5 )
|
hs.Add( self.Cancel, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
||||||
vs.AddSizer(hs, 0, wxALIGN_CENTRE|wxALL, 5 )
|
vs.Add(hs, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
||||||
|
|
||||||
self.SetAutoLayout( True )
|
self.SetAutoLayout( True )
|
||||||
self.SetSizer( vs )
|
self.SetSizer( vs )
|
||||||
vs.Fit( self )
|
vs.Fit( self )
|
||||||
vs.SetSizeHints( self )
|
vs.SetSizeHints( self )
|
||||||
EVT_MASKEDNUM(self, self.int_ctrl.GetId(), self.OnChange)
|
self.Bind(EVT_MASKEDNUM, self.OnChange, self.int_ctrl)
|
||||||
|
|
||||||
def OnChange(self, event):
|
def OnChange(self, event):
|
||||||
print 'value now', event.GetValue()
|
print 'value now', event.GetValue()
|
||||||
|
|
||||||
class TestApp(wxApp):
|
class TestApp(wx.App):
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
try:
|
try:
|
||||||
self.frame = wxFrame(NULL, -1, "Test",
|
self.frame = wx.Frame(None, -1, "Test", (20,20), (120,100) )
|
||||||
wxPoint(20,20), wxSize(120,100) )
|
self.panel = wx.Panel(self.frame, -1)
|
||||||
self.panel = wxPanel(self.frame, -1)
|
button = wx.Button(self.panel, -1, "Push Me", (20, 20))
|
||||||
button = wxButton(self.panel, 10, "Push Me",
|
self.Bind(wx.EVT_BUTTON, self.OnClick, button)
|
||||||
wxPoint(20, 20))
|
|
||||||
EVT_BUTTON(self, 10, self.OnClick)
|
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -9,6 +9,10 @@
|
|||||||
# Copyright: (c) 2001 by Total Control Software
|
# Copyright: (c) 2001 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,14 @@
|
|||||||
# Copyright: (c) 2001 by Total Control Software
|
# Copyright: (c) 2001 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
# o Untested
|
||||||
|
#
|
||||||
|
|
||||||
from wxPython import wx, grid
|
import wx
|
||||||
|
import wx.grid
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -25,8 +31,8 @@ class wxGridAutoEditMixin:
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.__enableEdit = 0
|
self.__enableEdit = 0
|
||||||
wx.EVT_IDLE(self, self.__OnIdle)
|
self.Bind(wx.EVT_IDLE, self.__OnIdle)
|
||||||
grid.EVT_GRID_SELECT_CELL(self, self.__OnSelectCell)
|
self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.__OnSelectCell)
|
||||||
|
|
||||||
|
|
||||||
def __OnIdle(self, evt):
|
def __OnIdle(self, evt):
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Name: wxPython.lib.mixins.listctrl
|
# Name: wx.lib.mixins.imagelist
|
||||||
# Purpose: Helpful mix-in classes for using a wxImageList
|
# Purpose: Helpful mix-in classes for using a wxImageList
|
||||||
#
|
#
|
||||||
# Author: Robin Dunn
|
# Author: Robin Dunn
|
||||||
@@ -9,8 +9,13 @@
|
|||||||
# Copyright: (c) 2001 by Total Control Software
|
# Copyright: (c) 2001 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
# o Untested.
|
||||||
|
#
|
||||||
|
|
||||||
from wxPython.wx import *
|
import wx
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -25,12 +30,12 @@ class MagicImageList:
|
|||||||
|
|
||||||
def SetupIcons(self, images=(), size=None):
|
def SetupIcons(self, images=(), size=None):
|
||||||
self.__size = size or self.DEFAULTICONSIZE
|
self.__size = size or self.DEFAULTICONSIZE
|
||||||
self.__magicImageList = wxImageList (self.__size,self.__size)
|
self.__magicImageList = wx.ImageList (self.__size,self.__size)
|
||||||
self.__magicImageListMapping = {}
|
self.__magicImageListMapping = {}
|
||||||
self.SetImageList (
|
self.SetImageList (
|
||||||
self.__magicImageList, {
|
self.__magicImageList, {
|
||||||
16:wxIMAGE_LIST_SMALL,
|
16:wx.IMAGE_LIST_SMALL,
|
||||||
32:wxIMAGE_LIST_NORMAL,
|
32:wx.IMAGE_LIST_NORMAL,
|
||||||
}[self.__size]
|
}[self.__size]
|
||||||
)
|
)
|
||||||
for image in images:
|
for image in images:
|
||||||
@@ -46,20 +51,20 @@ class MagicImageList:
|
|||||||
|
|
||||||
|
|
||||||
### Local methods...
|
### Local methods...
|
||||||
def AddIcon(self, icon, mask = wxNullBitmap):
|
def AddIcon(self, icon, mask = wx.NullBitmap):
|
||||||
'''Add an icon to the image list, or get the index if already there'''
|
'''Add an icon to the image list, or get the index if already there'''
|
||||||
index = self.__magicImageListMapping.get (id (icon))
|
index = self.__magicImageListMapping.get (id (icon))
|
||||||
if index is None:
|
if index is None:
|
||||||
if isinstance( icon, wxIconPtr ):
|
if isinstance( icon, wxIconPtr ):
|
||||||
index = self.__magicImageList.AddIcon( icon )
|
index = self.__magicImageList.AddIcon( icon )
|
||||||
elif isinstance( icon, wxBitmapPtr ):
|
elif isinstance( icon, wx.BitmapPtr ):
|
||||||
if isinstance( mask, wxColour ):
|
if isinstance( mask, wx.Colour ):
|
||||||
index = self.__magicImageList.AddWithColourMask( icon, mask )
|
index = self.__magicImageList.AddWithColourMask( icon, mask )
|
||||||
else:
|
else:
|
||||||
index = self.__magicImageList.Add( icon, mask )
|
index = self.__magicImageList.Add( icon, mask )
|
||||||
else:
|
else:
|
||||||
raise ValueError("Unexpected icon object %s, "
|
raise ValueError("Unexpected icon object %s, "
|
||||||
"expected wxIcon or wxBitmap" % (icon))
|
"expected wx.Icon or wx.Bitmap" % (icon))
|
||||||
self.__magicImageListMapping [id (icon)] = index
|
self.__magicImageListMapping [id (icon)] = index
|
||||||
return index
|
return index
|
||||||
|
|
||||||
|
|||||||
@@ -9,22 +9,27 @@
|
|||||||
# Copyright: (c) 2001 by Total Control Software
|
# Copyright: (c) 2001 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
# o ListCtrlSelectionManagerMix untested.
|
||||||
|
#
|
||||||
|
|
||||||
from wxPython.wx import *
|
|
||||||
import locale
|
import locale
|
||||||
|
import wx
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxColumnSorterMixin:
|
class wxColumnSorterMixin:
|
||||||
"""
|
"""
|
||||||
A mixin class that handles sorting of a wxListCtrl in REPORT mode when
|
A mixin class that handles sorting of a wx.ListCtrl in REPORT mode when
|
||||||
the column header is clicked on.
|
the column header is clicked on.
|
||||||
|
|
||||||
There are a few requirments needed in order for this to work genericly:
|
There are a few requirments needed in order for this to work genericly:
|
||||||
|
|
||||||
1. The combined class must have a GetListCtrl method that
|
1. The combined class must have a GetListCtrl method that
|
||||||
returns the wxListCtrl to be sorted, and the list control
|
returns the wx.ListCtrl to be sorted, and the list control
|
||||||
must exist at the time the wxColumnSorterMixin.__init__
|
must exist at the time the wx.ColumnSorterMixin.__init__
|
||||||
method is called because it uses GetListCtrl.
|
method is called because it uses GetListCtrl.
|
||||||
|
|
||||||
2. Items in the list control must have a unique data value set
|
2. Items in the list control must have a unique data value set
|
||||||
@@ -43,8 +48,8 @@ class wxColumnSorterMixin:
|
|||||||
self.SetColumnCount(numColumns)
|
self.SetColumnCount(numColumns)
|
||||||
list = self.GetListCtrl()
|
list = self.GetListCtrl()
|
||||||
if not list:
|
if not list:
|
||||||
raise ValueError, "No wxListCtrl available"
|
raise ValueError, "No wx.ListCtrl available"
|
||||||
EVT_LIST_COL_CLICK(list, list.GetId(), self.__OnColClick)
|
self.Bind(wx.EVT_LIST_COL_CLICK, self.__OnColClick, list)
|
||||||
|
|
||||||
|
|
||||||
def SetColumnCount(self, newNumColumns):
|
def SetColumnCount(self, newNumColumns):
|
||||||
@@ -141,15 +146,15 @@ class wxColumnSorterMixin:
|
|||||||
|
|
||||||
class wxListCtrlAutoWidthMixin:
|
class wxListCtrlAutoWidthMixin:
|
||||||
""" A mix-in class that automatically resizes the last column to take up
|
""" A mix-in class that automatically resizes the last column to take up
|
||||||
the remaining width of the wxListCtrl.
|
the remaining width of the wx.ListCtrl.
|
||||||
|
|
||||||
This causes the wxListCtrl to automatically take up the full width of
|
This causes the wx.ListCtrl to automatically take up the full width of
|
||||||
the list, without either a horizontal scroll bar (unless absolutely
|
the list, without either a horizontal scroll bar (unless absolutely
|
||||||
necessary) or empty space to the right of the last column.
|
necessary) or empty space to the right of the last column.
|
||||||
|
|
||||||
NOTE: This only works for report-style lists.
|
NOTE: This only works for report-style lists.
|
||||||
|
|
||||||
WARNING: If you override the EVT_SIZE event in your wxListCtrl, make
|
WARNING: If you override the EVT_SIZE event in your wx.ListCtrl, make
|
||||||
sure you call event.Skip() to ensure that the mixin's
|
sure you call event.Skip() to ensure that the mixin's
|
||||||
_OnResize method is called.
|
_OnResize method is called.
|
||||||
|
|
||||||
@@ -160,8 +165,8 @@ class wxListCtrlAutoWidthMixin:
|
|||||||
"""
|
"""
|
||||||
self._lastColMinWidth = None
|
self._lastColMinWidth = None
|
||||||
|
|
||||||
EVT_SIZE(self, self._onResize)
|
self.Bind(wx.EVT_SIZE, self._onResize)
|
||||||
EVT_LIST_COL_END_DRAG(self, self.GetId(), self._onResize)
|
self.Bind(wx.EVT_LIST_COL_END_DRAG, self._onResize, self)
|
||||||
|
|
||||||
|
|
||||||
def resizeLastColumn(self, minWidth):
|
def resizeLastColumn(self, minWidth):
|
||||||
@@ -171,7 +176,7 @@ class wxListCtrlAutoWidthMixin:
|
|||||||
a horizontal scrollbar. Otherwise, we expand the right-most column
|
a horizontal scrollbar. Otherwise, we expand the right-most column
|
||||||
to take up the remaining free space in the list.
|
to take up the remaining free space in the list.
|
||||||
|
|
||||||
This method is called automatically when the wxListCtrl is resized;
|
This method is called automatically when the wx.ListCtrl is resized;
|
||||||
you can also call it yourself whenever you want the last column to
|
you can also call it yourself whenever you want the last column to
|
||||||
be resized appropriately (eg, when adding, removing or resizing
|
be resized appropriately (eg, when adding, removing or resizing
|
||||||
columns).
|
columns).
|
||||||
@@ -186,11 +191,11 @@ class wxListCtrlAutoWidthMixin:
|
|||||||
# =====================
|
# =====================
|
||||||
|
|
||||||
def _onResize(self, event):
|
def _onResize(self, event):
|
||||||
""" Respond to the wxListCtrl being resized.
|
""" Respond to the wx.ListCtrl being resized.
|
||||||
|
|
||||||
We automatically resize the last column in the list.
|
We automatically resize the last column in the list.
|
||||||
"""
|
"""
|
||||||
wxCallAfter(self._doResize)
|
wx.CallAfter(self._doResize)
|
||||||
event.Skip()
|
event.Skip()
|
||||||
|
|
||||||
|
|
||||||
@@ -216,9 +221,9 @@ class wxListCtrlAutoWidthMixin:
|
|||||||
# NOTE: on GTK, the scrollbar is included in the client size, but on
|
# NOTE: on GTK, the scrollbar is included in the client size, but on
|
||||||
# Windows it is not included
|
# Windows it is not included
|
||||||
listWidth = self.GetClientSize().width
|
listWidth = self.GetClientSize().width
|
||||||
if wxPlatform != '__WXMSW__':
|
if wx.Platform != '__WXMSW__':
|
||||||
if self.GetItemCount() > self.GetCountPerPage():
|
if self.GetItemCount() > self.GetCountPerPage():
|
||||||
scrollWidth = wxSystemSettings_GetMetric(wxSYS_VSCROLL_X)
|
scrollWidth = wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
|
||||||
listWidth = listWidth - scrollWidth
|
listWidth = listWidth - scrollWidth
|
||||||
|
|
||||||
totColWidth = 0 # Width of all columns except last one.
|
totColWidth = 0 # Width of all columns except last one.
|
||||||
@@ -242,7 +247,7 @@ class wxListCtrlAutoWidthMixin:
|
|||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
SEL_FOC = wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED
|
SEL_FOC = wx.LIST_STATE_SELECTED | wx.LIST_STATE_FOCUSED
|
||||||
def selectBeforePopup(event):
|
def selectBeforePopup(event):
|
||||||
"""Ensures the item the mouse is pointing at is selected before a popup.
|
"""Ensures the item the mouse is pointing at is selected before a popup.
|
||||||
|
|
||||||
@@ -251,36 +256,39 @@ def selectBeforePopup(event):
|
|||||||
if isinstance(ctrl, wxListCtrl):
|
if isinstance(ctrl, wxListCtrl):
|
||||||
n, flags = ctrl.HitTest(event.GetPosition())
|
n, flags = ctrl.HitTest(event.GetPosition())
|
||||||
if n >= 0:
|
if n >= 0:
|
||||||
if not ctrl.GetItemState(n, wxLIST_STATE_SELECTED):
|
if not ctrl.GetItemState(n, wx.LIST_STATE_SELECTED):
|
||||||
for i in range(ctrl.GetItemCount()):
|
for i in range(ctrl.GetItemCount()):
|
||||||
ctrl.SetItemState(i, 0, SEL_FOC)
|
ctrl.SetItemState(i, 0, SEL_FOC)
|
||||||
#for i in getListCtrlSelection(ctrl, SEL_FOC):
|
#for i in getListCtrlSelection(ctrl, SEL_FOC):
|
||||||
# ctrl.SetItemState(i, 0, SEL_FOC)
|
# ctrl.SetItemState(i, 0, SEL_FOC)
|
||||||
ctrl.SetItemState(n, SEL_FOC, SEL_FOC)
|
ctrl.SetItemState(n, SEL_FOC, SEL_FOC)
|
||||||
|
|
||||||
def getListCtrlSelection(listctrl, state=wxLIST_STATE_SELECTED):
|
def getListCtrlSelection(listctrl, state=wx.LIST_STATE_SELECTED):
|
||||||
""" Returns list of item indexes of given state (selected by defaults) """
|
""" Returns list of item indexes of given state (selected by defaults) """
|
||||||
res = []
|
res = []
|
||||||
idx = -1
|
idx = -1
|
||||||
while 1:
|
while 1:
|
||||||
idx = listctrl.GetNextItem(idx, wxLIST_NEXT_ALL, state)
|
idx = listctrl.GetNextItem(idx, wx.LIST_NEXT_ALL, state)
|
||||||
if idx == -1:
|
if idx == -1:
|
||||||
break
|
break
|
||||||
res.append(idx)
|
res.append(idx)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
wxEVT_DOPOPUPMENU = wx.NewEventType()
|
||||||
|
EVT_DOPOPUPMENU = wx.PyEventBinder(wxEVT_DOPOPUPMENU, 0)
|
||||||
|
|
||||||
class ListCtrlSelectionManagerMix:
|
class ListCtrlSelectionManagerMix:
|
||||||
"""Mixin that defines a platform independent selection policy
|
"""Mixin that defines a platform independent selection policy
|
||||||
|
|
||||||
As selection single and multi-select list return the item index or a
|
As selection single and multi-select list return the item index or a
|
||||||
list of item indexes respectively.
|
list of item indexes respectively.
|
||||||
"""
|
"""
|
||||||
wxEVT_DOPOPUPMENU = wxNewId()
|
|
||||||
_menu = None
|
_menu = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
EVT_RIGHT_DOWN(self, self.OnLCSMRightDown)
|
self.Bind(wx.EVT_RIGHT_DOWN, self.OnLCSMRightDown)
|
||||||
self.Connect(-1, -1, self.wxEVT_DOPOPUPMENU, self.OnLCSMDoPopup)
|
self.Bind(EVT_DOPOPUPMENU, self.OnLCSMDoPopup)
|
||||||
|
# self.Connect(-1, -1, self.wxEVT_DOPOPUPMENU, self.OnLCSMDoPopup)
|
||||||
|
|
||||||
def getPopupMenu(self):
|
def getPopupMenu(self):
|
||||||
""" Override to implement dynamic menus (create) """
|
""" Override to implement dynamic menus (create) """
|
||||||
@@ -296,7 +304,7 @@ class ListCtrlSelectionManagerMix:
|
|||||||
|
|
||||||
def getSelection(self):
|
def getSelection(self):
|
||||||
res = getListCtrlSelection(self)
|
res = getListCtrlSelection(self)
|
||||||
if self.GetWindowStyleFlag() & wxLC_SINGLE_SEL:
|
if self.GetWindowStyleFlag() & wx.LC_SINGLE_SEL:
|
||||||
if res:
|
if res:
|
||||||
return res[0]
|
return res[0]
|
||||||
else:
|
else:
|
||||||
@@ -309,11 +317,11 @@ class ListCtrlSelectionManagerMix:
|
|||||||
event.Skip()
|
event.Skip()
|
||||||
menu = self.getPopupMenu()
|
menu = self.getPopupMenu()
|
||||||
if menu:
|
if menu:
|
||||||
evt = wxPyEvent()
|
evt = wx.PyEvent()
|
||||||
evt.SetEventType(self.wxEVT_DOPOPUPMENU)
|
evt.SetEventType(wxEVT_DOPOPUPMENU)
|
||||||
evt.menu = menu
|
evt.menu = menu
|
||||||
evt.pos = event.GetPosition()
|
evt.pos = event.GetPosition()
|
||||||
wxPostEvent(self, evt)
|
wx.PostEvent(self, evt)
|
||||||
|
|
||||||
def OnLCSMDoPopup(self, event):
|
def OnLCSMDoPopup(self, event):
|
||||||
self.PopupMenu(event.menu, event.pos)
|
self.PopupMenu(event.menu, event.pos)
|
||||||
|
|||||||
@@ -9,13 +9,19 @@
|
|||||||
# Copyright: (c) 2002 by db-X Corporation
|
# Copyright: (c) 2002 by db-X Corporation
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
# o Tested, but there is an anomaly between first use and subsequent uses.
|
||||||
|
# First use is odd, subsequent uses seem to be OK. Init error?
|
||||||
|
# -- No, the first time it uses an aspect ratio, but after the reset it doesn't.
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
A mixin class for doing "RubberBand"-ing on a window.
|
A mixin class for doing "RubberBand"-ing on a window.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from wxPython.wx import *
|
import wx
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Some miscellaneous mathematical and geometrical functions
|
# Some miscellaneous mathematical and geometrical functions
|
||||||
@@ -125,8 +131,9 @@ class RubberBand:
|
|||||||
self.currentBox = None
|
self.currentBox = None
|
||||||
self.__enabled = 1
|
self.__enabled = 1
|
||||||
self.__currentCursor = None
|
self.__currentCursor = None
|
||||||
EVT_MOUSE_EVENTS(drawingSurface, self.__handleMouseEvents)
|
|
||||||
EVT_PAINT(drawingSurface, self.__handleOnPaint)
|
drawingSurface.Bind(wx.EVT_MOUSE_EVENTS, self.__handleMouseEvents)
|
||||||
|
drawingSurface.Bind(wx.EVT_PAINT, self.__handleOnPaint)
|
||||||
|
|
||||||
def __setEnabled(self, enabled):
|
def __setEnabled(self, enabled):
|
||||||
self.__enabled = enabled
|
self.__enabled = enabled
|
||||||
@@ -143,19 +150,19 @@ class RubberBand:
|
|||||||
Return True if the current cursor is one used to
|
Return True if the current cursor is one used to
|
||||||
mean moving the rubberband.
|
mean moving the rubberband.
|
||||||
"""
|
"""
|
||||||
return self.__currentCursor == wxCURSOR_HAND
|
return self.__currentCursor == wx.CURSOR_HAND
|
||||||
|
|
||||||
def __isSizingCursor(self):
|
def __isSizingCursor(self):
|
||||||
"""
|
"""
|
||||||
Return True if the current cursor is one of the ones
|
Return True if the current cursor is one of the ones
|
||||||
I may use to signify sizing.
|
I may use to signify sizing.
|
||||||
"""
|
"""
|
||||||
sizingCursors = [wxCURSOR_SIZENESW,
|
sizingCursors = [wx.CURSOR_SIZENESW,
|
||||||
wxCURSOR_SIZENS,
|
wx.CURSOR_SIZENS,
|
||||||
wxCURSOR_SIZENWSE,
|
wx.CURSOR_SIZENWSE,
|
||||||
wxCURSOR_SIZEWE,
|
wx.CURSOR_SIZEWE,
|
||||||
wxCURSOR_SIZING,
|
wx.CURSOR_SIZING,
|
||||||
wxCURSOR_CROSS]
|
wx.CURSOR_CROSS]
|
||||||
try:
|
try:
|
||||||
sizingCursors.index(self.__currentCursor)
|
sizingCursors.index(self.__currentCursor)
|
||||||
return 1
|
return 1
|
||||||
@@ -177,7 +184,7 @@ class RubberBand:
|
|||||||
# First make sure we have started a box.
|
# First make sure we have started a box.
|
||||||
if self.currentBox == None and not event.LeftDown():
|
if self.currentBox == None and not event.LeftDown():
|
||||||
# No box started yet. Set cursor to the initial kind.
|
# No box started yet. Set cursor to the initial kind.
|
||||||
self.__setCursor(wxCURSOR_CROSS)
|
self.__setCursor(wx.CURSOR_CROSS)
|
||||||
return
|
return
|
||||||
|
|
||||||
if event.LeftDown():
|
if event.LeftDown():
|
||||||
@@ -228,9 +235,9 @@ class RubberBand:
|
|||||||
# Implement the correct behavior for dragging a side
|
# Implement the correct behavior for dragging a side
|
||||||
# of the box: Only change one dimension.
|
# of the box: Only change one dimension.
|
||||||
if not self.aspectRatio:
|
if not self.aspectRatio:
|
||||||
if self.__currentCursor == wxCURSOR_SIZENS:
|
if self.__currentCursor == wx.CURSOR_SIZENS:
|
||||||
x = None
|
x = None
|
||||||
elif self.__currentCursor == wxCURSOR_SIZEWE:
|
elif self.__currentCursor == wx.CURSOR_SIZEWE:
|
||||||
y = None
|
y = None
|
||||||
|
|
||||||
x0,y0,w0,h0 = self.currentBox
|
x0,y0,w0,h0 = self.currentBox
|
||||||
@@ -274,18 +281,18 @@ class RubberBand:
|
|||||||
if pointOnBox(x, y, self.currentBox, thickness=self.__THICKNESS):
|
if pointOnBox(x, y, self.currentBox, thickness=self.__THICKNESS):
|
||||||
position = getCursorPosition(x, y, self.currentBox, thickness=self.__THICKNESS)
|
position = getCursorPosition(x, y, self.currentBox, thickness=self.__THICKNESS)
|
||||||
cursor = [
|
cursor = [
|
||||||
wxCURSOR_SIZENWSE,
|
wx.CURSOR_SIZENWSE,
|
||||||
wxCURSOR_SIZENS,
|
wx.CURSOR_SIZENS,
|
||||||
wxCURSOR_SIZENESW,
|
wx.CURSOR_SIZENESW,
|
||||||
wxCURSOR_SIZEWE,
|
wx.CURSOR_SIZEWE,
|
||||||
wxCURSOR_SIZENWSE,
|
wx.CURSOR_SIZENWSE,
|
||||||
wxCURSOR_SIZENS,
|
wx.CURSOR_SIZENS,
|
||||||
wxCURSOR_SIZENESW,
|
wx.CURSOR_SIZENESW,
|
||||||
wxCURSOR_SIZEWE
|
wx.CURSOR_SIZEWE
|
||||||
] [position]
|
] [position]
|
||||||
self.__setCursor(cursor)
|
self.__setCursor(cursor)
|
||||||
elif pointInBox(x, y, self.currentBox):
|
elif pointInBox(x, y, self.currentBox):
|
||||||
self.__setCursor(wxCURSOR_HAND)
|
self.__setCursor(wx.CURSOR_HAND)
|
||||||
else:
|
else:
|
||||||
self.__setCursor()
|
self.__setCursor()
|
||||||
|
|
||||||
@@ -295,9 +302,9 @@ class RubberBand:
|
|||||||
"""
|
"""
|
||||||
if self.__currentCursor != id: # Avoid redundant calls
|
if self.__currentCursor != id: # Avoid redundant calls
|
||||||
if id:
|
if id:
|
||||||
self.drawingSurface.SetCursor(wxStockCursor(id))
|
self.drawingSurface.SetCursor(wx.StockCursor(id))
|
||||||
else:
|
else:
|
||||||
self.drawingSurface.SetCursor(wxNullCursor)
|
self.drawingSurface.SetCursor(wx.NullCursor)
|
||||||
self.__currentCursor = id
|
self.__currentCursor = id
|
||||||
|
|
||||||
def __moveCenterTo(self, x, y):
|
def __moveCenterTo(self, x, y):
|
||||||
@@ -320,14 +327,17 @@ class RubberBand:
|
|||||||
"""
|
"""
|
||||||
Draw one box shape and possibly erase another.
|
Draw one box shape and possibly erase another.
|
||||||
"""
|
"""
|
||||||
dc = wxClientDC(self.drawingSurface)
|
dc = wx.ClientDC(self.drawingSurface)
|
||||||
dc.BeginDrawing()
|
dc.BeginDrawing()
|
||||||
dc.SetPen(wxPen(wxWHITE, 1, wxDOT))
|
dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT))
|
||||||
dc.SetBrush(wxTRANSPARENT_BRUSH)
|
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
||||||
dc.SetLogicalFunction(wxXOR)
|
dc.SetLogicalFunction(wx.XOR)
|
||||||
if boxToErase:
|
if boxToErase:
|
||||||
dc.DrawRectangle(*boxToErase)
|
r = wx.Rect(*boxToErase)
|
||||||
dc.DrawRectangle(*boxToDraw)
|
dc.DrawRectangleRect(r)
|
||||||
|
|
||||||
|
r = wx.Rect(*boxToDraw)
|
||||||
|
dc.DrawRectangleRect(r)
|
||||||
dc.EndDrawing()
|
dc.EndDrawing()
|
||||||
|
|
||||||
def __dumpMouseEvent(self, event):
|
def __dumpMouseEvent(self, event):
|
||||||
@@ -369,12 +379,12 @@ class RubberBand:
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = wxPySimpleApp()
|
app = wx.PySimpleApp()
|
||||||
frame = wxFrame(None, -1, title='RubberBand Test', size=(300,300))
|
frame = wx.Frame(None, -1, title='RubberBand Test', size=(300,300))
|
||||||
|
|
||||||
# Add a panel that the rubberband will work on.
|
# Add a panel that the rubberband will work on.
|
||||||
panel = wxPanel(frame, -1)
|
panel = wx.Panel(frame, -1)
|
||||||
panel.SetBackgroundColour(wxBLUE)
|
panel.SetBackgroundColour(wx.BLUE)
|
||||||
|
|
||||||
# Create the rubberband
|
# Create the rubberband
|
||||||
frame.rubberBand = RubberBand(drawingSurface=panel)
|
frame.rubberBand = RubberBand(drawingSurface=panel)
|
||||||
@@ -383,13 +393,13 @@ if __name__ == '__main__':
|
|||||||
# Add a button that creates a new rubberband
|
# Add a button that creates a new rubberband
|
||||||
def __newRubberBand(event):
|
def __newRubberBand(event):
|
||||||
frame.rubberBand.reset()
|
frame.rubberBand.reset()
|
||||||
button = wxButton(frame, 100, 'Reset Rubberband')
|
button = wx.Button(frame, 100, 'Reset Rubberband')
|
||||||
EVT_BUTTON(frame, 100, __newRubberBand)
|
frame.Bind(wx.EVT_BUTTON, __newRubberBand, button)
|
||||||
|
|
||||||
# Layout the frame
|
# Layout the frame
|
||||||
sizer = wxBoxSizer(wxVERTICAL)
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
sizer.Add(panel, 1, wxEXPAND | wxALL, 5)
|
sizer.Add(panel, 1, wx.EXPAND | wx.ALL, 5)
|
||||||
sizer.Add(button, 0, wxALIGN_CENTER | wxALL, 5)
|
sizer.Add(button, 0, wx.ALIGN_CENTER | wx.ALL, 5)
|
||||||
frame.SetAutoLayout(1)
|
frame.SetAutoLayout(1)
|
||||||
frame.SetSizer(sizer)
|
frame.SetSizer(sizer)
|
||||||
frame.Show(1)
|
frame.Show(1)
|
||||||
|
|||||||
@@ -9,8 +9,12 @@
|
|||||||
# RCS-ID: $Id$
|
# RCS-ID: $Id$
|
||||||
# License: wxWindows licensie
|
# License: wxWindows licensie
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
#
|
||||||
|
|
||||||
from wxPython.wx import *
|
import wx
|
||||||
|
|
||||||
MV_HOR = 0
|
MV_HOR = 0
|
||||||
MV_VER = not MV_HOR
|
MV_VER = not MV_HOR
|
||||||
@@ -20,12 +24,12 @@ CR_SIZE = SH_SIZE * 3
|
|||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
class wxMultiSash(wxWindow):
|
class wxMultiSash(wx.Window):
|
||||||
def __init__(self, *_args,**_kwargs):
|
def __init__(self, *_args,**_kwargs):
|
||||||
apply(wxWindow.__init__,(self,) + _args,_kwargs)
|
apply(wx.Window.__init__,(self,) + _args,_kwargs)
|
||||||
self._defChild = EmptyChild
|
self._defChild = EmptyChild
|
||||||
self.child = wxMultiSplit(self,self,wxPoint(0,0),self.GetSize())
|
self.child = wxMultiSplit(self,self,(0,0),self.GetSize())
|
||||||
EVT_SIZE(self,self.OnMultiSize)
|
self.Bind(wx.EVT_SIZE,self.OnMultiSize)
|
||||||
|
|
||||||
def SetDefaultChildClass(self,childCls):
|
def SetDefaultChildClass(self,childCls):
|
||||||
self._defChild = childCls
|
self._defChild = childCls
|
||||||
@@ -39,7 +43,7 @@ class wxMultiSash(wxWindow):
|
|||||||
|
|
||||||
def Clear(self):
|
def Clear(self):
|
||||||
old = self.child
|
old = self.child
|
||||||
self.child = wxMultiSplit(self,self,wxPoint(0,0),self.GetSize())
|
self.child = wxMultiSplit(self,self,(0,0),self.GetSize())
|
||||||
old.Destroy()
|
old.Destroy()
|
||||||
self.child.OnSize(None)
|
self.child.OnSize(None)
|
||||||
|
|
||||||
@@ -65,10 +69,10 @@ class wxMultiSash(wxWindow):
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
class wxMultiSplit(wxWindow):
|
class wxMultiSplit(wx.Window):
|
||||||
def __init__(self,multiView,parent,pos,size,view1 = None):
|
def __init__(self,multiView,parent,pos,size,view1 = None):
|
||||||
wxWindow.__init__(self,id = -1,parent = parent,pos = pos,size = size,
|
wx.Window.__init__(self,id = -1,parent = parent,pos = pos,size = size,
|
||||||
style = wxCLIP_CHILDREN)
|
style = wx.CLIP_CHILDREN)
|
||||||
self.multiView = multiView
|
self.multiView = multiView
|
||||||
self.view2 = None
|
self.view2 = None
|
||||||
if view1:
|
if view1:
|
||||||
@@ -77,10 +81,10 @@ class wxMultiSplit(wxWindow):
|
|||||||
self.view1.MoveXY(0,0)
|
self.view1.MoveXY(0,0)
|
||||||
else:
|
else:
|
||||||
self.view1 = wxMultiViewLeaf(self.multiView,self,
|
self.view1 = wxMultiViewLeaf(self.multiView,self,
|
||||||
wxPoint(0,0),self.GetSize())
|
(0,0),self.GetSize())
|
||||||
self.direction = None
|
self.direction = None
|
||||||
|
|
||||||
EVT_SIZE(self,self.OnSize)
|
self.Bind(wx.EVT_SIZE,self.OnSize)
|
||||||
|
|
||||||
def GetSaveData(self):
|
def GetSaveData(self):
|
||||||
saveData = {}
|
saveData = {}
|
||||||
@@ -93,10 +97,10 @@ class wxMultiSplit(wxWindow):
|
|||||||
if isinstance(self.view2,wxMultiSplit):
|
if isinstance(self.view2,wxMultiSplit):
|
||||||
saveData['view2IsSplit'] = 1
|
saveData['view2IsSplit'] = 1
|
||||||
saveData['direction'] = self.direction
|
saveData['direction'] = self.direction
|
||||||
v1,v2 = self.GetPositionTuple()
|
v1,v2 = self.GetPosition()
|
||||||
saveData['x'] = v1
|
saveData['x'] = v1
|
||||||
saveData['y'] = v2
|
saveData['y'] = v2
|
||||||
v1,v2 = self.GetSizeTuple()
|
v1,v2 = self.GetSize()
|
||||||
saveData['w'] = v1
|
saveData['w'] = v1
|
||||||
saveData['h'] = v2
|
saveData['h'] = v2
|
||||||
return saveData
|
return saveData
|
||||||
@@ -110,10 +114,10 @@ class wxMultiSplit(wxWindow):
|
|||||||
old = self.view1
|
old = self.view1
|
||||||
if isSplit:
|
if isSplit:
|
||||||
self.view1 = wxMultiSplit(self.multiView,self,
|
self.view1 = wxMultiSplit(self.multiView,self,
|
||||||
wxPoint(0,0),self.GetSize())
|
(0,0),self.GetSize())
|
||||||
else:
|
else:
|
||||||
self.view1 = wxMultiViewLeaf(self.multiView,self,
|
self.view1 = wxMultiViewLeaf(self.multiView,self,
|
||||||
wxPoint(0,0),self.GetSize())
|
(0,0),self.GetSize())
|
||||||
self.view1.SetSaveData(v1Data)
|
self.view1.SetSaveData(v1Data)
|
||||||
if old:
|
if old:
|
||||||
old.Destroy()
|
old.Destroy()
|
||||||
@@ -123,10 +127,10 @@ class wxMultiSplit(wxWindow):
|
|||||||
old = self.view2
|
old = self.view2
|
||||||
if isSplit:
|
if isSplit:
|
||||||
self.view2 = wxMultiSplit(self.multiView,self,
|
self.view2 = wxMultiSplit(self.multiView,self,
|
||||||
wxPoint(0,0),self.GetSize())
|
(0,0),self.GetSize())
|
||||||
else:
|
else:
|
||||||
self.view2 = wxMultiViewLeaf(self.multiView,self,
|
self.view2 = wxMultiViewLeaf(self.multiView,self,
|
||||||
wxPoint(0,0),self.GetSize())
|
(0,0),self.GetSize())
|
||||||
self.view2.SetSaveData(v2Data)
|
self.view2.SetSaveData(v2Data)
|
||||||
if old:
|
if old:
|
||||||
old.Destroy()
|
old.Destroy()
|
||||||
@@ -161,7 +165,7 @@ class wxMultiSplit(wxWindow):
|
|||||||
self.view2.AddLeaf(direction,caller,pos)
|
self.view2.AddLeaf(direction,caller,pos)
|
||||||
else:
|
else:
|
||||||
self.direction = direction
|
self.direction = direction
|
||||||
w,h = self.GetSizeTuple()
|
w,h = self.GetSize()
|
||||||
if direction == MV_HOR:
|
if direction == MV_HOR:
|
||||||
x,y = (pos,0)
|
x,y = (pos,0)
|
||||||
w1,h1 = (w-pos,h)
|
w1,h1 = (w-pos,h)
|
||||||
@@ -170,9 +174,8 @@ class wxMultiSplit(wxWindow):
|
|||||||
x,y = (0,pos)
|
x,y = (0,pos)
|
||||||
w1,h1 = (w,h-pos)
|
w1,h1 = (w,h-pos)
|
||||||
w2,h2 = (w,pos)
|
w2,h2 = (w,pos)
|
||||||
self.view2 = wxMultiViewLeaf(self.multiView,self,
|
self.view2 = wxMultiViewLeaf(self.multiView, self, (x,y), (w1,h1))
|
||||||
wxPoint(x,y),wxSize(w1,h1))
|
self.view1.SetSize((w2,h2))
|
||||||
self.view1.SetSize(wxSize(w2,h2))
|
|
||||||
self.view2.OnSize(None)
|
self.view2.OnSize(None)
|
||||||
|
|
||||||
def DestroyLeaf(self,caller):
|
def DestroyLeaf(self,caller):
|
||||||
@@ -191,8 +194,8 @@ class wxMultiSplit(wxWindow):
|
|||||||
self.view1.SetSize(self.GetSize())
|
self.view1.SetSize(self.GetSize())
|
||||||
self.view1.Move(self.GetPosition())
|
self.view1.Move(self.GetPosition())
|
||||||
else:
|
else:
|
||||||
w,h = self.GetSizeTuple()
|
w,h = self.GetSize()
|
||||||
x,y = self.GetPositionTuple()
|
x,y = self.GetPosition()
|
||||||
if caller == self.view1:
|
if caller == self.view1:
|
||||||
if self == parent.view1:
|
if self == parent.view1:
|
||||||
parent.view1 = self.view2
|
parent.view1 = self.view2
|
||||||
@@ -230,7 +233,7 @@ class wxMultiSplit(wxWindow):
|
|||||||
if not (self.view1 and self.view2):
|
if not (self.view1 and self.view2):
|
||||||
return
|
return
|
||||||
if pos < 10: return
|
if pos < 10: return
|
||||||
w,h = self.GetSizeTuple()
|
w,h = self.GetSize()
|
||||||
if side == MV_HOR:
|
if side == MV_HOR:
|
||||||
if pos > w - 10: return
|
if pos > w - 10: return
|
||||||
else:
|
else:
|
||||||
@@ -247,11 +250,11 @@ class wxMultiSplit(wxWindow):
|
|||||||
self.view1.SetSize(self.GetSize())
|
self.view1.SetSize(self.GetSize())
|
||||||
self.view1.OnSize(None)
|
self.view1.OnSize(None)
|
||||||
return
|
return
|
||||||
v1w,v1h = self.view1.GetSizeTuple()
|
v1w,v1h = self.view1.GetSize()
|
||||||
v2w,v2h = self.view2.GetSizeTuple()
|
v2w,v2h = self.view2.GetSize()
|
||||||
v1x,v1y = self.view1.GetPositionTuple()
|
v1x,v1y = self.view1.GetPosition()
|
||||||
v2x,v2y = self.view2.GetPositionTuple()
|
v2x,v2y = self.view2.GetPosition()
|
||||||
w,h = self.GetSizeTuple()
|
w,h = self.GetSize()
|
||||||
|
|
||||||
if v1x != v2x:
|
if v1x != v2x:
|
||||||
ratio = float(w) / float((v1w + v2w))
|
ratio = float(w) / float((v1w + v2w))
|
||||||
@@ -278,10 +281,10 @@ class wxMultiSplit(wxWindow):
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
class wxMultiViewLeaf(wxWindow):
|
class wxMultiViewLeaf(wx.Window):
|
||||||
def __init__(self,multiView,parent,pos,size):
|
def __init__(self,multiView,parent,pos,size):
|
||||||
wxWindow.__init__(self,id = -1,parent = parent,pos = pos,size = size,
|
wx.Window.__init__(self,id = -1,parent = parent,pos = pos,size = size,
|
||||||
style = wxCLIP_CHILDREN)
|
style = wx.CLIP_CHILDREN)
|
||||||
self.multiView = multiView
|
self.multiView = multiView
|
||||||
|
|
||||||
self.sizerHor = MultiSizer(self,MV_HOR)
|
self.sizerHor = MultiSizer(self,MV_HOR)
|
||||||
@@ -291,7 +294,7 @@ class wxMultiViewLeaf(wxWindow):
|
|||||||
self.detail = MultiClient(self,multiView._defChild)
|
self.detail = MultiClient(self,multiView._defChild)
|
||||||
self.closer = MultiCloser(self)
|
self.closer = MultiCloser(self)
|
||||||
|
|
||||||
EVT_SIZE(self,self.OnSize)
|
self.Bind(wx.EVT_SIZE,self.OnSize)
|
||||||
|
|
||||||
def GetSaveData(self):
|
def GetSaveData(self):
|
||||||
saveData = {}
|
saveData = {}
|
||||||
@@ -302,10 +305,10 @@ class wxMultiViewLeaf(wxWindow):
|
|||||||
dData = attr()
|
dData = attr()
|
||||||
if dData:
|
if dData:
|
||||||
saveData['detail'] = dData
|
saveData['detail'] = dData
|
||||||
v1,v2 = self.GetPositionTuple()
|
v1,v2 = self.GetPosition()
|
||||||
saveData['x'] = v1
|
saveData['x'] = v1
|
||||||
saveData['y'] = v2
|
saveData['y'] = v2
|
||||||
v1,v2 = self.GetSizeTuple()
|
v1,v2 = self.GetSize()
|
||||||
saveData['w'] = v1
|
saveData['w'] = v1
|
||||||
saveData['h'] = v2
|
saveData['h'] = v2
|
||||||
return saveData
|
return saveData
|
||||||
@@ -335,7 +338,7 @@ class wxMultiViewLeaf(wxWindow):
|
|||||||
|
|
||||||
def AddLeaf(self,direction,pos):
|
def AddLeaf(self,direction,pos):
|
||||||
if pos < 10: return
|
if pos < 10: return
|
||||||
w,h = self.GetSizeTuple()
|
w,h = self.GetSize()
|
||||||
if direction == MV_VER:
|
if direction == MV_VER:
|
||||||
if pos > h - 10: return
|
if pos > h - 10: return
|
||||||
else:
|
else:
|
||||||
@@ -362,20 +365,20 @@ class wxMultiViewLeaf(wxWindow):
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
class MultiClient(wxWindow):
|
class MultiClient(wx.Window):
|
||||||
def __init__(self,parent,childCls):
|
def __init__(self,parent,childCls):
|
||||||
w,h = self.CalcSize(parent)
|
w,h = self.CalcSize(parent)
|
||||||
wxWindow.__init__(self,id = -1,parent = parent,
|
wx.Window.__init__(self,id = -1,parent = parent,
|
||||||
pos = wxPoint(0,0),
|
pos = (0,0),
|
||||||
size = wxSize(w,h),
|
size = (w,h),
|
||||||
style = wxCLIP_CHILDREN | wxSUNKEN_BORDER)
|
style = wx.CLIP_CHILDREN | wx.SUNKEN_BORDER)
|
||||||
self.child = childCls(self)
|
self.child = childCls(self)
|
||||||
self.child.MoveXY(2,2)
|
self.child.MoveXY(2,2)
|
||||||
self.normalColour = self.GetBackgroundColour()
|
self.normalColour = self.GetBackgroundColour()
|
||||||
self.selected = False
|
self.selected = False
|
||||||
|
|
||||||
EVT_SET_FOCUS(self,self.OnSetFocus)
|
self.Bind(wx.EVT_SET_FOCUS,self.OnSetFocus)
|
||||||
EVT_CHILD_FOCUS(self,self.OnChildFocus)
|
self.Bind(wx.EVT_CHILD_FOCUS,self.OnChildFocus)
|
||||||
|
|
||||||
def UnSelect(self):
|
def UnSelect(self):
|
||||||
if self.selected:
|
if self.selected:
|
||||||
@@ -386,11 +389,11 @@ class MultiClient(wxWindow):
|
|||||||
def Select(self):
|
def Select(self):
|
||||||
self.GetParent().multiView.UnSelect()
|
self.GetParent().multiView.UnSelect()
|
||||||
self.selected = True
|
self.selected = True
|
||||||
self.SetBackgroundColour(wxColour(255,255,0)) # Yellow
|
self.SetBackgroundColour(wx.Colour(255,255,0)) # Yellow
|
||||||
self.Refresh()
|
self.Refresh()
|
||||||
|
|
||||||
def CalcSize(self,parent):
|
def CalcSize(self,parent):
|
||||||
w,h = parent.GetSizeTuple()
|
w,h = parent.GetSize()
|
||||||
w -= SH_SIZE
|
w -= SH_SIZE
|
||||||
h -= SH_SIZE
|
h -= SH_SIZE
|
||||||
return (w,h)
|
return (w,h)
|
||||||
@@ -398,8 +401,8 @@ class MultiClient(wxWindow):
|
|||||||
def OnSize(self,evt):
|
def OnSize(self,evt):
|
||||||
w,h = self.CalcSize(self.GetParent())
|
w,h = self.CalcSize(self.GetParent())
|
||||||
self.SetDimensions(0,0,w,h)
|
self.SetDimensions(0,0,w,h)
|
||||||
w,h = self.GetClientSizeTuple()
|
w,h = self.GetClientSize()
|
||||||
self.child.SetSize(wxSize(w-4,h-4))
|
self.child.SetSize((w-4,h-4))
|
||||||
|
|
||||||
def SetNewChildCls(self,childCls):
|
def SetNewChildCls(self,childCls):
|
||||||
if self.child:
|
if self.child:
|
||||||
@@ -415,34 +418,34 @@ class MultiClient(wxWindow):
|
|||||||
self.OnSetFocus(evt)
|
self.OnSetFocus(evt)
|
||||||
## from Funcs import FindFocusedChild
|
## from Funcs import FindFocusedChild
|
||||||
## child = FindFocusedChild(self)
|
## child = FindFocusedChild(self)
|
||||||
## EVT_KILL_FOCUS(child,self.OnChildKillFocus)
|
## child.Bind(wx.EVT_KILL_FOCUS,self.OnChildKillFocus)
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
class MultiSizer(wxWindow):
|
class MultiSizer(wx.Window):
|
||||||
def __init__(self,parent,side):
|
def __init__(self,parent,side):
|
||||||
self.side = side
|
self.side = side
|
||||||
x,y,w,h = self.CalcSizePos(parent)
|
x,y,w,h = self.CalcSizePos(parent)
|
||||||
wxWindow.__init__(self,id = -1,parent = parent,
|
wx.Window.__init__(self,id = -1,parent = parent,
|
||||||
pos = wxPoint(x,y),
|
pos = (x,y),
|
||||||
size = wxSize(w,h),
|
size = (w,h),
|
||||||
style = wxCLIP_CHILDREN)
|
style = wx.CLIP_CHILDREN)
|
||||||
|
|
||||||
self.px = None # Previous X
|
self.px = None # Previous X
|
||||||
self.py = None # Previous Y
|
self.py = None # Previous Y
|
||||||
self.isDrag = False # In Dragging
|
self.isDrag = False # In Dragging
|
||||||
self.dragTarget = None # View being sized
|
self.dragTarget = None # View being sized
|
||||||
|
|
||||||
EVT_LEAVE_WINDOW(self,self.OnLeave)
|
self.Bind(wx.EVT_LEAVE_WINDOW,self.OnLeave)
|
||||||
EVT_ENTER_WINDOW(self,self.OnEnter)
|
self.Bind(wx.EVT_ENTER_WINDOW,self.OnEnter)
|
||||||
EVT_MOTION(self,self.OnMouseMove)
|
self.Bind(wx.EVT_MOTION,self.OnMouseMove)
|
||||||
EVT_LEFT_DOWN(self,self.OnPress)
|
self.Bind(wx.EVT_LEFT_DOWN,self.OnPress)
|
||||||
EVT_LEFT_UP(self,self.OnRelease)
|
self.Bind(wx.EVT_LEFT_UP,self.OnRelease)
|
||||||
|
|
||||||
def CalcSizePos(self,parent):
|
def CalcSizePos(self,parent):
|
||||||
pw,ph = parent.GetSizeTuple()
|
pw,ph = parent.GetSize()
|
||||||
if self.side == MV_HOR:
|
if self.side == MV_HOR:
|
||||||
x = CR_SIZE + 2
|
x = CR_SIZE + 2
|
||||||
y = ph - SH_SIZE
|
y = ph - SH_SIZE
|
||||||
@@ -460,15 +463,15 @@ class MultiSizer(wxWindow):
|
|||||||
self.SetDimensions(x,y,w,h)
|
self.SetDimensions(x,y,w,h)
|
||||||
|
|
||||||
def OnLeave(self,evt):
|
def OnLeave(self,evt):
|
||||||
self.SetCursor(wxStockCursor(wxCURSOR_ARROW))
|
self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
|
||||||
|
|
||||||
def OnEnter(self,evt):
|
def OnEnter(self,evt):
|
||||||
if not self.GetParent().CanSize(not self.side):
|
if not self.GetParent().CanSize(not self.side):
|
||||||
return
|
return
|
||||||
if self.side == MV_HOR:
|
if self.side == MV_HOR:
|
||||||
self.SetCursor(wxStockCursor(wxCURSOR_SIZENS))
|
self.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS))
|
||||||
else:
|
else:
|
||||||
self.SetCursor(wxStockCursor(wxCURSOR_SIZEWE))
|
self.SetCursor(wx.StockCursor(wx.CURSOR_SIZEWE))
|
||||||
|
|
||||||
def OnMouseMove(self,evt):
|
def OnMouseMove(self,evt):
|
||||||
if self.isDrag:
|
if self.isDrag:
|
||||||
@@ -508,28 +511,28 @@ class MultiSizer(wxWindow):
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
class MultiCreator(wxWindow):
|
class MultiCreator(wx.Window):
|
||||||
def __init__(self,parent,side):
|
def __init__(self,parent,side):
|
||||||
self.side = side
|
self.side = side
|
||||||
x,y,w,h = self.CalcSizePos(parent)
|
x,y,w,h = self.CalcSizePos(parent)
|
||||||
wxWindow.__init__(self,id = -1,parent = parent,
|
wx.Window.__init__(self,id = -1,parent = parent,
|
||||||
pos = wxPoint(x,y),
|
pos = (x,y),
|
||||||
size = wxSize(w,h),
|
size = (w,h),
|
||||||
style = wxCLIP_CHILDREN)
|
style = wx.CLIP_CHILDREN)
|
||||||
|
|
||||||
self.px = None # Previous X
|
self.px = None # Previous X
|
||||||
self.py = None # Previous Y
|
self.py = None # Previous Y
|
||||||
self.isDrag = False # In Dragging
|
self.isDrag = False # In Dragging
|
||||||
|
|
||||||
EVT_LEAVE_WINDOW(self,self.OnLeave)
|
self.Bind(wx.EVT_LEAVE_WINDOW,self.OnLeave)
|
||||||
EVT_ENTER_WINDOW(self,self.OnEnter)
|
self.Bind(wx.EVT_ENTER_WINDOW,self.OnEnter)
|
||||||
EVT_MOTION(self,self.OnMouseMove)
|
self.Bind(wx.EVT_MOTION,self.OnMouseMove)
|
||||||
EVT_LEFT_DOWN(self,self.OnPress)
|
self.Bind(wx.EVT_LEFT_DOWN,self.OnPress)
|
||||||
EVT_LEFT_UP(self,self.OnRelease)
|
self.Bind(wx.EVT_LEFT_UP,self.OnRelease)
|
||||||
EVT_PAINT(self,self.OnPaint)
|
self.Bind(wx.EVT_PAINT,self.OnPaint)
|
||||||
|
|
||||||
def CalcSizePos(self,parent):
|
def CalcSizePos(self,parent):
|
||||||
pw,ph = parent.GetSizeTuple()
|
pw,ph = parent.GetSize()
|
||||||
if self.side == MV_HOR:
|
if self.side == MV_HOR:
|
||||||
x = 2
|
x = 2
|
||||||
y = ph - SH_SIZE
|
y = ph - SH_SIZE
|
||||||
@@ -547,13 +550,13 @@ class MultiCreator(wxWindow):
|
|||||||
self.SetDimensions(x,y,w,h)
|
self.SetDimensions(x,y,w,h)
|
||||||
|
|
||||||
def OnLeave(self,evt):
|
def OnLeave(self,evt):
|
||||||
self.SetCursor(wxStockCursor(wxCURSOR_ARROW))
|
self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
|
||||||
|
|
||||||
def OnEnter(self,evt):
|
def OnEnter(self,evt):
|
||||||
if self.side == MV_HOR:
|
if self.side == MV_HOR:
|
||||||
self.SetCursor(wxStockCursor(wxCURSOR_HAND))
|
self.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
|
||||||
else:
|
else:
|
||||||
self.SetCursor(wxStockCursor(wxCURSOR_POINT_LEFT))
|
self.SetCursor(wx.StockCursor(wx.CURSOR_POINT_LEFT))
|
||||||
|
|
||||||
def OnMouseMove(self,evt):
|
def OnMouseMove(self,evt):
|
||||||
if self.isDrag:
|
if self.isDrag:
|
||||||
@@ -588,14 +591,14 @@ class MultiCreator(wxWindow):
|
|||||||
evt.Skip()
|
evt.Skip()
|
||||||
|
|
||||||
def OnPaint(self,evt):
|
def OnPaint(self,evt):
|
||||||
dc = wxPaintDC(self)
|
dc = wx.PaintDC(self)
|
||||||
dc.SetBackground(wxBrush(self.GetBackgroundColour(),wxSOLID))
|
dc.SetBackground(wx.Brush(self.GetBackgroundColour(),wx.SOLID))
|
||||||
dc.Clear()
|
dc.Clear()
|
||||||
|
|
||||||
highlight = wxPen(wxSystemSettings_GetColour(wxSYS_COLOUR_BTNHIGHLIGHT), 1, wxSOLID)
|
highlight = wx.Pen(wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT), 1, wx.SOLID)
|
||||||
shadow = wxPen(wxSystemSettings_GetColour(wxSYS_COLOUR_BTNSHADOW), 1, wxSOLID)
|
shadow = wx.Pen(wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNSHADOW), 1, wx.SOLID)
|
||||||
black = wxPen(wxBLACK,1,wxSOLID)
|
black = wx.Pen(wx.BLACK,1,wx.SOLID)
|
||||||
w,h = self.GetSizeTuple()
|
w,h = self.GetSize()
|
||||||
w -= 1
|
w -= 1
|
||||||
h -= 1
|
h -= 1
|
||||||
|
|
||||||
@@ -612,29 +615,29 @@ class MultiCreator(wxWindow):
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
class MultiCloser(wxWindow):
|
class MultiCloser(wx.Window):
|
||||||
def __init__(self,parent):
|
def __init__(self,parent):
|
||||||
x,y,w,h = self.CalcSizePos(parent)
|
x,y,w,h = self.CalcSizePos(parent)
|
||||||
wxWindow.__init__(self,id = -1,parent = parent,
|
wx.Window.__init__(self,id = -1,parent = parent,
|
||||||
pos = wxPoint(x,y),
|
pos = (x,y),
|
||||||
size = wxSize(w,h),
|
size = (w,h),
|
||||||
style = wxCLIP_CHILDREN)
|
style = wx.CLIP_CHILDREN)
|
||||||
|
|
||||||
self.down = False
|
self.down = False
|
||||||
self.entered = False
|
self.entered = False
|
||||||
|
|
||||||
EVT_LEFT_DOWN(self,self.OnPress)
|
self.Bind(wx.EVT_LEFT_DOWN,self.OnPress)
|
||||||
EVT_LEFT_UP(self,self.OnRelease)
|
self.Bind(wx.EVT_LEFT_UP,self.OnRelease)
|
||||||
EVT_PAINT(self,self.OnPaint)
|
self.Bind(wx.EVT_PAINT,self.OnPaint)
|
||||||
EVT_LEAVE_WINDOW(self,self.OnLeave)
|
self.Bind(wx.EVT_LEAVE_WINDOW,self.OnLeave)
|
||||||
EVT_ENTER_WINDOW(self,self.OnEnter)
|
self.Bind(wx.EVT_ENTER_WINDOW,self.OnEnter)
|
||||||
|
|
||||||
def OnLeave(self,evt):
|
def OnLeave(self,evt):
|
||||||
self.SetCursor(wxStockCursor(wxCURSOR_ARROW))
|
self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
|
||||||
self.entered = False
|
self.entered = False
|
||||||
|
|
||||||
def OnEnter(self,evt):
|
def OnEnter(self,evt):
|
||||||
self.SetCursor(wxStockCursor(wxCURSOR_BULLSEYE))
|
self.SetCursor(wx.StockCursor(wx.CURSOR_BULLSEYE))
|
||||||
self.entered = True
|
self.entered = True
|
||||||
|
|
||||||
def OnPress(self,evt):
|
def OnPress(self,evt):
|
||||||
@@ -649,12 +652,12 @@ class MultiCloser(wxWindow):
|
|||||||
self.down = False
|
self.down = False
|
||||||
|
|
||||||
def OnPaint(self,evt):
|
def OnPaint(self,evt):
|
||||||
dc = wxPaintDC(self)
|
dc = wx.PaintDC(self)
|
||||||
dc.SetBackground(wxBrush(wxRED,wxSOLID))
|
dc.SetBackground(wx.Brush(wx.RED,wx.SOLID))
|
||||||
dc.Clear()
|
dc.Clear()
|
||||||
|
|
||||||
def CalcSizePos(self,parent):
|
def CalcSizePos(self,parent):
|
||||||
pw,ph = parent.GetSizeTuple()
|
pw,ph = parent.GetSize()
|
||||||
x = pw - SH_SIZE
|
x = pw - SH_SIZE
|
||||||
w = SH_SIZE
|
w = SH_SIZE
|
||||||
h = SH_SIZE + 2
|
h = SH_SIZE + 2
|
||||||
@@ -669,19 +672,19 @@ class MultiCloser(wxWindow):
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
class EmptyChild(wxWindow):
|
class EmptyChild(wx.Window):
|
||||||
def __init__(self,parent):
|
def __init__(self,parent):
|
||||||
wxWindow.__init__(self,parent,-1, style = wxCLIP_CHILDREN)
|
wx.Window.__init__(self,parent,-1, style = wx.CLIP_CHILDREN)
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def DrawSash(win,x,y,direction):
|
def DrawSash(win,x,y,direction):
|
||||||
dc = wxScreenDC()
|
dc = wx.ScreenDC()
|
||||||
dc.StartDrawingOnTopWin(win)
|
dc.StartDrawingOnTopWin(win)
|
||||||
bmp = wxEmptyBitmap(8,8)
|
bmp = wx.EmptyBitmap(8,8)
|
||||||
bdc = wxMemoryDC()
|
bdc = wx.MemoryDC()
|
||||||
bdc.SelectObject(bmp)
|
bdc.SelectObject(bmp)
|
||||||
bdc.DrawRectangle((-1,-1), (10,10))
|
bdc.DrawRectangle((-1,-1), (10,10))
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
@@ -689,13 +692,13 @@ def DrawSash(win,x,y,direction):
|
|||||||
if ((i + j) & 1):
|
if ((i + j) & 1):
|
||||||
bdc.DrawPoint((i,j))
|
bdc.DrawPoint((i,j))
|
||||||
|
|
||||||
brush = wxBrush(wxColour(0,0,0))
|
brush = wx.Brush(wx.Colour(0,0,0))
|
||||||
brush.SetStipple(bmp)
|
brush.SetStipple(bmp)
|
||||||
|
|
||||||
dc.SetBrush(brush)
|
dc.SetBrush(brush)
|
||||||
dc.SetLogicalFunction(wxXOR)
|
dc.SetLogicalFunction(wx.XOR)
|
||||||
|
|
||||||
body_w,body_h = win.GetClientSizeTuple()
|
body_w,body_h = win.GetClientSize()
|
||||||
|
|
||||||
if y < 0:
|
if y < 0:
|
||||||
y = 0
|
y = 0
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
# 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
# o I'm a little nervous about some of it though.
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
wxMVCTree is a control which handles hierarchical data. It is constructed
|
wxMVCTree is a control which handles hierarchical data. It is constructed
|
||||||
in model-view-controller architecture, so the display of that data, and
|
in model-view-controller architecture, so the display of that data, and
|
||||||
@@ -27,8 +33,26 @@ NOTE: This module is *not* supported in any way. Use it however you
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
from wxPython.wx import *
|
import os
|
||||||
import os, sys, traceback
|
import sys
|
||||||
|
import traceback
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
import wx
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
|
||||||
|
warningmsg = r"""\
|
||||||
|
|
||||||
|
################################################\
|
||||||
|
# This module is not supported in any way! |
|
||||||
|
# |
|
||||||
|
# See cource code for wx.lib.mvctree for more |
|
||||||
|
# information. |
|
||||||
|
################################################/
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
warnings.warn(warningmsg, DeprecationWarning, stacklevel=2)
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
|
|
||||||
class MVCTreeNode:
|
class MVCTreeNode:
|
||||||
@@ -132,11 +156,11 @@ class Painter:
|
|||||||
"""
|
"""
|
||||||
def __init__(self, tree):
|
def __init__(self, tree):
|
||||||
self.tree = tree
|
self.tree = tree
|
||||||
self.textcolor = wxNamedColour("BLACK")
|
self.textcolor = wx.NamedColour("BLACK")
|
||||||
self.bgcolor = wxNamedColour("WHITE")
|
self.bgcolor = wx.NamedColour("WHITE")
|
||||||
self.fgcolor = wxNamedColour("BLUE")
|
self.fgcolor = wx.NamedColour("BLUE")
|
||||||
self.linecolor = wxNamedColour("GREY")
|
self.linecolor = wx.NamedColour("GREY")
|
||||||
self.font = wxFont(9, wxDEFAULT, wxNORMAL, wxNORMAL, False)
|
self.font = wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False)
|
||||||
self.bmp = None
|
self.bmp = None
|
||||||
|
|
||||||
def GetFont(self):
|
def GetFont(self):
|
||||||
@@ -155,26 +179,26 @@ class Painter:
|
|||||||
return self.textcolor
|
return self.textcolor
|
||||||
def SetTextColour(self, color):
|
def SetTextColour(self, color):
|
||||||
self.textcolor = color
|
self.textcolor = color
|
||||||
self.textbrush = wxBrush(color)
|
self.textbrush = wx.Brush(color)
|
||||||
self.textpen = wxPen(color, 1, wxSOLID)
|
self.textpen = wx.Pen(color, 1, wx.SOLID)
|
||||||
def GetBackgroundColour(self):
|
def GetBackgroundColour(self):
|
||||||
return self.bgcolor
|
return self.bgcolor
|
||||||
def SetBackgroundColour(self, color):
|
def SetBackgroundColour(self, color):
|
||||||
self.bgcolor = color
|
self.bgcolor = color
|
||||||
self.bgbrush = wxBrush(color)
|
self.bgbrush = wx.Brush(color)
|
||||||
self.bgpen = wxPen(color, 1, wxSOLID)
|
self.bgpen = wx.Pen(color, 1, wx.SOLID)
|
||||||
def GetForegroundColour(self):
|
def GetForegroundColour(self):
|
||||||
return self.fgcolor
|
return self.fgcolor
|
||||||
def SetForegroundColour(self, color):
|
def SetForegroundColour(self, color):
|
||||||
self.fgcolor = color
|
self.fgcolor = color
|
||||||
self.fgbrush = wxBrush(color)
|
self.fgbrush = wx.Brush(color)
|
||||||
self.fgpen = wxPen(color, 1, wxSOLID)
|
self.fgpen = wx.Pen(color, 1, wx.SOLID)
|
||||||
def GetLineColour(self):
|
def GetLineColour(self):
|
||||||
return self.linecolor
|
return self.linecolor
|
||||||
def SetLineColour(self, color):
|
def SetLineColour(self, color):
|
||||||
self.linecolor = color
|
self.linecolor = color
|
||||||
self.linebrush = wxBrush(color)
|
self.linebrush = wx.Brush(color)
|
||||||
self.linepen = wxPen( color, 1, wxSOLID)
|
self.linepen = wx.Pen( color, 1, wx.SOLID)
|
||||||
def GetForegroundPen(self):
|
def GetForegroundPen(self):
|
||||||
return self.fgpen
|
return self.fgpen
|
||||||
def GetBackgroundPen(self):
|
def GetBackgroundPen(self):
|
||||||
@@ -348,9 +372,9 @@ class FileEditor(Editor):
|
|||||||
self.editcomp.SetSelection(0, len(node.fileName))
|
self.editcomp.SetSelection(0, len(node.fileName))
|
||||||
self.editcomp.SetFocus()
|
self.editcomp.SetFocus()
|
||||||
self.treenode = treenode
|
self.treenode = treenode
|
||||||
# EVT_KEY_DOWN(self.editcomp, self._key)
|
# self.editcomp.Bind(wx.EVT_KEY_DOWN, self._key)
|
||||||
EVT_KEY_UP(self.editcomp, self._key)
|
self.editcomp.Bind(wx.EVT_KEY_UP, self._key)
|
||||||
EVT_LEFT_DOWN(self.editcomp, self._mdown)
|
self.editcomp.Bind(wx.EVT_LEFT_DOWN, self._mdown)
|
||||||
self.editcomp.CaptureMouse()
|
self.editcomp.CaptureMouse()
|
||||||
|
|
||||||
def CanEdit(self, node):
|
def CanEdit(self, node):
|
||||||
@@ -373,18 +397,18 @@ class FileEditor(Editor):
|
|||||||
|
|
||||||
|
|
||||||
def _key(self, evt):
|
def _key(self, evt):
|
||||||
if evt.KeyCode() == WXK_RETURN:
|
if evt.KeyCode() == wx.WXK_RETURN:
|
||||||
self.EndEdit(True)
|
self.EndEdit(True)
|
||||||
elif evt.KeyCode() == WXK_ESCAPE:
|
elif evt.KeyCode() == wx.WXK_ESCAPE:
|
||||||
self.EndEdit(False)
|
self.EndEdit(False)
|
||||||
else:
|
else:
|
||||||
evt.Skip()
|
evt.Skip()
|
||||||
|
|
||||||
def _mdown(self, evt):
|
def _mdown(self, evt):
|
||||||
if evt.IsButton():
|
if evt.IsButton():
|
||||||
pos = evt.GetPosition()
|
x, y = evt.GetPosition()
|
||||||
edsize = self.editcomp.GetSize()
|
w, h = self.editcomp.GetSize()
|
||||||
if pos.x < 0 or pos.y < 0 or pos.x > edsize.width or pos.y > edsize.height:
|
if x < 0 or y < 0 or x > w or y > h:
|
||||||
self.EndEdit(False)
|
self.EndEdit(False)
|
||||||
|
|
||||||
|
|
||||||
@@ -555,36 +579,36 @@ class TreePainter(Painter):
|
|||||||
for i in range(25):
|
for i in range(25):
|
||||||
self.charWidths.append(dc.GetTextExtent("D")[0] * i)
|
self.charWidths.append(dc.GetTextExtent("D")[0] * i)
|
||||||
self.charHeight = dc.GetTextExtent("D")[1]
|
self.charHeight = dc.GetTextExtent("D")[1]
|
||||||
self.textpen = wxPen(self.GetTextColour(), 1, wxSOLID)
|
self.textpen = wx.Pen(self.GetTextColour(), 1, wx.SOLID)
|
||||||
self.fgpen = wxPen(self.GetForegroundColour(), 1, wxSOLID)
|
self.fgpen = wx.Pen(self.GetForegroundColour(), 1, wx.SOLID)
|
||||||
self.bgpen = wxPen(self.GetBackgroundColour(), 1, wxSOLID)
|
self.bgpen = wx.Pen(self.GetBackgroundColour(), 1, wx.SOLID)
|
||||||
self.linepen = wxPen(self.GetLineColour(), 1, wxSOLID)
|
self.linepen = wx.Pen(self.GetLineColour(), 1, wx.SOLID)
|
||||||
self.dashpen = wxPen(self.GetLineColour(), 1, wxDOT)
|
self.dashpen = wx.Pen(self.GetLineColour(), 1, wx.DOT)
|
||||||
self.textbrush = wxBrush(self.GetTextColour(), wxSOLID)
|
self.textbrush = wx.Brush(self.GetTextColour(), wx.SOLID)
|
||||||
self.fgbrush = wxBrush(self.GetForegroundColour(), wxSOLID)
|
self.fgbrush = wx.Brush(self.GetForegroundColour(), wx.SOLID)
|
||||||
self.bgbrush = wxBrush(self.GetBackgroundColour(), wxSOLID)
|
self.bgbrush = wx.Brush(self.GetBackgroundColour(), wx.SOLID)
|
||||||
self.linebrush = wxPen(self.GetLineColour(), 1, wxSOLID)
|
self.linebrush = wx.Pen(self.GetLineColour(), 1, wx.SOLID)
|
||||||
treesize = self.tree.GetSize()
|
treesize = self.tree.GetSize()
|
||||||
size = self.tree.transform.GetSize()
|
size = self.tree.transform.GetSize()
|
||||||
size = (max(treesize.width, size[0]+50), max(treesize.height, size[1]+50))
|
size = (max(treesize.width, size[0]+50), max(treesize.height, size[1]+50))
|
||||||
dc.BeginDrawing()
|
dc.BeginDrawing()
|
||||||
if doubleBuffered:
|
if doubleBuffered:
|
||||||
mem_dc = wxMemoryDC()
|
mem_dc = wx.MemoryDC()
|
||||||
if not self.GetBuffer():
|
if not self.GetBuffer():
|
||||||
self.knobs = []
|
self.knobs = []
|
||||||
self.rectangles = []
|
self.rectangles = []
|
||||||
self.bmp = wxEmptyBitmap(size[0], size[1])
|
self.bmp = wx.EmptyBitmap(size[0], size[1])
|
||||||
mem_dc.SelectObject(self.GetBuffer())
|
mem_dc.SelectObject(self.GetBuffer())
|
||||||
mem_dc.SetPen(self.GetBackgroundPen())
|
mem_dc.SetPen(self.GetBackgroundPen())
|
||||||
mem_dc.SetBrush(self.GetBackgroundBrush())
|
mem_dc.SetBrush(self.GetBackgroundBrush())
|
||||||
mem_dc.DrawRectangle(0, 0, size[0], size[1])
|
mem_dc.DrawRectangle((0, 0), (size[0], size[1]))
|
||||||
mem_dc.SetFont(self.tree.GetFont())
|
mem_dc.SetFont(self.tree.GetFont())
|
||||||
self.paintWalk(node, mem_dc)
|
self.paintWalk(node, mem_dc)
|
||||||
else:
|
else:
|
||||||
mem_dc.SelectObject(self.GetBuffer())
|
mem_dc.SelectObject(self.GetBuffer())
|
||||||
xstart, ystart = self.tree.CalcUnscrolledPosition(0,0)
|
xstart, ystart = self.tree.CalcUnscrolledPosition(0,0)
|
||||||
size = self.tree.GetClientSizeTuple()
|
size = self.tree.GetClientSizeTuple()
|
||||||
dc.Blit(xstart, ystart, size[0], size[1], mem_dc, xstart, ystart)
|
dc.Blit((xstart, ystart), (size[0], size[1]), mem_dc, (xstart, ystart))
|
||||||
else:
|
else:
|
||||||
if node == self.tree.currentRoot:
|
if node == self.tree.currentRoot:
|
||||||
self.knobs = []
|
self.knobs = []
|
||||||
@@ -593,7 +617,7 @@ class TreePainter(Painter):
|
|||||||
dc.SetBrush(self.GetBackgroundBrush())
|
dc.SetBrush(self.GetBackgroundBrush())
|
||||||
dc.SetFont(self.tree.GetFont())
|
dc.SetFont(self.tree.GetFont())
|
||||||
if paintBackground:
|
if paintBackground:
|
||||||
dc.DrawRectangle(0, 0, size[0], size[1])
|
dc.DrawRectangle((0, 0), (size[0], size[1]))
|
||||||
if node:
|
if node:
|
||||||
#Call with not paintBackground because if we are told not to paint the
|
#Call with not paintBackground because if we are told not to paint the
|
||||||
#whole background, we have to paint in parts to undo selection coloring.
|
#whole background, we have to paint in parts to undo selection coloring.
|
||||||
@@ -606,7 +630,7 @@ class TreePainter(Painter):
|
|||||||
|
|
||||||
def SetLinePen(self, pen):
|
def SetLinePen(self, pen):
|
||||||
Painter.SetLinePen(self, pen)
|
Painter.SetLinePen(self, pen)
|
||||||
self.dashpen = wxPen(pen.GetColour(), 1, wxDOT)
|
self.dashpen = wx.Pen(pen.GetColour(), 1, wx.DOT)
|
||||||
|
|
||||||
def paintWalk(self, node, dc, paintRects=0):
|
def paintWalk(self, node, dc, paintRects=0):
|
||||||
self.linePainter.Paint(node.parent, node, dc)
|
self.linePainter.Paint(node.parent, node, dc)
|
||||||
@@ -621,23 +645,23 @@ class TreePainter(Painter):
|
|||||||
if (not self.tree.model.IsLeaf(kid.data)) or ((kid.expanded or self.tree._assumeChildren) and len(kid.kids)):
|
if (not self.tree.model.IsLeaf(kid.data)) or ((kid.expanded or self.tree._assumeChildren) and len(kid.kids)):
|
||||||
dc.SetPen(self.linepen)
|
dc.SetPen(self.linepen)
|
||||||
dc.SetBrush(self.bgbrush)
|
dc.SetBrush(self.bgbrush)
|
||||||
dc.DrawRectangle(px -4, py-4, 9, 9)
|
dc.DrawRectangle((px -4, py-4), (9, 9))
|
||||||
self.knobs.append( (kid, Rect(px -4, py -4, 9, 9)) )
|
self.knobs.append( (kid, Rect(px -4, py -4, 9, 9)) )
|
||||||
dc.SetPen(self.textpen)
|
dc.SetPen(self.textpen)
|
||||||
if not kid.expanded:
|
if not kid.expanded:
|
||||||
dc.DrawLine(px, py -2, px, py + 3)
|
dc.DrawLine((px, py -2), (px, py + 3))
|
||||||
dc.DrawLine(px -2, py, px + 3, py)
|
dc.DrawLine((px -2, py), (px + 3, py))
|
||||||
if node == self.tree.currentRoot:
|
if node == self.tree.currentRoot:
|
||||||
px = (node.projx - self.tree.layout.NODE_STEP) + 5
|
px = (node.projx - self.tree.layout.NODE_STEP) + 5
|
||||||
py = node.projy + node.height/2
|
py = node.projy + node.height/2
|
||||||
dc.SetPen(self.linepen)
|
dc.SetPen(self.linepen)
|
||||||
dc.SetBrush(self.bgbrush)
|
dc.SetBrush(self.bgbrush)
|
||||||
dc.DrawRectangle(px -4, py-4, 9, 9)
|
dc.DrawRectangle((px -4, py-4), (9, 9))
|
||||||
self.knobs.append( (node, Rect(px -4, py -4, 9, 9)) )
|
self.knobs.append( (node, Rect(px -4, py -4, 9, 9)) )
|
||||||
dc.SetPen(self.textpen)
|
dc.SetPen(self.textpen)
|
||||||
if not node.expanded:
|
if not node.expanded:
|
||||||
dc.DrawLine(px, py -2, px, py + 3)
|
dc.DrawLine((px, py -2), (px, py + 3))
|
||||||
dc.DrawLine(px -2, py, px + 3, py)
|
dc.DrawLine((px -2, py), (px + 3, py))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def OnMouse(self, evt):
|
def OnMouse(self, evt):
|
||||||
@@ -652,15 +676,15 @@ class TreeNodePainter(NodePainter):
|
|||||||
if node.selected:
|
if node.selected:
|
||||||
dc.SetPen(self.painter.GetLinePen())
|
dc.SetPen(self.painter.GetLinePen())
|
||||||
dc.SetBrush(self.painter.GetForegroundBrush())
|
dc.SetBrush(self.painter.GetForegroundBrush())
|
||||||
dc.SetTextForeground(wxNamedColour("WHITE"))
|
dc.SetTextForeground(wx.NamedColour("WHITE"))
|
||||||
dc.DrawRectangle(node.projx -1, node.projy -1, node.width + 3, node.height + 3)
|
dc.DrawRectangle((node.projx -1, node.projy -1), (node.width + 3, node.height + 3))
|
||||||
else:
|
else:
|
||||||
if drawRects:
|
if drawRects:
|
||||||
dc.SetBrush(self.painter.GetBackgroundBrush())
|
dc.SetBrush(self.painter.GetBackgroundBrush())
|
||||||
dc.SetPen(self.painter.GetBackgroundPen())
|
dc.SetPen(self.painter.GetBackgroundPen())
|
||||||
dc.DrawRectangle(node.projx -1, node.projy -1, node.width + 3, node.height + 3)
|
dc.DrawRectangle((node.projx -1, node.projy -1), (node.width + 3, node.height + 3))
|
||||||
dc.SetTextForeground(self.painter.GetTextColour())
|
dc.SetTextForeground(self.painter.GetTextColour())
|
||||||
dc.DrawText(text, node.projx, node.projy)
|
dc.DrawText(text, (node.projx, node.projy))
|
||||||
self.painter.rectangles.append((node, Rect(node.projx, node.projy, node.width, node.height)))
|
self.painter.rectangles.append((node, Rect(node.projx, node.projy, node.width, node.height)))
|
||||||
|
|
||||||
class TreeLinePainter(LinePainter):
|
class TreeLinePainter(LinePainter):
|
||||||
@@ -672,59 +696,41 @@ class TreeLinePainter(LinePainter):
|
|||||||
py = child.projy + self.painter.tree.layout.NODE_HEIGHT/2 -2
|
py = child.projy + self.painter.tree.layout.NODE_HEIGHT/2 -2
|
||||||
cx = child.projx
|
cx = child.projx
|
||||||
cy = py
|
cy = py
|
||||||
dc.DrawLine(px, py, cx, cy)
|
dc.DrawLine((px, py), (cx, cy))
|
||||||
else:
|
else:
|
||||||
px = parent.projx + 5
|
px = parent.projx + 5
|
||||||
py = parent.projy + parent.height
|
py = parent.projy + parent.height
|
||||||
cx = child.projx -5
|
cx = child.projx -5
|
||||||
cy = child.projy + self.painter.tree.layout.NODE_HEIGHT/2 -3
|
cy = child.projy + self.painter.tree.layout.NODE_HEIGHT/2 -3
|
||||||
dc.DrawLine(px, py, px, cy)
|
dc.DrawLine((px, py), (px, cy))
|
||||||
dc.DrawLine(px, cy, cx, cy)
|
dc.DrawLine((px, cy), (cx, cy))
|
||||||
|
|
||||||
|
#>> Event defs
|
||||||
|
wxEVT_MVCTREE_BEGIN_EDIT = wx.NewEventType() #Start editing. Vetoable.
|
||||||
|
wxEVT_MVCTREE_END_EDIT = wx.NewEventType() #Stop editing. Vetoable.
|
||||||
|
wxEVT_MVCTREE_DELETE_ITEM = wx.NewEventType() #Item removed from model.
|
||||||
|
wxEVT_MVCTREE_ITEM_EXPANDED = wx.NewEventType()
|
||||||
|
wxEVT_MVCTREE_ITEM_EXPANDING = wx.NewEventType()
|
||||||
|
wxEVT_MVCTREE_ITEM_COLLAPSED = wx.NewEventType()
|
||||||
|
wxEVT_MVCTREE_ITEM_COLLAPSING = wx.NewEventType()
|
||||||
|
wxEVT_MVCTREE_SEL_CHANGED = wx.NewEventType()
|
||||||
|
wxEVT_MVCTREE_SEL_CHANGING = wx.NewEventType() #Vetoable.
|
||||||
|
wxEVT_MVCTREE_KEY_DOWN = wx.NewEventType()
|
||||||
|
wxEVT_MVCTREE_ADD_ITEM = wx.NewEventType() #Item added to model.
|
||||||
|
|
||||||
wxEVT_MVCTREE_BEGIN_EDIT = 20204 #Start editing. Vetoable.
|
EVT_MVCTREE_SEL_CHANGED = wx.PyEventBinder(wxEVT_MVCTREE_SEL_CHANGED, 1)
|
||||||
wxEVT_MVCTREE_END_EDIT = 20205 #Stop editing. Vetoable.
|
EVT_MVCTREE_SEL_CHANGING = wx.PyEventBinder(wxEVT_MVCTREE_SEL_CHANGING, 1)
|
||||||
wxEVT_MVCTREE_DELETE_ITEM = 20206 #Item removed from model.
|
EVT_MVCTREE_ITEM_EXPANDED = wx.PyEventBinder(wxEVT_MVCTREE_ITEM_EXPANDED, 1)
|
||||||
wxEVT_MVCTREE_ITEM_EXPANDED = 20209
|
EVT_MVCTREE_ITEM_EXPANDING = wx.PyEventBinder(wxEVT_MVCTREE_ITEM_EXPANDING, 1)
|
||||||
wxEVT_MVCTREE_ITEM_EXPANDING = 20210
|
EVT_MVCTREE_ITEM_COLLAPSED = wx.PyEventBinder(wxEVT_MVCTREE_ITEM_COLLAPSED, 1)
|
||||||
wxEVT_MVCTREE_ITEM_COLLAPSED = 20211
|
EVT_MVCTREE_ITEM_COLLAPSING = wx.PyEventBinder(wxEVT_MVCTREE_ITEM_COLLAPSING, 1)
|
||||||
wxEVT_MVCTREE_ITEM_COLLAPSING = 20212
|
EVT_MVCTREE_ADD_ITEM = wx.PyEventBinder(wxEVT_MVCTREE_ADD_ITEM, 1)
|
||||||
wxEVT_MVCTREE_SEL_CHANGED = 20213
|
EVT_MVCTREE_DELETE_ITEM = wx.PyEventBinder(wxEVT_MVCTREE_DELETE_ITEM, 1)
|
||||||
wxEVT_MVCTREE_SEL_CHANGING = 20214 #Vetoable.
|
EVT_MVCTREE_KEY_DOWN = wx.PyEventBinder(wxEVT_MVCTREE_KEY_DOWN, 1)
|
||||||
wxEVT_MVCTREE_KEY_DOWN = 20215
|
|
||||||
wxEVT_MVCTREE_ADD_ITEM = 20216 #Item added to model.
|
|
||||||
|
|
||||||
def EVT_MVCTREE_SEL_CHANGED(win, id, func):
|
class wxMVCTreeEvent(wx.PyCommandEvent):
|
||||||
win.Connect(id, -1, wxEVT_MVCTREE_SEL_CHANGED, func)
|
|
||||||
|
|
||||||
def EVT_MVCTREE_SEL_CHANGING(win, id, func):
|
|
||||||
win.Connect(id, -1, wxEVT_MVCTREE_SEL_CHANGING, func)
|
|
||||||
|
|
||||||
def EVT_MVCTREE_ITEM_EXPANDED(win, id, func):
|
|
||||||
win.Connect(id, -1, wxEVT_MVCTREE_ITEM_EXPANDED, func)
|
|
||||||
|
|
||||||
def EVT_MVCTREE_ITEM_EXPANDING(win, id, func):
|
|
||||||
win.Connect(id, -1, wxEVT_MVCTREE_ITEM_EXPANDING, func)
|
|
||||||
|
|
||||||
def EVT_MVCTREE_ITEM_COLLAPSED(win, id, func):
|
|
||||||
win.Connect(id, -1, wxEVT_MVCTREE_ITEM_COLLAPSED, func)
|
|
||||||
|
|
||||||
def EVT_MVCTREE_ITEM_COLLAPSING(win, id, func):
|
|
||||||
win.Connect(id, -1, wxEVT_MVCTREE_ITEM_COLLAPSING, func)
|
|
||||||
|
|
||||||
def EVT_MVCTREE_ADD_ITEM(win, id, func):
|
|
||||||
win.Connect(id, -1, wxEVT_MVCTREE_ADD_ITEM, func)
|
|
||||||
|
|
||||||
def EVT_MVCTREE_DELETE_ITEM(win, id, func):
|
|
||||||
win.Connect(id, -1, wxEVT_MVCTREE_DELETE_ITEM, func)
|
|
||||||
|
|
||||||
def EVT_MVCTREE_KEY_DOWN(win, id, func):
|
|
||||||
win.Connect(id, -1, wxEVT_MVCTREE_KEY_DOWN, func)
|
|
||||||
|
|
||||||
|
|
||||||
class wxMVCTreeEvent(wxPyCommandEvent):
|
|
||||||
def __init__(self, type, id, node = None, nodes = None, keyEvent = None, **kwargs):
|
def __init__(self, type, id, node = None, nodes = None, keyEvent = None, **kwargs):
|
||||||
apply(wxPyCommandEvent.__init__, (self, type, id), kwargs)
|
apply(wx.PyCommandEvent.__init__, (self, type, id), kwargs)
|
||||||
self.node = node
|
self.node = node
|
||||||
self.nodes = nodes
|
self.nodes = nodes
|
||||||
self.keyEvent = keyEvent
|
self.keyEvent = keyEvent
|
||||||
@@ -738,17 +744,17 @@ class wxMVCTreeEvent(wxPyCommandEvent):
|
|||||||
class wxMVCTreeNotifyEvent(wxMVCTreeEvent):
|
class wxMVCTreeNotifyEvent(wxMVCTreeEvent):
|
||||||
def __init__(self, type, id, node = None, nodes = None, **kwargs):
|
def __init__(self, type, id, node = None, nodes = None, **kwargs):
|
||||||
apply(wxMVCTreeEvent.__init__, (self, type, id, node, nodes), kwargs)
|
apply(wxMVCTreeEvent.__init__, (self, type, id, node, nodes), kwargs)
|
||||||
self.notify = wxNotifyEvent(type, id)
|
self.notify = wx.NotifyEvent(type, id)
|
||||||
def getNotifyEvent(self):
|
def getNotifyEvent(self):
|
||||||
return self.notify
|
return self.notify
|
||||||
|
|
||||||
class wxMVCTree(wxScrolledWindow):
|
class wxMVCTree(wx.ScrolledWindow):
|
||||||
"""
|
"""
|
||||||
The main mvc tree class.
|
The main mvc tree class.
|
||||||
"""
|
"""
|
||||||
def __init__(self, parent, id, model = None, layout = None, transform = None,
|
def __init__(self, parent, id, model = None, layout = None, transform = None,
|
||||||
painter = None, *args, **kwargs):
|
painter = None, *args, **kwargs):
|
||||||
apply(wxScrolledWindow.__init__, (self, parent, id), kwargs)
|
apply(wx.ScrolledWindow.__init__, (self, parent, id), kwargs)
|
||||||
self.nodemap = {}
|
self.nodemap = {}
|
||||||
self._multiselect = False
|
self._multiselect = False
|
||||||
self._selections = []
|
self._selections = []
|
||||||
@@ -771,19 +777,19 @@ class wxMVCTree(wxScrolledWindow):
|
|||||||
if not painter:
|
if not painter:
|
||||||
painter = TreePainter(self)
|
painter = TreePainter(self)
|
||||||
self.painter = painter
|
self.painter = painter
|
||||||
self.SetFont(wxFont(9, wxDEFAULT, wxNORMAL, wxNORMAL, False))
|
self.SetFont(wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False))
|
||||||
EVT_MOUSE_EVENTS(self, self.OnMouse)
|
self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
|
||||||
EVT_KEY_DOWN(self, self.OnKeyDown)
|
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
|
||||||
self.doubleBuffered = True
|
self.doubleBuffered = True
|
||||||
EVT_SIZE(self, self.OnSize)
|
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||||
EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
|
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
|
||||||
EVT_PAINT(self, self.OnPaint)
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||||
|
|
||||||
|
|
||||||
def Refresh(self):
|
def Refresh(self):
|
||||||
if self.doubleBuffered:
|
if self.doubleBuffered:
|
||||||
self.painter.ClearBuffer()
|
self.painter.ClearBuffer()
|
||||||
wxScrolledWindow.Refresh(self, False)
|
wx.ScrolledWindow.Refresh(self, False)
|
||||||
|
|
||||||
def GetPainter(self):
|
def GetPainter(self):
|
||||||
return self.painter
|
return self.painter
|
||||||
@@ -821,7 +827,7 @@ class wxMVCTree(wxScrolledWindow):
|
|||||||
|
|
||||||
def SetFont(self, font):
|
def SetFont(self, font):
|
||||||
self.painter.SetFont(font)
|
self.painter.SetFont(font)
|
||||||
dc = wxClientDC(self)
|
dc = wx.ClientDC(self)
|
||||||
dc.SetFont(font)
|
dc.SetFont(font)
|
||||||
self.layout.SetHeight(dc.GetTextExtent("")[1] + 18)
|
self.layout.SetHeight(dc.GetTextExtent("")[1] + 18)
|
||||||
self.painter.ClearBuffer()
|
self.painter.ClearBuffer()
|
||||||
@@ -1042,7 +1048,7 @@ class wxMVCTree(wxScrolledWindow):
|
|||||||
changeparents.append(treenode)
|
changeparents.append(treenode)
|
||||||
e = wxMVCTreeEvent(wxEVT_MVCTREE_SEL_CHANGED, self.GetId(), nodeTuple[0], nodes = nodeTuple)
|
e = wxMVCTreeEvent(wxEVT_MVCTREE_SEL_CHANGED, self.GetId(), nodeTuple[0], nodes = nodeTuple)
|
||||||
self.GetEventHandler().ProcessEvent(e)
|
self.GetEventHandler().ProcessEvent(e)
|
||||||
dc = wxClientDC(self)
|
dc = wx.ClientDC(self)
|
||||||
self.PrepareDC(dc)
|
self.PrepareDC(dc)
|
||||||
for node in changeparents:
|
for node in changeparents:
|
||||||
if node:
|
if node:
|
||||||
@@ -1060,7 +1066,7 @@ class wxMVCTree(wxScrolledWindow):
|
|||||||
treenode.selected = False
|
treenode.selected = False
|
||||||
e = wxMVCTreeEvent(wxEVT_MVCTREE_SEL_CHANGED, self.GetId(), node, nodes = nodeTuple)
|
e = wxMVCTreeEvent(wxEVT_MVCTREE_SEL_CHANGED, self.GetId(), node, nodes = nodeTuple)
|
||||||
self.GetEventHandler().ProcessEvent(e)
|
self.GetEventHandler().ProcessEvent(e)
|
||||||
dc = wxClientDC(self)
|
dc = wx.ClientDC(self)
|
||||||
self.PrepareDC(dc)
|
self.PrepareDC(dc)
|
||||||
for node in changeparents:
|
for node in changeparents:
|
||||||
if node:
|
if node:
|
||||||
@@ -1072,22 +1078,22 @@ class wxMVCTree(wxScrolledWindow):
|
|||||||
if hasattr(self, 'painter') and self.painter:
|
if hasattr(self, 'painter') and self.painter:
|
||||||
return self.painter.GetBackgroundColour()
|
return self.painter.GetBackgroundColour()
|
||||||
else:
|
else:
|
||||||
return wxWindow.GetBackgroundColour(self)
|
return wx.Window.GetBackgroundColour(self)
|
||||||
def SetBackgroundColour(self, color):
|
def SetBackgroundColour(self, color):
|
||||||
if hasattr(self, 'painter') and self.painter:
|
if hasattr(self, 'painter') and self.painter:
|
||||||
self.painter.SetBackgroundColour(color)
|
self.painter.SetBackgroundColour(color)
|
||||||
else:
|
else:
|
||||||
wxWindow.SetBackgroundColour(self, color)
|
wx.Window.SetBackgroundColour(self, color)
|
||||||
def GetForegroundColour(self):
|
def GetForegroundColour(self):
|
||||||
if hasattr(self, 'painter') and self.painter:
|
if hasattr(self, 'painter') and self.painter:
|
||||||
return self.painter.GetForegroundColour()
|
return self.painter.GetForegroundColour()
|
||||||
else:
|
else:
|
||||||
return wxWindow.GetBackgroundColour(self)
|
return wx.Window.GetBackgroundColour(self)
|
||||||
def SetForegroundColour(self, color):
|
def SetForegroundColour(self, color):
|
||||||
if hasattr(self, 'painter') and self.painter:
|
if hasattr(self, 'painter') and self.painter:
|
||||||
self.painter.SetForegroundColour(color)
|
self.painter.SetForegroundColour(color)
|
||||||
else:
|
else:
|
||||||
wxWindow.SetBackgroundColour(self, color)
|
wx.Window.SetBackgroundColour(self, color)
|
||||||
|
|
||||||
def SetAssumeChildren(self, bool):
|
def SetAssumeChildren(self, bool):
|
||||||
self._assumeChildren = bool
|
self._assumeChildren = bool
|
||||||
@@ -1113,15 +1119,15 @@ class wxMVCTree(wxScrolledWindow):
|
|||||||
tsize = list(self.transform.GetSize())
|
tsize = list(self.transform.GetSize())
|
||||||
tsize[0] = tsize[0] + 50
|
tsize[0] = tsize[0] + 50
|
||||||
tsize[1] = tsize[1] + 50
|
tsize[1] = tsize[1] + 50
|
||||||
size = self.GetSizeTuple()
|
w, h = self.GetSize()
|
||||||
if tsize[0] > size[0] or tsize[1] > size[1]:
|
if tsize[0] > w or tsize[1] > h:
|
||||||
if not hasattr(self, '_oldsize') or (tsize[0] > self._oldsize[0] or tsize[1] > self._oldsize[1]):
|
if not hasattr(self, '_oldsize') or (tsize[0] > self._oldsize[0] or tsize[1] > self._oldsize[1]):
|
||||||
self._oldsize = tsize
|
self._oldsize = tsize
|
||||||
oldstart = self.ViewStart()
|
oldstart = self.GetViewStart()
|
||||||
self._lastPhysicalSize = self.GetSize()
|
self._lastPhysicalSize = self.GetSize()
|
||||||
self.SetScrollbars(10, 10, tsize[0]/10, tsize[1]/10)
|
self.SetScrollbars(10, 10, tsize[0]/10, tsize[1]/10)
|
||||||
self.Scroll(oldstart[0], oldstart[1])
|
self.Scroll(oldstart[0], oldstart[1])
|
||||||
dc = wxPaintDC(self)
|
dc = wx.PaintDC(self)
|
||||||
self.PrepareDC(dc)
|
self.PrepareDC(dc)
|
||||||
dc.SetFont(self.GetFont())
|
dc.SetFont(self.GetFont())
|
||||||
self.painter.Paint(dc, self.currentRoot, self.doubleBuffered)
|
self.painter.Paint(dc, self.currentRoot, self.doubleBuffered)
|
||||||
@@ -1130,12 +1136,3 @@ class wxMVCTree(wxScrolledWindow):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,38 +9,42 @@
|
|||||||
# RCS-ID: $Id$
|
# RCS-ID: $Id$
|
||||||
# License: wxWindows license
|
# License: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
#
|
||||||
|
|
||||||
from wxPython.wx import *
|
import wx
|
||||||
from wxPython.lib.buttons import wxGenButtonEvent
|
from wx.lib.buttons import GenButtonEvent
|
||||||
|
|
||||||
|
|
||||||
class PopButton(wxPyControl):
|
class PopButton(wx.PyControl):
|
||||||
def __init__(self,*_args,**_kwargs):
|
def __init__(self,*_args,**_kwargs):
|
||||||
apply(wxPyControl.__init__,(self,) + _args,_kwargs)
|
apply(wx.PyControl.__init__,(self,) + _args,_kwargs)
|
||||||
|
|
||||||
self.up = True
|
self.up = True
|
||||||
self.didDown = False
|
self.didDown = False
|
||||||
|
|
||||||
self.InitColours()
|
self.InitColours()
|
||||||
|
|
||||||
EVT_LEFT_DOWN(self, self.OnLeftDown)
|
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
|
||||||
EVT_LEFT_UP(self, self.OnLeftUp)
|
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
|
||||||
EVT_MOTION(self, self.OnMotion)
|
self.Bind(wx.EVT_MOTION, self.OnMotion)
|
||||||
EVT_PAINT(self, self.OnPaint)
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||||
|
|
||||||
def InitColours(self):
|
def InitColours(self):
|
||||||
faceClr = wxSystemSettings_GetColour(wxSYS_COLOUR_BTNFACE)
|
faceClr = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE)
|
||||||
self.faceDnClr = faceClr
|
self.faceDnClr = faceClr
|
||||||
self.SetBackgroundColour(faceClr)
|
self.SetBackgroundColour(faceClr)
|
||||||
|
|
||||||
shadowClr = wxSystemSettings_GetColour(wxSYS_COLOUR_BTNSHADOW)
|
shadowClr = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNSHADOW)
|
||||||
highlightClr = wxSystemSettings_GetColour(wxSYS_COLOUR_BTNHIGHLIGHT)
|
highlightClr = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT)
|
||||||
self.shadowPen = wxPen(shadowClr, 1, wxSOLID)
|
self.shadowPen = wx.Pen(shadowClr, 1, wx.SOLID)
|
||||||
self.highlightPen = wxPen(highlightClr, 1, wxSOLID)
|
self.highlightPen = wx.Pen(highlightClr, 1, wx.SOLID)
|
||||||
self.blackPen = wxPen(wxBLACK, 1, wxSOLID)
|
self.blackPen = wx.Pen(wx.BLACK, 1, wx.SOLID)
|
||||||
|
|
||||||
def Notify(self):
|
def Notify(self):
|
||||||
evt = wxGenButtonEvent(wxEVT_COMMAND_BUTTON_CLICKED, self.GetId())
|
evt = GenButtonEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, self.GetId())
|
||||||
evt.SetIsDown(not self.up)
|
evt.SetIsDown(not self.up)
|
||||||
evt.SetButtonObj(self)
|
evt.SetButtonObj(self)
|
||||||
evt.SetEventObject(self)
|
evt.SetEventObject(self)
|
||||||
@@ -76,8 +80,8 @@ class PopButton(wxPyControl):
|
|||||||
return
|
return
|
||||||
if event.LeftIsDown():
|
if event.LeftIsDown():
|
||||||
if self.didDown:
|
if self.didDown:
|
||||||
x,y = event.GetPositionTuple()
|
x,y = event.GetPosition()
|
||||||
w,h = self.GetClientSizeTuple()
|
w,h = self.GetClientSize()
|
||||||
if self.up and x<w and x>=0 and y<h and y>=0:
|
if self.up and x<w and x>=0 and y<h and y>=0:
|
||||||
self.up = False
|
self.up = False
|
||||||
self.Refresh()
|
self.Refresh()
|
||||||
@@ -108,9 +112,9 @@ class PopButton(wxPyControl):
|
|||||||
dc.DrawLine((x2-i, y1+i), (x2-i, y2))
|
dc.DrawLine((x2-i, y1+i), (x2-i, y2))
|
||||||
|
|
||||||
def DrawArrow(self,dc):
|
def DrawArrow(self,dc):
|
||||||
size = self.GetSize()
|
w, h = self.GetSize()
|
||||||
mx = size.width / 2
|
mx = w / 2
|
||||||
my = size.height / 2
|
my = h / 2
|
||||||
dc.SetPen(self.highlightPen)
|
dc.SetPen(self.highlightPen)
|
||||||
dc.DrawLine((mx-5,my-5), (mx+5,my-5))
|
dc.DrawLine((mx-5,my-5), (mx+5,my-5))
|
||||||
dc.DrawLine((mx-5,my-5), (mx,my+5))
|
dc.DrawLine((mx-5,my-5), (mx,my+5))
|
||||||
@@ -120,15 +124,15 @@ class PopButton(wxPyControl):
|
|||||||
dc.DrawLine((mx+5,my-5), (mx,my+5))
|
dc.DrawLine((mx+5,my-5), (mx,my+5))
|
||||||
|
|
||||||
def OnPaint(self, event):
|
def OnPaint(self, event):
|
||||||
width, height = self.GetClientSizeTuple()
|
width, height = self.GetClientSize()
|
||||||
x1 = y1 = 0
|
x1 = y1 = 0
|
||||||
x2 = width - 1
|
x2 = width - 1
|
||||||
y2 = height - 1
|
y2 = height - 1
|
||||||
dc = wxBufferedPaintDC(self)
|
dc = wx.BufferedPaintDC(self)
|
||||||
if self.up:
|
if self.up:
|
||||||
dc.SetBackground(wxBrush(self.GetBackgroundColour(), wxSOLID))
|
dc.SetBackground(wx.Brush(self.GetBackgroundColour(), wx.SOLID))
|
||||||
else:
|
else:
|
||||||
dc.SetBackground(wxBrush(self.faceDnClr, wxSOLID))
|
dc.SetBackground(wx.Brush(self.faceDnClr, wx.SOLID))
|
||||||
dc.Clear()
|
dc.Clear()
|
||||||
self.DrawBezel(dc, x1, y1, x2, y2)
|
self.DrawBezel(dc, x1, y1, x2, y2)
|
||||||
self.DrawArrow(dc)
|
self.DrawArrow(dc)
|
||||||
@@ -138,12 +142,12 @@ class PopButton(wxPyControl):
|
|||||||
|
|
||||||
|
|
||||||
# Tried to use wxPopupWindow but the control misbehaves on MSW
|
# Tried to use wxPopupWindow but the control misbehaves on MSW
|
||||||
class wxPopupDialog(wxDialog):
|
class wxPopupDialog(wx.Dialog):
|
||||||
def __init__(self,parent,content = None):
|
def __init__(self,parent,content = None):
|
||||||
wxDialog.__init__(self,parent,-1,'', style = wxBORDER_SIMPLE|wxSTAY_ON_TOP)
|
wx.Dialog.__init__(self,parent,-1,'', style = wx.BORDER_SIMPLE|wx.STAY_ON_TOP)
|
||||||
|
|
||||||
self.ctrl = parent
|
self.ctrl = parent
|
||||||
self.win = wxWindow(self,-1,pos = wxPoint(0,0),style = 0)
|
self.win = wx.Window(self,-1,pos = (0,0),style = 0)
|
||||||
|
|
||||||
if content:
|
if content:
|
||||||
self.SetContent(content)
|
self.SetContent(content)
|
||||||
@@ -157,7 +161,7 @@ class wxPopupDialog(wxDialog):
|
|||||||
|
|
||||||
def Display(self):
|
def Display(self):
|
||||||
pos = self.ctrl.ClientToScreen( (0,0) )
|
pos = self.ctrl.ClientToScreen( (0,0) )
|
||||||
dSize = wxGetDisplaySize()
|
dSize = wx.GetDisplaySize()
|
||||||
selfSize = self.GetSize()
|
selfSize = self.GetSize()
|
||||||
tcSize = self.ctrl.GetSize()
|
tcSize = self.ctrl.GetSize()
|
||||||
|
|
||||||
@@ -173,7 +177,7 @@ class wxPopupDialog(wxDialog):
|
|||||||
if pos.y < 0:
|
if pos.y < 0:
|
||||||
pos.y = 0
|
pos.y = 0
|
||||||
|
|
||||||
self.MoveXY(pos.x,pos.y)
|
self.Move(pos)
|
||||||
|
|
||||||
self.ctrl.FormatContent()
|
self.ctrl.FormatContent()
|
||||||
|
|
||||||
@@ -183,29 +187,29 @@ class wxPopupDialog(wxDialog):
|
|||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
class wxPopupControl(wxPyControl):
|
class wxPopupControl(wx.PyControl):
|
||||||
def __init__(self,*_args,**_kwargs):
|
def __init__(self,*_args,**_kwargs):
|
||||||
if _kwargs.has_key('value'):
|
if _kwargs.has_key('value'):
|
||||||
del _kwargs['value']
|
del _kwargs['value']
|
||||||
apply(wxPyControl.__init__,(self,) + _args,_kwargs)
|
apply(wx.PyControl.__init__,(self,) + _args,_kwargs)
|
||||||
|
|
||||||
self.textCtrl = wxTextCtrl(self,-1,'',pos = wxPoint(0,0))
|
self.textCtrl = wx.TextCtrl(self,-1,'',pos = (0,0))
|
||||||
self.bCtrl = PopButton(self,-1)
|
self.bCtrl = PopButton(self,-1)
|
||||||
self.pop = None
|
self.pop = None
|
||||||
self.content = None
|
self.content = None
|
||||||
self.OnSize(None)
|
self.OnSize(None)
|
||||||
|
|
||||||
EVT_SIZE(self,self.OnSize)
|
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||||
EVT_BUTTON(self.bCtrl,self.bCtrl.GetId(),self.OnButton)
|
self.bCtrl.Bind(wx.EVT_BUTTON, self.OnButton, self.bCtrl)
|
||||||
# embedded control should get focus on TAB keypress
|
# embedded control should get focus on TAB keypress
|
||||||
EVT_SET_FOCUS(self,self.OnFocus)
|
self.Bind(wx.EVT_SET_FOCUS, self.OnFocus)
|
||||||
|
|
||||||
def OnFocus(self,evt):
|
def OnFocus(self,evt):
|
||||||
self.textCtrl.SetFocus()
|
self.textCtrl.SetFocus()
|
||||||
evt.Skip()
|
evt.Skip()
|
||||||
|
|
||||||
def OnSize(self,evt):
|
def OnSize(self,evt):
|
||||||
w,h = self.GetClientSizeTuple()
|
w,h = self.GetClientSize()
|
||||||
self.textCtrl.SetDimensions(0,0,w-17,h)
|
self.textCtrl.SetDimensions(0,0,w-17,h)
|
||||||
self.bCtrl.SetDimensions(w-17,0,17,h)
|
self.bCtrl.SetDimensions(w-17,0,17,h)
|
||||||
|
|
||||||
@@ -220,7 +224,7 @@ class wxPopupControl(wxPyControl):
|
|||||||
self.pop.Display()
|
self.pop.Display()
|
||||||
|
|
||||||
def Enable(self,flag):
|
def Enable(self,flag):
|
||||||
wxPyControl.Enable(self,flag)
|
wx.PyControl.Enable(self,flag)
|
||||||
self.textCtrl.Enable(flag)
|
self.textCtrl.Enable(flag)
|
||||||
self.bCtrl.Enable(flag)
|
self.bCtrl.Enable(flag)
|
||||||
|
|
||||||
|
|||||||
@@ -14,36 +14,41 @@
|
|||||||
# fixed bug for string wider than print region
|
# fixed bug for string wider than print region
|
||||||
# add index to data list after parsing total pages for paging
|
# add index to data list after parsing total pages for paging
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
# 12/10/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
#
|
||||||
|
|
||||||
import os, sys, copy
|
|
||||||
|
|
||||||
from wxPython.wx import *
|
|
||||||
import copy
|
import copy
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import wx
|
||||||
|
|
||||||
class PrintBase:
|
class PrintBase:
|
||||||
def SetPrintFont(self, font): # set the DC font parameters
|
def SetPrintFont(self, font): # set the DC font parameters
|
||||||
fattr = font["Attr"]
|
fattr = font["Attr"]
|
||||||
if fattr[0] == 1:
|
if fattr[0] == 1:
|
||||||
weight = wxBOLD
|
weight = wx.BOLD
|
||||||
else:
|
else:
|
||||||
weight = wxNORMAL
|
weight = wx.NORMAL
|
||||||
|
|
||||||
if fattr[1] == 1:
|
if fattr[1] == 1:
|
||||||
set_style = wxITALIC
|
set_style = wx.ITALIC
|
||||||
else:
|
else:
|
||||||
set_style = wxNORMAL
|
set_style = wx.NORMAL
|
||||||
|
|
||||||
underline = fattr[2]
|
underline = fattr[2]
|
||||||
fcolour = self.GetFontColour(font)
|
fcolour = self.GetFontColour(font)
|
||||||
self.DC.SetTextForeground(fcolour)
|
self.DC.SetTextForeground(fcolour)
|
||||||
|
|
||||||
setfont = wxFont(font["Size"], wxSWISS, set_style, weight, underline)
|
setfont = wx.Font(font["Size"], wx.SWISS, set_style, weight, underline)
|
||||||
setfont.SetFaceName(font["Name"])
|
setfont.SetFaceName(font["Name"])
|
||||||
self.DC.SetFont(setfont)
|
self.DC.SetFont(setfont)
|
||||||
|
|
||||||
def GetFontColour(self, font):
|
def GetFontColour(self, font):
|
||||||
fcolour = font["Colour"]
|
fcolour = font["Colour"]
|
||||||
return wxColour(fcolour[0], fcolour[1], fcolour[2])
|
return wx.Colour(fcolour[0], fcolour[1], fcolour[2])
|
||||||
|
|
||||||
def OutTextRegion(self, textout, txtdraw = True):
|
def OutTextRegion(self, textout, txtdraw = True):
|
||||||
textlines = textout.split('\n')
|
textlines = textout.split('\n')
|
||||||
@@ -54,19 +59,19 @@ class PrintBase:
|
|||||||
vout, remain = self.SetFlow(text, self.region)
|
vout, remain = self.SetFlow(text, self.region)
|
||||||
if self.draw == True and txtdraw == True:
|
if self.draw == True and txtdraw == True:
|
||||||
test_out = self.TestFull(vout)
|
test_out = self.TestFull(vout)
|
||||||
if self.align == wxALIGN_LEFT:
|
if self.align == wx.ALIGN_LEFT:
|
||||||
self.DC.DrawText(test_out, self.indent+self.pcell_left_margin, y)
|
self.DC.DrawText(test_out, (self.indent+self.pcell_left_margin, y))
|
||||||
|
|
||||||
elif self.align == wxALIGN_CENTRE:
|
elif self.align == wx.ALIGN_CENTRE:
|
||||||
diff = self.GetCellDiff(test_out, self.region)
|
diff = self.GetCellDiff(test_out, self.region)
|
||||||
self.DC.DrawText(test_out, self.indent+diff/2, y)
|
self.DC.DrawText(test_out, (self.indent+diff/2, y))
|
||||||
|
|
||||||
elif self.align == wxALIGN_RIGHT:
|
elif self.align == wx.ALIGN_RIGHT:
|
||||||
diff = self.GetCellDiff(test_out, self.region)
|
diff = self.GetCellDiff(test_out, self.region)
|
||||||
self.DC.DrawText(test_out, self.indent+diff, y)
|
self.DC.DrawText(test_out, (self.indent+diff, y))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.DC.DrawText(test_out, self.indent+self.pcell_left_margin, y)
|
self.DC.DrawText(test_out, (self.indent+self.pcell_left_margin, y))
|
||||||
text = remain
|
text = remain
|
||||||
y = y + self.space
|
y = y + self.space
|
||||||
return y - self.space + self.pt_space_after
|
return y - self.space + self.pt_space_after
|
||||||
@@ -142,19 +147,19 @@ class PrintBase:
|
|||||||
vout, remain = self.SetFlow(text, pagew)
|
vout, remain = self.SetFlow(text, pagew)
|
||||||
if self.draw == True and txtdraw == True:
|
if self.draw == True and txtdraw == True:
|
||||||
test_out = vout
|
test_out = vout
|
||||||
if align == wxALIGN_LEFT:
|
if align == wx.ALIGN_LEFT:
|
||||||
self.DC.DrawText(test_out, indent, y)
|
self.DC.DrawText(test_out, (indent, y))
|
||||||
|
|
||||||
elif align == wxALIGN_CENTRE:
|
elif align == wx.ALIGN_CENTRE:
|
||||||
diff = self.GetCellDiff(test_out, pagew)
|
diff = self.GetCellDiff(test_out, pagew)
|
||||||
self.DC.DrawText(test_out, indent+diff/2, y)
|
self.DC.DrawText(test_out, (indent+diff/2, y))
|
||||||
|
|
||||||
elif align == wxALIGN_RIGHT:
|
elif align == wx.ALIGN_RIGHT:
|
||||||
diff = self.GetCellDiff(test_out, pagew)
|
diff = self.GetCellDiff(test_out, pagew)
|
||||||
self.DC.DrawText(test_out, indent+diff, y)
|
self.DC.DrawText(test_out, (indent+diff, y))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.DC.DrawText(test_out, indent, y_out)
|
self.DC.DrawText(test_out, (indent, y_out))
|
||||||
text = remain
|
text = remain
|
||||||
y = y + y_line
|
y = y + y_line
|
||||||
return y - y_line
|
return y - y_line
|
||||||
@@ -168,7 +173,7 @@ class PrintBase:
|
|||||||
return date + ' ' + time
|
return date + ' ' + time
|
||||||
|
|
||||||
def GetNow(self):
|
def GetNow(self):
|
||||||
full = str(wxDateTime_Now()) # get the current date and time in print format
|
full = str(wx.DateTime_Now()) # get the current date and time in print format
|
||||||
flds = full.split()
|
flds = full.split()
|
||||||
date = flds[0]
|
date = flds[0]
|
||||||
time = flds[1]
|
time = flds[1]
|
||||||
@@ -195,7 +200,7 @@ class PrintBase:
|
|||||||
return self.sizeh
|
return self.sizeh
|
||||||
|
|
||||||
|
|
||||||
class PrintTableDraw(wxScrolledWindow, PrintBase):
|
class PrintTableDraw(wx.ScrolledWindow, PrintBase):
|
||||||
def __init__(self, parent, DC, size):
|
def __init__(self, parent, DC, size):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.DC = DC
|
self.DC = DC
|
||||||
@@ -297,7 +302,7 @@ class PrintTableDraw(wxScrolledWindow, PrintBase):
|
|||||||
try:
|
try:
|
||||||
align = set_column_align[col] # check if custom column alignment
|
align = set_column_align[col] # check if custom column alignment
|
||||||
except:
|
except:
|
||||||
align = wxALIGN_LEFT
|
align = wx.ALIGN_LEFT
|
||||||
self.column_align.append(align)
|
self.column_align.append(align)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -316,7 +321,7 @@ class PrintTableDraw(wxScrolledWindow, PrintBase):
|
|||||||
col = col + 1
|
col = col + 1
|
||||||
|
|
||||||
def SetPointAdjust(self):
|
def SetPointAdjust(self):
|
||||||
f = wxFont(10, wxSWISS, wxNORMAL, wxNORMAL) # setup using 10 point
|
f = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL) # setup using 10 point
|
||||||
self.DC.SetFont(f)
|
self.DC.SetFont(f)
|
||||||
f.SetFaceName(self.text_font["Name"])
|
f.SetFaceName(self.text_font["Name"])
|
||||||
x, y = self.DC.GetTextExtent("W")
|
x, y = self.DC.GetTextExtent("W")
|
||||||
@@ -429,7 +434,7 @@ class PrintTableDraw(wxScrolledWindow, PrintBase):
|
|||||||
self.region = self.column[self.col+1] - self.column[self.col]
|
self.region = self.column[self.col+1] - self.column[self.col]
|
||||||
self.indent = self.column[self.col]
|
self.indent = self.column[self.col]
|
||||||
|
|
||||||
self.align = wxALIGN_LEFT
|
self.align = wx.ALIGN_LEFT
|
||||||
|
|
||||||
max_out = self.OutTextRegion(vtxt, True)
|
max_out = self.OutTextRegion(vtxt, True)
|
||||||
if max_out > max_y:
|
if max_out > max_y:
|
||||||
@@ -488,10 +493,11 @@ class PrintTableDraw(wxScrolledWindow, PrintBase):
|
|||||||
|
|
||||||
|
|
||||||
def LabelColorRow(self, colour):
|
def LabelColorRow(self, colour):
|
||||||
brush = wxBrush(colour, wxSOLID)
|
brush = wx.Brush(colour, wx.SOLID)
|
||||||
self.DC.SetBrush(brush)
|
self.DC.SetBrush(brush)
|
||||||
height = self.label_space + self.label_pt_space_before + self.label_pt_space_after
|
height = self.label_space + self.label_pt_space_before + self.label_pt_space_after
|
||||||
self.DC.DrawRectangle(self.column[0], self.y, self.end_x-self.column[0]+1, height)
|
self.DC.DrawRectangle((self.column[0], self.y),
|
||||||
|
(self.end_x-self.column[0]+1, height))
|
||||||
|
|
||||||
def ColourRowCells(self, height):
|
def ColourRowCells(self, height):
|
||||||
if self.draw == False:
|
if self.draw == False:
|
||||||
@@ -503,16 +509,16 @@ class PrintTableDraw(wxScrolledWindow, PrintBase):
|
|||||||
if cellcolour is not None:
|
if cellcolour is not None:
|
||||||
colour = cellcolour
|
colour = cellcolour
|
||||||
|
|
||||||
brush = wxBrush(colour, wxSOLID)
|
brush = wx.Brush(colour, wx.SOLID)
|
||||||
self.DC.SetBrush(brush)
|
self.DC.SetBrush(brush)
|
||||||
self.DC.SetPen(wxPen(wxNamedColour('WHITE'), 0))
|
self.DC.SetPen(wx.Pen(wx.NamedColour('WHITE'), 0))
|
||||||
|
|
||||||
start_x = self.column[col]
|
start_x = self.column[col]
|
||||||
width = self.column[col+1] - start_x + 2
|
width = self.column[col+1] - start_x + 2
|
||||||
self.DC.DrawRectangle(start_x, self.y, width, height)
|
self.DC.DrawRectangle((start_x, self.y), (width, height))
|
||||||
col = col + 1
|
col = col + 1
|
||||||
|
|
||||||
def PrintRow(self, row_val, draw = True, align = wxALIGN_LEFT):
|
def PrintRow(self, row_val, draw = True, align = wx.ALIGN_LEFT):
|
||||||
self.SetPrintFont(self.text_font)
|
self.SetPrintFont(self.text_font)
|
||||||
|
|
||||||
self.pt_space_before = self.text_pt_space_before # set the point spacing
|
self.pt_space_before = self.text_pt_space_before # set the point spacing
|
||||||
@@ -576,11 +582,11 @@ class PrintTableDraw(wxScrolledWindow, PrintBase):
|
|||||||
except:
|
except:
|
||||||
colour = self.row_def_line_colour
|
colour = self.row_def_line_colour
|
||||||
|
|
||||||
self.DC.SetPen(wxPen(colour, size))
|
self.DC.SetPen(wx.Pen(colour, size))
|
||||||
|
|
||||||
y_out = self.y
|
y_out = self.y
|
||||||
# y_out = self.y + self.pt_space_before + self.pt_space_after # adjust for extra spacing
|
# y_out = self.y + self.pt_space_before + self.pt_space_after # adjust for extra spacing
|
||||||
self.DC.DrawLine(self.column[0], y_out, self.end_x, y_out)
|
self.DC.DrawLine((self.column[0], y_out), (self.end_x, y_out))
|
||||||
|
|
||||||
def DrawColumns(self):
|
def DrawColumns(self):
|
||||||
if self.draw == True:
|
if self.draw == True:
|
||||||
@@ -598,15 +604,15 @@ class PrintTableDraw(wxScrolledWindow, PrintBase):
|
|||||||
|
|
||||||
indent = val
|
indent = val
|
||||||
|
|
||||||
self.DC.SetPen(wxPen(colour, size))
|
self.DC.SetPen(wx.Pen(colour, size))
|
||||||
self.DC.DrawLine(indent, self.y_start, indent, self.y)
|
self.DC.DrawLine((indent, self.y_start), (indent, self.y))
|
||||||
col = col + 1
|
col = col + 1
|
||||||
|
|
||||||
def DrawText(self):
|
def DrawText(self):
|
||||||
self.DoRefresh()
|
self.DoRefresh()
|
||||||
|
|
||||||
def DoDrawing(self, DC):
|
def DoDrawing(self, DC):
|
||||||
size = DC.GetSizeTuple()
|
size = DC.GetSize()
|
||||||
self.DC = DC
|
self.DC = DC
|
||||||
|
|
||||||
DC.BeginDrawing()
|
DC.BeginDrawing()
|
||||||
@@ -638,7 +644,7 @@ class PrintTable:
|
|||||||
self.parentFrame = parentFrame
|
self.parentFrame = parentFrame
|
||||||
self.SetPreviewSize()
|
self.SetPreviewSize()
|
||||||
|
|
||||||
self.printData = wxPrintData()
|
self.printData = wx.PrintData()
|
||||||
self.scale = 1.0
|
self.scale = 1.0
|
||||||
|
|
||||||
self.SetParms()
|
self.SetParms()
|
||||||
@@ -652,11 +658,11 @@ class PrintTable:
|
|||||||
self.SetMargins()
|
self.SetMargins()
|
||||||
self.SetPortrait()
|
self.SetPortrait()
|
||||||
|
|
||||||
def SetPreviewSize(self, position = wxPoint(0, 0), size="Full"):
|
def SetPreviewSize(self, position = wx.Point(0, 0), size="Full"):
|
||||||
if size == "Full":
|
if size == "Full":
|
||||||
r = wxGetClientDisplayRect()
|
r = wx.GetClientDisplayRect()
|
||||||
self.preview_frame_size = wxSize(r.width, r.height)
|
self.preview_frame_size = r.GetSize()
|
||||||
self.preview_frame_pos = wxPoint(r.x, r.y)
|
self.preview_frame_pos = r.GetPosition()
|
||||||
else:
|
else:
|
||||||
self.preview_frame_size = size
|
self.preview_frame_size = size
|
||||||
self.preview_frame_pos = position
|
self.preview_frame_pos = position
|
||||||
@@ -668,14 +674,14 @@ class PrintTable:
|
|||||||
self.printData.SetOrientation(orient)
|
self.printData.SetOrientation(orient)
|
||||||
|
|
||||||
def SetColors(self):
|
def SetColors(self):
|
||||||
self.row_def_line_colour = wxNamedColour('BLACK')
|
self.row_def_line_colour = wx.NamedColour('BLACK')
|
||||||
self.row_def_line_size = 1
|
self.row_def_line_size = 1
|
||||||
|
|
||||||
self.column_def_line_colour = wxNamedColour('BLACK')
|
self.column_def_line_colour = wx.NamedColour('BLACK')
|
||||||
self.column_def_line_size = 1
|
self.column_def_line_size = 1
|
||||||
self.column_colour = wxNamedColour('WHITE')
|
self.column_colour = wx.NamedColour('WHITE')
|
||||||
|
|
||||||
self.label_colour = wxNamedColour('LIGHT GREY')
|
self.label_colour = wx.NamedColour('LIGHT GREY')
|
||||||
|
|
||||||
def SetFonts(self):
|
def SetFonts(self):
|
||||||
self.label_font = { "Name": self.default_font_name, "Size": 12, "Colour": [0, 0, 0], "Attr": [0, 0, 0] }
|
self.label_font = { "Name": self.default_font_name, "Size": 12, "Colour": [0, 0, 0], "Attr": [0, 0, 0] }
|
||||||
@@ -703,14 +709,14 @@ class PrintTable:
|
|||||||
def SetHeaderValue(self):
|
def SetHeaderValue(self):
|
||||||
self.header_margin = 0.25
|
self.header_margin = 0.25
|
||||||
self.header_font = { "Name": self.default_font_name, "Size": 11, "Colour": [0, 0, 0], "Attr": [0, 0, 0] }
|
self.header_font = { "Name": self.default_font_name, "Size": 11, "Colour": [0, 0, 0], "Attr": [0, 0, 0] }
|
||||||
self.header_align = wxALIGN_CENTRE
|
self.header_align = wx.ALIGN_CENTRE
|
||||||
self.header_indent = 0
|
self.header_indent = 0
|
||||||
self.header_type = "Text"
|
self.header_type = "Text"
|
||||||
|
|
||||||
def SetFooterValue(self):
|
def SetFooterValue(self):
|
||||||
self.footer_margin = 0.7
|
self.footer_margin = 0.7
|
||||||
self.footer_font = { "Name": self.default_font_name, "Size": 11, "Colour": [0, 0, 0], "Attr": [0, 0, 0] }
|
self.footer_font = { "Name": self.default_font_name, "Size": 11, "Colour": [0, 0, 0], "Attr": [0, 0, 0] }
|
||||||
self.footer_align = wxALIGN_CENTRE
|
self.footer_align = wx.ALIGN_CENTRE
|
||||||
self.footer_indent = 0
|
self.footer_indent = 0
|
||||||
self.footer_type = "Pageof"
|
self.footer_type = "Pageof"
|
||||||
|
|
||||||
@@ -724,13 +730,13 @@ class PrintTable:
|
|||||||
self.cell_right_margin = 0.1
|
self.cell_right_margin = 0.1
|
||||||
|
|
||||||
def SetPortrait(self):
|
def SetPortrait(self):
|
||||||
self.printData.SetPaperId(wxPAPER_LETTER)
|
self.printData.SetPaperId(wx.PAPER_LETTER)
|
||||||
self.printData.SetOrientation(wxPORTRAIT)
|
self.printData.SetOrientation(wx.PORTRAIT)
|
||||||
self.page_width = 8.5
|
self.page_width = 8.5
|
||||||
self.page_height = 11.0
|
self.page_height = 11.0
|
||||||
|
|
||||||
def SetLandscape(self):
|
def SetLandscape(self):
|
||||||
self.printData.SetOrientation(wxLANDSCAPE)
|
self.printData.SetOrientation(wx.LANDSCAPE)
|
||||||
self.page_width = 11.0
|
self.page_width = 11.0
|
||||||
self.page_height = 8.5
|
self.page_height = 8.5
|
||||||
|
|
||||||
@@ -746,7 +752,7 @@ class PrintTable:
|
|||||||
self.default_font_name = "Arial"
|
self.default_font_name = "Arial"
|
||||||
self.default_font = { "Name": self.default_font_name, "Size": 10, "Colour": [0, 0, 0], "Attr": [0, 0, 0] }
|
self.default_font = { "Name": self.default_font_name, "Size": 10, "Colour": [0, 0, 0], "Attr": [0, 0, 0] }
|
||||||
|
|
||||||
def SetColAlignment(self, col, align=wxALIGN_LEFT):
|
def SetColAlignment(self, col, align=wx.ALIGN_LEFT):
|
||||||
self.set_column_align[col] = align
|
self.set_column_align[col] = align
|
||||||
|
|
||||||
def SetColBackgroundColour(self, col, colour):
|
def SetColBackgroundColour(self, col, colour):
|
||||||
@@ -866,14 +872,14 @@ class PrintTable:
|
|||||||
def Preview(self):
|
def Preview(self):
|
||||||
printout = SetPrintout(self)
|
printout = SetPrintout(self)
|
||||||
printout2 = SetPrintout(self)
|
printout2 = SetPrintout(self)
|
||||||
self.preview = wxPrintPreview(printout, printout2, self.printData)
|
self.preview = wx.PrintPreview(printout, printout2, self.printData)
|
||||||
if not self.preview.Ok():
|
if not self.preview.Ok():
|
||||||
wxMessageBox("There was a problem printing!", "Printing", wxOK)
|
wxMessageBox("There was a problem printing!", "Printing", wx.OK)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.preview.SetZoom(60) # initial zoom value
|
self.preview.SetZoom(60) # initial zoom value
|
||||||
|
|
||||||
frame = wxPreviewFrame(self.preview, self.parentFrame, "Print preview")
|
frame = wx.PreviewFrame(self.preview, self.parentFrame, "Print preview")
|
||||||
|
|
||||||
frame.Initialize()
|
frame.Initialize()
|
||||||
if self.parentFrame:
|
if self.parentFrame:
|
||||||
@@ -882,18 +888,18 @@ class PrintTable:
|
|||||||
frame.Show(True)
|
frame.Show(True)
|
||||||
|
|
||||||
def Print(self):
|
def Print(self):
|
||||||
pdd = wxPrintDialogData()
|
pdd = wx.PrintDialogData()
|
||||||
pdd.SetPrintData(self.printData)
|
pdd.SetPrintData(self.printData)
|
||||||
printer = wxPrinter(pdd)
|
printer = wx.Printer(pdd)
|
||||||
printout = SetPrintout(self)
|
printout = SetPrintout(self)
|
||||||
if not printer.Print(self.parentFrame, printout):
|
if not printer.Print(self.parentFrame, printout):
|
||||||
wxMessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wxOK)
|
wx.MessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wx.OK)
|
||||||
else:
|
else:
|
||||||
self.printData = printer.GetPrintDialogData().GetPrintData()
|
self.printData = printer.GetPrintDialogData().GetPrintData()
|
||||||
printout.Destroy()
|
printout.Destroy()
|
||||||
|
|
||||||
def DoDrawing(self, DC):
|
def DoDrawing(self, DC):
|
||||||
size = DC.GetSizeTuple()
|
size = DC.GetSize()
|
||||||
DC.BeginDrawing()
|
DC.BeginDrawing()
|
||||||
|
|
||||||
table = PrintTableDraw(self, DC, size)
|
table = PrintTableDraw(self, DC, size)
|
||||||
@@ -1008,9 +1014,9 @@ class PrintGrid:
|
|||||||
self.table.Print()
|
self.table.Print()
|
||||||
|
|
||||||
|
|
||||||
class SetPrintout(wxPrintout):
|
class SetPrintout(wx.Printout):
|
||||||
def __init__(self, canvas):
|
def __init__(self, canvas):
|
||||||
wxPrintout.__init__(self)
|
wx.Printout.__init__(self)
|
||||||
self.canvas = canvas
|
self.canvas = canvas
|
||||||
self.end_pg = 1000
|
self.end_pg = 1000
|
||||||
|
|
||||||
@@ -1049,7 +1055,7 @@ class SetPrintout(wxPrintout):
|
|||||||
else:
|
else:
|
||||||
self.pixelsPerInch = self.GetPPIPrinter()
|
self.pixelsPerInch = self.GetPPIPrinter()
|
||||||
|
|
||||||
(w, h) = dc.GetSizeTuple()
|
(w, h) = dc.GetSize()
|
||||||
scaleX = float(w) / 1000
|
scaleX = float(w) / 1000
|
||||||
scaleY = float(h) / 1000
|
scaleY = float(h) / 1000
|
||||||
self.printUserScale = min(scaleX, scaleY)
|
self.printUserScale = min(scaleX, scaleY)
|
||||||
@@ -1066,7 +1072,7 @@ class SetPrintout(wxPrintout):
|
|||||||
|
|
||||||
def OnPrintPage(self, page):
|
def OnPrintPage(self, page):
|
||||||
dc = self.GetDC()
|
dc = self.GetDC()
|
||||||
(w, h) = dc.GetSizeTuple()
|
(w, h) = dc.GetSize()
|
||||||
scaleX = float(w) / 1000
|
scaleX = float(w) / 1000
|
||||||
scaleY = float(h) / 1000
|
scaleY = float(h) / 1000
|
||||||
self.printUserScale = min(scaleX, scaleY)
|
self.printUserScale = min(scaleX, scaleY)
|
||||||
|
|||||||
@@ -10,6 +10,11 @@
|
|||||||
# Copyright: (c) 2000 by Total Control Software
|
# Copyright: (c) 2000 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 12/10/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
# o Added deprecation warning.
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
PyShellWindow is a class that provides an Interactive Interpreter running
|
PyShellWindow is a class that provides an Interactive Interpreter running
|
||||||
@@ -26,17 +31,32 @@ etc... But it's a good start.
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import keyword
|
||||||
|
import sys
|
||||||
|
import warnings
|
||||||
|
|
||||||
from wxPython.wx import *
|
|
||||||
from wxPython.stc import *
|
|
||||||
|
|
||||||
import sys, keyword
|
|
||||||
from code import InteractiveInterpreter
|
from code import InteractiveInterpreter
|
||||||
|
|
||||||
|
import wx
|
||||||
|
import wx.stc as stc
|
||||||
|
|
||||||
|
warningmsg = r"""\
|
||||||
|
|
||||||
|
########################################\
|
||||||
|
# THIS MODULE IS NOW DEPRECATED |
|
||||||
|
# |
|
||||||
|
# Please see the most excellent PyCrust |
|
||||||
|
# package instead. |
|
||||||
|
########################################/
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
warnings.warn(warningmsg, DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
# default styles, etc. to use for the STC
|
# default styles, etc. to use for the STC
|
||||||
|
|
||||||
if wxPlatform == '__WXMSW__':
|
if wx.Platform == '__WXMSW__':
|
||||||
_defaultSize = 8
|
_defaultSize = 8
|
||||||
else:
|
else:
|
||||||
_defaultSize = 10
|
_defaultSize = 10
|
||||||
@@ -77,11 +97,11 @@ _trace_style = 17
|
|||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
|
class PyShellWindow(stc.StyledTextCtrl, InteractiveInterpreter):
|
||||||
def __init__(self, parent, ID, pos=wxDefaultPosition,
|
def __init__(self, parent, ID, pos=wx.DefaultPosition,
|
||||||
size=wxDefaultSize, style=0,
|
size=wx.DefaultSize, style=0,
|
||||||
locals=None, properties=None, banner=None):
|
locals=None, properties=None, banner=None):
|
||||||
wxStyledTextCtrl.__init__(self, parent, ID, pos, size, style)
|
stc.StyledTextCtrl.__init__(self, parent, ID, pos, size, style)
|
||||||
InteractiveInterpreter.__init__(self, locals)
|
InteractiveInterpreter.__init__(self, locals)
|
||||||
|
|
||||||
self.lastPromptPos = 0
|
self.lastPromptPos = 0
|
||||||
@@ -110,9 +130,9 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
|
|||||||
self.Prompt()
|
self.Prompt()
|
||||||
|
|
||||||
# Event handlers
|
# Event handlers
|
||||||
EVT_KEY_DOWN(self, self.OnKey)
|
self.Bind(wx.EVT_KEY_DOWN, self.OnKey)
|
||||||
EVT_STC_UPDATEUI(self, ID, self.OnUpdateUI)
|
self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI, id=ID)
|
||||||
#EVT_STC_STYLENEEDED(self, ID, self.OnStyle)
|
#self.Bind(stc.EVT_STC_STYLENEEDED, self.OnStyle, id=ID)
|
||||||
|
|
||||||
|
|
||||||
def GetLocals(self): return self.locals
|
def GetLocals(self): return self.locals
|
||||||
@@ -131,7 +151,7 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
|
|||||||
"""
|
"""
|
||||||
p = self.props
|
p = self.props
|
||||||
|
|
||||||
#self.SetEdgeMode(wxSTC_EDGE_LINE)
|
#self.SetEdgeMode(stc.STC_EDGE_LINE)
|
||||||
#self.SetEdgeColumn(80)
|
#self.SetEdgeColumn(80)
|
||||||
|
|
||||||
|
|
||||||
@@ -140,25 +160,25 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
|
|||||||
self.SetMargins(p['marginWidth'], p['marginWidth'])
|
self.SetMargins(p['marginWidth'], p['marginWidth'])
|
||||||
|
|
||||||
# styles
|
# styles
|
||||||
self.StyleSetSpec(wxSTC_STYLE_DEFAULT, p['default'])
|
self.StyleSetSpec(stc.STC_STYLE_DEFAULT, p['default'])
|
||||||
self.StyleClearAll()
|
self.StyleClearAll()
|
||||||
self.StyleSetSpec(_stdout_style, p['stdout'])
|
self.StyleSetSpec(_stdout_style, p['stdout'])
|
||||||
self.StyleSetSpec(_stderr_style, p['stderr'])
|
self.StyleSetSpec(_stderr_style, p['stderr'])
|
||||||
self.StyleSetSpec(_trace_style, p['trace'])
|
self.StyleSetSpec(_trace_style, p['trace'])
|
||||||
|
|
||||||
self.StyleSetSpec(wxSTC_STYLE_BRACELIGHT, p['bracegood'])
|
self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, p['bracegood'])
|
||||||
self.StyleSetSpec(wxSTC_STYLE_BRACEBAD, p['bracebad'])
|
self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, p['bracebad'])
|
||||||
self.StyleSetSpec(wxSTC_P_COMMENTLINE, p['comment'])
|
self.StyleSetSpec(stc.STC_P_COMMENTLINE, p['comment'])
|
||||||
self.StyleSetSpec(wxSTC_P_NUMBER, p['number'])
|
self.StyleSetSpec(stc.STC_P_NUMBER, p['number'])
|
||||||
self.StyleSetSpec(wxSTC_P_STRING, p['string'])
|
self.StyleSetSpec(stc.STC_P_STRING, p['string'])
|
||||||
self.StyleSetSpec(wxSTC_P_CHARACTER, p['char'])
|
self.StyleSetSpec(stc.STC_P_CHARACTER, p['char'])
|
||||||
self.StyleSetSpec(wxSTC_P_WORD, p['keyword'])
|
self.StyleSetSpec(stc.STC_P_WORD, p['keyword'])
|
||||||
self.StyleSetSpec(wxSTC_P_TRIPLE, p['triple'])
|
self.StyleSetSpec(stc.STC_P_TRIPLE, p['triple'])
|
||||||
self.StyleSetSpec(wxSTC_P_TRIPLEDOUBLE, p['tripledouble'])
|
self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, p['tripledouble'])
|
||||||
self.StyleSetSpec(wxSTC_P_CLASSNAME, p['class'])
|
self.StyleSetSpec(stc.STC_P_CLASSNAME, p['class'])
|
||||||
self.StyleSetSpec(wxSTC_P_DEFNAME, p['def'])
|
self.StyleSetSpec(stc.STC_P_DEFNAME, p['def'])
|
||||||
self.StyleSetSpec(wxSTC_P_OPERATOR, p['operator'])
|
self.StyleSetSpec(stc.STC_P_OPERATOR, p['operator'])
|
||||||
self.StyleSetSpec(wxSTC_P_COMMENTBLOCK, p['comment'])
|
self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, p['comment'])
|
||||||
|
|
||||||
|
|
||||||
# used for writing to stdout, etc.
|
# used for writing to stdout, etc.
|
||||||
@@ -169,7 +189,7 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
|
|||||||
self.StartStyling(pos, 0xFF)
|
self.StartStyling(pos, 0xFF)
|
||||||
self.SetStyling(len(text), style)
|
self.SetStyling(len(text), style)
|
||||||
self.EnsureCaretVisible()
|
self.EnsureCaretVisible()
|
||||||
wxYield()
|
wx.Yield()
|
||||||
|
|
||||||
write = _write
|
write = _write
|
||||||
|
|
||||||
@@ -197,7 +217,7 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
|
|||||||
|
|
||||||
def OnKey(self, evt):
|
def OnKey(self, evt):
|
||||||
key = evt.KeyCode()
|
key = evt.KeyCode()
|
||||||
if key == WXK_RETURN:
|
if key == wx.WXK_RETURN:
|
||||||
pos = self.GetCurrentPos()
|
pos = self.GetCurrentPos()
|
||||||
lastPos = self.GetTextLength()
|
lastPos = self.GetTextLength()
|
||||||
|
|
||||||
@@ -237,7 +257,7 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
|
|||||||
# Only style from the prompt pos to the end
|
# Only style from the prompt pos to the end
|
||||||
lastPos = self.GetTextLength()
|
lastPos = self.GetTextLength()
|
||||||
if self.lastPromptPos and self.lastPromptPos != lastPos:
|
if self.lastPromptPos and self.lastPromptPos != lastPos:
|
||||||
self.SetLexer(wxSTC_LEX_PYTHON)
|
self.SetLexer(stc.STC_LEX_PYTHON)
|
||||||
self.SetKeywords(0, ' '.join(keyword.kwlist))
|
self.SetKeywords(0, ' '.join(keyword.kwlist))
|
||||||
|
|
||||||
self.Colourise(self.lastPromptPos, lastPos)
|
self.Colourise(self.lastPromptPos, lastPos)
|
||||||
@@ -256,14 +276,14 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
|
|||||||
styleBefore = self.GetStyleAt(caretPos - 1)
|
styleBefore = self.GetStyleAt(caretPos - 1)
|
||||||
|
|
||||||
# check before
|
# check before
|
||||||
if charBefore and chr(charBefore) in "[]{}()" and styleBefore == wxSTC_P_OPERATOR:
|
if charBefore and chr(charBefore) in "[]{}()" and styleBefore == stc.STC_P_OPERATOR:
|
||||||
braceAtCaret = caretPos - 1
|
braceAtCaret = caretPos - 1
|
||||||
|
|
||||||
# check after
|
# check after
|
||||||
if braceAtCaret < 0:
|
if braceAtCaret < 0:
|
||||||
charAfter = self.GetCharAt(caretPos)
|
charAfter = self.GetCharAt(caretPos)
|
||||||
styleAfter = self.GetStyleAt(caretPos)
|
styleAfter = self.GetStyleAt(caretPos)
|
||||||
if charAfter and chr(charAfter) in "[]{}()" and styleAfter == wxSTC_P_OPERATOR:
|
if charAfter and chr(charAfter) in "[]{}()" and styleAfter == stc.STC_P_OPERATOR:
|
||||||
braceAtCaret = caretPos
|
braceAtCaret = caretPos
|
||||||
|
|
||||||
if braceAtCaret >= 0:
|
if braceAtCaret >= 0:
|
||||||
@@ -319,7 +339,7 @@ class FauxFile:
|
|||||||
# test code
|
# test code
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = wxPyWidgetTester(size = (640, 480))
|
app = wx.PyWidgetTester(size = (640, 480))
|
||||||
app.SetWidget(PyShellWindow, -1)
|
app.SetWidget(PyShellWindow, -1)
|
||||||
app.MainLoop()
|
app.MainLoop()
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,11 @@
|
|||||||
# Copyright: (c) 2002 by Total Control Software
|
# Copyright: (c) 2002 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 12/10/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
# o There appears to be a prob with the wx.PySizer.GetSize() method.
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
A pure-Python wxSizer that lays out items in a grid similar to
|
A pure-Python wxSizer that lays out items in a grid similar to
|
||||||
@@ -17,24 +22,41 @@ specified by row and col, and row/col spanning is supported.
|
|||||||
|
|
||||||
Adapted from code by Niki Spahiev.
|
Adapted from code by Niki Spahiev.
|
||||||
|
|
||||||
If anyone is interested, it would be nice to have this ported to C++.
|
NOTE: There is now a C++ version of this class that has been wrapped
|
||||||
|
as wx.GridBagSizer. It is quicker and more capable so you are
|
||||||
|
encouraged to switch.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from wxPython.wx import *
|
|
||||||
import operator
|
import operator
|
||||||
|
import wx
|
||||||
|
|
||||||
|
|
||||||
|
# After the lib and demo no longer uses this sizer enable this warning...
|
||||||
|
|
||||||
|
## import warnings
|
||||||
|
## warningmsg = r"""\
|
||||||
|
|
||||||
|
## #####################################################\
|
||||||
|
## # THIS MODULE IS NOW DEPRECATED |
|
||||||
|
## # |
|
||||||
|
## # The core wx library now contains a similar class |
|
||||||
|
## # wrapped as wx.GridBagSizer. |
|
||||||
|
## #####################################################/
|
||||||
|
|
||||||
|
## """
|
||||||
|
|
||||||
|
## warnings.warn(warningmsg, DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
class RowColSizer(wxPySizer):
|
class RowColSizer(wx.PySizer):
|
||||||
|
|
||||||
# default sizes for cells with no item
|
# default sizes for cells with no item
|
||||||
col_w = 10
|
col_w = 10
|
||||||
row_h = 22
|
row_h = 22
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
wxPySizer.__init__(self)
|
wx.PySizer.__init__(self)
|
||||||
self.growableRows = []
|
self.growableRows = []
|
||||||
self.growableCols = []
|
self.growableCols = []
|
||||||
|
|
||||||
@@ -64,9 +86,9 @@ class RowColSizer(wxPySizer):
|
|||||||
|
|
||||||
# Do I really want to do this? Probably not...
|
# Do I really want to do this? Probably not...
|
||||||
#if rowspan > 1 or colspan > 1:
|
#if rowspan > 1 or colspan > 1:
|
||||||
# flag = flag | wxEXPAND
|
# flag = flag | wx.EXPAND
|
||||||
|
|
||||||
wxPySizer.Add(self, item, option, flag, border,
|
wx.PySizer.Add(self, item, option, flag, border,
|
||||||
userData=(row, col, row+rowspan, col+colspan))
|
userData=(row, col, row+rowspan, col+colspan))
|
||||||
|
|
||||||
#AddWindow = Add
|
#AddWindow = Add
|
||||||
@@ -85,7 +107,7 @@ class RowColSizer(wxPySizer):
|
|||||||
assert row != -1, "Row must be specified"
|
assert row != -1, "Row must be specified"
|
||||||
assert col != -1, "Column must be specified"
|
assert col != -1, "Column must be specified"
|
||||||
|
|
||||||
wxPySizer.AddSpacer(self, (width, height), option, flag, border,
|
wx.PySizer.AddSpacer(self, (width, height), option, flag, border,
|
||||||
userData=(row, col, row+rowspan, col+colspan))
|
userData=(row, col, row+rowspan, col+colspan))
|
||||||
|
|
||||||
#--------------------------------------------------
|
#--------------------------------------------------
|
||||||
@@ -116,12 +138,12 @@ class RowColSizer(wxPySizer):
|
|||||||
|
|
||||||
items = self.GetChildren()
|
items = self.GetChildren()
|
||||||
if not items:
|
if not items:
|
||||||
return wxSize(10, 10)
|
return wx.Size(10, 10)
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
self._add( item.CalcMin(), item.GetUserData() )
|
self._add( item.CalcMin(), item.GetUserData() )
|
||||||
|
|
||||||
size = wxSize( reduce( operator.add, self.colWidths),
|
size = wx.Size( reduce( operator.add, self.colWidths),
|
||||||
reduce( operator.add, self.rowHeights) )
|
reduce( operator.add, self.rowHeights) )
|
||||||
return size
|
return size
|
||||||
|
|
||||||
@@ -129,12 +151,9 @@ class RowColSizer(wxPySizer):
|
|||||||
#--------------------------------------------------
|
#--------------------------------------------------
|
||||||
def RecalcSizes( self ):
|
def RecalcSizes( self ):
|
||||||
# save current dimensions, etc.
|
# save current dimensions, etc.
|
||||||
curWidth = self.GetSize().width
|
curWidth, curHeight = self.GetSize()
|
||||||
curHeight = self.GetSize().height
|
px, py = self.GetPosition()
|
||||||
px = self.GetPosition().x
|
minWidth, minHeight = self.CalcMin()
|
||||||
py = self.GetPosition().y
|
|
||||||
minWidth = self.CalcMin().width
|
|
||||||
minHeight = self.CalcMin().height
|
|
||||||
|
|
||||||
# Check for growables
|
# Check for growables
|
||||||
if self.growableRows and curHeight > minHeight:
|
if self.growableRows and curHeight > minHeight:
|
||||||
@@ -176,21 +195,21 @@ class RowColSizer(wxPySizer):
|
|||||||
def SetItemBounds(self, item, x, y, w, h):
|
def SetItemBounds(self, item, x, y, w, h):
|
||||||
# calculate the item's actual size and position within
|
# calculate the item's actual size and position within
|
||||||
# its grid cell
|
# its grid cell
|
||||||
ipt = wxPoint(x, y)
|
ipt = wx.Point(x, y)
|
||||||
isz = item.CalcMin()
|
isz = item.CalcMin()
|
||||||
flag = item.GetFlag()
|
flag = item.GetFlag()
|
||||||
|
|
||||||
if flag & wxEXPAND or flag & wxSHAPED:
|
if flag & wx.EXPAND or flag & wx.SHAPED:
|
||||||
isz = wxSize(w, h)
|
isz = wx.Size(w, h)
|
||||||
else:
|
else:
|
||||||
if flag & wxALIGN_CENTER_HORIZONTAL:
|
if flag & wx.ALIGN_CENTER_HORIZONTAL:
|
||||||
ipt.x = x + (w - isz.width) / 2
|
ipt.x = x + (w - isz.width) / 2
|
||||||
elif flag & wxALIGN_RIGHT:
|
elif flag & wx.ALIGN_RIGHT:
|
||||||
ipt.x = x + (w - isz.width)
|
ipt.x = x + (w - isz.width)
|
||||||
|
|
||||||
if flag & wxALIGN_CENTER_VERTICAL:
|
if flag & wx.ALIGN_CENTER_VERTICAL:
|
||||||
ipt.y = y + (h - isz.height) / 2
|
ipt.y = y + (h - isz.height) / 2
|
||||||
elif flag & wxALIGN_BOTTOM:
|
elif flag & wx.ALIGN_BOTTOM:
|
||||||
ipt.y = y + (h - isz.height)
|
ipt.y = y + (h - isz.height)
|
||||||
|
|
||||||
item.SetDimension(ipt, isz)
|
item.SetDimension(ipt, isz)
|
||||||
|
|||||||
@@ -11,6 +11,11 @@
|
|||||||
# Copyright: (c) 2001 by Total Control Software
|
# Copyright: (c) 2001 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 12/11/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
# o Added deprecation warning.
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Some time ago, I asked about how to right-align
|
Some time ago, I asked about how to right-align
|
||||||
@@ -34,23 +39,40 @@ Ubera Servicios Inform
|
|||||||
P.S. This only works well on wxMSW.
|
P.S. This only works well on wxMSW.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from wxPython.wx import *
|
import warnings
|
||||||
|
import wx
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
class wxRightTextCtrl(wxTextCtrl):
|
warningmsg = r"""\
|
||||||
|
|
||||||
|
##############################################################\
|
||||||
|
# THIS MODULE IS DEPRECATED |
|
||||||
|
# |
|
||||||
|
# This control still functions, but it is deprecated because |
|
||||||
|
# wx.TextCtrl now supports the wx.TE_RIGHT style flag |
|
||||||
|
##############################################################/
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
warnings.warn(warningmsg, DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxRightTextCtrl(wx.TextCtrl):
|
||||||
def __init__(self, parent, id, *args, **kwargs):
|
def __init__(self, parent, id, *args, **kwargs):
|
||||||
wxTextCtrl.__init__(self, parent, id, *args, **kwargs)
|
wx.TextCtrl.__init__(self, parent, id, *args, **kwargs)
|
||||||
EVT_KILL_FOCUS(self, self.OnKillFocus)
|
self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
|
||||||
EVT_PAINT(self, self.OnPaint)
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||||
|
|
||||||
def OnPaint(self, event):
|
def OnPaint(self, event):
|
||||||
dc = wxPaintDC(self)
|
dc = wx.PaintDC(self)
|
||||||
dc.SetFont(self.GetFont())
|
dc.SetFont(self.GetFont())
|
||||||
dc.Clear()
|
dc.Clear()
|
||||||
text = self.GetValue()
|
text = self.GetValue()
|
||||||
textwidth, textheight = dc.GetTextExtent(text)
|
textwidth, textheight = dc.GetTextExtent(text)
|
||||||
dcwidth, dcheight = self.GetClientSizeTuple()
|
dcwidth, dcheight = self.GetClientSize()
|
||||||
|
|
||||||
y = (dcheight - textheight) / 2
|
y = (dcheight - textheight) / 2
|
||||||
x = dcwidth - textwidth - 2
|
x = dcwidth - textwidth - 2
|
||||||
@@ -58,21 +80,22 @@ class wxRightTextCtrl(wxTextCtrl):
|
|||||||
if self.IsEnabled():
|
if self.IsEnabled():
|
||||||
fclr = self.GetForegroundColour()
|
fclr = self.GetForegroundColour()
|
||||||
else:
|
else:
|
||||||
fclr = wxSystemSettings_GetColour(wxSYS_COLOUR_GRAYTEXT)
|
fclr = wx.SystemSettings_GetColour(wx.SYS_COLOUR_GRAYTEXT)
|
||||||
|
|
||||||
dc.SetTextForeground(fclr)
|
dc.SetTextForeground(fclr)
|
||||||
|
|
||||||
dc.SetClippingRegionXY(0, 0, dcwidth, dcheight)
|
dc.SetClippingRegion(0, 0, dcwidth, dcheight)
|
||||||
dc.DrawText(text, x, y)
|
dc.DrawText(text, (x, y))
|
||||||
|
|
||||||
if x < 0:
|
if x < 0:
|
||||||
toofat = '...'
|
toofat = '...'
|
||||||
markwidth = dc.GetTextExtent(toofat)[0]
|
markwidth = dc.GetTextExtent(toofat)[0]
|
||||||
dc.SetPen(wxPen(dc.GetBackground().GetColour(), 1, wxSOLID ))
|
dc.SetPen(wx.Pen(dc.GetBackground().GetColour(), 1, wx.SOLID ))
|
||||||
dc.DrawRectangle(0,0, markwidth, dcheight)
|
dc.DrawRectangle((0,0), (markwidth, dcheight))
|
||||||
dc.SetPen(wxPen(wxRED, 1, wxSOLID ))
|
dc.SetPen(wx.Pen(wx.RED, 1, wx.SOLID ))
|
||||||
dc.SetBrush(wxTRANSPARENT_BRUSH)
|
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
||||||
dc.DrawRectangle(1, 1, dcwidth-2, dcheight-2)
|
dc.DrawRectangle((1, 1), (dcwidth-2, dcheight-2))
|
||||||
dc.DrawText(toofat, 1, y)
|
dc.DrawText(toofat, (1, y))
|
||||||
|
|
||||||
|
|
||||||
def OnKillFocus(self, event):
|
def OnKillFocus(self, event):
|
||||||
|
|||||||
@@ -17,6 +17,11 @@
|
|||||||
# Copyright: (c) 2000, 2001 by Greg Landrum and Rational Discovery LLC
|
# Copyright: (c) 2000, 2001 by Greg Landrum and Rational Discovery LLC
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 12/11/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
# o xmlrpcserver not available.
|
||||||
|
#
|
||||||
|
|
||||||
"""provides xmlrpc server functionality for wxPython applications via a mixin class
|
"""provides xmlrpc server functionality for wxPython applications via a mixin class
|
||||||
|
|
||||||
@@ -68,12 +73,14 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from wxPython.wx import *
|
|
||||||
import xmlrpcserver,xmlrpclib
|
|
||||||
import threading
|
|
||||||
import SocketServer
|
|
||||||
import new
|
import new
|
||||||
|
import SocketServer
|
||||||
import sys
|
import sys
|
||||||
|
import threading
|
||||||
|
import xmlrpclib
|
||||||
|
import xmlrpcserver
|
||||||
|
|
||||||
|
import wx
|
||||||
|
|
||||||
rpcPENDING = 0
|
rpcPENDING = 0
|
||||||
rpcDONE = 1
|
rpcDONE = 1
|
||||||
@@ -85,14 +92,16 @@ class RPCRequest:
|
|||||||
result = None
|
result = None
|
||||||
|
|
||||||
# here's the ID for external events
|
# here's the ID for external events
|
||||||
wxEVT_EXTERNAL_EVENT = 25015
|
wxEVT_EXTERNAL_EVENT = wx.NewEventType()
|
||||||
class ExternalEvent(wxPyEvent):
|
EVT_EXTERNAL_EVENT = wx.PyEventBinder(wxEVT_EXTERNAL_EVENT, 0)
|
||||||
|
|
||||||
|
class ExternalEvent(wx.PyEvent):
|
||||||
"""The custom event class used to pass xmlrpc calls from
|
"""The custom event class used to pass xmlrpc calls from
|
||||||
the server thread into the GUI thread
|
the server thread into the GUI thread
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self,method,args):
|
def __init__(self,method,args):
|
||||||
wxPyEvent.__init__(self)
|
wx.PyEvent.__init__(self)
|
||||||
self.SetEventType(wxEVT_EXTERNAL_EVENT)
|
self.SetEventType(wxEVT_EXTERNAL_EVENT)
|
||||||
self.method = method
|
self.method = method
|
||||||
self.args = args
|
self.args = args
|
||||||
@@ -107,9 +116,6 @@ class ExternalEvent(wxPyEvent):
|
|||||||
self.rpcStatusLock = None
|
self.rpcStatusLock = None
|
||||||
self.rpcondVar = None
|
self.rpcondVar = None
|
||||||
|
|
||||||
def EVT_EXTERNAL_EVENT(win,func):
|
|
||||||
win.Connect(-1,-1,wxEVT_EXTERNAL_EVENT,func)
|
|
||||||
|
|
||||||
class Handler(xmlrpcserver.RequestHandler):
|
class Handler(xmlrpcserver.RequestHandler):
|
||||||
"""The handler class that the xmlrpcserver actually calls
|
"""The handler class that the xmlrpcserver actually calls
|
||||||
when a request comes in.
|
when a request comes in.
|
||||||
@@ -145,7 +151,7 @@ class Handler(xmlrpcserver.RequestHandler):
|
|||||||
|
|
||||||
evt.rpcCondVar.acquire()
|
evt.rpcCondVar.acquire()
|
||||||
# dispatch the event to the GUI
|
# dispatch the event to the GUI
|
||||||
wxPostEvent(self._app,evt)
|
wx.PostEvent(self._app,evt)
|
||||||
|
|
||||||
# wait for the GUI to finish
|
# wait for the GUI to finish
|
||||||
while evt.rpcStatus.status == rpcPENDING:
|
while evt.rpcStatus.status == rpcPENDING:
|
||||||
@@ -227,14 +233,14 @@ class rpcMixin:
|
|||||||
if port == -1:
|
if port == -1:
|
||||||
port = self.defPort
|
port = self.defPort
|
||||||
self.verbose=verbose
|
self.verbose=verbose
|
||||||
EVT_EXTERNAL_EVENT(self,self.OnExternal)
|
self.Bind(EVT_EXTERNAL_EVENT,self.OnExternal)
|
||||||
if hasattr(self,'OnClose'):
|
if hasattr(self,'OnClose'):
|
||||||
self._origOnClose = self.OnClose
|
self._origOnClose = self.OnClose
|
||||||
self.Disconnect(-1,-1,wxEVT_CLOSE_WINDOW)
|
self.Disconnect(-1,-1,wx.EVT_CLOSE_WINDOW)
|
||||||
else:
|
else:
|
||||||
self._origOnClose = None
|
self._origOnClose = None
|
||||||
self.OnClose = self.RPCOnClose
|
self.OnClose = self.RPCOnClose
|
||||||
EVT_CLOSE(self,self.RPCOnClose)
|
self.Bind(wx.EVT_CLOSE,self.RPCOnClose)
|
||||||
|
|
||||||
tClass = new.classobj('Handler%d'%(port),(Handler,),{})
|
tClass = new.classobj('Handler%d'%(port),(Handler,),{})
|
||||||
tClass._app = self
|
tClass._app = self
|
||||||
@@ -342,7 +348,7 @@ if __name__ == '__main__':
|
|||||||
else:
|
else:
|
||||||
port = 8023
|
port = 8023
|
||||||
|
|
||||||
class rpcFrame(wxFrame,rpcMixin):
|
class rpcFrame(wx.Frame,rpcMixin):
|
||||||
"""A simple wxFrame with the rpcMixin functionality added
|
"""A simple wxFrame with the rpcMixin functionality added
|
||||||
"""
|
"""
|
||||||
def __init__(self,*args,**kwargs):
|
def __init__(self,*args,**kwargs):
|
||||||
@@ -360,10 +366,10 @@ if __name__ == '__main__':
|
|||||||
mixinArgs['portScan'] = kwargs['rpcPortScan']
|
mixinArgs['portScan'] = kwargs['rpcPortScan']
|
||||||
del kwargs['rpcPortScan']
|
del kwargs['rpcPortScan']
|
||||||
|
|
||||||
apply(wxFrame.__init__,(self,)+args,kwargs)
|
apply(wx.Frame.__init__,(self,)+args,kwargs)
|
||||||
apply(rpcMixin.__init__,(self,),mixinArgs)
|
apply(rpcMixin.__init__,(self,),mixinArgs)
|
||||||
|
|
||||||
EVT_CHAR(self,self.OnChar)
|
self.Bind(wx.EVT_CHAR,self.OnChar)
|
||||||
|
|
||||||
def TestFunc(self,args):
|
def TestFunc(self,args):
|
||||||
"""a demo method"""
|
"""a demo method"""
|
||||||
@@ -382,11 +388,10 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MyApp(wxApp):
|
class MyApp(wx.App):
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
self.frame = rpcFrame(NULL, -1, "wxPython RPCDemo", wxDefaultPosition,
|
self.frame = rpcFrame(None, -1, "wxPython RPCDemo", wx.DefaultPosition,
|
||||||
wxSize(300,300),
|
(300,300), rpcHost='localhost',rpcPort=port)
|
||||||
rpcHost='localhost',rpcPort=port)
|
|
||||||
self.frame.Show(True)
|
self.frame.Show(True)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -6,13 +6,16 @@
|
|||||||
# RCS-ID: $Id$
|
# RCS-ID: $Id$
|
||||||
# License: wxWindows license
|
# License: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
# 12/11/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
#
|
#
|
||||||
|
|
||||||
from wxPython.wx import *
|
import wx
|
||||||
|
|
||||||
|
|
||||||
class wxScrolledPanel( wxScrolledWindow ):
|
class wxScrolledPanel( wx.ScrolledWindow ):
|
||||||
"""
|
"""\
|
||||||
wxScrolledPanel fills a "hole" in the implementation of wxScrolledWindow,
|
wxScrolledPanel fills a "hole" in the implementation of wxScrolledWindow,
|
||||||
providing automatic scrollbar and scrolling behavior and the tab traversal
|
providing automatic scrollbar and scrolling behavior and the tab traversal
|
||||||
management that wxScrolledWindow lacks. This code was based on the original
|
management that wxScrolledWindow lacks. This code was based on the original
|
||||||
@@ -20,14 +23,14 @@ demo code showing how to do this, but is now available for general use
|
|||||||
as a proper class (and the demo is now converted to just use it.)
|
as a proper class (and the demo is now converted to just use it.)
|
||||||
"""
|
"""
|
||||||
def __init__(self, parent, id=-1,
|
def __init__(self, parent, id=-1,
|
||||||
pos = wxDefaultPosition, size = wxDefaultSize,
|
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||||
style = wxTAB_TRAVERSAL, name = "scrolledpanel"):
|
style = wx.TAB_TRAVERSAL, name = "scrolledpanel"):
|
||||||
|
|
||||||
wxScrolledWindow.__init__(self, parent, -1,
|
wx.ScrolledWindow.__init__(self, parent, -1,
|
||||||
pos=pos, size=size,
|
pos=pos, size=size,
|
||||||
style=style, name=name)
|
style=style, name=name)
|
||||||
|
|
||||||
EVT_CHILD_FOCUS(self, self.OnChildFocus)
|
self.Bind(wx.EVT_CHILD_FOCUS, self.OnChildFocus)
|
||||||
|
|
||||||
|
|
||||||
def SetupScrolling(self, scroll_x=True, scroll_y=True, rate_x=20, rate_y=20):
|
def SetupScrolling(self, scroll_x=True, scroll_y=True, rate_x=20, rate_y=20):
|
||||||
@@ -56,7 +59,7 @@ as a proper class (and the demo is now converted to just use it.)
|
|||||||
self.SetVirtualSizeHints( w, h )
|
self.SetVirtualSizeHints( w, h )
|
||||||
|
|
||||||
self.SetScrollRate(rate_x, rate_y)
|
self.SetScrollRate(rate_x, rate_y)
|
||||||
wxCallAfter(self.Scroll, 0, 0) # scroll back to top after initial events
|
wx.CallAfter(self.Scroll, 0, 0) # scroll back to top after initial events
|
||||||
|
|
||||||
|
|
||||||
def OnChildFocus(self, evt):
|
def OnChildFocus(self, evt):
|
||||||
@@ -79,15 +82,16 @@ as a proper class (and the demo is now converted to just use it.)
|
|||||||
if cpos.y < 0 and sppu_y > 0:
|
if cpos.y < 0 and sppu_y > 0:
|
||||||
new_vs_y = vs_y + (cpos.y / sppu_y)
|
new_vs_y = vs_y + (cpos.y / sppu_y)
|
||||||
|
|
||||||
|
clntsz = self.GetClientSize()
|
||||||
|
|
||||||
# is it past the right edge ?
|
# is it past the right edge ?
|
||||||
if cpos.x + csz.width > self.GetClientSize().width and sppu_x > 0:
|
if cpos.x + csz.width > clntsz.width and sppu_x > 0:
|
||||||
diff = (cpos.x + csz.width - self.GetClientSize().width) / sppu_x
|
diff = (cpos.x + csz.width - clntsz.width) / sppu_x
|
||||||
new_vs_x = vs_x + diff + 1
|
new_vs_x = vs_x + diff + 1
|
||||||
|
|
||||||
# is it below the bottom ?
|
# is it below the bottom ?
|
||||||
if cpos.y + csz.height > self.GetClientSize().height and sppu_y > 0:
|
if cpos.y + csz.height > clntsz.height and sppu_y > 0:
|
||||||
diff = (cpos.y + csz.height - self.GetClientSize().height) / sppu_y
|
diff = (cpos.y + csz.height - clntsz.height) / sppu_y
|
||||||
new_vs_y = vs_y + diff + 1
|
new_vs_y = vs_y + diff + 1
|
||||||
|
|
||||||
# if we need to adjust
|
# if we need to adjust
|
||||||
|
|||||||
@@ -2,42 +2,48 @@
|
|||||||
# CSheet - A wxPython spreadsheet class.
|
# CSheet - A wxPython spreadsheet class.
|
||||||
# This is free software. Feel free to adapt it as you like.
|
# This is free software. Feel free to adapt it as you like.
|
||||||
# Author: Mark F. Russo (russomf@hotmail.com) 2002/01/31
|
# Author: Mark F. Russo (russomf@hotmail.com) 2002/01/31
|
||||||
|
#---------------------------------------------------------------------------
|
||||||
|
# 12/11/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
# o Untested.
|
||||||
|
#
|
||||||
|
|
||||||
from wxPython.wx import *
|
|
||||||
from wxPython.grid import *
|
|
||||||
import string
|
import string
|
||||||
|
import wx
|
||||||
|
import wx.grid
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
class CTextCellEditor(wxTextCtrl):
|
class CTextCellEditor(wx.TextCtrl):
|
||||||
""" Custom text control for cell editing """
|
""" Custom text control for cell editing """
|
||||||
def __init__(self, parent, id, grid):
|
def __init__(self, parent, id, grid):
|
||||||
wxTextCtrl.__init__(self, parent, id, "", style=wxNO_BORDER)
|
wx.TextCtrl.__init__(self, parent, id, "", style=wx.NO_BORDER)
|
||||||
self._grid = grid # Save grid reference
|
self._grid = grid # Save grid reference
|
||||||
EVT_CHAR(self, self.OnChar)
|
self.Bind(wx.EVT_CHAR, self.OnChar)
|
||||||
|
|
||||||
def OnChar(self, evt): # Hook OnChar for custom behavior
|
def OnChar(self, evt): # Hook OnChar for custom behavior
|
||||||
"""Customizes char events """
|
"""Customizes char events """
|
||||||
key = evt.GetKeyCode()
|
key = evt.GetKeyCode()
|
||||||
if key == WXK_DOWN:
|
if key == wx.WXK_DOWN:
|
||||||
self._grid.DisableCellEditControl() # Commit the edit
|
self._grid.DisableCellEditControl() # Commit the edit
|
||||||
self._grid.MoveCursorDown(False) # Change the current cell
|
self._grid.MoveCursorDown(False) # Change the current cell
|
||||||
elif key == WXK_UP:
|
elif key == wx.WXK_UP:
|
||||||
self._grid.DisableCellEditControl() # Commit the edit
|
self._grid.DisableCellEditControl() # Commit the edit
|
||||||
self._grid.MoveCursorUp(False) # Change the current cell
|
self._grid.MoveCursorUp(False) # Change the current cell
|
||||||
elif key == WXK_LEFT:
|
elif key == wx.WXK_LEFT:
|
||||||
self._grid.DisableCellEditControl() # Commit the edit
|
self._grid.DisableCellEditControl() # Commit the edit
|
||||||
self._grid.MoveCursorLeft(False) # Change the current cell
|
self._grid.MoveCursorLeft(False) # Change the current cell
|
||||||
elif key == WXK_RIGHT:
|
elif key == wx.WXK_RIGHT:
|
||||||
self._grid.DisableCellEditControl() # Commit the edit
|
self._grid.DisableCellEditControl() # Commit the edit
|
||||||
self._grid.MoveCursorRight(False) # Change the current cell
|
self._grid.MoveCursorRight(False) # Change the current cell
|
||||||
|
|
||||||
evt.Skip() # Continue event
|
evt.Skip() # Continue event
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
class CCellEditor(wxPyGridCellEditor):
|
class CCellEditor(wx.grid.PyGridCellEditor):
|
||||||
""" Custom cell editor """
|
""" Custom cell editor """
|
||||||
def __init__(self, grid):
|
def __init__(self, grid):
|
||||||
wxPyGridCellEditor.__init__(self)
|
wx.grid.PyGridCellEditor.__init__(self)
|
||||||
self._grid = grid # Save a reference to the grid
|
self._grid = grid # Save a reference to the grid
|
||||||
|
|
||||||
def Create(self, parent, id, evtHandler):
|
def Create(self, parent, id, evtHandler):
|
||||||
@@ -106,7 +112,7 @@ class CCellEditor(wxPyGridCellEditor):
|
|||||||
and will always start the editor.
|
and will always start the editor.
|
||||||
"""
|
"""
|
||||||
return (not (evt.ControlDown() or evt.AltDown())
|
return (not (evt.ControlDown() or evt.AltDown())
|
||||||
and evt.GetKeyCode() != WXK_SHIFT)
|
and evt.GetKeyCode() != wx.WXK_SHIFT)
|
||||||
|
|
||||||
def StartingKey(self, evt):
|
def StartingKey(self, evt):
|
||||||
""" If the editor is enabled by pressing keys on the grid, this will be
|
""" If the editor is enabled by pressing keys on the grid, this will be
|
||||||
@@ -114,11 +120,12 @@ class CCellEditor(wxPyGridCellEditor):
|
|||||||
"""
|
"""
|
||||||
key = evt.GetKeyCode() # Get the key code
|
key = evt.GetKeyCode() # Get the key code
|
||||||
ch = None # Handle num pad keys
|
ch = None # Handle num pad keys
|
||||||
if key in [WXK_NUMPAD0, WXK_NUMPAD1, WXK_NUMPAD2, WXK_NUMPAD3, WXK_NUMPAD4,
|
if key in [ wx.WXK_NUMPAD0, wx.WXK_NUMPAD1, wx.WXK_NUMPAD2, wx.WXK_NUMPAD3,
|
||||||
WXK_NUMPAD5, WXK_NUMPAD6, WXK_NUMPAD7, WXK_NUMPAD8, WXK_NUMPAD9]:
|
wx.WXK_NUMPAD4, wx.WXK_NUMPAD5, wx.WXK_NUMPAD6, wx.WXK_NUMPAD7,
|
||||||
ch = chr(ord('0') + key - WXK_NUMPAD0)
|
wx.WXK_NUMPAD8, wx.WXK_NUMPAD9]:
|
||||||
|
ch = chr(ord('0') + key - wx.WXK_NUMPAD0)
|
||||||
|
|
||||||
elif key == WXK_BACK: # Empty text control when init w/ back key
|
elif key == wx.WXK_BACK: # Empty text control when init w/ back key
|
||||||
ch = ""
|
ch = ""
|
||||||
# Handle normal keys
|
# Handle normal keys
|
||||||
elif key < 256 and key >= 0 and chr(key) in string.printable:
|
elif key < 256 and key >= 0 and chr(key) in string.printable:
|
||||||
@@ -147,36 +154,36 @@ class CCellEditor(wxPyGridCellEditor):
|
|||||||
return CCellEditor()
|
return CCellEditor()
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
class CSheet(wxGrid):
|
class CSheet(wx.grid.Grid):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
wxGrid.__init__(self, parent, -1)
|
wx.grid.Grid.__init__(self, parent, -1)
|
||||||
|
|
||||||
# Init variables
|
# Init variables
|
||||||
self._lastCol = -1 # Init last cell column clicked
|
self._lastCol = -1 # Init last cell column clicked
|
||||||
self._lastRow = -1 # Init last cell row clicked
|
self._lastRow = -1 # Init last cell row clicked
|
||||||
self._selected = None # Init range currently selected
|
self._selected = None # Init range currently selected
|
||||||
# Map string datatype to default renderer/editor
|
# Map string datatype to default renderer/editor
|
||||||
self.RegisterDataType(wxGRID_VALUE_STRING,
|
self.RegisterDataType(wx.grid.GRID_VALUE_STRING,
|
||||||
wxGridCellStringRenderer(),
|
wx.grid.GridCellStringRenderer(),
|
||||||
CCellEditor(self))
|
CCellEditor(self))
|
||||||
|
|
||||||
self.CreateGrid(4, 3) # By default start with a 4 x 3 grid
|
self.CreateGrid(4, 3) # By default start with a 4 x 3 grid
|
||||||
self.SetColLabelSize(18) # Default sizes and alignment
|
self.SetColLabelSize(18) # Default sizes and alignment
|
||||||
self.SetRowLabelSize(50)
|
self.SetRowLabelSize(50)
|
||||||
self.SetRowLabelAlignment(wxALIGN_RIGHT, wxALIGN_BOTTOM)
|
self.SetRowLabelAlignment(wx.ALIGN_RIGHT, wx.ALIGN_BOTTOM)
|
||||||
self.SetColSize(0, 75) # Default column sizes
|
self.SetColSize(0, 75) # Default column sizes
|
||||||
self.SetColSize(1, 75)
|
self.SetColSize(1, 75)
|
||||||
self.SetColSize(2, 75)
|
self.SetColSize(2, 75)
|
||||||
|
|
||||||
# Sink events
|
# Sink events
|
||||||
EVT_GRID_CELL_LEFT_CLICK( self, self.OnLeftClick)
|
self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnLeftClick)
|
||||||
EVT_GRID_CELL_RIGHT_CLICK( self, self.OnRightClick)
|
self.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.OnRightClick)
|
||||||
EVT_GRID_CELL_LEFT_DCLICK( self, self.OnLeftDoubleClick)
|
self.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.OnLeftDoubleClick)
|
||||||
EVT_GRID_RANGE_SELECT( self, self.OnRangeSelect)
|
self.Bind(wx.grid.EVT_GRID_RANGE_SELECT, self.OnRangeSelect)
|
||||||
EVT_GRID_ROW_SIZE( self, self.OnRowSize)
|
self.Bind(wx.grid.EVT_GRID_ROW_SIZE, self.OnRowSize)
|
||||||
EVT_GRID_COL_SIZE( self, self.OnColSize)
|
self.Bind(wx.grid.EVT_GRID_COL_SIZE, self.OnColSize)
|
||||||
EVT_GRID_CELL_CHANGE( self, self.OnCellChange)
|
self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnCellChange)
|
||||||
EVT_GRID_SELECT_CELL( self, self.OnGridSelectCell)
|
self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnGridSelectCell)
|
||||||
|
|
||||||
def OnGridSelectCell(self, event):
|
def OnGridSelectCell(self, event):
|
||||||
""" Track cell selections """
|
""" Track cell selections """
|
||||||
@@ -247,18 +254,18 @@ class CSheet(wxGrid):
|
|||||||
s += crlf
|
s += crlf
|
||||||
|
|
||||||
# Put the string on the clipboard
|
# Put the string on the clipboard
|
||||||
if wxTheClipboard.Open():
|
if wx.TheClipboard.Open():
|
||||||
wxTheClipboard.Clear()
|
wx.TheClipboard.Clear()
|
||||||
wxTheClipboard.SetData(wxTextDataObject(s))
|
wx.TheClipboard.SetData(wx.TextDataObject(s))
|
||||||
wxTheClipboard.Close()
|
wx.TheClipboard.Close()
|
||||||
|
|
||||||
def Paste(self):
|
def Paste(self):
|
||||||
""" Paste the contents of the clipboard into the currently selected cells """
|
""" Paste the contents of the clipboard into the currently selected cells """
|
||||||
# (Is there a better way to do this?)
|
# (Is there a better way to do this?)
|
||||||
if wxTheClipboard.Open():
|
if wx.TheClipboard.Open():
|
||||||
td = wxTextDataObject()
|
td = wx.TextDataObject()
|
||||||
success = wxTheClipboard.GetData(td)
|
success = wx.TheClipboard.GetData(td)
|
||||||
wxTheClipboard.Close()
|
wx.TheClipboard.Close()
|
||||||
if not success: return # Exit on failure
|
if not success: return # Exit on failure
|
||||||
s = td.GetText() # Get the text
|
s = td.GetText() # Get the text
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
# shell.py
|
# shell.py
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
# 12/10/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
# o Added deprecation warning.
|
||||||
|
#
|
||||||
|
|
||||||
"""wxPython interactive shell
|
"""wxPython interactive shell
|
||||||
|
|
||||||
Copyright (c) 1999 SIA "ANK"
|
Copyright (c) 1999 SIA "ANK"
|
||||||
@@ -29,12 +36,30 @@ History:
|
|||||||
__version__ ="$Revision$"
|
__version__ ="$Revision$"
|
||||||
# $RCSfile$
|
# $RCSfile$
|
||||||
|
|
||||||
import sys, code, traceback
|
import code
|
||||||
from wxPython.wx import *
|
import sys
|
||||||
from wxPython.html import *
|
import traceback
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
import wx
|
||||||
|
import wx.html
|
||||||
|
|
||||||
class PyShellInput(wxPanel):
|
warningmsg = r"""\
|
||||||
|
|
||||||
|
########################################\
|
||||||
|
# THIS MODULE IS NOW DEPRECATED |
|
||||||
|
# |
|
||||||
|
# Please see the most excellent PyCrust |
|
||||||
|
# package instead. |
|
||||||
|
########################################/
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
warnings.warn(warningmsg, DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
class PyShellInput(wx.Panel):
|
||||||
"""PyShell input window
|
"""PyShell input window
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@@ -48,22 +73,22 @@ class PyShellInput(wxPanel):
|
|||||||
and shell.output is used for output
|
and shell.output is used for output
|
||||||
(print's go to overridden stdout)
|
(print's go to overridden stdout)
|
||||||
"""
|
"""
|
||||||
wxPanel.__init__(self, parent, id)
|
wx.Panel.__init__(self, parent, id)
|
||||||
self.shell =shell
|
self.shell =shell
|
||||||
# make a private copy of class attrs
|
# make a private copy of class attrs
|
||||||
self.PS1 =PyShellInput.PS1
|
self.PS1 =PyShellInput.PS1
|
||||||
self.PS2 =PyShellInput.PS2
|
self.PS2 =PyShellInput.PS2
|
||||||
# create controls
|
# create controls
|
||||||
self.label =wxStaticText(self, -1, self.PS1)
|
self.label =wx.StaticText(self, -1, self.PS1)
|
||||||
tid =wxNewId()
|
tid =wx.NewId()
|
||||||
self.entry =wxTextCtrl(self, tid, style = wxTE_MULTILINE)
|
self.entry =wx.TextCtrl(self, tid, style = wx.TE_MULTILINE)
|
||||||
EVT_CHAR(self.entry, self.OnChar)
|
self.entry.Bind(wx.EVT_CHAR, self.OnChar)
|
||||||
self.entry.SetFont(wxFont(9, wxMODERN, wxNORMAL, wxNORMAL, False))
|
self.entry.SetFont(wx.Font(9, wx.MODERN, wx.NORMAL, wx.NORMAL, False))
|
||||||
sizer =wxBoxSizer(wxVERTICAL)
|
sizer =wx.BoxSizer(wx.VERTICAL)
|
||||||
sizer.AddMany([(self.label, 0, wxEXPAND), (self.entry, 1, wxEXPAND)])
|
sizer.AddMany([(self.label, 0, wx.EXPAND), (self.entry, 1, wx.EXPAND)])
|
||||||
self.SetSizer(sizer)
|
self.SetSizer(sizer)
|
||||||
self.SetAutoLayout(True)
|
self.SetAutoLayout(True)
|
||||||
EVT_SET_FOCUS(self, self.OnSetFocus)
|
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
|
||||||
# when in "continuation" mode,
|
# when in "continuation" mode,
|
||||||
# two consecutive newlines are required
|
# two consecutive newlines are required
|
||||||
# to avoid execution of unfinished block
|
# to avoid execution of unfinished block
|
||||||
@@ -84,7 +109,7 @@ class PyShellInput(wxPanel):
|
|||||||
def OnChar(self, event):
|
def OnChar(self, event):
|
||||||
"""called on CHARevent. executes input on newline"""
|
"""called on CHARevent. executes input on newline"""
|
||||||
# print "On Char:", event.__dict__.keys()
|
# print "On Char:", event.__dict__.keys()
|
||||||
if event.KeyCode() !=WXK_RETURN:
|
if event.KeyCode() !=wx.WXK_RETURN:
|
||||||
# not of our business
|
# not of our business
|
||||||
event.Skip()
|
event.Skip()
|
||||||
return
|
return
|
||||||
@@ -110,7 +135,7 @@ class PyShellInput(wxPanel):
|
|||||||
else:
|
else:
|
||||||
self.Clear()
|
self.Clear()
|
||||||
|
|
||||||
class PyShellOutput(wxPanel):
|
class PyShellOutput(wx.Panel):
|
||||||
"""PyShell output window
|
"""PyShell output window
|
||||||
|
|
||||||
for now, it is based on simple wxTextCtrl,
|
for now, it is based on simple wxTextCtrl,
|
||||||
@@ -128,7 +153,7 @@ class PyShellOutput(wxPanel):
|
|||||||
# entity references
|
# entity references
|
||||||
erefs =(("&", "&"), (">", ">"), ("<", "<"), (" ", " "))
|
erefs =(("&", "&"), (">", ">"), ("<", "<"), (" ", " "))
|
||||||
def __init__(self, parent, id=-1):
|
def __init__(self, parent, id=-1):
|
||||||
wxPanel.__init__(self, parent, id)
|
wx.Panel.__init__(self, parent, id)
|
||||||
# make a private copy of class attrs
|
# make a private copy of class attrs
|
||||||
self.in_style =PyShellOutput.in_style
|
self.in_style =PyShellOutput.in_style
|
||||||
self.out_style =PyShellOutput.out_style
|
self.out_style =PyShellOutput.out_style
|
||||||
@@ -139,17 +164,17 @@ class PyShellOutput(wxPanel):
|
|||||||
if self.html_debug:
|
if self.html_debug:
|
||||||
# this was used in html debugging,
|
# this was used in html debugging,
|
||||||
# but i don't want to delete it; it's funny
|
# but i don't want to delete it; it's funny
|
||||||
splitter =wxSplitterWindow(self, -1)
|
splitter =wx.SplitterWindow(self, -1)
|
||||||
self.view =wxTextCtrl(splitter, -1,
|
self.view =wx.TextCtrl(splitter, -1,
|
||||||
style = wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL)
|
style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
|
||||||
self.html =wxHtmlWindow(splitter)
|
self.html =wx.html.HtmlWindow(splitter)
|
||||||
splitter.SplitVertically(self.view, self.html)
|
splitter.SplitVertically(self.view, self.html)
|
||||||
splitter.SetSashPosition(40)
|
splitter.SetSashPosition(40)
|
||||||
splitter.SetMinimumPaneSize(3)
|
splitter.SetMinimumPaneSize(3)
|
||||||
self.client =splitter
|
self.client =splitter
|
||||||
else:
|
else:
|
||||||
self.view =None
|
self.view =None
|
||||||
self.html =wxHtmlWindow(self)
|
self.html =wx.html.HtmlWindow(self)
|
||||||
self.client =self.html # used in OnSize()
|
self.client =self.html # used in OnSize()
|
||||||
self.text =self.intro
|
self.text =self.intro
|
||||||
self.html.SetPage(self.text)
|
self.html.SetPage(self.text)
|
||||||
@@ -158,8 +183,8 @@ class PyShellOutput(wxPanel):
|
|||||||
# refreshes are annoying
|
# refreshes are annoying
|
||||||
self.in_batch =0
|
self.in_batch =0
|
||||||
self.dirty =0
|
self.dirty =0
|
||||||
EVT_SIZE(self, self.OnSize)
|
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||||
EVT_IDLE(self, self.OnIdle)
|
self.Bind(wx.EVT_IDLE, self.OnIdle)
|
||||||
|
|
||||||
def OnSize(self, event):
|
def OnSize(self, event):
|
||||||
self.client.SetSize(self.GetClientSize())
|
self.client.SetSize(self.GetClientSize())
|
||||||
@@ -232,18 +257,18 @@ class PyShellOutput(wxPanel):
|
|||||||
if style ==None: style =self.exc_style
|
if style ==None: style =self.exc_style
|
||||||
self.AddText(str, style)
|
self.AddText(str, style)
|
||||||
|
|
||||||
class PyShell(wxPanel):
|
class PyShell(wx.Panel):
|
||||||
"""interactive Python shell with wxPython interface
|
"""interactive Python shell with wxPython interface
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, parent, globals=globals(), locals={},
|
def __init__(self, parent, globals=globals(), locals={},
|
||||||
id=-1, pos=wxDefaultPosition, size=wxDefaultSize,
|
id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize,
|
||||||
style=wxTAB_TRAVERSAL, name="shell"):
|
style=wx.TAB_TRAVERSAL, name="shell"):
|
||||||
"""create PyShell window"""
|
"""create PyShell window"""
|
||||||
wxPanel.__init__(self, parent, id, pos, size, style, name)
|
wx.Panel.__init__(self, parent, id, pos, size, style, name)
|
||||||
self.globals =globals
|
self.globals =globals
|
||||||
self.locals =locals
|
self.locals =locals
|
||||||
splitter =wxSplitterWindow(self, -1)
|
splitter =wx.SplitterWindow(self, -1)
|
||||||
self.output =PyShellOutput(splitter)
|
self.output =PyShellOutput(splitter)
|
||||||
self.input =PyShellInput(splitter, self)
|
self.input =PyShellInput(splitter, self)
|
||||||
self.input.SetFocus()
|
self.input.SetFocus()
|
||||||
@@ -251,8 +276,8 @@ class PyShell(wxPanel):
|
|||||||
splitter.SetSashPosition(100)
|
splitter.SetSashPosition(100)
|
||||||
splitter.SetMinimumPaneSize(20)
|
splitter.SetMinimumPaneSize(20)
|
||||||
self.splitter =splitter
|
self.splitter =splitter
|
||||||
EVT_SET_FOCUS(self, self.OnSetFocus)
|
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
|
||||||
EVT_SIZE(self, self.OnSize)
|
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||||
|
|
||||||
def OnSetFocus(self, event):
|
def OnSetFocus(self, event):
|
||||||
self.input.SetFocus()
|
self.input.SetFocus()
|
||||||
@@ -317,14 +342,14 @@ class PyShell(wxPanel):
|
|||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
class MyFrame(wxFrame):
|
class MyFrame(wx.Frame):
|
||||||
"""Very standard Frame class. Nothing special here!"""
|
"""Very standard Frame class. Nothing special here!"""
|
||||||
def __init__(self, parent=NULL, id =-1,
|
def __init__(self, parent=None, id =-1,
|
||||||
title="wxPython Interactive Shell"):
|
title="wxPython Interactive Shell"):
|
||||||
wxFrame.__init__(self, parent, id, title)
|
wx.Frame.__init__(self, parent, id, title)
|
||||||
self.shell =PyShell(self)
|
self.shell =PyShell(self)
|
||||||
|
|
||||||
class MyApp(wxApp):
|
class MyApp(wx.App):
|
||||||
"""Demonstrates usage of both default and customized shells"""
|
"""Demonstrates usage of both default and customized shells"""
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
frame = MyFrame()
|
frame = MyFrame()
|
||||||
|
|||||||
@@ -10,6 +10,11 @@
|
|||||||
# Copyright: (c) 1999 by Total Control Software
|
# Copyright: (c) 1999 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 12/11/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
# o Untested.
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
A Splash Screen implemented in Python.
|
A Splash Screen implemented in Python.
|
||||||
@@ -18,52 +23,67 @@ NOTE: Now that wxWindows has a wxSplashScrren class and it is wrapped
|
|||||||
in wxPython this class is deprecated. See the docs for more details.
|
in wxPython this class is deprecated. See the docs for more details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from wxPython.wx import *
|
import warnings
|
||||||
|
import wx
|
||||||
|
|
||||||
|
warningmsg = r"""\
|
||||||
|
|
||||||
|
#####################################################\
|
||||||
|
# THIS MODULE IS NOW DEPRECATED |
|
||||||
|
# |
|
||||||
|
# The core wx library now contains an implementation |
|
||||||
|
# of the 'real' wx.SpashScreen. |
|
||||||
|
#####################################################/
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
warnings.warn(warningmsg, DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
class SplashScreen(wxFrame):
|
class SplashScreen(wx.Frame):
|
||||||
def __init__(self, parent, ID=-1, title="SplashScreen",
|
def __init__(self, parent, ID=-1, title="SplashScreen",
|
||||||
style=wxSIMPLE_BORDER|wxSTAY_ON_TOP,
|
style=wx.SIMPLE_BORDER|wx.STAY_ON_TOP,
|
||||||
duration=1500, bitmapfile="bitmaps/splashscreen.bmp",
|
duration=1500, bitmapfile="bitmaps/splashscreen.bmp",
|
||||||
callback = None):
|
callback = None):
|
||||||
'''
|
'''
|
||||||
parent, ID, title, style -- see wxFrame
|
parent, ID, title, style -- see wx.Frame
|
||||||
duration -- milliseconds to display the splash screen
|
duration -- milliseconds to display the splash screen
|
||||||
bitmapfile -- absolute or relative pathname to image file
|
bitmapfile -- absolute or relative pathname to image file
|
||||||
callback -- if specified, is called when timer completes, callback is
|
callback -- if specified, is called when timer completes, callback is
|
||||||
responsible for closing the splash screen
|
responsible for closing the splash screen
|
||||||
'''
|
'''
|
||||||
### Loading bitmap
|
### Loading bitmap
|
||||||
self.bitmap = bmp = wxImage(bitmapfile, wxBITMAP_TYPE_ANY).ConvertToBitmap()
|
self.bitmap = bmp = wx.Image(bitmapfile, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
|
||||||
|
|
||||||
### Determine size of bitmap to size window...
|
### Determine size of bitmap to size window...
|
||||||
size = (bmp.GetWidth(), bmp.GetHeight())
|
size = (bmp.GetWidth(), bmp.GetHeight())
|
||||||
|
|
||||||
# size of screen
|
# size of screen
|
||||||
width = wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_X)
|
width = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
|
||||||
height = wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_Y)
|
height = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)
|
||||||
pos = ((width-size[0])/2, (height-size[1])/2)
|
pos = ((width-size[0])/2, (height-size[1])/2)
|
||||||
|
|
||||||
# check for overflow...
|
# check for overflow...
|
||||||
if pos[0] < 0:
|
if pos[0] < 0:
|
||||||
size = (wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_X), size[1])
|
size = (wx.SystemSettings_GetSystemMetric(wx.SYS_SCREEN_X), size[1])
|
||||||
if pos[1] < 0:
|
if pos[1] < 0:
|
||||||
size = (size[0], wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_Y))
|
size = (size[0], wx.SystemSettings_GetSystemMetric(wx.SYS_SCREEN_Y))
|
||||||
|
|
||||||
wxFrame.__init__(self, parent, ID, title, pos, size, style)
|
wx.Frame.__init__(self, parent, ID, title, pos, size, style)
|
||||||
EVT_LEFT_DOWN(self, self.OnMouseClick)
|
self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseClick)
|
||||||
EVT_CLOSE(self, self.OnCloseWindow)
|
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
||||||
EVT_PAINT(self, self.OnPaint)
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||||
EVT_ERASE_BACKGROUND(self, self.OnEraseBG)
|
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBG)
|
||||||
|
|
||||||
self.Show(True)
|
self.Show(True)
|
||||||
|
|
||||||
|
|
||||||
class SplashTimer(wxTimer):
|
class SplashTimer(wx.Timer):
|
||||||
def __init__(self, targetFunction):
|
def __init__(self, targetFunction):
|
||||||
self.Notify = targetFunction
|
self.Notify = targetFunction
|
||||||
wxTimer.__init__(self)
|
wx.Timer.__init__(self)
|
||||||
|
|
||||||
if callback is None:
|
if callback is None:
|
||||||
callback = self.OnSplashExitDefault
|
callback = self.OnSplashExitDefault
|
||||||
@@ -72,8 +92,8 @@ class SplashScreen(wxFrame):
|
|||||||
self.timer.Start(duration, 1) # one-shot only
|
self.timer.Start(duration, 1) # one-shot only
|
||||||
|
|
||||||
def OnPaint(self, event):
|
def OnPaint(self, event):
|
||||||
dc = wxPaintDC(self)
|
dc = wx.PaintDC(self)
|
||||||
dc.DrawBitmap(self.bitmap, 0,0, False)
|
dc.DrawBitmap(self.bitmap, (0,0), False)
|
||||||
|
|
||||||
def OnEraseBG(self, event):
|
def OnEraseBG(self, event):
|
||||||
pass
|
pass
|
||||||
@@ -94,12 +114,10 @@ class SplashScreen(wxFrame):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
class DemoApp(wxApp):
|
class DemoApp(wx.App):
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
wxImage_AddHandler(wxJPEGHandler())
|
wx.InitAllImageHandlers()
|
||||||
wxImage_AddHandler(wxPNGHandler())
|
self.splash = SplashScreen(None, bitmapfile="splashscreen.jpg", callback=self.OnSplashExit)
|
||||||
wxImage_AddHandler(wxGIFHandler())
|
|
||||||
self.splash = SplashScreen(NULL, bitmapfile="splashscreen.jpg", callback=self.OnSplashExit)
|
|
||||||
self.splash.Show(True)
|
self.splash.Show(True)
|
||||||
self.SetTopWindow(self.splash)
|
self.SetTopWindow(self.splash)
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -11,9 +11,11 @@
|
|||||||
# Copyright: (c) 2002 by Total Control Software
|
# Copyright: (c) 2002 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 12/12/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
"""
|
#
|
||||||
"""
|
# o 2.5 compatability update.
|
||||||
|
# o Untested.
|
||||||
|
#
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
|
|
||||||
@@ -52,8 +54,8 @@ class GenStaticText(wx.PyControl):
|
|||||||
if rh == -1: rh = bh
|
if rh == -1: rh = bh
|
||||||
self.SetSize(wx.Size(rw, rh))
|
self.SetSize(wx.Size(rw, rh))
|
||||||
|
|
||||||
wx.EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
|
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
|
||||||
wx.EVT_PAINT(self, self.OnPaint)
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||||
|
|
||||||
|
|
||||||
def SetLabel(self, label):
|
def SetLabel(self, label):
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ can continue unencumbered.
|
|||||||
#
|
#
|
||||||
# $Id$
|
# $Id$
|
||||||
#
|
#
|
||||||
|
# 12/12/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o 2.5 compatability update.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import wx
|
import wx
|
||||||
@@ -23,8 +28,7 @@ import wx
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
THROBBER_EVENT = wx.NewEventType()
|
THROBBER_EVENT = wx.NewEventType()
|
||||||
def EVT_UPDATE_THROBBER(win, func):
|
EVT_UPDATE_THROBBER = wx.PyEventBinder(THROBBER_EVENT, 0)
|
||||||
win.Connect(-1, -1, THROBBER_EVENT, func)
|
|
||||||
|
|
||||||
class UpdateThrobberEvent(wx.PyEvent):
|
class UpdateThrobberEvent(wx.PyEvent):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -119,10 +123,10 @@ class Throbber(wx.Panel):
|
|||||||
timerID = wx.NewId()
|
timerID = wx.NewId()
|
||||||
self.timer = wx.Timer(self, timerID)
|
self.timer = wx.Timer(self, timerID)
|
||||||
|
|
||||||
EVT_UPDATE_THROBBER(self, self.Rotate)
|
self.Bind(EVT_UPDATE_THROBBER, self.Rotate)
|
||||||
wx.EVT_PAINT(self, self.OnPaint)
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||||
wx.EVT_TIMER(self, timerID, self.OnTimer)
|
self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
|
||||||
wx.EVT_WINDOW_DESTROY(self, self.OnDestroyWindow)
|
self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroyWindow)
|
||||||
|
|
||||||
|
|
||||||
def OnTimer(self, event):
|
def OnTimer(self, event):
|
||||||
|
|||||||
@@ -29,6 +29,13 @@
|
|||||||
# or be counted twice (1 day each per year, for DST adjustments), the date
|
# or be counted twice (1 day each per year, for DST adjustments), the date
|
||||||
# portion of all wxDateTimes used/returned have their date portion set to
|
# portion of all wxDateTimes used/returned have their date portion set to
|
||||||
# Jan 1, 1970 (the "epoch.")
|
# Jan 1, 1970 (the "epoch.")
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# 12/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Updated for V2.5 compatability
|
||||||
|
# o wx.SpinCtl has some issues that cause the control to
|
||||||
|
# lock up. Noted in other places using it too, it's not this module
|
||||||
|
# that's at fault.
|
||||||
#
|
#
|
||||||
|
|
||||||
"""<html><body>
|
"""<html><body>
|
||||||
@@ -239,10 +246,14 @@ value to fall within the current bounds.
|
|||||||
</body></html>
|
</body></html>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import string, copy, types
|
import copy
|
||||||
from wxPython.wx import *
|
import string
|
||||||
from wxPython.tools.dbg import Logger
|
import types
|
||||||
from wxPython.lib.maskededit import wxMaskedTextCtrl, Field
|
|
||||||
|
import wx
|
||||||
|
|
||||||
|
from wx.tools.dbg import Logger
|
||||||
|
from wx.lib.maskededit import wxMaskedTextCtrl, Field
|
||||||
|
|
||||||
dbg = Logger()
|
dbg = Logger()
|
||||||
dbg(enable=0)
|
dbg(enable=0)
|
||||||
@@ -254,14 +265,12 @@ except ImportError:
|
|||||||
accept_mx = False
|
accept_mx = False
|
||||||
|
|
||||||
# This class of event fires whenever the value of the time changes in the control:
|
# This class of event fires whenever the value of the time changes in the control:
|
||||||
wxEVT_TIMEVAL_UPDATED = wxNewId()
|
wxEVT_TIMEVAL_UPDATED = wx.NewEventType()
|
||||||
def EVT_TIMEUPDATE(win, id, func):
|
EVT_TIMEUPDATE = wx.PyEventBinder(wxEVT_TIMEVAL_UPDATED, 1)
|
||||||
"""Used to trap events indicating that the current time has been changed."""
|
|
||||||
win.Connect(id, -1, wxEVT_TIMEVAL_UPDATED, func)
|
|
||||||
|
|
||||||
class TimeUpdatedEvent(wxPyCommandEvent):
|
class TimeUpdatedEvent(wx.PyCommandEvent):
|
||||||
def __init__(self, id, value ='12:00:00 AM'):
|
def __init__(self, id, value ='12:00:00 AM'):
|
||||||
wxPyCommandEvent.__init__(self, wxEVT_TIMEVAL_UPDATED, id)
|
wx.PyCommandEvent.__init__(self, wxEVT_TIMEVAL_UPDATED, id)
|
||||||
self.value = value
|
self.value = value
|
||||||
def GetValue(self):
|
def GetValue(self):
|
||||||
"""Retrieve the value of the time control at the time this event was generated"""
|
"""Retrieve the value of the time control at the time this event was generated"""
|
||||||
@@ -281,11 +290,11 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
|||||||
|
|
||||||
def __init__ (
|
def __init__ (
|
||||||
self, parent, id=-1, value = '12:00:00 AM',
|
self, parent, id=-1, value = '12:00:00 AM',
|
||||||
pos = wxDefaultPosition, size = wxDefaultSize,
|
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||||
fmt24hr=False,
|
fmt24hr=False,
|
||||||
spinButton = None,
|
spinButton = None,
|
||||||
style = wxTE_PROCESS_TAB,
|
style = wx.TE_PROCESS_TAB,
|
||||||
validator = wxDefaultValidator,
|
validator = wx.DefaultValidator,
|
||||||
name = "time",
|
name = "time",
|
||||||
**kwargs ):
|
**kwargs ):
|
||||||
|
|
||||||
@@ -369,7 +378,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
|||||||
maskededit_kwargs['useFixedWidthFont'] = self.__useFixedWidthFont
|
maskededit_kwargs['useFixedWidthFont'] = self.__useFixedWidthFont
|
||||||
|
|
||||||
# allow for explicit size specification:
|
# allow for explicit size specification:
|
||||||
if size != wxDefaultSize:
|
if size != wx.DefaultSize:
|
||||||
# override (and remove) "autofit" autoformat code in standard time formats:
|
# override (and remove) "autofit" autoformat code in standard time formats:
|
||||||
maskededit_kwargs['formatcodes'] = 'T!'
|
maskededit_kwargs['formatcodes'] = 'T!'
|
||||||
|
|
||||||
@@ -389,8 +398,8 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
|||||||
|
|
||||||
|
|
||||||
# This makes the up/down keys act like spin button controls:
|
# This makes the up/down keys act like spin button controls:
|
||||||
self._SetKeycodeHandler(WXK_UP, self.__OnSpinUp)
|
self._SetKeycodeHandler(wx.WXK_UP, self.__OnSpinUp)
|
||||||
self._SetKeycodeHandler(WXK_DOWN, self.__OnSpinDown)
|
self._SetKeycodeHandler(wx.WXK_DOWN, self.__OnSpinDown)
|
||||||
|
|
||||||
|
|
||||||
# This allows ! and c/C to set the control to the current time:
|
# This allows ! and c/C to set the control to the current time:
|
||||||
@@ -405,15 +414,15 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
|||||||
# that : takes you forward, not back, and so we can issue
|
# that : takes you forward, not back, and so we can issue
|
||||||
# EVT_TIMEUPDATE events on changes:
|
# EVT_TIMEUPDATE events on changes:
|
||||||
|
|
||||||
EVT_SET_FOCUS( self, self._OnFocus ) ## defeat automatic full selection
|
self.Bind(wx.EVT_SET_FOCUS, self._OnFocus ) ## defeat automatic full selection
|
||||||
EVT_KILL_FOCUS( self, self._OnKillFocus ) ## run internal validator
|
self.Bind(wx.EVT_KILL_FOCUS, self._OnKillFocus ) ## run internal validator
|
||||||
EVT_LEFT_UP(self, self.__LimitSelection) ## limit selections to single field
|
self.Bind(wx.EVT_LEFT_UP, self.__LimitSelection) ## limit selections to single field
|
||||||
EVT_LEFT_DCLICK(self, self._OnDoubleClick ) ## select field under cursor on dclick
|
self.Bind(wx.EVT_LEFT_DCLICK, self._OnDoubleClick ) ## select field under cursor on dclick
|
||||||
EVT_KEY_DOWN( self, self._OnKeyDown ) ## capture control events not normally seen, eg ctrl-tab.
|
self.Bind(wx.EVT_KEY_DOWN, self._OnKeyDown ) ## capture control events not normally seen, eg ctrl-tab.
|
||||||
EVT_CHAR( self, self.__OnChar ) ## remove "shift" attribute from colon key event,
|
self.Bind(wx.EVT_CHAR, self.__OnChar ) ## remove "shift" attribute from colon key event,
|
||||||
## then call wxMaskedTextCtrl._OnChar with
|
## then call wxMaskedTextCtrl._OnChar with
|
||||||
## the possibly modified event.
|
## the possibly modified event.
|
||||||
EVT_TEXT( self, self.GetId(), self.__OnTextChange ) ## color control appropriately and EVT_TIMEUPDATE events
|
self.Bind(wx.EVT_TEXT, self.__OnTextChange, self ) ## color control appropriately and EVT_TIMEUPDATE events
|
||||||
|
|
||||||
|
|
||||||
# Validate initial value and set if appropriate
|
# Validate initial value and set if appropriate
|
||||||
@@ -438,8 +447,8 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
|||||||
self.__spinButton = sb
|
self.__spinButton = sb
|
||||||
if self.__spinButton:
|
if self.__spinButton:
|
||||||
# bind event handlers to spin ctrl
|
# bind event handlers to spin ctrl
|
||||||
EVT_SPIN_UP(self.__spinButton, self.__spinButton.GetId(), self.__OnSpinUp)
|
self.__spinButton.Bind(wx.EVT_SPIN_UP, self.__OnSpinUp, self.__spinButton)
|
||||||
EVT_SPIN_DOWN(self.__spinButton, self.__spinButton.GetId(), self.__OnSpinDown)
|
self.__spinButton.Bind(wx.EVT_SPIN_DOWN, self.__OnSpinDown, self.__spinButton)
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@@ -478,7 +487,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
|||||||
elif as_mxDateTime:
|
elif as_mxDateTime:
|
||||||
value = DateTime.DateTime(1970, 1, 1, value.GetHour(), value.GetMinute(), value.GetSecond())
|
value = DateTime.DateTime(1970, 1, 1, value.GetHour(), value.GetMinute(), value.GetSecond())
|
||||||
elif as_wxTimeSpan:
|
elif as_wxTimeSpan:
|
||||||
value = wxTimeSpan(value.GetHour(), value.GetMinute(), value.GetSecond())
|
value = wx.TimeSpan(value.GetHour(), value.GetMinute(), value.GetSecond())
|
||||||
elif as_mxDateTimeDelta:
|
elif as_mxDateTimeDelta:
|
||||||
value = DateTime.DateTimeDelta(0, value.GetHour(), value.GetMinute(), value.GetSecond())
|
value = DateTime.DateTimeDelta(0, value.GetHour(), value.GetMinute(), value.GetSecond())
|
||||||
else:
|
else:
|
||||||
@@ -524,7 +533,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
|||||||
if type(value) == types.StringType:
|
if type(value) == types.StringType:
|
||||||
|
|
||||||
# Construct constant wxDateTime, then try to parse the string:
|
# Construct constant wxDateTime, then try to parse the string:
|
||||||
wxdt = wxDateTimeFromDMY(1, 0, 1970)
|
wxdt = wx.DateTimeFromDMY(1, 0, 1970)
|
||||||
dbg('attempting conversion')
|
dbg('attempting conversion')
|
||||||
value = value.strip() # (parser doesn't like leading spaces)
|
value = value.strip() # (parser doesn't like leading spaces)
|
||||||
checkTime = wxdt.ParseTime(value)
|
checkTime = wxdt.ParseTime(value)
|
||||||
@@ -536,9 +545,9 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
|||||||
raise ValueError('cannot convert string "%s" to valid time' % value)
|
raise ValueError('cannot convert string "%s" to valid time' % value)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if isinstance(value, wxDateTime):
|
if isinstance(value, wx.DateTime):
|
||||||
hour, minute, second = value.GetHour(), value.GetMinute(), value.GetSecond()
|
hour, minute, second = value.GetHour(), value.GetMinute(), value.GetSecond()
|
||||||
elif isinstance(value, wxTimeSpan):
|
elif isinstance(value, wx.TimeSpan):
|
||||||
totalseconds = value.GetSeconds()
|
totalseconds = value.GetSeconds()
|
||||||
hour = totalseconds / 3600
|
hour = totalseconds / 3600
|
||||||
minute = totalseconds / 60 - (hour * 60)
|
minute = totalseconds / 60 - (hour * 60)
|
||||||
@@ -557,7 +566,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
|||||||
dbg(indent=0, suspend=0)
|
dbg(indent=0, suspend=0)
|
||||||
raise ValueError(error)
|
raise ValueError(error)
|
||||||
|
|
||||||
wxdt = wxDateTimeFromDMY(1, 0, 1970)
|
wxdt = wx.DateTimeFromDMY(1, 0, 1970)
|
||||||
wxdt.SetHour(hour)
|
wxdt.SetHour(hour)
|
||||||
wxdt.SetMinute(minute)
|
wxdt.SetMinute(minute)
|
||||||
wxdt.SetSecond(second)
|
wxdt.SetSecond(second)
|
||||||
@@ -772,9 +781,9 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
|||||||
|
|
||||||
# Note: relies on min and max and value date portions
|
# Note: relies on min and max and value date portions
|
||||||
# always being the same.
|
# always being the same.
|
||||||
interval = (min + wxTimeSpan(24, 0, 0, 0)) - max
|
interval = (min + wx.TimeSpan(24, 0, 0, 0)) - max
|
||||||
|
|
||||||
half_interval = wxTimeSpan(
|
half_interval = wx.TimeSpan(
|
||||||
0, # hours
|
0, # hours
|
||||||
0, # minutes
|
0, # minutes
|
||||||
interval.GetSeconds() / 2, # seconds
|
interval.GetSeconds() / 2, # seconds
|
||||||
@@ -782,7 +791,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
|||||||
|
|
||||||
if value < min: # min is on next day, so use value on
|
if value < min: # min is on next day, so use value on
|
||||||
# "next day" for "nearest" interval calculation:
|
# "next day" for "nearest" interval calculation:
|
||||||
cmp_value = value + wxTimeSpan(24, 0, 0, 0)
|
cmp_value = value + wx.TimeSpan(24, 0, 0, 0)
|
||||||
else: # "before midnight; ok
|
else: # "before midnight; ok
|
||||||
cmp_value = value
|
cmp_value = value
|
||||||
|
|
||||||
@@ -850,7 +859,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
|||||||
min = self.GetMin()
|
min = self.GetMin()
|
||||||
max = self.GetMax()
|
max = self.GetMax()
|
||||||
|
|
||||||
midnight = wxDateTimeFromDMY(1, 0, 1970)
|
midnight = wx.DateTimeFromDMY(1, 0, 1970)
|
||||||
if min <= max: # they don't span midnight
|
if min <= max: # they don't span midnight
|
||||||
ret = min <= value <= max
|
ret = min <= value <= max
|
||||||
|
|
||||||
@@ -993,7 +1002,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
|||||||
This is the key handler for '!' and 'c'; this allows the user to
|
This is the key handler for '!' and 'c'; this allows the user to
|
||||||
quickly set the value of the control to the current time.
|
quickly set the value of the control to the current time.
|
||||||
"""
|
"""
|
||||||
self.SetValue(wxDateTime_Now().FormatTime())
|
self.SetValue(wx.DateTime_Now().FormatTime())
|
||||||
keep_processing = False
|
keep_processing = False
|
||||||
return keep_processing
|
return keep_processing
|
||||||
|
|
||||||
@@ -1028,7 +1037,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
|||||||
dbg('field: ', field._index)
|
dbg('field: ', field._index)
|
||||||
start, end = field._extent
|
start, end = field._extent
|
||||||
slice = text[start:end]
|
slice = text[start:end]
|
||||||
if key == WXK_UP: increment = 1
|
if key == wx.WXK_UP: increment = 1
|
||||||
else: increment = -1
|
else: increment = -1
|
||||||
|
|
||||||
if slice in ('A', 'P'):
|
if slice in ('A', 'P'):
|
||||||
@@ -1040,7 +1049,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
|||||||
# adjusting this field is trickier, as its value can affect the
|
# adjusting this field is trickier, as its value can affect the
|
||||||
# am/pm setting. So, we use wxDateTime to generate a new value for us:
|
# am/pm setting. So, we use wxDateTime to generate a new value for us:
|
||||||
# (Use a fixed date not subject to DST variations:)
|
# (Use a fixed date not subject to DST variations:)
|
||||||
converter = wxDateTimeFromDMY(1, 0, 1970)
|
converter = wx.DateTimeFromDMY(1, 0, 1970)
|
||||||
dbg('text: "%s"' % text)
|
dbg('text: "%s"' % text)
|
||||||
converter.ParseTime(text.strip())
|
converter.ParseTime(text.strip())
|
||||||
currenthour = converter.GetHour()
|
currenthour = converter.GetHour()
|
||||||
@@ -1059,8 +1068,8 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
|||||||
self.SetValue(newvalue)
|
self.SetValue(newvalue)
|
||||||
|
|
||||||
except ValueError: # must not be in bounds:
|
except ValueError: # must not be in bounds:
|
||||||
if not wxValidator_IsSilent():
|
if not wx.Validator_IsSilent():
|
||||||
wxBell()
|
wx.Bell()
|
||||||
dbg(indent=0)
|
dbg(indent=0)
|
||||||
|
|
||||||
|
|
||||||
@@ -1111,30 +1120,30 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
class TestPanel(wxPanel):
|
class TestPanel(wx.Panel):
|
||||||
def __init__(self, parent, id,
|
def __init__(self, parent, id,
|
||||||
pos = wxPyDefaultPosition, size = wxPyDefaultSize,
|
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||||
fmt24hr = 0, test_mx = 0,
|
fmt24hr = 0, test_mx = 0,
|
||||||
style = wxTAB_TRAVERSAL ):
|
style = wx.TAB_TRAVERSAL ):
|
||||||
|
|
||||||
wxPanel.__init__(self, parent, id, pos, size, style)
|
wx.Panel.__init__(self, parent, id, pos, size, style)
|
||||||
|
|
||||||
self.test_mx = test_mx
|
self.test_mx = test_mx
|
||||||
|
|
||||||
self.tc = wxTimeCtrl(self, 10, fmt24hr = fmt24hr)
|
self.tc = wxTimeCtrl(self, 10, fmt24hr = fmt24hr)
|
||||||
sb = wxSpinButton( self, 20, wxDefaultPosition, wxSize(-1,20), 0 )
|
sb = wx.SpinButton( self, 20, wx.DefaultPosition, (-1,20), 0 )
|
||||||
self.tc.BindSpinButton(sb)
|
self.tc.BindSpinButton(sb)
|
||||||
|
|
||||||
sizer = wxBoxSizer( wxHORIZONTAL )
|
sizer = wx.BoxSizer( wx.HORIZONTAL )
|
||||||
sizer.AddWindow( self.tc, 0, wxALIGN_CENTRE|wxLEFT|wxTOP|wxBOTTOM, 5 )
|
sizer.Add( self.tc, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.TOP|wx.BOTTOM, 5 )
|
||||||
sizer.AddWindow( sb, 0, wxALIGN_CENTRE|wxRIGHT|wxTOP|wxBOTTOM, 5 )
|
sizer.Add( sb, 0, wx.ALIGN_CENTRE|wx.RIGHT|wx.TOP|wx.BOTTOM, 5 )
|
||||||
|
|
||||||
self.SetAutoLayout( True )
|
self.SetAutoLayout( True )
|
||||||
self.SetSizer( sizer )
|
self.SetSizer( sizer )
|
||||||
sizer.Fit( self )
|
sizer.Fit( self )
|
||||||
sizer.SetSizeHints( self )
|
sizer.SetSizeHints( self )
|
||||||
|
|
||||||
EVT_TIMEUPDATE(self, self.tc.GetId(), self.OnTimeChange)
|
self.Bind(EVT_TIMEUPDATE, self.OnTimeChange, self.tc)
|
||||||
|
|
||||||
def OnTimeChange(self, event):
|
def OnTimeChange(self, event):
|
||||||
dbg('OnTimeChange: value = ', event.GetValue())
|
dbg('OnTimeChange: value = ', event.GetValue())
|
||||||
@@ -1145,14 +1154,14 @@ if __name__ == '__main__':
|
|||||||
dbg('mxdt =', mxdt.hour, mxdt.minute, mxdt.second)
|
dbg('mxdt =', mxdt.hour, mxdt.minute, mxdt.second)
|
||||||
|
|
||||||
|
|
||||||
class MyApp(wxApp):
|
class MyApp(wx.App):
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
import sys
|
import sys
|
||||||
fmt24hr = '24' in sys.argv
|
fmt24hr = '24' in sys.argv
|
||||||
test_mx = 'mx' in sys.argv
|
test_mx = 'mx' in sys.argv
|
||||||
try:
|
try:
|
||||||
frame = wxFrame(NULL, -1, "wxTimeCtrl Test", wxPoint(20,20), wxSize(100,100) )
|
frame = wx.Frame(None, -1, "wxTimeCtrl Test", (20,20), (100,100) )
|
||||||
panel = TestPanel(frame, -1, wxPoint(-1,-1), fmt24hr=fmt24hr, test_mx = test_mx)
|
panel = TestPanel(frame, -1, (-1,-1), fmt24hr=fmt24hr, test_mx = test_mx)
|
||||||
frame.Show(True)
|
frame.Show(True)
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|||||||
@@ -18,8 +18,28 @@ Original comment follows below:
|
|||||||
# Last revision: 1998-7-28
|
# Last revision: 1998-7-28
|
||||||
#
|
#
|
||||||
"""
|
"""
|
||||||
|
# 12/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Updated for V2.5 compatability
|
||||||
|
# o wx.SpinCtl has some issues that cause the control to
|
||||||
|
# lock up. Noted in other places using it too, it's not this module
|
||||||
|
# that's at fault.
|
||||||
|
# o Added deprecation warning.
|
||||||
|
#
|
||||||
|
|
||||||
from wxPython import wx
|
import warnings
|
||||||
|
import wx
|
||||||
|
|
||||||
|
warningmsg = r"""\
|
||||||
|
|
||||||
|
THIS MODULE IS NOW DEPRECATED
|
||||||
|
|
||||||
|
This module has been replaced by wxPyPlot, which in wxPython
|
||||||
|
can be found in wx.lib.plot.py.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
warnings.warn(warningmsg, DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
# Not everybody will have Numeric, so let's be cool about it...
|
# Not everybody will have Numeric, so let's be cool about it...
|
||||||
try:
|
try:
|
||||||
@@ -31,10 +51,10 @@ imported. It probably is not installed (it's not part of the standard
|
|||||||
Python distribution). See the Python site (http://www.python.org) for
|
Python distribution). See the Python site (http://www.python.org) for
|
||||||
information on downloading source or binaries."""
|
information on downloading source or binaries."""
|
||||||
|
|
||||||
if wx.wxPlatform == '__WXMSW__':
|
if wx.Platform == '__WXMSW__':
|
||||||
d = wx.wxMessageDialog(wx.NULL, msg, "Numeric not found")
|
d = wx.MessageDialog(None, msg, "Numeric not found")
|
||||||
if d.ShowModal() == wx.wxID_CANCEL:
|
if d.ShowModal() == wx.ID_CANCEL:
|
||||||
d = wx.wxMessageDialog(wx.NULL, "I kid you not! Pressing Cancel won't help you!", "Not a joke", wx.wxOK)
|
d = wx.MessageDialog(None, "I kid you not! Pressing Cancel won't help you!", "Not a joke", wx.OK)
|
||||||
d.ShowModal()
|
d.ShowModal()
|
||||||
else:
|
else:
|
||||||
print msg
|
print msg
|
||||||
@@ -75,7 +95,7 @@ class PolyLine(PolyPoints):
|
|||||||
color = self.attributes['color']
|
color = self.attributes['color']
|
||||||
width = self.attributes['width']
|
width = self.attributes['width']
|
||||||
arguments = []
|
arguments = []
|
||||||
dc.SetPen(wx.wxPen(wx.wxNamedColour(color), width))
|
dc.SetPen(wx.Pen(wx.NamedColour(color), width))
|
||||||
dc.DrawLines(map(tuple,self.scaled))
|
dc.DrawLines(map(tuple,self.scaled))
|
||||||
|
|
||||||
|
|
||||||
@@ -89,7 +109,7 @@ class PolyMarker(PolyPoints):
|
|||||||
'width': 1,
|
'width': 1,
|
||||||
'fillcolor': None,
|
'fillcolor': None,
|
||||||
'size': 2,
|
'size': 2,
|
||||||
'fillstyle': wx.wxSOLID,
|
'fillstyle': wx.SOLID,
|
||||||
'outline': 'black',
|
'outline': 'black',
|
||||||
'marker': 'circle'}
|
'marker': 'circle'}
|
||||||
|
|
||||||
@@ -101,11 +121,11 @@ class PolyMarker(PolyPoints):
|
|||||||
fillstyle = self.attributes['fillstyle']
|
fillstyle = self.attributes['fillstyle']
|
||||||
marker = self.attributes['marker']
|
marker = self.attributes['marker']
|
||||||
|
|
||||||
dc.SetPen(wx.wxPen(wx.wxNamedColour(color),width))
|
dc.SetPen(wx.Pen(wx.NamedColour(color),width))
|
||||||
if fillcolor:
|
if fillcolor:
|
||||||
dc.SetBrush(wx.wxBrush(wx.wxNamedColour(fillcolor),fillstyle))
|
dc.SetBrush(wx.Brush(wx.NamedColour(fillcolor),fillstyle))
|
||||||
else:
|
else:
|
||||||
dc.SetBrush(wx.wxBrush(wx.wxNamedColour('black'), wx.wxTRANSPARENT))
|
dc.SetBrush(wx.Brush(wx.NamedColour('black'), wx.TRANSPARENT))
|
||||||
|
|
||||||
self._drawmarkers(dc, self.scaled, marker, size)
|
self._drawmarkers(dc, self.scaled, marker, size)
|
||||||
|
|
||||||
@@ -115,7 +135,7 @@ class PolyMarker(PolyPoints):
|
|||||||
f(dc, xc, yc, size)
|
f(dc, xc, yc, size)
|
||||||
|
|
||||||
def _circle(self, dc, xc, yc, size=1):
|
def _circle(self, dc, xc, yc, size=1):
|
||||||
dc.DrawEllipse(xc-2.5*size,yc-2.5*size,5.*size,5.*size)
|
dc.DrawEllipse((xc-2.5*size,yc-2.5*size), (5.*size,5.*size))
|
||||||
|
|
||||||
def _dot(self, dc, xc, yc, size=1):
|
def _dot(self, dc, xc, yc, size=1):
|
||||||
dc.DrawPoint(xc,yc)
|
dc.DrawPoint(xc,yc)
|
||||||
@@ -134,12 +154,12 @@ class PolyMarker(PolyPoints):
|
|||||||
(0.0,0.577350*size*5)],xc,yc)
|
(0.0,0.577350*size*5)],xc,yc)
|
||||||
|
|
||||||
def _cross(self, dc, xc, yc, size=1):
|
def _cross(self, dc, xc, yc, size=1):
|
||||||
dc.DrawLine(xc-2.5*size,yc-2.5*size,xc+2.5*size,yc+2.5*size)
|
dc.DrawLine((xc-2.5*size, yc-2.5*size), (xc+2.5*size,yc+2.5*size))
|
||||||
dc.DrawLine(xc-2.5*size,yc+2.5*size,xc+2.5*size,yc-2.5*size)
|
dc.DrawLine((xc-2.5*size,yc+2.5*size), (xc+2.5*size,yc-2.5*size))
|
||||||
|
|
||||||
def _plus(self, dc, xc, yc, size=1):
|
def _plus(self, dc, xc, yc, size=1):
|
||||||
dc.DrawLine(xc-2.5*size,yc,xc+2.5*size,yc)
|
dc.DrawLine((xc-2.5*size,yc), (xc+2.5*size,yc))
|
||||||
dc.DrawLine(xc,yc-2.5*size,xc,yc+2.5*size)
|
dc.DrawLine((xc,yc-2.5*size,xc), (yc+2.5*size))
|
||||||
|
|
||||||
class PlotGraphics:
|
class PlotGraphics:
|
||||||
|
|
||||||
@@ -169,29 +189,29 @@ class PlotGraphics:
|
|||||||
return self.objects[item]
|
return self.objects[item]
|
||||||
|
|
||||||
|
|
||||||
class PlotCanvas(wx.wxWindow):
|
class PlotCanvas(wx.Window):
|
||||||
|
|
||||||
def __init__(self, parent, id=-1,
|
def __init__(self, parent, id=-1,
|
||||||
pos = wx.wxDefaultPosition, size = wx.wxDefaultSize,
|
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||||
style = 0, name = 'plotCanvas'):
|
style = 0, name = 'plotCanvas'):
|
||||||
wx.wxWindow.__init__(self, parent, id, pos, size, style, name)
|
wx.Window.__init__(self, parent, id, pos, size, style, name)
|
||||||
self.border = (1,1)
|
self.border = (1,1)
|
||||||
self.SetClientSizeWH(400,400)
|
self.SetClientSize((400,400))
|
||||||
self.SetBackgroundColour(wx.wxNamedColour("white"))
|
self.SetBackgroundColour("white")
|
||||||
|
|
||||||
wx.EVT_SIZE(self,self.reconfigure)
|
self.Bind(wx.EVT_SIZE,self.reconfigure)
|
||||||
wx.EVT_PAINT(self, self.OnPaint)
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||||
self._setsize()
|
self._setsize()
|
||||||
self.last_draw = None
|
self.last_draw = None
|
||||||
# self.font = self._testFont(font)
|
# self.font = self._testFont(font)
|
||||||
|
|
||||||
def OnPaint(self, event):
|
def OnPaint(self, event):
|
||||||
pdc = wx.wxPaintDC(self)
|
pdc = wx.PaintDC(self)
|
||||||
if self.last_draw is not None:
|
if self.last_draw is not None:
|
||||||
apply(self.draw, self.last_draw + (pdc,))
|
apply(self.draw, self.last_draw + (pdc,))
|
||||||
|
|
||||||
def reconfigure(self, event):
|
def reconfigure(self, event):
|
||||||
(new_width,new_height) = self.GetClientSizeTuple()
|
(new_width,new_height) = self.GetClientSize()
|
||||||
if new_width == self.width and new_height == self.height:
|
if new_width == self.width and new_height == self.height:
|
||||||
return
|
return
|
||||||
self._setsize()
|
self._setsize()
|
||||||
@@ -209,14 +229,14 @@ class PlotCanvas(wx.wxWindow):
|
|||||||
return font
|
return font
|
||||||
|
|
||||||
def _setsize(self):
|
def _setsize(self):
|
||||||
(self.width,self.height) = self.GetClientSizeTuple();
|
(self.width,self.height) = self.GetClientSize();
|
||||||
self.plotbox_size = 0.97*Numeric.array([self.width, -self.height])
|
self.plotbox_size = 0.97*Numeric.array([self.width, -self.height])
|
||||||
xo = 0.5*(self.width-self.plotbox_size[0])
|
xo = 0.5*(self.width-self.plotbox_size[0])
|
||||||
yo = self.height-0.5*(self.height+self.plotbox_size[1])
|
yo = self.height-0.5*(self.height+self.plotbox_size[1])
|
||||||
self.plotbox_origin = Numeric.array([xo, yo])
|
self.plotbox_origin = Numeric.array([xo, yo])
|
||||||
|
|
||||||
def draw(self, graphics, xaxis = None, yaxis = None, dc = None):
|
def draw(self, graphics, xaxis = None, yaxis = None, dc = None):
|
||||||
if dc == None: dc = wx.wxClientDC(self)
|
if dc == None: dc = wx.ClientDC(self)
|
||||||
dc.BeginDrawing()
|
dc.BeginDrawing()
|
||||||
dc.Clear()
|
dc.Clear()
|
||||||
self.last_draw = (graphics, xaxis, yaxis)
|
self.last_draw = (graphics, xaxis, yaxis)
|
||||||
@@ -291,19 +311,19 @@ class PlotCanvas(wx.wxWindow):
|
|||||||
|
|
||||||
def _drawAxes(self, dc, xaxis, yaxis,
|
def _drawAxes(self, dc, xaxis, yaxis,
|
||||||
bb1, bb2, scale, shift, xticks, yticks):
|
bb1, bb2, scale, shift, xticks, yticks):
|
||||||
dc.SetPen(wx.wxPen(wx.wxNamedColour('BLACK'),1))
|
dc.SetPen(wx.Pen(wx.NamedColour('BLACK'),1))
|
||||||
if xaxis is not None:
|
if xaxis is not None:
|
||||||
lower, upper = xaxis
|
lower, upper = xaxis
|
||||||
text = 1
|
text = 1
|
||||||
for y, d in [(bb1[1], -3), (bb2[1], 3)]:
|
for y, d in [(bb1[1], -3), (bb2[1], 3)]:
|
||||||
p1 = scale*Numeric.array([lower, y])+shift
|
p1 = scale*Numeric.array([lower, y])+shift
|
||||||
p2 = scale*Numeric.array([upper, y])+shift
|
p2 = scale*Numeric.array([upper, y])+shift
|
||||||
dc.DrawLine(p1[0],p1[1],p2[0],p2[1])
|
dc.DrawLine((p1[0],p1[1]), (p2[0],p2[1]))
|
||||||
for x, label in xticks:
|
for x, label in xticks:
|
||||||
p = scale*Numeric.array([x, y])+shift
|
p = scale*Numeric.array([x, y])+shift
|
||||||
dc.DrawLine(p[0],p[1],p[0],p[1]+d)
|
dc.DrawLine((p[0],p[1]), (p[0],p[1]+d))
|
||||||
if text:
|
if text:
|
||||||
dc.DrawText(label,p[0],p[1])
|
dc.DrawText(label, (p[0],p[1]))
|
||||||
text = 0
|
text = 0
|
||||||
|
|
||||||
if yaxis is not None:
|
if yaxis is not None:
|
||||||
@@ -313,13 +333,13 @@ class PlotCanvas(wx.wxWindow):
|
|||||||
for x, d in [(bb1[0], -3), (bb2[0], 3)]:
|
for x, d in [(bb1[0], -3), (bb2[0], 3)]:
|
||||||
p1 = scale*Numeric.array([x, lower])+shift
|
p1 = scale*Numeric.array([x, lower])+shift
|
||||||
p2 = scale*Numeric.array([x, upper])+shift
|
p2 = scale*Numeric.array([x, upper])+shift
|
||||||
dc.DrawLine(p1[0],p1[1],p2[0],p2[1])
|
dc.DrawLine((p1[0],p1[1]), (p2[0],p2[1]))
|
||||||
for y, label in yticks:
|
for y, label in yticks:
|
||||||
p = scale*Numeric.array([x, y])+shift
|
p = scale*Numeric.array([x, y])+shift
|
||||||
dc.DrawLine(p[0],p[1],p[0]-d,p[1])
|
dc.DrawLine((p[0],p[1]), (p[0]-d,p[1]))
|
||||||
if text:
|
if text:
|
||||||
dc.DrawText(label,p[0]-dc.GetTextExtent(label)[0],
|
dc.DrawText(label,
|
||||||
p[1]-0.5*h)
|
(p[0]-dc.GetTextExtent(label)[0], p[1]-0.5*h))
|
||||||
text = 0
|
text = 0
|
||||||
|
|
||||||
def _ticks(self, lower, upper):
|
def _ticks(self, lower, upper):
|
||||||
@@ -389,33 +409,33 @@ if __name__ == '__main__':
|
|||||||
return PlotGraphics([markers1, lines, markers2])
|
return PlotGraphics([markers1, lines, markers2])
|
||||||
|
|
||||||
|
|
||||||
class AppFrame(wx.wxFrame):
|
class AppFrame(wx.Frame):
|
||||||
def __init__(self, parent, id, title):
|
def __init__(self, parent, id, title):
|
||||||
wx.wxFrame.__init__(self, parent, id, title,
|
wx.Frame.__init__(self, parent, id, title,
|
||||||
wx.wxPyDefaultPosition, wx.wxSize(400, 400))
|
wx.DefaultPosition, (400, 400))
|
||||||
|
|
||||||
# Now Create the menu bar and items
|
# Now Create the menu bar and items
|
||||||
self.mainmenu = wx.wxMenuBar()
|
self.mainmenu = wx.MenuBar()
|
||||||
|
|
||||||
menu = wx.wxMenu()
|
menu = wx.Menu()
|
||||||
menu.Append(200, '&Print...', 'Print the current plot')
|
menu.Append(200, '&Print...', 'Print the current plot')
|
||||||
wx.EVT_MENU(self, 200, self.OnFilePrint)
|
self.Bind(wx.EVT_MENU, self.OnFilePrint, id=200)
|
||||||
menu.Append(209, 'E&xit', 'Enough of this already!')
|
menu.Append(209, 'E&xit', 'Enough of this already!')
|
||||||
wx.EVT_MENU(self, 209, self.OnFileExit)
|
self.Bind(wx.EVT_MENU, self.OnFileExit, id=209)
|
||||||
self.mainmenu.Append(menu, '&File')
|
self.mainmenu.Append(menu, '&File')
|
||||||
|
|
||||||
menu = wx.wxMenu()
|
menu = wx.Menu()
|
||||||
menu.Append(210, '&Draw', 'Draw plots')
|
menu.Append(210, '&Draw', 'Draw plots')
|
||||||
wx.EVT_MENU(self,210,self.OnPlotDraw)
|
self.Bind(wx.EVT_MENU,self.OnPlotDraw, id=210)
|
||||||
menu.Append(211, '&Redraw', 'Redraw plots')
|
menu.Append(211, '&Redraw', 'Redraw plots')
|
||||||
wx.EVT_MENU(self,211,self.OnPlotRedraw)
|
self.Bind(wx.EVT_MENU,self.OnPlotRedraw, id=211)
|
||||||
menu.Append(212, '&Clear', 'Clear canvas')
|
menu.Append(212, '&Clear', 'Clear canvas')
|
||||||
wx.EVT_MENU(self,212,self.OnPlotClear)
|
self.Bind(wx.EVT_MENU,self.OnPlotClear, id=212)
|
||||||
self.mainmenu.Append(menu, '&Plot')
|
self.mainmenu.Append(menu, '&Plot')
|
||||||
|
|
||||||
menu = wx.wxMenu()
|
menu = wx.Menu()
|
||||||
menu.Append(220, '&About', 'About this thing...')
|
menu.Append(220, '&About', 'About this thing...')
|
||||||
wx.EVT_MENU(self, 220, self.OnHelpAbout)
|
self.Bind(wx.EVT_MENU, self.OnHelpAbout, id=220)
|
||||||
self.mainmenu.Append(menu, '&Help')
|
self.mainmenu.Append(menu, '&Help')
|
||||||
|
|
||||||
self.SetMenuBar(self.mainmenu)
|
self.SetMenuBar(self.mainmenu)
|
||||||
@@ -426,11 +446,11 @@ if __name__ == '__main__':
|
|||||||
self.client = PlotCanvas(self)
|
self.client = PlotCanvas(self)
|
||||||
|
|
||||||
def OnFilePrint(self, event):
|
def OnFilePrint(self, event):
|
||||||
d = wx.wxMessageDialog(self,
|
d = wx.MessageDialog(self,
|
||||||
"""As of this writing, printing support in wxPython is shaky at best.
|
"""As of this writing, printing support in wxPython is shaky at best.
|
||||||
Are you sure you want to do this?""", "Danger!", wx.wxYES_NO)
|
Are you sure you want to do this?""", "Danger!", wx.YES_NO)
|
||||||
if d.ShowModal() == wx.wxID_YES:
|
if d.ShowModal() == wx.ID_YES:
|
||||||
psdc = wx.wxPostScriptDC("out.ps", wx.True, self)
|
psdc = wx.PostScriptDC("out.ps", True, self)
|
||||||
self.client.redraw(psdc)
|
self.client.redraw(psdc)
|
||||||
|
|
||||||
def OnFileExit(self, event):
|
def OnFileExit(self, event):
|
||||||
@@ -444,21 +464,21 @@ Are you sure you want to do this?""", "Danger!", wx.wxYES_NO)
|
|||||||
|
|
||||||
def OnPlotClear(self,event):
|
def OnPlotClear(self,event):
|
||||||
self.client.last_draw = None
|
self.client.last_draw = None
|
||||||
dc = wx.wxClientDC(self.client)
|
dc = wx.ClientDC(self.client)
|
||||||
dc.Clear()
|
dc.Clear()
|
||||||
|
|
||||||
def OnHelpAbout(self, event):
|
def OnHelpAbout(self, event):
|
||||||
about = wx.wxMessageDialog(self, __doc__, "About...", wx.wxOK)
|
about = wx.MessageDialog(self, __doc__, "About...", wx.OK)
|
||||||
about.ShowModal()
|
about.ShowModal()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MyApp(wx.wxApp):
|
class MyApp(wx.App):
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
frame = AppFrame(wx.NULL, -1, "wxPlotCanvas")
|
frame = AppFrame(None, -1, "wxPlotCanvas")
|
||||||
frame.Show(wx.True)
|
frame.Show(True)
|
||||||
self.SetTopWindow(frame)
|
self.SetTopWindow(frame)
|
||||||
return wx.True
|
return True
|
||||||
|
|
||||||
|
|
||||||
app = MyApp(0)
|
app = MyApp(0)
|
||||||
|
|||||||
@@ -10,6 +10,10 @@
|
|||||||
# Copyright: (c) 1999 by Total Control Software
|
# Copyright: (c) 1999 by Total Control Software
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
# 12/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||||
|
#
|
||||||
|
# o Updated for V2.5 compatability
|
||||||
|
#
|
||||||
|
|
||||||
'''
|
'''
|
||||||
wxPython.lib.wxpTag
|
wxPython.lib.wxpTag
|
||||||
@@ -69,9 +73,9 @@ be converted from strings to alternate datatypes. They are:
|
|||||||
|
|
||||||
An example:
|
An example:
|
||||||
|
|
||||||
<wxp module="" class="wxButton">
|
<wxp module="wx" class="Button">
|
||||||
<param name="label" value="Click here">
|
<param name="label" value="Click here">
|
||||||
<param name="id" value="wxID_OK">
|
<param name="id" value="ID_OK">
|
||||||
</wxp>
|
</wxp>
|
||||||
|
|
||||||
Both the begining and ending WXP tags are required.
|
Both the begining and ending WXP tags are required.
|
||||||
@@ -85,12 +89,12 @@ server as is done with java applets.
|
|||||||
'''
|
'''
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
from wxPython.wx import *
|
|
||||||
from wxPython.html import *
|
|
||||||
import wxPython.wx
|
|
||||||
|
|
||||||
import types
|
import types
|
||||||
|
|
||||||
|
import wx
|
||||||
|
import wx.html
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
WXPTAG = 'WXP'
|
WXPTAG = 'WXP'
|
||||||
@@ -98,9 +102,9 @@ PARAMTAG = 'PARAM'
|
|||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
class wxpTagHandler(wxHtmlWinTagHandler):
|
class wxpTagHandler(wx.html.HtmlWinTagHandler):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
wxHtmlWinTagHandler.__init__(self)
|
wx.html.HtmlWinTagHandler.__init__(self)
|
||||||
self.ctx = None
|
self.ctx = None
|
||||||
|
|
||||||
def GetSupportedTags(self):
|
def GetSupportedTags(self):
|
||||||
@@ -128,7 +132,7 @@ class wxpTagHandler(wxHtmlWinTagHandler):
|
|||||||
if modName:
|
if modName:
|
||||||
self.ctx.classMod = _my_import(modName)
|
self.ctx.classMod = _my_import(modName)
|
||||||
else:
|
else:
|
||||||
self.ctx.classMod = wxPython.wx
|
self.ctx.classMod = wx
|
||||||
|
|
||||||
# find and verify the class
|
# find and verify the class
|
||||||
if not tag.HasParam('CLASS'):
|
if not tag.HasParam('CLASS'):
|
||||||
@@ -151,7 +155,7 @@ class wxpTagHandler(wxHtmlWinTagHandler):
|
|||||||
width = int(width)
|
width = int(width)
|
||||||
if tag.HasParam('HEIGHT'):
|
if tag.HasParam('HEIGHT'):
|
||||||
height = int(tag.GetParam('HEIGHT'))
|
height = int(tag.GetParam('HEIGHT'))
|
||||||
self.ctx.kwargs['size'] = wxSize(width, height)
|
self.ctx.kwargs['size'] = wx.Size(width, height)
|
||||||
|
|
||||||
# parse up to the closing tag, and gather any nested Param tags.
|
# parse up to the closing tag, and gather any nested Param tags.
|
||||||
self.ParseInner(tag)
|
self.ParseInner(tag)
|
||||||
@@ -165,7 +169,7 @@ class wxpTagHandler(wxHtmlWinTagHandler):
|
|||||||
obj.Show(True)
|
obj.Show(True)
|
||||||
|
|
||||||
# add it to the HtmlWindow
|
# add it to the HtmlWindow
|
||||||
self.GetParser().GetContainer().InsertCell(wxHtmlWidgetCell(obj, self.ctx.floatWidth))
|
self.GetParser().GetContainer().InsertCell(wx.html.HtmlWidgetCell(obj, self.ctx.floatWidth))
|
||||||
self.ctx = None
|
self.ctx = None
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@@ -198,13 +202,13 @@ class wxpTagHandler(wxHtmlWinTagHandler):
|
|||||||
except:
|
except:
|
||||||
value = saveVal
|
value = saveVal
|
||||||
|
|
||||||
# convert to wxColour
|
# convert to wx.Colour
|
||||||
elif value[0] == '#':
|
elif value[0] == '#':
|
||||||
try:
|
try:
|
||||||
red = int('0x'+value[1:3], 16)
|
red = int('0x'+value[1:3], 16)
|
||||||
green = int('0x'+value[3:5], 16)
|
green = int('0x'+value[3:5], 16)
|
||||||
blue = int('0x'+value[5:], 16)
|
blue = int('0x'+value[5:], 16)
|
||||||
value = wxColor(red, green, blue)
|
value = wx.Color(red, green, blue)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -267,4 +271,4 @@ def _param2dict(param):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
wxHtmlWinParser_AddTagHandler(wxpTagHandler)
|
wx.html.HtmlWinParser_AddTagHandler(wxpTagHandler)
|
||||||
|
|||||||
Reference in New Issue
Block a user