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
|
||||
# wx renamer.
|
||||
#
|
||||
# 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o A few changes to correct my own mistakes earlier :-).
|
||||
#
|
||||
|
||||
import string
|
||||
import sys
|
||||
@@ -577,9 +581,9 @@ with right-insert for ordinal:""")
|
||||
self.log.write(line)
|
||||
|
||||
def OnParensCheck( self, event ):
|
||||
self.intctrl1.SetCtrlParameters(useParensForNegatives=event.Checked())
|
||||
self.intctrl2.SetCtrlParameters(useParensForNegatives=event.Checked())
|
||||
self.floatctrl.SetCtrlParameters(useParensForNegatives=event.Checked())
|
||||
self.intctrl1.SetCtrlParameters(useParensForNegatives=event.IsChecked())
|
||||
self.intctrl2.SetCtrlParameters(useParensForNegatives=event.IsChecked())
|
||||
self.floatctrl.SetCtrlParameters(useParensForNegatives=event.IsChecked())
|
||||
|
||||
def OnIpAddrChange( self, event ):
|
||||
ipaddr = self.FindWindowById( event.GetId() )
|
||||
@@ -597,7 +601,7 @@ with right-insert for ordinal:""")
|
||||
formatcodes += 'r'
|
||||
mask = '###'
|
||||
else:
|
||||
choices = states
|
||||
choices = med.states
|
||||
mask = 'AA'
|
||||
formatcodes += '!'
|
||||
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
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
text = """\
|
||||
|
||||
Right-click on the panel (or Ctrl-click on the Mac) to show a popup
|
||||
menu. Then look at the code for this sample. Notice how the
|
||||
PopupMenu method is similar to the ShowModal method of a wxDialog in
|
||||
that it doesn't return until the popup menu has been dismissed. The
|
||||
event handlers for the popup menu items can either be attached to the
|
||||
menu itself, or to the window that invokes PopupMenu.
|
||||
Right-click on any bare area of this panel (or Ctrl-click on the Mac)
|
||||
to show a popup menu. Then look at the code for this sample. Notice
|
||||
how the PopupMenu method is similar to the ShowModal method of a
|
||||
wx.Dialog in that it doesn't return until the popup menu has been
|
||||
dismissed. The event handlers for the popup menu items can either be
|
||||
attached to the menu itself, or to the window that invokes PopupMenu.
|
||||
"""
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
class TestPanel(wx.Panel):
|
||||
def __init__(self, parent, log):
|
||||
self.log = log
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
box = wxBoxSizer(wxVERTICAL)
|
||||
wx.Panel.__init__(self, parent, -1)
|
||||
box = wx.BoxSizer(wx.VERTICAL)
|
||||
|
||||
# Make and layout the controls
|
||||
fs = self.GetFont().GetPointSize()
|
||||
bf = wxFont(fs+4, wxSWISS, wxNORMAL, wxBOLD)
|
||||
nf = wxFont(fs+2, wxSWISS, wxNORMAL, wxNORMAL)
|
||||
bf = wx.Font(fs+4, wx.SWISS, wx.NORMAL, wx.BOLD)
|
||||
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)
|
||||
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))
|
||||
|
||||
t = wxStaticText(self, -1, text)
|
||||
t = wx.StaticText(self, -1, text)
|
||||
t.SetFont(nf)
|
||||
box.Add(t, 0, wxCENTER|wxALL, 5)
|
||||
box.Add(t, 0, wx.CENTER|wx.ALL, 5)
|
||||
|
||||
self.SetSizer(box)
|
||||
|
||||
EVT_RIGHT_UP(self, self.OnRightClick)
|
||||
self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
|
||||
|
||||
|
||||
def OnRightClick(self, event):
|
||||
self.log.WriteText("OnRightClick\n")
|
||||
|
||||
# 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"):
|
||||
self.popupID1 = wxNewId()
|
||||
self.popupID2 = wxNewId()
|
||||
self.popupID3 = wxNewId()
|
||||
self.popupID4 = wxNewId()
|
||||
self.popupID5 = wxNewId()
|
||||
self.popupID6 = wxNewId()
|
||||
self.popupID7 = wxNewId()
|
||||
self.popupID8 = wxNewId()
|
||||
self.popupID9 = wxNewId()
|
||||
EVT_MENU(self, self.popupID1, self.OnPopupOne)
|
||||
EVT_MENU(self, self.popupID2, self.OnPopupTwo)
|
||||
EVT_MENU(self, self.popupID3, self.OnPopupThree)
|
||||
EVT_MENU(self, self.popupID4, self.OnPopupFour)
|
||||
EVT_MENU(self, self.popupID5, self.OnPopupFive)
|
||||
EVT_MENU(self, self.popupID6, self.OnPopupSix)
|
||||
EVT_MENU(self, self.popupID7, self.OnPopupSeven)
|
||||
EVT_MENU(self, self.popupID8, self.OnPopupEIght)
|
||||
EVT_MENU(self, self.popupID9, self.OnPopupNine)
|
||||
self.popupID1 = wx.NewId()
|
||||
self.popupID2 = wx.NewId()
|
||||
self.popupID3 = wx.NewId()
|
||||
self.popupID4 = wx.NewId()
|
||||
self.popupID5 = wx.NewId()
|
||||
self.popupID6 = wx.NewId()
|
||||
self.popupID7 = wx.NewId()
|
||||
self.popupID8 = wx.NewId()
|
||||
self.popupID9 = wx.NewId()
|
||||
|
||||
self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
|
||||
self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
|
||||
self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
|
||||
self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
|
||||
self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
|
||||
self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
|
||||
self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
|
||||
self.Bind(wx.EVT_MENU, self.OnPopupEight, id=self.popupID8)
|
||||
self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
|
||||
|
||||
# make a menu
|
||||
menu = wxMenu()
|
||||
menu = wx.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())
|
||||
menu.AppendItem(item)
|
||||
# add some other items
|
||||
@@ -80,7 +91,7 @@ class TestPanel(wxPanel):
|
||||
menu.Append(self.popupID5, "Five")
|
||||
menu.Append(self.popupID6, "Six")
|
||||
# make a submenu
|
||||
sm = wxMenu()
|
||||
sm = wx.Menu()
|
||||
sm.Append(self.popupID8, "sub item 1")
|
||||
sm.Append(self.popupID9, "sub item 1")
|
||||
menu.AppendMenu(self.popupID7, "Test Submenu", sm)
|
||||
@@ -113,7 +124,7 @@ class TestPanel(wxPanel):
|
||||
def OnPopupSeven(self, event):
|
||||
self.log.WriteText("Popup seven\n")
|
||||
|
||||
def OnPopupEIght(self, event):
|
||||
def OnPopupEight(self, event):
|
||||
self.log.WriteText("Popup eight\n")
|
||||
|
||||
def OnPopupNine(self, event):
|
||||
|
@@ -9,6 +9,10 @@
|
||||
# o printout.py is generating a snootful of errors all related to the
|
||||
# requirement for tuples on the base DC calls now
|
||||
#
|
||||
# 12/10/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o Issues corrected.
|
||||
#
|
||||
|
||||
import os
|
||||
|
||||
|
@@ -1,4 +1,10 @@
|
||||
<html>
|
||||
|
||||
<!-- 12/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
|
||||
o Updated for wx namespace.
|
||||
-->
|
||||
|
||||
<head>
|
||||
<title>wxHTML does wxPython!</title>
|
||||
</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:
|
||||
|
||||
<pre>
|
||||
<center><wxp class="wxButton" width="50%">
|
||||
<center><wxp module="wx" class="Button" width="50%">
|
||||
<param name="label" value="It works!">
|
||||
<param name="id" value="wxID_OK">
|
||||
<param name="id" value="ID_OK">
|
||||
</wxp></center>
|
||||
</pre>
|
||||
|
||||
<hr>
|
||||
|
||||
<center>
|
||||
<wxp class="wxButton" width="50%">
|
||||
<wxp module="wx" class="Button" width="50%">
|
||||
<param name="label" value="It works!">
|
||||
<param name="id" value="wxID_OK">
|
||||
<param name="id" value="ID_OK">
|
||||
</wxp>
|
||||
</center>
|
||||
|
||||
|
@@ -117,9 +117,10 @@ if __name__ == "__main__":
|
||||
## sys.stdout.close()
|
||||
## self.Destroy()
|
||||
|
||||
class MyApp(wx.App):
|
||||
|
||||
# Override the default output window and point it to the
|
||||
# custom class.
|
||||
#>>Todo: wx renamer didn't get this
|
||||
outputWindowClass = infoframe.wxPyInformationalMessagesFrame
|
||||
|
||||
def OnInit(self):
|
||||
@@ -141,7 +142,6 @@ if __name__ == "__main__":
|
||||
self.SetTopWindow(frame)
|
||||
|
||||
# Associate the frame with stdout.
|
||||
#>>Todo: wx renamer didn't get this
|
||||
if isinstance(sys.stdout, infoframe.wxPyInformationalMessagesFrame):
|
||||
sys.stdout.SetParent(frame)
|
||||
|
||||
|
@@ -2,17 +2,20 @@
|
||||
#
|
||||
# o Updated for wx namespace
|
||||
#
|
||||
# 12/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o got the wxpTag stuff working right.
|
||||
#
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import wx
|
||||
import wx.html as html
|
||||
import wx.lib.wxpTag
|
||||
|
||||
from Main import opj
|
||||
|
||||
##wxTrap()
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
# 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 new event binders.
|
||||
#
|
||||
# 12/08/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o All issues corrected
|
||||
#
|
||||
|
||||
import wx
|
||||
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.OnSetAllowLong, self.allow_long)
|
||||
|
||||
# Once the intctrl library is updated, this should be too.
|
||||
intctrl.EVT_INT(self, self.min.GetId(), self.SetTargetMinMax)
|
||||
intctrl.EVT_INT(self, self.max.GetId(), self.SetTargetMinMax)
|
||||
intctrl.EVT_INT(self, self.target_ctl.GetId(), self.OnTargetChange)
|
||||
self.Bind(intctrl.EVT_INT, self.SetTargetMinMax, self.min)
|
||||
self.Bind(intctrl.EVT_INT, self.SetTargetMinMax, self.max)
|
||||
self.Bind(intctrl.EVT_INT, self.OnTargetChange, self.target_ctl)
|
||||
|
||||
|
||||
def OnSetMin( self, event ):
|
||||
|
@@ -19,6 +19,11 @@
|
||||
# o listctrl mixin needs wx renamer.
|
||||
# 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.lib.mixins.listctrl as listmix
|
||||
@@ -263,6 +268,7 @@ class TestListCtrlPanel(wx.Panel, listmix.wxColumnSorterMixin):
|
||||
|
||||
def OnColClick(self, event):
|
||||
self.log.WriteText("OnColClick: %d\n" % event.GetColumn())
|
||||
event.Skip()
|
||||
|
||||
def OnColRightClick(self, event):
|
||||
item = self.list.GetColumn(event.GetColumn())
|
||||
|
@@ -6,6 +6,10 @@
|
||||
#
|
||||
# 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 sys
|
||||
@@ -148,15 +152,15 @@ value entry ctrl:""")
|
||||
panel.Move( (50,10) )
|
||||
self.panel = panel
|
||||
|
||||
mnum.EVT_MASKEDNUM( self, self.integerwidth.GetId(), self.OnSetIntWidth )
|
||||
mnum.EVT_MASKEDNUM( self, self.fractionwidth.GetId(), self.OnSetFractionWidth )
|
||||
self.Bind(mnum.EVT_MASKEDNUM, self.OnSetIntWidth, self.integerwidth )
|
||||
self.Bind(mnum.EVT_MASKEDNUM, self.OnSetFractionWidth, self.fractionwidth )
|
||||
self.Bind(wx.EVT_TEXT, self.OnSetGroupChar, self.groupchar )
|
||||
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.OnSetMax, self.set_max )
|
||||
mnum.EVT_MASKEDNUM( self, self.min.GetId(), self.SetTargetMinMax )
|
||||
mnum.EVT_MASKEDNUM( self, self.max.GetId(), self.SetTargetMinMax )
|
||||
self.Bind(mnum.EVT_MASKEDNUM, self.SetTargetMinMax, self.min )
|
||||
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.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.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 )
|
||||
|
||||
|
||||
|
@@ -8,6 +8,10 @@
|
||||
# o There appears to be a problem with the image that
|
||||
# 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.lib.multisash as sash
|
||||
@@ -38,6 +42,10 @@ returned by GetSaveData, as it is just another object in the dictionary.
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class TestWindow(stc.StyledTextCtrl):
|
||||
|
||||
# shared document reference
|
||||
doc = None
|
||||
|
||||
def __init__(self, parent):
|
||||
stc.StyledTextCtrl.__init__(self, parent, -1, style=wx.NO_BORDER)
|
||||
self.SetMarginWidth(1,0)
|
||||
@@ -52,17 +60,16 @@ class TestWindow(stc.StyledTextCtrl):
|
||||
wx.Font(fSize, wx.MODERN, wx.NORMAL, wx.NORMAL)
|
||||
)
|
||||
|
||||
if self.doc:
|
||||
self.SetDocPointer(self.doc)
|
||||
else:
|
||||
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
|
||||
# a new sash is created. The class's constructor needs 1 parameter
|
||||
# which is the parent of the window
|
||||
self.multi.SetDefaultChildClass(TestWindow)
|
||||
def SutdownDemo(self):
|
||||
# Reset doc reference in case this demo is run again
|
||||
TestWindow.doc = None
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
@@ -78,9 +85,6 @@ def runTest(frame, nb, log):
|
||||
|
||||
return multi
|
||||
|
||||
# win = TestPanel(nb, log)
|
||||
# return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
@@ -2,9 +2,9 @@
|
||||
#
|
||||
# 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
|
||||
@@ -54,7 +54,7 @@ wxPyColourChooser was written and is maintained by:
|
||||
Michael Gilfix <mgilfix@eecs.tufts.edu>
|
||||
|
||||
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
|
||||
it my way at: mgilfix@eecs.tufts.edu
|
||||
"""
|
||||
|
@@ -6,6 +6,11 @@
|
||||
#
|
||||
# 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 |
|
||||
|
@@ -6,6 +6,10 @@
|
||||
#
|
||||
# o scrolledpanel lib needs wx update
|
||||
#
|
||||
# 12/11/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o lib updated, all is well.
|
||||
#
|
||||
|
||||
import wx
|
||||
import wx.lib.scrolledpanel as scrolled
|
||||
|
@@ -7,6 +7,10 @@
|
||||
# o wx renamer needed for timectrl lib
|
||||
# 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.lib.timectrl as timectl
|
||||
@@ -146,17 +150,14 @@ class TestPanel( scrolled.wxScrolledPanel ):
|
||||
self.SetupScrolling()
|
||||
|
||||
self.Bind(wx.EVT_BUTTON, self.OnButtonClick, buttonChange )
|
||||
timectl.EVT_TIMEUPDATE( self, self.time12.GetId(), self.OnTimeChange )
|
||||
timectl.EVT_TIMEUPDATE( self, self.time24.GetId(), self.OnTimeChange )
|
||||
timectl.EVT_TIMEUPDATE( self, self.spinless_ctrl.GetId(), self.OnTimeChange )
|
||||
|
||||
|
||||
self.Bind(timectl.EVT_TIMEUPDATE, self.OnTimeChange, self.time12 )
|
||||
self.Bind(timectl.EVT_TIMEUPDATE, self.OnTimeChange, self.time24 )
|
||||
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.SetTargetMinMax, self.limit_check )
|
||||
timectl.EVT_TIMEUPDATE( self, self.min.GetId(), self.SetTargetMinMax )
|
||||
timectl.EVT_TIMEUPDATE( self, self.max.GetId(), self.SetTargetMinMax )
|
||||
timectl.EVT_TIMEUPDATE( self, self.target_ctrl.GetId(), self.OnTimeChange )
|
||||
|
||||
self.Bind(timectl.EVT_TIMEUPDATE, self.SetTargetMinMax, self.min )
|
||||
self.Bind(timectl.EVT_TIMEUPDATE, self.SetTargetMinMax, self.max )
|
||||
self.Bind(timectl.EVT_TIMEUPDATE, self.OnTimeChange, self.target_ctrl )
|
||||
|
||||
|
||||
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...
|
||||
@@ -5,28 +9,27 @@ Christopher J. Fama
|
||||
"""
|
||||
|
||||
|
||||
import wx
|
||||
import wx.html as html
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.html import *
|
||||
|
||||
class wxPyClickableHtmlWindow(wxHtmlWindow):
|
||||
class wxPyClickableHtmlWindow(html.HtmlWindow):
|
||||
"""
|
||||
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
|
||||
to the clipboard.
|
||||
"""
|
||||
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):
|
||||
self.link = wxTextDataObject(link.GetHref())
|
||||
self.link = wx.TextDataObject(link.GetHref())
|
||||
if link.GetEvent().ShiftDown():
|
||||
if wxTheClipboard.Open():
|
||||
wxTheClipboard.SetData(self.link)
|
||||
wxTheClipboard.Close()
|
||||
if wx.TheClipboard.Open():
|
||||
wx.TheClipboard.SetData(self.link)
|
||||
wx.TheClipboard.Close()
|
||||
else:
|
||||
dlg = wxMessageDialog(self,"Couldn't open clipboard!\n",wxOK)
|
||||
wxBell()
|
||||
dlg = wx.MessageDialog(self,"Couldn't open clipboard!\n",wx.OK)
|
||||
wx.Bell()
|
||||
dlg.ShowModal()
|
||||
dlg.Destroy()
|
||||
else:
|
||||
|
@@ -8,8 +8,13 @@
|
||||
# Copyright: (c) 2000 by Total Control Software
|
||||
# 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:
|
||||
import win32ui
|
||||
@@ -58,7 +63,7 @@ def MakeActiveXClass(CoClass, eventClass=None, eventObj=None):
|
||||
|
||||
# determine the base classes
|
||||
axEventClass = CoClass.default_source
|
||||
baseClasses = [wxWindow, pywin.mfc.activex.Control, CoClass, axEventClass]
|
||||
baseClasses = [wx.Window, pywin.mfc.activex.Control, CoClass, axEventClass]
|
||||
if eventClass:
|
||||
baseClasses.append(eventClass)
|
||||
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
|
||||
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
|
||||
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()
|
||||
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_)
|
||||
|
||||
# hook some wx events
|
||||
EVT_SIZE(self, self.axw_OnSize)
|
||||
#EVT_ERASE_BACKGROUND(self, self.axw_OEB)
|
||||
self.Bind(wx.EVT_SIZE, self.axw_OnSize)
|
||||
|
||||
|
||||
def axw__getattr__(self, attr):
|
||||
@@ -133,7 +138,6 @@ def axw_Cleanup(self):
|
||||
del self._wnd
|
||||
self.close()
|
||||
pass
|
||||
## anything else???
|
||||
|
||||
|
||||
|
||||
|
@@ -9,23 +9,31 @@
|
||||
# Copyright: (c) 2003 by Total Control Software
|
||||
# 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
|
||||
from wxPython.wx import *
|
||||
import math
|
||||
import string
|
||||
import sys
|
||||
import time
|
||||
|
||||
import wx
|
||||
|
||||
|
||||
class AnalogClockWindow(wxWindow):
|
||||
class AnalogClockWindow(wx.Window):
|
||||
"""A simple analog clock window"""
|
||||
|
||||
TICKS_NONE = 0
|
||||
TICKS_SQUARE = 1
|
||||
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"):
|
||||
|
||||
# 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...
|
||||
self.minuteMarks = 60
|
||||
@@ -37,20 +45,20 @@ class AnalogClockWindow(wxWindow):
|
||||
# Make an initial bitmap for the face, it will be updated and
|
||||
# painted at the first EVT_SIZE event.
|
||||
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
|
||||
# face. Update every half second to ensure that there is at
|
||||
# least one true update during each realtime second.
|
||||
self.timer = wxTimer(self)
|
||||
self.timer = wx.Timer(self)
|
||||
self.timer.Start(500)
|
||||
|
||||
# Set event handlers...
|
||||
EVT_PAINT(self, self.OnPaint)
|
||||
EVT_ERASE_BACKGROUND(self, lambda x: None)
|
||||
EVT_SIZE(self, self.OnSize)
|
||||
EVT_TIMER(self, -1, self.OnTimerExpire)
|
||||
EVT_WINDOW_DESTROY(self, self.OnQuit)
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None)
|
||||
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||
self.Bind(wx.EVT_TIMER, self.OnTimerExpire)
|
||||
self.Bind(wx.EVT_WINDOW_DESTROY, self.OnQuit)
|
||||
|
||||
|
||||
def SetTickMarkStyle(self, style):
|
||||
@@ -77,7 +85,6 @@ class AnalogClockWindow(wxWindow):
|
||||
self.SetForegroundColour(c) # the hands just use the foreground colour
|
||||
|
||||
|
||||
|
||||
# Using the current settings, render the points and line endings for the
|
||||
# circle inside the specified device context. In this case, the DC is
|
||||
# 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 same size as the Window
|
||||
size = self.GetClientSize()
|
||||
self.faceBitmap = wxEmptyBitmap(size.width, size.height)
|
||||
self.faceBitmap = wx.EmptyBitmap(size.width, size.height)
|
||||
self.DrawFace()
|
||||
|
||||
|
||||
def OnPaint(self, event):
|
||||
self.DrawHands(wxPaintDC(self))
|
||||
self.DrawHands(wx.PaintDC(self))
|
||||
|
||||
|
||||
def OnQuit(self, event):
|
||||
@@ -100,7 +107,7 @@ class AnalogClockWindow(wxWindow):
|
||||
|
||||
|
||||
def OnTimerExpire(self, event):
|
||||
self.DrawHands(wxClientDC(self))
|
||||
self.DrawHands(wx.ClientDC(self))
|
||||
|
||||
|
||||
def DrawHands(self, drawDC):
|
||||
@@ -124,23 +131,23 @@ class AnalogClockWindow(wxWindow):
|
||||
secondsX, secondsY = (x + centerX), (centerY - y)
|
||||
|
||||
# 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))
|
||||
|
||||
# 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))
|
||||
|
||||
# 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))
|
||||
|
||||
|
||||
# Draw the specified set of line marks inside the clock face for the
|
||||
# hours or minutes...
|
||||
def DrawFace(self):
|
||||
backgroundBrush = wxBrush(self.GetBackgroundColour(), wxSOLID)
|
||||
drawDC = wxMemoryDC()
|
||||
backgroundBrush = wx.Brush(self.GetBackgroundColour(), wx.SOLID)
|
||||
drawDC = wx.MemoryDC()
|
||||
drawDC.SelectObject(self.faceBitmap)
|
||||
drawDC.SetBackground(backgroundBrush)
|
||||
drawDC.Clear()
|
||||
@@ -160,8 +167,9 @@ class AnalogClockWindow(wxWindow):
|
||||
scaledX = x + centerX - markSize/2
|
||||
scaledY = centerY - y - markSize/2
|
||||
|
||||
drawDC.SetBrush(wxBrush(self.tickMarksBrushC, wxSOLID))
|
||||
drawDC.SetPen(wxPen(self.tickMarksPenC, 1, wxSOLID))
|
||||
drawDC.SetBrush(wx.Brush(self.tickMarksBrushC, wx.SOLID))
|
||||
drawDC.SetPen(wx.Pen(self.tickMarksPenC, 1, wx.SOLID))
|
||||
|
||||
if self.tickMarkStyle != self.TICKS_NONE:
|
||||
if self.tickMarkStyle == self.TICKS_CIRCLE:
|
||||
drawDC.DrawEllipse((scaledX - 2, scaledY), (markSize, markSize))
|
||||
@@ -174,25 +182,25 @@ class AnalogClockWindow(wxWindow):
|
||||
radiansPerDegree = math.pi / 180
|
||||
pointX = int(round(radius * math.sin(angle * radiansPerDegree)))
|
||||
pointY = int(round(radius * math.cos(angle * radiansPerDegree)))
|
||||
return wxPoint(pointX, pointY)
|
||||
return wx.Point(pointX, pointY)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
class App(wxApp):
|
||||
class App(wx.App):
|
||||
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.SetTickMarkColours("RED")
|
||||
clock.SetHandsColour("WHITE")
|
||||
clock.SetBackgroundColour("BLUE")
|
||||
|
||||
frame.Centre(wxBOTH)
|
||||
frame.Centre(wx.BOTH)
|
||||
frame.Show(True)
|
||||
self.SetTopWindow(frame)
|
||||
return true
|
||||
return True
|
||||
|
||||
theApp = App(0)
|
||||
theApp.MainLoop()
|
||||
|
@@ -10,12 +10,16 @@
|
||||
# Copyright: (c) 2000 by Total Control Software
|
||||
# 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, \
|
||||
wxHeight, wxWidth
|
||||
import wx
|
||||
|
||||
class LayoutAnchors(wxLayoutConstraints):
|
||||
""" A class that implements Delphi's Anchors with wxLayoutConstraints.
|
||||
class LayoutAnchors(wx.LayoutConstraints):
|
||||
""" A class that implements Delphi's Anchors with wx.LayoutConstraints.
|
||||
|
||||
Anchored sides maintain the distance from the edge of the
|
||||
control to the same edge of the parent.
|
||||
@@ -57,21 +61,21 @@ class LayoutAnchors(wxLayoutConstraints):
|
||||
* = anchored edge
|
||||
"""
|
||||
def __init__(self, control, left=1, top=1, right=0, bottom=0):
|
||||
wxLayoutConstraints.__init__(self)
|
||||
wx.LayoutConstraints.__init__(self)
|
||||
parent = control.GetParent()
|
||||
if not parent: return
|
||||
|
||||
pPos, pSize = parent.GetPosition(), parent.GetClientSize()
|
||||
cPos, cSize = control.GetPosition(), control.GetSize()
|
||||
|
||||
self.setConstraintSides(self.left, wxLeft, left,
|
||||
self.right, wxRight, right,
|
||||
self.width, wxWidth, self.centreX,
|
||||
self.setConstraintSides(self.left, wx.Left, left,
|
||||
self.right, wx.Right, right,
|
||||
self.width, wx.Width, self.centreX,
|
||||
cPos.x, cSize.width, pSize.width, parent)
|
||||
|
||||
self.setConstraintSides(self.top, wxTop, top,
|
||||
self.bottom, wxBottom, bottom,
|
||||
self.height, wxHeight, self.centreY,
|
||||
self.setConstraintSides(self.top, wx.Top, top,
|
||||
self.bottom, wx.Bottom, bottom,
|
||||
self.height, wx.Height, self.centreY,
|
||||
cPos.y, cSize.height, pSize.height, parent)
|
||||
|
||||
def setConstraintSides(self, side1, side1Edge, side1Anchor,
|
||||
@@ -80,12 +84,16 @@ class LayoutAnchors(wxLayoutConstraints):
|
||||
cPos, cSize, pSize, parent):
|
||||
if side2Anchor:
|
||||
side2.SameAs(parent, side2Edge, pSize - (cPos + cSize))
|
||||
|
||||
if side1Anchor:
|
||||
side1.SameAs(parent, side1Edge, cPos)
|
||||
|
||||
if not side2Anchor:
|
||||
size.AsIs()
|
||||
else:
|
||||
size.AsIs()
|
||||
|
||||
if not side2Anchor:
|
||||
centre.PercentOf(parent, sizeEdge,
|
||||
int(((cPos + cSize / 2.0) / pSize)*100))
|
||||
|
||||
|
@@ -10,6 +10,11 @@
|
||||
# Copyright: (c) 1999 by Total Control Software
|
||||
# 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
|
||||
|
@@ -9,19 +9,44 @@
|
||||
# Date: Nov 26, 2001
|
||||
# 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 *
|
||||
|
||||
|
||||
CalDays = [6, 0, 1, 2, 3, 4, 5]
|
||||
AbrWeekday = {6:"Sun", 0:"Mon", 1:"Tue", 2:"Wed", 3:"Thu", 4:"Fri", 5:"Sat"}
|
||||
_MIDSIZE = 180
|
||||
|
||||
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():
|
||||
monthlist = []
|
||||
@@ -31,6 +56,8 @@ def GetMonthList():
|
||||
monthlist.append(name)
|
||||
return monthlist
|
||||
|
||||
# calendar drawing routing
|
||||
|
||||
class CalDraw:
|
||||
def __init__(self, parent):
|
||||
self.pwidth = 1
|
||||
@@ -47,8 +74,8 @@ class CalDraw:
|
||||
self.num_size = 12 # default size of calendar if no auto size
|
||||
self.max_num_size = 12 # maximum size for calendar number
|
||||
|
||||
self.num_align_horz = wxALIGN_CENTRE # alignment of numbers
|
||||
self.num_align_vert = wxALIGN_CENTRE
|
||||
self.num_align_horz = wx.ALIGN_CENTRE # alignment of numbers
|
||||
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_vert = 0
|
||||
|
||||
@@ -67,8 +94,8 @@ class CalDraw:
|
||||
self.week_font_color = 'BLACK' # font colors
|
||||
self.day_font_color = 'BLACK'
|
||||
|
||||
self.font = wxSWISS
|
||||
self.bold = wxNORMAL
|
||||
self.font = wx.SWISS
|
||||
self.bold = wx.NORMAL
|
||||
|
||||
self.hide_title = False
|
||||
self.hide_grid = False
|
||||
@@ -84,8 +111,8 @@ class CalDraw:
|
||||
self.week_color = week_color
|
||||
|
||||
def SetSize(self, size):
|
||||
self.set_sizew = size.width
|
||||
self.set_sizeh = size.height
|
||||
self.set_sizew = size[0]
|
||||
self.set_sizeh = size[1]
|
||||
|
||||
def InitValues(self): # default dimensions of various elements of the calendar
|
||||
self.rg = {}
|
||||
@@ -122,6 +149,7 @@ class CalDraw:
|
||||
self.InitScale()
|
||||
|
||||
self.DrawBorder()
|
||||
|
||||
if self.hide_title is False:
|
||||
self.DrawMonth()
|
||||
|
||||
@@ -142,19 +170,22 @@ class CalDraw:
|
||||
def AddSelect(self, list, cfont=None, cbackgrd = None):
|
||||
if cfont is None:
|
||||
cfont = self.sel_color # font digit color
|
||||
|
||||
if cbackgrd is None:
|
||||
cbackgrd = self.high_color # select background color
|
||||
|
||||
for val in list:
|
||||
self.cal_sel[val] = (cfont, cbackgrd)
|
||||
|
||||
def DrawBorder(self): # draw border around the outside of the main display rectangle
|
||||
brush = wxBrush(wxNamedColour(self.back_color), wxSOLID)
|
||||
# draw border around the outside of the main display rectangle
|
||||
def DrawBorder(self):
|
||||
brush = wx.Brush(wx.NamedColour(self.back_color), wx.SOLID)
|
||||
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:
|
||||
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)
|
||||
|
||||
def DrawNumVal(self):
|
||||
@@ -172,6 +203,7 @@ class CalDraw:
|
||||
t = Date(year, month, day)
|
||||
dow = self.dow = t.day_of_week # start day in month
|
||||
dim = self.dim = t.days_in_month # number of days in month
|
||||
|
||||
if self.cal_type == "NORMAL":
|
||||
start_pos = dow+1
|
||||
else:
|
||||
@@ -182,17 +214,21 @@ class CalDraw:
|
||||
self.cal = []
|
||||
for i in range(start_pos):
|
||||
self.cal.append('')
|
||||
|
||||
i = 1
|
||||
while i <= dim:
|
||||
self.cal.append(str(i))
|
||||
i = i + 1
|
||||
|
||||
return start_pos
|
||||
|
||||
def SetWeekEnd(self, font_color='BLACK', backgrd = 'LIGHT GREY'):
|
||||
date = 6 - int(self.dow) # start day of first saturday
|
||||
|
||||
while date <= self.dim:
|
||||
self.cal_sel[date] = (font_color, backgrd) # Saturday
|
||||
date = date + 1
|
||||
|
||||
if date <= self.dim:
|
||||
self.cal_sel[date] = (font_color, backgrd) # Sunday
|
||||
date = date + 6
|
||||
@@ -203,9 +239,10 @@ class CalDraw:
|
||||
cnt = 0
|
||||
for y in self.gridy[1:-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
|
||||
cnt = cnt + 1
|
||||
|
||||
return self.rg
|
||||
|
||||
def GetCal(self):
|
||||
@@ -221,7 +258,7 @@ class CalDraw:
|
||||
if self.sizeh < _MIDSIZE:
|
||||
sizef = 10
|
||||
|
||||
f = wxFont(sizef, self.font, wxNORMAL, self.bold)
|
||||
f = wx.Font(sizef, self.font, wx.NORMAL, self.bold)
|
||||
self.DC.SetFont(f)
|
||||
|
||||
tw,th = self.DC.GetTextExtent(month)
|
||||
@@ -234,7 +271,7 @@ class CalDraw:
|
||||
|
||||
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.DrawText(year, (self.cx_st + adjust, self.cy_st + th))
|
||||
|
||||
@@ -243,7 +280,8 @@ class CalDraw:
|
||||
height = self.gridy[1] - self.gridy[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:
|
||||
test_size = self.max_week_size # max size
|
||||
test_day = ' Sun '
|
||||
@@ -251,21 +289,23 @@ class CalDraw:
|
||||
f.SetPointSize(test_size)
|
||||
self.DC.SetFont(f)
|
||||
tw,th = self.DC.GetTextExtent(test_day)
|
||||
|
||||
if tw < width and th < height:
|
||||
break
|
||||
|
||||
test_size = test_size - 1
|
||||
else:
|
||||
f.SetPointSize(self.week_size) # set fixed size
|
||||
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_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.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":
|
||||
cal_days = CalDays
|
||||
@@ -274,8 +314,10 @@ class CalDraw:
|
||||
|
||||
for val in cal_days:
|
||||
day = AbrWeekday[val]
|
||||
|
||||
if self.sizew < 200:
|
||||
day = day[0]
|
||||
|
||||
dw,dh = self.DC.GetTextExtent(day)
|
||||
diffx = (width-dw)/2
|
||||
diffy = (height-dh)/2
|
||||
@@ -287,14 +329,17 @@ class CalDraw:
|
||||
cnt_x = cnt_x + 1
|
||||
|
||||
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:
|
||||
test_size = self.max_num_size # max size
|
||||
test_day = ' 99 '
|
||||
|
||||
while test_size > 2:
|
||||
f.SetPointSize(test_size)
|
||||
self.DC.SetFont(f)
|
||||
tw,th = self.DC.GetTextExtent(test_day)
|
||||
|
||||
if tw < self.dl_w and th < self.dl_h:
|
||||
sizef = test_size
|
||||
break
|
||||
@@ -315,22 +360,23 @@ class CalDraw:
|
||||
except:
|
||||
num_color = self.day_font_color
|
||||
|
||||
self.DC.SetTextForeground(wxNamedColour(num_color))
|
||||
self.DC.SetTextForeground(wx.NamedColour(num_color))
|
||||
self.DC.SetFont(f)
|
||||
|
||||
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
|
||||
elif self.num_align_horz == wxALIGN_RIGHT:
|
||||
elif self.num_align_horz == wx.ALIGN_RIGHT:
|
||||
adj_h = self.dl_w - tw
|
||||
else:
|
||||
adj_h = 0 # left alignment
|
||||
|
||||
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
|
||||
elif self.num_align_horz == wxALIGN_RIGHT:
|
||||
elif self.num_align_horz == wx.ALIGN_RIGHT:
|
||||
adj_v = self.dl_h - th
|
||||
else:
|
||||
adj_v = 0 # left alignment
|
||||
@@ -338,6 +384,7 @@ class CalDraw:
|
||||
adj_v = adj_v + self.num_indent_vert
|
||||
|
||||
self.DC.DrawText(val, (x+adj_h, y+adj_v))
|
||||
|
||||
if cnt_x < 6:
|
||||
cnt_x = cnt_x + 1
|
||||
else:
|
||||
@@ -358,19 +405,20 @@ class CalDraw:
|
||||
def DrawSel(self): # highlighted selected days
|
||||
for key in self.cal_sel.keys():
|
||||
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)
|
||||
|
||||
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:
|
||||
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
|
||||
rect = self.rg[nkey]
|
||||
self.DC.DrawRectangle((rect.x, rect.y), (rect.width+1, rect.height+1))
|
||||
|
||||
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.gridy = []
|
||||
@@ -380,8 +428,8 @@ class CalDraw:
|
||||
|
||||
x1 = self.x_st
|
||||
y1 = self.y_st
|
||||
|
||||
y2 = y1 + self.cheight
|
||||
|
||||
for i in range(8):
|
||||
if self.hide_grid is False:
|
||||
self.DC.DrawLine((x1, y1), (x1, y2))
|
||||
@@ -390,12 +438,14 @@ class CalDraw:
|
||||
|
||||
x1 = self.x_st
|
||||
y1 = self.y_st
|
||||
|
||||
x2 = x1 + self.cwidth
|
||||
|
||||
for i in range(8):
|
||||
if self.hide_grid is False:
|
||||
self.DC.DrawLine((x1, y1), (x2, y1))
|
||||
|
||||
self.gridy.append(y1)
|
||||
|
||||
if i == 0:
|
||||
y1 = y1 + self.dl_th
|
||||
else:
|
||||
@@ -413,16 +463,17 @@ class PrtCalDraw(CalDraw):
|
||||
self.set_x_mrg = 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.pheight = int(pheight)/self.scale
|
||||
|
||||
def SetPreview(self, preview):
|
||||
self.preview = preview
|
||||
|
||||
class wxCalendar(wxWindow):
|
||||
def __init__(self, parent, id, pos=wxDefaultPosition, size=wxDefaultSize):
|
||||
wxWindow.__init__(self, parent, id, pos, size)
|
||||
class wxCalendar(wx.Window):
|
||||
def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize):
|
||||
wx.Window.__init__(self, parent, id, pos, size)
|
||||
|
||||
# set the calendar control attributes
|
||||
|
||||
@@ -439,11 +490,11 @@ class wxCalendar(wxWindow):
|
||||
|
||||
self.select_list = []
|
||||
|
||||
self.SetBackgroundColour(wxNamedColour(self.back_color))
|
||||
self.Connect(-1, -1, wxEVT_LEFT_DOWN, self.OnLeftEvent)
|
||||
self.Connect(-1, -1, wxEVT_LEFT_DCLICK, self.OnLeftDEvent)
|
||||
self.Connect(-1, -1, wxEVT_RIGHT_DOWN, self.OnRightEvent)
|
||||
self.Connect(-1, -1, wxEVT_RIGHT_DCLICK, self.OnRightDEvent)
|
||||
self.SetBackgroundColour(self.back_color)
|
||||
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftEvent)
|
||||
self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDEvent)
|
||||
self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightEvent)
|
||||
self.Bind(wx.EVT_RIGHT_DCLICK, self.OnRightDEvent)
|
||||
|
||||
self.sel_key = None # last used by
|
||||
self.sel_lst = [] # highlighted selected days
|
||||
@@ -453,8 +504,8 @@ class wxCalendar(wxWindow):
|
||||
self.size = None
|
||||
self.set_day = None
|
||||
|
||||
EVT_PAINT(self, self.OnPaint)
|
||||
EVT_SIZE(self, self.OnSize)
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||
|
||||
# control some of the main calendar attributes
|
||||
|
||||
@@ -574,7 +625,8 @@ class wxCalendar(wxWindow):
|
||||
if self.day == "":
|
||||
return None
|
||||
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.shiftkey = self.shiftkey
|
||||
evt.ctrlkey = self.ctrlkey
|
||||
@@ -588,10 +640,11 @@ class wxCalendar(wxWindow):
|
||||
def GetDayHit(self, mx, my):
|
||||
for key in self.rg.keys():
|
||||
val = self.rg[key]
|
||||
ms_rect = wxRect(mx, my, 1, 1)
|
||||
if wxIntersectRect(ms_rect, val) is not None:
|
||||
ms_rect = wx.Rect(mx, my, 1, 1)
|
||||
if wx.IntersectRect(ms_rect, val) is not None:
|
||||
result = self.TestDay(key)
|
||||
return result
|
||||
|
||||
return None
|
||||
|
||||
# calendar drawing
|
||||
@@ -615,11 +668,11 @@ class wxCalendar(wxWindow):
|
||||
evt.Skip()
|
||||
|
||||
def OnPaint(self, event):
|
||||
DC = wxPaintDC(self)
|
||||
DC = wx.PaintDC(self)
|
||||
self.DoDrawing(DC)
|
||||
|
||||
def DoDrawing(self, DC):
|
||||
DC = wxPaintDC(self)
|
||||
DC = wx.PaintDC(self)
|
||||
DC.BeginDrawing()
|
||||
|
||||
self.cal = cal = CalDraw(self)
|
||||
@@ -644,6 +697,7 @@ class wxCalendar(wxWindow):
|
||||
|
||||
cal.SetSize(size)
|
||||
cal.SetCal(self.year, self.month)
|
||||
|
||||
for val in self.select_list:
|
||||
cal.AddSelect(val[0], val[1], val[2])
|
||||
|
||||
@@ -656,6 +710,7 @@ class wxCalendar(wxWindow):
|
||||
|
||||
if self.set_day != None:
|
||||
self.SetDay(self.set_day)
|
||||
|
||||
DC.EndDrawing()
|
||||
|
||||
# draw the selection rectangle
|
||||
@@ -663,12 +718,13 @@ class wxCalendar(wxWindow):
|
||||
def DrawRect(self, key, color = 'BLACK', width = 0):
|
||||
if key == None:
|
||||
return
|
||||
DC = wxClientDC(self)
|
||||
|
||||
DC = wx.ClientDC(self)
|
||||
DC.BeginDrawing()
|
||||
|
||||
brush = wxBrush(wxColour(0, 0xFF, 0x80), wxTRANSPARENT)
|
||||
brush = wx.Brush(wx.Colour(0, 0xFF, 0x80), wx.TRANSPARENT)
|
||||
DC.SetBrush(brush)
|
||||
DC.SetPen(wxPen(wxNamedColour(color), width))
|
||||
DC.SetPen(wx.Pen(wx.NamedColour(color), width))
|
||||
|
||||
rect = self.rg[key]
|
||||
DC.DrawRectangle((rect.x, rect.y), (rect.width+1, rect.height+1))
|
||||
@@ -684,6 +740,7 @@ class wxCalendar(wxWindow):
|
||||
def SelectDay(self, key):
|
||||
sel_size = 1
|
||||
self.DrawRect(self.sel_key, self.back_color, sel_size) # clear large selection
|
||||
|
||||
if self.hide_grid is False:
|
||||
self.DrawRect(self.sel_key, self.grid_color)
|
||||
|
||||
@@ -694,12 +751,13 @@ class wxCalendar(wxWindow):
|
||||
def ClearDsp(self):
|
||||
self.Clear()
|
||||
|
||||
class CalenDlg(wxDialog):
|
||||
class CalenDlg(wx.Dialog):
|
||||
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
|
||||
self.calend = wxCalendar(self, -1, wxPoint(20, 60), wxSize(240, 200))
|
||||
self.calend = wxCalendar(self, -1, (20, 60), (240, 200))
|
||||
|
||||
if month == None:
|
||||
self.calend.SetCurrentDay()
|
||||
start_month = self.calend.GetMonth()
|
||||
@@ -716,49 +774,43 @@ class CalenDlg(wxDialog):
|
||||
monthlist = GetMonthList()
|
||||
|
||||
# select the month
|
||||
mID = wxNewId()
|
||||
self.date = wxComboBox(self, mID, Month[start_month], wxPoint(20, 20), wxSize(90, -1), monthlist, wxCB_DROPDOWN)
|
||||
EVT_COMBOBOX(self, mID, self.EvtComboBox)
|
||||
self.date = wx.ComboBox(self, -1, Month[start_month], (20, 20), (90, -1),
|
||||
monthlist, wx.CB_DROPDOWN)
|
||||
self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, self.date)
|
||||
|
||||
# alternate spin button to control the month
|
||||
mID = wxNewId()
|
||||
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.SetValue(start_month)
|
||||
|
||||
EVT_SPIN(self, mID, self.OnMonthSpin)
|
||||
self.Bind(wx.EVT_SPIN, self.OnMonthSpin, self.m_spin)
|
||||
|
||||
# spin button to control the year
|
||||
mID = wxNewId()
|
||||
self.dtext = wxTextCtrl(self, -1, str(start_year), wxPoint(160, 20), wxSize(60, -1))
|
||||
self.dtext = wx.TextCtrl(self, -1, str(start_year), (160, 20), (60, -1))
|
||||
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.SetValue(start_year)
|
||||
|
||||
EVT_SPIN(self, mID, self.OnYrSpin)
|
||||
|
||||
self.Connect(self.calend.GetId(), -1, 2100, self.MouseClick)
|
||||
self.Bind(wx.EVT_SPIN, self.OnYrSpin, self.y_spin)
|
||||
self.Bind(EVT_CALENDAR, self.MouseClick, self.calend)
|
||||
|
||||
x_pos = 50
|
||||
y_pos = 280
|
||||
but_size = wxSize(60, 25)
|
||||
but_size = (60, 25)
|
||||
|
||||
mID = wxNewId()
|
||||
wxButton(self, mID, ' Ok ', wxPoint(x_pos, y_pos), but_size)
|
||||
EVT_BUTTON(self, mID, self.OnOk)
|
||||
btn = wx.Button(self, -1, ' Ok ', (x_pos, y_pos), but_size)
|
||||
self.Bind(wx.EVT_BUTTON, self.OnOk, btn)
|
||||
|
||||
mID = wxNewId()
|
||||
wxButton(self, mID, ' Close ', wxPoint(x_pos + 120, y_pos), but_size)
|
||||
EVT_BUTTON(self, mID, self.OnCancel)
|
||||
btn = wx.Button(self, mID, ' Close ', (x_pos + 120, y_pos), but_size)
|
||||
self.Bind(wx.EVT_BUTTON, self.OnCancel, btn)
|
||||
|
||||
def OnOk(self, event):
|
||||
self.EndModal(wxID_OK)
|
||||
self.EndModal(wx.ID_OK)
|
||||
|
||||
def OnCancel(self, event):
|
||||
self.EndModal(wxID_CANCEL)
|
||||
self.EndModal(wx.ID_CANCEL)
|
||||
|
||||
# log the mouse clicks
|
||||
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
|
||||
|
||||
if evt.click == 'DLEFT':
|
||||
self.EndModal(wxID_OK)
|
||||
self.EndModal(wx.ID_OK)
|
||||
|
||||
# month and year spin selection routines
|
||||
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.
|
||||
"""
|
||||
|
||||
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o 2.5 compatability update.
|
||||
#
|
||||
|
||||
from pycolourchooser import *
|
||||
|
||||
# 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.
|
||||
"""
|
||||
|
||||
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.
|
||||
|
||||
This class implements a screen output buffer. Data is meant to
|
||||
@@ -23,27 +28,27 @@ class BitmapBuffer(wxMemoryDC):
|
||||
"""
|
||||
def __init__(self, width, height, colour):
|
||||
"""Initialize the empty buffer object."""
|
||||
wxMemoryDC.__init__(self)
|
||||
wx.MemoryDC.__init__(self)
|
||||
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.colour = colour
|
||||
|
||||
self.bitmap = wxEmptyBitmap(self.width, self.height)
|
||||
self.bitmap = wx.EmptyBitmap(self.width, self.height)
|
||||
self.SelectObject(self.bitmap)
|
||||
|
||||
# Initialize the buffer to the background colour
|
||||
self.SetBackground(wxBrush(self.colour, wxSOLID))
|
||||
self.SetBackground(wx.Brush(self.colour, wx.SOLID))
|
||||
self.Clear()
|
||||
|
||||
# Make each logical unit of the buffer equal to 1 pixel
|
||||
self.SetMapMode(wxMM_TEXT)
|
||||
self.SetMapMode(wx.MM_TEXT)
|
||||
|
||||
def GetBitmap(self):
|
||||
"""Returns the internal bitmap for direct drawing."""
|
||||
return self.bitmap
|
||||
|
||||
class Canvas(wxWindow):
|
||||
class Canvas(wx.Window):
|
||||
"""A canvas class for arbitrary drawing.
|
||||
|
||||
The Canvas class implements a window that allows for drawing
|
||||
@@ -55,24 +60,24 @@ class Canvas(wxWindow):
|
||||
are also provided.
|
||||
"""
|
||||
def __init__(self, parent, id,
|
||||
pos=wxDefaultPosition,
|
||||
size=wxDefaultSize,
|
||||
style=wxSIMPLE_BORDER):
|
||||
pos=wx.DefaultPosition,
|
||||
size=wx.DefaultSize,
|
||||
style=wx.SIMPLE_BORDER):
|
||||
"""Creates a canvas instance and initializes the off-screen
|
||||
buffer. Also sets the handler for rendering the canvas
|
||||
automatically via size and paint calls from the windowing
|
||||
system."""
|
||||
wxWindow.__init__(self, parent, id, pos, size, style)
|
||||
wx.Window.__init__(self, parent, id, pos, size, style)
|
||||
|
||||
# Perform an intial sizing
|
||||
self.ReDraw()
|
||||
|
||||
# Register event handlers
|
||||
EVT_SIZE(self, self.onSize)
|
||||
EVT_PAINT(self, self.onPaint)
|
||||
self.Bind(wx.EVT_SIZE, self.onSize)
|
||||
self.Bind(wx.EVT_PAINT, self.onPaint)
|
||||
|
||||
def MakeNewBuffer(self):
|
||||
size = self.GetSizeTuple()
|
||||
size = self.GetSize()
|
||||
self.buffer = BitmapBuffer(size[0], size[1],
|
||||
self.GetBackgroundColour())
|
||||
|
||||
@@ -91,12 +96,12 @@ class Canvas(wxWindow):
|
||||
|
||||
def Refresh(self):
|
||||
"""Re-draws the buffer contents on-screen."""
|
||||
dc = wxClientDC(self)
|
||||
dc = wx.ClientDC(self)
|
||||
self.Blit(dc)
|
||||
|
||||
def onPaint(self, event):
|
||||
"""Renders the off-screen buffer on-screen."""
|
||||
dc = wxPaintDC(self)
|
||||
dc = wx.PaintDC(self)
|
||||
self.Blit(dc)
|
||||
|
||||
def Blit(self, dc):
|
||||
@@ -109,7 +114,7 @@ class Canvas(wxWindow):
|
||||
def GetBoundingRect(self):
|
||||
"""Returns a tuple that contains the co-ordinates of the
|
||||
top-left and bottom-right corners of the canvas."""
|
||||
x, y = self.GetPositionTuple()
|
||||
x, y = self.GetPosition()
|
||||
w, h = self.GetSize()
|
||||
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
|
||||
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
|
||||
|
||||
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)):
|
||||
"""Creates a new colour box instance and initializes the colour
|
||||
content."""
|
||||
wxPanel.__init__(self, parent, id,
|
||||
size=wxSize(size[0], size[1]))
|
||||
wx.Panel.__init__(self, parent, id, size=size)
|
||||
|
||||
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.Add(self.colour_box, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL)
|
||||
sizer = wx.GridSizer(1, 1)
|
||||
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)
|
||||
self.SetAutoLayout(True)
|
||||
self.SetSizer(sizer)
|
||||
@@ -57,10 +60,10 @@ class PyColourBox(wxPanel):
|
||||
def SetColourTuple(self, colour):
|
||||
"""Sets the box's current couple to the given tuple."""
|
||||
self.colour = colour
|
||||
self.colour_box.SetBackgroundColour(wxColour(*self.colour))
|
||||
self.colour_box.SetBackgroundColour(wx.Colour(*self.colour))
|
||||
|
||||
def Update(self):
|
||||
wxPanel.Update(self)
|
||||
wx.Panel.Update(self)
|
||||
self.colour_box.Update()
|
||||
|
||||
def SetHighlight(self, val):
|
||||
@@ -72,7 +75,7 @@ class PyColourBox(wxPanel):
|
||||
red =(self.real_bg.Red() - 45) % 255
|
||||
green =(self.real_bg.Green() - 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)
|
||||
else:
|
||||
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.
|
||||
"""
|
||||
|
||||
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o 2.5 compatability update.
|
||||
#
|
||||
|
||||
import wx
|
||||
|
||||
import pycolourbox
|
||||
import pypalette
|
||||
import pycolourslider
|
||||
import colorsys
|
||||
from intl import _
|
||||
from wxPython.wx import *
|
||||
import intl
|
||||
|
||||
class wxPyColourChooser(wxPanel):
|
||||
from intl import _ # _
|
||||
|
||||
class wxPyColourChooser(wx.Panel):
|
||||
"""A Pure-Python implementation of the colour chooser dialog.
|
||||
|
||||
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
|
||||
# all instances of the colour chooser
|
||||
NO_CUSTOM_COLOURS = 16
|
||||
custom_colours = [ (wxColour(255, 255, 255),
|
||||
custom_colours = [ (wx.Colour(255, 255, 255),
|
||||
pycolourslider.PyColourSlider.HEIGHT / 2)
|
||||
] * NO_CUSTOM_COLOURS
|
||||
last_custom = 0
|
||||
|
||||
idADD_CUSTOM = wxNewId()
|
||||
idSCROLL = wxNewId()
|
||||
idADD_CUSTOM = wx.NewId()
|
||||
idSCROLL = wx.NewId()
|
||||
|
||||
def __init__(self, parent, id):
|
||||
"""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
|
||||
resizeable."""
|
||||
wxPanel.__init__(self, parent, id)
|
||||
wx.Panel.__init__(self, parent, id)
|
||||
|
||||
self.basic_label = wxStaticText(self, -1, _("Basic Colours:"))
|
||||
self.custom_label = wxStaticText(self, -1, _("Custom Colours:"))
|
||||
self.add_button = wxButton(self, self.idADD_CUSTOM, _("Add to Custom Colours"))
|
||||
self.basic_label = wx.StaticText(self, -1, _("Basic Colours:"))
|
||||
self.custom_label = wx.StaticText(self, -1, _("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
|
||||
# computation, let's process any events (like redraws) right now
|
||||
wxYield()
|
||||
wx.Yield()
|
||||
|
||||
# Create the basic colours palette
|
||||
self.colour_boxs = [ ]
|
||||
colour_grid = wxGridSizer(6, 8)
|
||||
colour_grid = wx.GridSizer(6, 8)
|
||||
for name in self.colour_names:
|
||||
new_id = wxNewId()
|
||||
new_id = wx.NewId()
|
||||
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)
|
||||
colour_grid.Add(box, 0, wxEXPAND)
|
||||
colour_grid.Add(box, 0, wx.EXPAND)
|
||||
|
||||
# Create the custom colours palette
|
||||
self.custom_boxs = [ ]
|
||||
custom_grid = wxGridSizer(2, 8)
|
||||
custom_grid = wx.GridSizer(2, 8)
|
||||
for wxcolour, slidepos in self.custom_colours:
|
||||
new_id = wxNewId()
|
||||
new_id = wx.NewId()
|
||||
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_grid.Add(custom, 0, wxEXPAND)
|
||||
custom_grid.Add(custom, 0, wx.EXPAND)
|
||||
self.custom_boxs.append(custom)
|
||||
|
||||
csizer = wxBoxSizer(wxVERTICAL)
|
||||
csizer = wx.BoxSizer(wx.VERTICAL)
|
||||
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(colour_grid, 0, wxEXPAND)
|
||||
csizer.Add(colour_grid, 0, wx.EXPAND)
|
||||
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(custom_grid, 0, wxEXPAND)
|
||||
csizer.Add(custom_grid, 0, wx.EXPAND)
|
||||
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.colour_slider = pycolourslider.PyColourSlider(self, -1)
|
||||
self.slider = wxSlider(self, self.idSCROLL, 86, 0, self.colour_slider.HEIGHT - 1,
|
||||
style=wxSL_VERTICAL, size=wxSize(15, self.colour_slider.HEIGHT))
|
||||
EVT_COMMAND_SCROLL(self, self.idSCROLL, self.onScroll)
|
||||
psizer = wxBoxSizer(wxHORIZONTAL)
|
||||
self.slider = wx.Slider(
|
||||
self, self.idSCROLL, 86, 0, self.colour_slider.HEIGHT - 1,
|
||||
style=wx.SL_VERTICAL, size=(15, self.colour_slider.HEIGHT)
|
||||
)
|
||||
|
||||
self.Bind(wx.EVT_COMMAND_SCROLL, self.onScroll, self.slider)
|
||||
psizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
psizer.Add(self.palette, 0, 0)
|
||||
psizer.Add((10, 1))
|
||||
psizer.Add(self.colour_slider, 0, wxALIGN_CENTER_VERTICAL)
|
||||
psizer.Add(self.slider, 0, wxALIGN_CENTER_VERTICAL)
|
||||
psizer.Add(self.colour_slider, 0, wx.ALIGN_CENTER_VERTICAL)
|
||||
psizer.Add(self.slider, 0, wx.ALIGN_CENTER_VERTICAL)
|
||||
|
||||
# Register mouse events for dragging across the palette
|
||||
EVT_LEFT_DOWN(self.palette, self.onPaletteDown)
|
||||
EVT_LEFT_UP(self.palette, self.onPaletteUp)
|
||||
EVT_MOTION(self.palette, self.onPaletteMotion)
|
||||
self.palette.Bind(wx.EVT_LEFT_DOWN, self.onPaletteDown)
|
||||
self.palette.Bind(wx.EVT_LEFT_UP, self.onPaletteUp)
|
||||
self.palette.Bind(wx.EVT_MOTION, self.onPaletteMotion)
|
||||
self.mouse_down = False
|
||||
|
||||
self.solid = pycolourbox.PyColourBox(self, -1, size=wxSize(75, 50))
|
||||
slabel = wxStaticText(self, -1, _("Solid Colour"))
|
||||
ssizer = wxBoxSizer(wxVERTICAL)
|
||||
self.solid = pycolourbox.PyColourBox(self, -1, size=(75, 50))
|
||||
slabel = wx.StaticText(self, -1, _("Solid Colour"))
|
||||
ssizer = wx.BoxSizer(wx.VERTICAL)
|
||||
ssizer.Add(self.solid, 0, 0)
|
||||
ssizer.Add((1, 2))
|
||||
ssizer.Add(slabel, 0, wxALIGN_CENTER_HORIZONTAL)
|
||||
ssizer.Add(slabel, 0, wx.ALIGN_CENTER_HORIZONTAL)
|
||||
|
||||
hlabel = wxStaticText(self, -1, _("H:"))
|
||||
self.hentry = wxTextCtrl(self, -1)
|
||||
hlabel = wx.StaticText(self, -1, _("H:"))
|
||||
self.hentry = wx.TextCtrl(self, -1)
|
||||
self.hentry.SetSize((40, -1))
|
||||
slabel = wxStaticText(self, -1, _("S:"))
|
||||
self.sentry = wxTextCtrl(self, -1)
|
||||
slabel = wx.StaticText(self, -1, _("S:"))
|
||||
self.sentry = wx.TextCtrl(self, -1)
|
||||
self.sentry.SetSize((40, -1))
|
||||
vlabel = wxStaticText(self, -1, _("V:"))
|
||||
self.ventry = wxTextCtrl(self, -1)
|
||||
vlabel = wx.StaticText(self, -1, _("V:"))
|
||||
self.ventry = wx.TextCtrl(self, -1)
|
||||
self.ventry.SetSize((40, -1))
|
||||
hsvgrid = wxFlexGridSizer(1, 6, 2, 2)
|
||||
hsvgrid = wx.FlexGridSizer(1, 6, 2, 2)
|
||||
hsvgrid.AddMany ([
|
||||
(hlabel, 0, wxALIGN_CENTER_VERTICAL), (self.hentry, 0, 0),
|
||||
(slabel, 0, wxALIGN_CENTER_VERTICAL), (self.sentry, 0, 0),
|
||||
(vlabel, 0, wxALIGN_CENTER_VERTICAL), (self.ventry, 0, 0),
|
||||
(hlabel, 0, wx.ALIGN_CENTER_VERTICAL), (self.hentry, 0, 0),
|
||||
(slabel, 0, wx.ALIGN_CENTER_VERTICAL), (self.sentry, 0, 0),
|
||||
(vlabel, 0, wx.ALIGN_CENTER_VERTICAL), (self.ventry, 0, 0),
|
||||
])
|
||||
|
||||
rlabel = wxStaticText(self, -1, _("R:"))
|
||||
self.rentry = wxTextCtrl(self, -1)
|
||||
rlabel = wx.StaticText(self, -1, _("R:"))
|
||||
self.rentry = wx.TextCtrl(self, -1)
|
||||
self.rentry.SetSize((40, -1))
|
||||
glabel = wxStaticText(self, -1, _("G:"))
|
||||
self.gentry = wxTextCtrl(self, -1)
|
||||
glabel = wx.StaticText(self, -1, _("G:"))
|
||||
self.gentry = wx.TextCtrl(self, -1)
|
||||
self.gentry.SetSize((40, -1))
|
||||
blabel = wxStaticText(self, -1, _("B:"))
|
||||
self.bentry = wxTextCtrl(self, -1)
|
||||
blabel = wx.StaticText(self, -1, _("B:"))
|
||||
self.bentry = wx.TextCtrl(self, -1)
|
||||
self.bentry.SetSize((40, -1))
|
||||
lgrid = wxFlexGridSizer(1, 6, 2, 2)
|
||||
lgrid = wx.FlexGridSizer(1, 6, 2, 2)
|
||||
lgrid.AddMany([
|
||||
(rlabel, 0, wxALIGN_CENTER_VERTICAL), (self.rentry, 0, 0),
|
||||
(glabel, 0, wxALIGN_CENTER_VERTICAL), (self.gentry, 0, 0),
|
||||
(blabel, 0, wxALIGN_CENTER_VERTICAL), (self.bentry, 0, 0),
|
||||
(rlabel, 0, wx.ALIGN_CENTER_VERTICAL), (self.rentry, 0, 0),
|
||||
(glabel, 0, wx.ALIGN_CENTER_VERTICAL), (self.gentry, 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.SetHGap (2)
|
||||
gsizer.Add(hsvgrid, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL)
|
||||
gsizer.Add(lgrid, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL)
|
||||
gsizer.Add(hsvgrid, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL)
|
||||
gsizer.Add(lgrid, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL)
|
||||
|
||||
hsizer = wxBoxSizer(wxHORIZONTAL)
|
||||
hsizer.Add(ssizer, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL)
|
||||
hsizer.Add(gsizer, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL)
|
||||
hsizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
hsizer.Add(ssizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_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(psizer, 0, 0)
|
||||
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(csizer, 0, wxEXPAND)
|
||||
sizer.Add(csizer, 0, wx.EXPAND)
|
||||
sizer.Add((10, 1))
|
||||
sizer.Add(vsizer, 0, wxEXPAND)
|
||||
sizer.Add(vsizer, 0, wx.EXPAND)
|
||||
self.SetAutoLayout(True)
|
||||
self.SetSizer(sizer)
|
||||
sizer.Fit(self)
|
||||
@@ -232,7 +247,7 @@ class wxPyColourChooser(wxPanel):
|
||||
def InitColours(self):
|
||||
"""Initializes the pre-set palette colours."""
|
||||
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(),
|
||||
colour.Green(),
|
||||
colour.Blue()))
|
||||
@@ -364,12 +379,12 @@ class wxPyColourChooser(wxPanel):
|
||||
|
||||
def main():
|
||||
"""Simple test display."""
|
||||
class App(wxApp):
|
||||
class App(wx.App):
|
||||
def OnInit(self):
|
||||
frame = wxFrame(NULL, -1, 'PyColourChooser Test')
|
||||
frame = wx.Frame(None, -1, 'PyColourChooser Test')
|
||||
|
||||
chooser = wxPyColourChooser(frame, -1)
|
||||
sizer = wxBoxSizer(wxVERTICAL)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(chooser, 0, 0)
|
||||
frame.SetAutoLayout(True)
|
||||
frame.SetSizer(sizer)
|
||||
@@ -378,7 +393,7 @@ def main():
|
||||
frame.Show(True)
|
||||
self.SetTopWindow(frame)
|
||||
return True
|
||||
app = App()
|
||||
app = App(False)
|
||||
app.MainLoop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@@ -16,9 +16,15 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
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 colorsys
|
||||
from wxPython.wx import *
|
||||
|
||||
class PyColourSlider(canvas.Canvas):
|
||||
"""A Pure-Python Colour Slider
|
||||
@@ -41,8 +47,7 @@ class PyColourSlider(canvas.Canvas):
|
||||
# drawing function
|
||||
self.SetBaseColour(colour)
|
||||
|
||||
canvas.Canvas.__init__(self, parent, id,
|
||||
size=wxSize(self.WIDTH, self.HEIGHT))
|
||||
canvas.Canvas.__init__(self, parent, id, size=(self.WIDTH, self.HEIGHT))
|
||||
|
||||
def SetBaseColour(self, 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
|
||||
for y_pos in range(0, self.HEIGHT):
|
||||
r,g,b = [c * 255.0 for c in colorsys.hsv_to_rgb(h,s,v)]
|
||||
colour = wxColour(int(r), int(g), int(b))
|
||||
self.buffer.SetPen(wxPen(colour, 1, wxSOLID))
|
||||
colour = wx.Colour(int(r), int(g), int(b))
|
||||
self.buffer.SetPen(wx.Pen(colour, 1, wx.SOLID))
|
||||
self.buffer.DrawRectangle((0, y_pos), (15, 1))
|
||||
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
|
||||
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 colorsys
|
||||
import cStringIO, zlib
|
||||
from wxPython.wx import *
|
||||
|
||||
|
||||
# Bitmap functions generated from img2py
|
||||
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=' )
|
||||
|
||||
def getBitmap():
|
||||
return wxBitmapFromImage(getImage())
|
||||
return wx.BitmapFromImage(getImage())
|
||||
|
||||
def getImage():
|
||||
stream = cStringIO.StringIO(getData())
|
||||
return wxImageFromStream(stream)
|
||||
return wx.ImageFromStream(stream)
|
||||
|
||||
class PyPalette(canvas.Canvas):
|
||||
"""The Pure-Python Palette
|
||||
@@ -156,8 +164,9 @@ class PyPalette(canvas.Canvas):
|
||||
def __init__(self, parent, id):
|
||||
"""Creates a palette object."""
|
||||
# Load the pre-generated palette XPM
|
||||
wx.InitAllImageHandlers()
|
||||
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):
|
||||
"""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):
|
||||
"""Highlights an area of the palette with a little circle around
|
||||
the coordinate point"""
|
||||
colour = wxColour(0, 0, 0)
|
||||
self.buffer.SetPen(wxPen(colour, 1, wxSOLID))
|
||||
self.buffer.SetBrush(wxBrush(colour, wxTRANSPARENT))
|
||||
colour = wx.Colour(0, 0, 0)
|
||||
self.buffer.SetPen(wx.Pen(colour, 1, wx.SOLID))
|
||||
self.buffer.SetBrush(wx.Brush(colour, wx.TRANSPARENT))
|
||||
self.buffer.DrawCircle((x, y), 3)
|
||||
self.Refresh()
|
||||
|
||||
@@ -201,13 +210,13 @@ class PyPalette(canvas.Canvas):
|
||||
for x in range(0, width, self.HORIZONTAL_STEP):
|
||||
hue = float(x) / float(width)
|
||||
r,g,b = colorsys.hsv_to_rgb(hue, saturation, value)
|
||||
colour = wxColour(int(r * 255.0), int(g * 255.0), int(b * 255.0))
|
||||
self.buffer.SetPen(wxPen(colour, 1, wxSOLID))
|
||||
self.buffer.SetBrush(wxBrush(colour, wxSOLID))
|
||||
colour = wx.Colour(int(r * 255.0), int(g * 255.0), int(b * 255.0))
|
||||
self.buffer.SetPen(wx.Pen(colour, 1, wx.SOLID))
|
||||
self.buffer.SetBrush(wx.Brush(colour, wx.SOLID))
|
||||
self.buffer.DrawRectangle((x, y),
|
||||
(self.HORIZONTAL_STEP, self.vertical_step))
|
||||
|
||||
# this code is now simpler (and works)
|
||||
bitmap = self.buffer.GetBitmap()
|
||||
image = wxImageFromBitmap(bitmap)
|
||||
image.SaveFile (file_name, wxBITMAP_TYPE_XPM)
|
||||
image = wx.ImageFromBitmap(bitmap)
|
||||
image.SaveFile (file_name, wx.BITMAP_TYPE_XPM)
|
||||
|
@@ -664,7 +664,9 @@ def updateColourDB():
|
||||
import wx
|
||||
assert wx.GetApp() is not None, "You must have a wx.App object before you can use the colour database."
|
||||
cl = getColourInfoList()
|
||||
|
||||
for info in cl:
|
||||
wx.TheColourDatabase.Append(*info)
|
||||
|
||||
_haveUpdated = True
|
||||
|
||||
|
@@ -8,8 +8,6 @@
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
# creates a colour wxButton with selectable color
|
||||
# button click provides a colour selection box
|
||||
# button colour will change to new colour
|
||||
@@ -29,26 +27,35 @@ from wxPython.wx import *
|
||||
# Cliff Wells, 2002/02/07
|
||||
# - 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):
|
||||
wxPyCommandEvent.__init__(self, id = id)
|
||||
self.SetEventType(EVT_COMMAND_COLOURSELECT)
|
||||
wx.PyCommandEvent.__init__(self, id = id)
|
||||
self.SetEventType(wxEVT_COMMAND_COLOURSELECT)
|
||||
self.value = value
|
||||
|
||||
def GetValue(self):
|
||||
return self.value
|
||||
|
||||
def EVT_COLOURSELECT(win, id, func):
|
||||
win.Connect(id, -1, EVT_COMMAND_COLOURSELECT, func)
|
||||
EVT_COLOURSELECT = wx.PyEventBinder(wxEVT_COMMAND_COLOURSELECT, 1)
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
class ColourSelect(wxBitmapButton):
|
||||
def __init__(self, parent, id, label="", colour=wxBLACK,
|
||||
pos=wxDefaultPosition, size=wxDefaultSize,
|
||||
class ColourSelect(wx.BitmapButton):
|
||||
def __init__(self, parent, id, label="", colour=wx.BLACK,
|
||||
pos=wx.DefaultPosition, size=wx.DefaultSize,
|
||||
callback=None, style=0):
|
||||
if label:
|
||||
w, h = parent.GetTextExtent(label)
|
||||
@@ -56,33 +63,32 @@ class ColourSelect(wxBitmapButton):
|
||||
h += 6
|
||||
else:
|
||||
w, h = 20, 20
|
||||
wxBitmapButton.__init__(self, parent, id, wxEmptyBitmap(w,h),
|
||||
pos=pos, size=size, style=style|wxBU_AUTODRAW)
|
||||
wx.BitmapButton.__init__(self, parent, id, wx.EmptyBitmap(w,h),
|
||||
pos=pos, size=size, style=style|wx.BU_AUTODRAW)
|
||||
|
||||
if type(colour) == type( () ):
|
||||
colour = wxColour(*colour)
|
||||
colour = wx.Colour(*colour)
|
||||
self.colour = colour
|
||||
self.SetLabel(label)
|
||||
self.callback = callback
|
||||
bmp = self.MakeBitmap()
|
||||
self.SetBitmap(bmp)
|
||||
EVT_BUTTON(parent, self.GetId(), self.OnClick)
|
||||
parent.Bind(wx.EVT_BUTTON, self.OnClick, self)
|
||||
|
||||
|
||||
def GetColour(self):
|
||||
return self.colour
|
||||
|
||||
|
||||
def GetValue(self):
|
||||
return self.colour
|
||||
|
||||
|
||||
def SetValue(self, colour):
|
||||
self.SetColour(colour)
|
||||
|
||||
|
||||
def SetColour(self, colour):
|
||||
if type(colour) == type( () ):
|
||||
colour = wxColour(*colour)
|
||||
|
||||
self.colour = colour
|
||||
bmp = self.MakeBitmap()
|
||||
self.SetBitmap(bmp)
|
||||
@@ -90,23 +96,24 @@ class ColourSelect(wxBitmapButton):
|
||||
|
||||
def MakeBitmap(self):
|
||||
bdr = 10
|
||||
sz = self.GetSize()
|
||||
bmp = wxEmptyBitmap(sz.width-bdr, sz.height-bdr)
|
||||
dc = wxMemoryDC()
|
||||
width, height = self.GetSize()
|
||||
bmp = wx.EmptyBitmap(width-bdr, height-bdr)
|
||||
dc = wx.MemoryDC()
|
||||
dc.SelectObject(bmp)
|
||||
label = self.GetLabel()
|
||||
# Just make a little colored bitmap
|
||||
dc.SetBackground(wxBrush(self.colour))
|
||||
dc.SetBackground(wx.Brush(self.colour))
|
||||
dc.Clear()
|
||||
|
||||
if label:
|
||||
# Add a label to it
|
||||
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.DrawLabel(label, (0,0, sz.width-bdr, sz.height-bdr),
|
||||
wxALIGN_CENTER)
|
||||
dc.DrawLabel(label, (0,0, width-bdr, height-bdr),
|
||||
wx.ALIGN_CENTER)
|
||||
|
||||
dc.SelectObject(wxNullBitmap)
|
||||
dc.SelectObject(wx.NullBitmap)
|
||||
return bmp
|
||||
|
||||
|
||||
@@ -119,21 +126,24 @@ class ColourSelect(wxBitmapButton):
|
||||
|
||||
|
||||
def OnChange(self):
|
||||
wxPostEvent(self, ColourSelectEvent(self.GetId(), self.GetValue()))
|
||||
wx.PostEvent(self, ColourSelectEvent(self.GetId(), self.GetValue()))
|
||||
if self.callback is not None:
|
||||
self.callback()
|
||||
|
||||
def OnClick(self, event):
|
||||
data = wxColourData()
|
||||
data = wx.ColourData()
|
||||
data.SetChooseFull(True)
|
||||
data.SetColour(self.colour)
|
||||
dlg = wxColourDialog(self.GetParent(), data)
|
||||
changed = dlg.ShowModal() == wxID_OK
|
||||
dlg = wx.ColourDialog(self.GetParent(), data)
|
||||
changed = dlg.ShowModal() == wx.ID_OK
|
||||
|
||||
if changed:
|
||||
data = dlg.GetColourData()
|
||||
self.SetColour(data.GetColour())
|
||||
|
||||
dlg.Destroy()
|
||||
|
||||
# moved after dlg.Destroy, since who knows what the callback will do...
|
||||
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
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------
|
||||
# 12/01/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o Updated for 2.5 compatability.
|
||||
#
|
||||
|
||||
from wxPython import wx
|
||||
from layoutf import Layoutf
|
||||
import wx
|
||||
import layoutf
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class wxScrolledMessageDialog(wx.wxDialog):
|
||||
def __init__(self, parent, msg, caption, pos = wx.wxDefaultPosition, size = (500,300)):
|
||||
wx.wxDialog.__init__(self, parent, -1, caption, pos, size)
|
||||
class wxScrolledMessageDialog(wx.Dialog):
|
||||
def __init__(self, parent, msg, caption, pos = wx.DefaultPosition,
|
||||
size = (500,300)):
|
||||
wx.Dialog.__init__(self, parent, -1, caption, pos, size)
|
||||
x, y = pos
|
||||
if x == -1 and y == -1:
|
||||
self.CenterOnScreen(wx.wxBOTH)
|
||||
text = wx.wxTextCtrl(self, -1, msg, wx.wxDefaultPosition,
|
||||
wx.wxDefaultSize,
|
||||
wx.wxTE_MULTILINE | wx.wxTE_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.SetConstraints(Layoutf('b=b5#1;x%w50#1;w!80;h!25', (self,)))
|
||||
self.CenterOnScreen(wx.BOTH)
|
||||
|
||||
text = wx.TextCtrl(self, -1, msg, wx.DefaultPosition, wx.DefaultSize,
|
||||
wx.TE_MULTILINE | wx.TE_READONLY)
|
||||
|
||||
ok = wx.Button(self, wx.ID_OK, "OK")
|
||||
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.Layout()
|
||||
|
||||
|
||||
class wxMultipleChoiceDialog(wx.wxDialog):
|
||||
def __init__(self, parent, msg, title, lst, pos = wx.wxDefaultPosition,
|
||||
size = (200,200), style = wx.wxDEFAULT_DIALOG_STYLE):
|
||||
wx.wxDialog.__init__(self, parent, -1, title, pos, size, style)
|
||||
class wxMultipleChoiceDialog(wx.Dialog):
|
||||
def __init__(self, parent, msg, title, lst, pos = wx.DefaultPosition,
|
||||
size = (200,200), style = wx.DEFAULT_DIALOG_STYLE):
|
||||
wx.Dialog.__init__(self, parent, -1, title, pos, size, style)
|
||||
|
||||
x, y = pos
|
||||
if x == -1 and y == -1:
|
||||
self.CenterOnScreen(wx.wxBOTH)
|
||||
dc = wx.wxClientDC(self)
|
||||
self.CenterOnScreen(wx.BOTH)
|
||||
|
||||
dc = wx.ClientDC(self)
|
||||
height = 0
|
||||
for line in msg.splitlines():
|
||||
height = height + dc.GetTextExtent(line)[1] + 2
|
||||
stat = wx.wxStaticText(self, -1, msg)
|
||||
self.lbox = wx.wxListBox(self, 100, wx.wxDefaultPosition,
|
||||
wx.wxDefaultSize, lst, wx.wxLB_MULTIPLE)
|
||||
ok = wx.wxButton(self, wx.wxID_OK, "OK")
|
||||
cancel = wx.wxButton(self, wx.wxID_CANCEL, "Cancel")
|
||||
stat.SetConstraints(Layoutf('t=t10#1;l=l5#1;r=r5#1;h!%d' % (height,),
|
||||
(self,)))
|
||||
self.lbox.SetConstraints(Layoutf('t=b10#2;l=l5#1;r=r5#1;b=t5#3',
|
||||
(self, stat, ok)))
|
||||
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,)))
|
||||
|
||||
stat = wx.StaticText(self, -1, msg)
|
||||
self.lbox = wx.ListBox(self, 100, wx.DefaultPosition, wx.DefaultSize,
|
||||
lst, wx.LB_MULTIPLE)
|
||||
|
||||
ok = wx.Button(self, wx.ID_OK, "OK")
|
||||
cancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
|
||||
lc = layoutf.Layoutf('t=t10#1;l=l5#1;r=r5#1;h!%d' % (height,), (self,))
|
||||
stat.SetConstraints(lc)
|
||||
|
||||
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.lst = lst
|
||||
self.Layout()
|
||||
@@ -64,10 +83,11 @@ class wxMultipleChoiceDialog(wx.wxDialog):
|
||||
def GetValueString(self):
|
||||
sel = self.lbox.GetSelections()
|
||||
val = []
|
||||
|
||||
for i in sel:
|
||||
val.append(self.lst[i])
|
||||
return tuple(val)
|
||||
|
||||
return tuple(val)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@@ -102,45 +122,47 @@ rev 2:
|
||||
class DialogResults:
|
||||
def __init__(self, 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)
|
||||
|
||||
def __repr__(self):
|
||||
return str(self.__dict__)
|
||||
|
||||
def returnedString(ret):
|
||||
if ret == wx.wxID_OK:
|
||||
if ret == wx.ID_OK:
|
||||
return "Ok"
|
||||
elif ret == wx.wxID_CANCEL:
|
||||
elif ret == wx.ID_CANCEL:
|
||||
return "Cancel"
|
||||
elif ret == wx.wxID_YES:
|
||||
elif ret == wx.ID_YES:
|
||||
return "Yes"
|
||||
elif ret == wx.wxID_NO:
|
||||
elif ret == wx.ID_NO:
|
||||
return "No"
|
||||
|
||||
|
||||
# findDialog was created before wxPython got a Find/Replace dialog
|
||||
# but it may be instructive as to how a function wrapper can
|
||||
# be added for your own custom dialogs
|
||||
# this dialog is always modal, while wxFindReplaceDialog is
|
||||
# modeless and so doesn't lend itself to a function wrapper
|
||||
## findDialog was created before wxPython got a Find/Replace dialog
|
||||
## but it may be instructive as to how a function wrapper can
|
||||
## be added for your own custom dialogs
|
||||
## this dialog is always modal, while wxFindReplaceDialog is
|
||||
## modeless and so doesn't lend itself to a function wrapper
|
||||
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))
|
||||
wSearchText = wx.wxTextCtrl(dlg, -1, searchText,
|
||||
wx.wxPoint(70, 7), wx.wxSize(195, -1))
|
||||
wx.StaticText(dlg, -1, 'Find what:', (7, 10))
|
||||
wSearchText = wx.TextCtrl(dlg, -1, searchText, (70, 7), (195, -1))
|
||||
wSearchText.SetValue(searchText)
|
||||
wx.wxButton(dlg, wx.wxID_OK, "Find Next", wx.wxPoint(280, 5), wx.wxDefaultSize).SetDefault()
|
||||
wx.wxButton(dlg, wx.wxID_CANCEL, "Cancel", wx.wxPoint(280, 35), wx.wxDefaultSize)
|
||||
wWholeWord = wx.wxCheckBox(dlg, -1, 'Match whole word only',
|
||||
wx.wxPoint(7, 35), wx.wxDefaultSize, wx.wxNO_BORDER)
|
||||
wx.wxButton(dlg, wx.ID_OK, "Find Next", (280, 5), wx.DefaultSize).SetDefault()
|
||||
wx.wxButton(dlg, wx.ID_CANCEL, "Cancel", (280, 35), wx.DefaultSize)
|
||||
wWholeWord = wx.CheckBox(dlg, -1, 'Match whole word only',
|
||||
(7, 35), wx.DefaultSize, wx.NO_BORDER)
|
||||
|
||||
if wholeWordsOnly:
|
||||
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:
|
||||
wCase.SetValue(1)
|
||||
|
||||
wSearchText.SetSelection(0, len(wSearchText.GetValue()))
|
||||
wSearchText.SetFocus()
|
||||
|
||||
@@ -154,28 +176,33 @@ def findDialog(parent=None, searchText='', wholeWordsOnly=0, caseSensitive=0):
|
||||
|
||||
def colorDialog(parent=None, colorData=None, color=None):
|
||||
if colorData:
|
||||
dialog = wx.wxColourDialog(parent, colorData)
|
||||
dialog = wx.ColourDialog(parent, colorData)
|
||||
else:
|
||||
dialog = wx.wxColourDialog(parent)
|
||||
dialog = wx.ColourDialog(parent)
|
||||
dialog.GetColourData().SetChooseFull(1)
|
||||
|
||||
if color is not None:
|
||||
dialog.GetColourData().SetColour(color)
|
||||
|
||||
result = DialogResults(dialog.ShowModal())
|
||||
result.colorData = dialog.GetColourData()
|
||||
result.color = result.colorData.GetColour().Get()
|
||||
dialog.Destroy()
|
||||
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):
|
||||
if colourData:
|
||||
dialog = wx.wxColourDialog(parent, colourData)
|
||||
dialog = wx.ColourDialog(parent, colourData)
|
||||
else:
|
||||
dialog = wx.wxColourDialog(parent)
|
||||
dialog = wx.ColourDialog(parent)
|
||||
dialog.GetColourData().SetChooseFull(1)
|
||||
|
||||
if colour is not None:
|
||||
dialog.GetColourData().SetColour(color)
|
||||
|
||||
result = DialogResults(dialog.ShowModal())
|
||||
result.colourData = dialog.GetColourData()
|
||||
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):
|
||||
if fontData is None:
|
||||
fontData = wx.wxFontData()
|
||||
fontData = wx.FontData()
|
||||
|
||||
if font is not None:
|
||||
aFontData.SetInitialFont(font)
|
||||
dialog = wx.wxFontDialog(parent, fontData)
|
||||
|
||||
dialog = wx.FontDialog(parent, fontData)
|
||||
result = DialogResults(dialog.ShowModal())
|
||||
|
||||
if result.accepted:
|
||||
fontData = dialog.GetFontData()
|
||||
result.fontData = fontData
|
||||
@@ -200,12 +230,14 @@ def fontDialog(parent=None, fontData=None, font=None):
|
||||
result.color = None
|
||||
result.colour = None
|
||||
result.font = None
|
||||
|
||||
dialog.Destroy()
|
||||
return result
|
||||
|
||||
|
||||
def textEntryDialog(parent=None, message='', title='', defaultText='', style=wx.wxOK | wx.wxCANCEL):
|
||||
dialog = wx.wxTextEntryDialog(parent, message, title, defaultText, style)
|
||||
def textEntryDialog(parent=None, message='', title='', defaultText='',
|
||||
style=wx.OK | wx.CANCEL):
|
||||
dialog = wx.TextEntryDialog(parent, message, title, defaultText, style)
|
||||
result = DialogResults(dialog.ShowModal())
|
||||
result.text = dialog.GetValue()
|
||||
dialog.Destroy()
|
||||
@@ -213,22 +245,24 @@ def textEntryDialog(parent=None, message='', title='', defaultText='', style=wx.
|
||||
|
||||
|
||||
def messageDialog(parent=None, message='', title='Message box',
|
||||
aStyle = wx.wxOK | wx.wxCANCEL | wx.wxCENTRE,
|
||||
pos=wx.wxDefaultPosition):
|
||||
dialog = wx.wxMessageDialog(parent, message, title, aStyle, pos)
|
||||
aStyle = wx.OK | wx.CANCEL | wx.CENTRE,
|
||||
pos=wx.DefaultPosition):
|
||||
dialog = wx.MessageDialog(parent, message, title, aStyle, pos)
|
||||
result = DialogResults(dialog.ShowModal())
|
||||
dialog.Destroy()
|
||||
return result
|
||||
|
||||
|
||||
# KEA alerts are common, so I'm providing a class rather than
|
||||
# requiring the user code to set up the right icons and buttons
|
||||
# the with messageDialog function
|
||||
def alertDialog(parent=None, message='', title='Alert', pos=wx.wxDefaultPosition):
|
||||
return messageDialog(parent, message, title, wx.wxICON_EXCLAMATION | wx.wxOK, pos)
|
||||
## KEA: alerts are common, so I'm providing a class rather than
|
||||
## requiring the user code to set up the right icons and buttons
|
||||
## the with messageDialog function
|
||||
def alertDialog(parent=None, message='', title='Alert', pos=wx.DefaultPosition):
|
||||
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)
|
||||
result = DialogResults(dialog.ShowModal())
|
||||
dialog.Destroy()
|
||||
@@ -236,8 +270,9 @@ def scrolledMessageDialog(parent=None, message='', title='', pos=wx.wxDefaultPos
|
||||
|
||||
|
||||
def fileDialog(parent=None, title='Open', directory='', filename='', wildcard='*.*',
|
||||
style=wx.wxOPEN | wx.wxMULTIPLE):
|
||||
dialog = wx.wxFileDialog(parent, title, directory, filename, wildcard, style)
|
||||
style=wx.OPEN | wx.MULTIPLE):
|
||||
|
||||
dialog = wx.FileDialog(parent, title, directory, filename, wildcard, style)
|
||||
result = DialogResults(dialog.ShowModal())
|
||||
if result.accepted:
|
||||
result.paths = dialog.GetPaths()
|
||||
@@ -247,24 +282,25 @@ def fileDialog(parent=None, title='Open', directory='', filename='', wildcard='*
|
||||
return result
|
||||
|
||||
|
||||
# openFileDialog and saveFileDialog are convenience functions
|
||||
# they represent the most common usages of the fileDialog
|
||||
# with the most common style options
|
||||
## openFileDialog and saveFileDialog are convenience functions
|
||||
## they represent the most common usages of the fileDialog
|
||||
## with the most common style options
|
||||
def openFileDialog(parent=None, title='Open', directory='', filename='',
|
||||
wildcard='All Files (*.*)|*.*',
|
||||
style=wx.wxOPEN | wx.wxMULTIPLE):
|
||||
style=wx.OPEN | wx.MULTIPLE):
|
||||
return fileDialog(parent, title, directory, filename, wildcard, style)
|
||||
|
||||
|
||||
def saveFileDialog(parent=None, title='Save', directory='', filename='',
|
||||
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)
|
||||
|
||||
|
||||
def dirDialog(parent=None, message='Choose a directory', path='', style=0,
|
||||
pos=wx.wxDefaultPosition, size=wx.wxDefaultSize):
|
||||
dialog = wx.wxDirDialog(parent, message, path, style, pos, size)
|
||||
pos=wx.DefaultPosition, size=wx.DefaultSize):
|
||||
|
||||
dialog = wx.DirDialog(parent, message, path, style, pos, size)
|
||||
result = DialogResults(dialog.ShowModal())
|
||||
if result.accepted:
|
||||
result.path = dialog.GetPath()
|
||||
@@ -277,19 +313,17 @@ directoryDialog = dirDialog
|
||||
|
||||
|
||||
def singleChoiceDialog(parent=None, message='', title='', lst=[],
|
||||
style=wx.wxOK | wx.wxCANCEL | wx.wxCENTRE):
|
||||
dialog = wx.wxSingleChoiceDialog(parent,
|
||||
message,
|
||||
title,
|
||||
lst,
|
||||
style)
|
||||
style=wx.OK | wx.CANCEL | wx.CENTRE):
|
||||
dialog = wx.SingleChoiceDialog(parent, message, title, lst, style)
|
||||
result = DialogResults(dialog.ShowModal())
|
||||
result.selection = dialog.GetStringSelection()
|
||||
dialog.Destroy()
|
||||
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)
|
||||
result = DialogResults(dialog.ShowModal())
|
||||
result.selection = dialog.GetValueString()
|
||||
@@ -298,11 +332,11 @@ def multipleChoiceDialog(parent=None, message='', title='', lst=[], pos=wx.wxDef
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
class MyApp(wx.wxApp):
|
||||
class MyApp(wx.App):
|
||||
|
||||
def OnInit(self):
|
||||
frame = wx.wxFrame(wx.NULL, -1, "Dialogs", size=(400, 200))
|
||||
panel = wx.wxPanel(frame, -1)
|
||||
frame = wx.Frame(None, -1, "Dialogs", size=(400, 200))
|
||||
panel = wx.Panel(frame, -1)
|
||||
self.panel = panel
|
||||
|
||||
frame.Show(1)
|
||||
@@ -322,11 +356,11 @@ if __name__ == '__main__':
|
||||
'singleChoiceDialog',
|
||||
'textEntryDialog',
|
||||
]
|
||||
self.nameList = wx.wxListBox(panel, -1, (0, 0), (130, 180), dialogNames, style=wx.wxLB_SINGLE)
|
||||
wx.EVT_LISTBOX(panel, self.nameList.GetId(), self.OnNameListSelected)
|
||||
self.nameList = wx.ListBox(panel, -1, (0, 0), (130, 180), dialogNames, style=wx.LB_SINGLE)
|
||||
self.Bind(wx.EVT_LISTBOX, self.OnNameListSelected, id=self.nameList.GetId())
|
||||
|
||||
tstyle = wx.wxTE_RICH2 | wx.wxTE_PROCESS_TAB | wx.wxTE_MULTILINE
|
||||
self.text1 = wx.wxTextCtrl(panel, -1, pos=(150, 0), size=(200, 180), style=tstyle)
|
||||
tstyle = wx.TE_RICH2 | wx.TE_PROCESS_TAB | wx.TE_MULTILINE
|
||||
self.text1 = wx.TextCtrl(panel, -1, pos=(150, 0), size=(200, 180), style=tstyle)
|
||||
|
||||
self.SetTopWindow(frame)
|
||||
|
||||
@@ -381,5 +415,7 @@ if __name__ == '__main__':
|
||||
#self.text1.SetValue(pprint.pformat(result.__dict__))
|
||||
self.text1.SetValue(str(result))
|
||||
|
||||
app = MyApp(0)
|
||||
app = MyApp(True)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
@@ -9,6 +9,10 @@
|
||||
# Copyright: (c) 1999 by Total Control Software
|
||||
# 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
|
||||
|
||||
|
@@ -20,10 +20,15 @@
|
||||
# Copyright: (c) 1999 by Dirk Holtwick, 1999
|
||||
# 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 images
|
||||
@@ -70,14 +75,14 @@ class Scroller:
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class wxEditor(wxScrolledWindow):
|
||||
class wxEditor(wx.ScrolledWindow):
|
||||
|
||||
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,
|
||||
style|wxWANTS_CHARS)
|
||||
style|wx.WANTS_CHARS)
|
||||
|
||||
self.isDrawing = False
|
||||
|
||||
@@ -108,26 +113,33 @@ class wxEditor(wxScrolledWindow):
|
||||
self.sco_y = 0
|
||||
|
||||
def MapEvents(self):
|
||||
EVT_LEFT_DOWN(self, self.OnLeftDown)
|
||||
EVT_LEFT_UP(self, self.OnLeftUp)
|
||||
EVT_MOTION(self, self.OnMotion)
|
||||
EVT_SCROLLWIN(self, self.OnScroll)
|
||||
EVT_CHAR(self, self.OnChar)
|
||||
EVT_PAINT(self, self.OnPaint)
|
||||
EVT_SIZE(self, self.OnSize)
|
||||
EVT_WINDOW_DESTROY(self, self.OnDestroy)
|
||||
EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
|
||||
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
|
||||
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
|
||||
self.Bind(wx.EVT_MOTION, self.OnMotion)
|
||||
self.Bind(wx.EVT_SCROLLWIN, self.OnScroll)
|
||||
self.Bind(wx.EVT_CHAR, self.OnChar)
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||
self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
|
||||
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
|
||||
|
||||
##------------------- Platform-specific stuff
|
||||
|
||||
def NiceFontForPlatform(self):
|
||||
if wxPlatform == "__WXMSW__":
|
||||
return wxFont(10, wxMODERN, wxNORMAL, wxNORMAL)
|
||||
if wx.Platform == "__WXMSW__":
|
||||
return wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL)
|
||||
else:
|
||||
return wxFont(12, wxMODERN, wxNORMAL, wxNORMAL, False)
|
||||
return wx.Font(12, wx.MODERN, wx.NORMAL, wx.NORMAL, False)
|
||||
|
||||
def UnixKeyHack(self, key):
|
||||
#
|
||||
# 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:
|
||||
key += ord('a') - 1
|
||||
return key
|
||||
@@ -141,26 +153,26 @@ class wxEditor(wxScrolledWindow):
|
||||
def SetCharDimensions(self):
|
||||
# TODO: We need a code review on this. It appears that Linux
|
||||
# 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.sw = (self.bw / self.fw) - 1
|
||||
else:
|
||||
self.sh = self.bh / self.fh
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
def UpdateView(self, dc = None):
|
||||
if dc is None:
|
||||
dc = wxClientDC(self)
|
||||
dc = wx.ClientDC(self)
|
||||
if dc.Ok():
|
||||
self.SetCharDimensions()
|
||||
self.KeepCursorOnScreen()
|
||||
@@ -168,12 +180,12 @@ class wxEditor(wxScrolledWindow):
|
||||
self.Draw(dc)
|
||||
|
||||
def OnPaint(self, event):
|
||||
dc = wxPaintDC(self)
|
||||
dc = wx.PaintDC(self)
|
||||
if self.isDrawing:
|
||||
return
|
||||
self.isDrawing = True
|
||||
self.UpdateView(dc)
|
||||
wxCallAfter(self.AdjustScrollbars)
|
||||
wx.CallAfter(self.AdjustScrollbars)
|
||||
self.isDrawing = False
|
||||
|
||||
def OnEraseBackground(self, evt):
|
||||
@@ -182,16 +194,16 @@ class wxEditor(wxScrolledWindow):
|
||||
##-------------------- Drawing code
|
||||
|
||||
def InitFonts(self):
|
||||
dc = wxClientDC(self)
|
||||
dc = wx.ClientDC(self)
|
||||
self.font = self.NiceFontForPlatform()
|
||||
dc.SetFont(self.font)
|
||||
self.fw = dc.GetCharWidth()
|
||||
self.fh = dc.GetCharHeight()
|
||||
|
||||
def SetColors(self):
|
||||
self.fgColor = wxNamedColour('black')
|
||||
self.bgColor = wxNamedColour('white')
|
||||
self.selectColor = wxColour(238, 220, 120) # r, g, b = emacsOrange
|
||||
self.fgColor = wx.NamedColour('black')
|
||||
self.bgColor = wx.NamedColour('white')
|
||||
self.selectColor = wx.Colour(238, 220, 120) # r, g, b = emacsOrange
|
||||
|
||||
def InitDoubleBuffering(self):
|
||||
pass
|
||||
@@ -220,13 +232,13 @@ class wxEditor(wxScrolledWindow):
|
||||
|
||||
def Draw(self, odc=None):
|
||||
if not odc:
|
||||
odc = wxClientDC(self)
|
||||
odc = wx.ClientDC(self)
|
||||
|
||||
bmp = wxEmptyBitmap(max(1,self.bw), max(1,self.bh))
|
||||
dc = wxBufferedDC(odc, bmp)
|
||||
bmp = wx.EmptyBitmap(max(1,self.bw), max(1,self.bh))
|
||||
dc = wx.BufferedDC(odc, bmp)
|
||||
if dc.Ok():
|
||||
dc.SetFont(self.font)
|
||||
dc.SetBackgroundMode(wxSOLID)
|
||||
dc.SetBackgroundMode(wx.SOLID)
|
||||
dc.SetTextBackground(self.bgColor)
|
||||
dc.SetTextForeground(self.fgColor)
|
||||
dc.Clear()
|
||||
@@ -251,7 +263,7 @@ class wxEditor(wxScrolledWindow):
|
||||
|
||||
def DrawCursor(self, dc = None):
|
||||
if not dc:
|
||||
dc = wxClientDC(self)
|
||||
dc = wx.ClientDC(self)
|
||||
|
||||
if (self.LinesInFile())<self.cy: #-1 ?
|
||||
self.cy = self.LinesInFile()-1
|
||||
@@ -264,7 +276,7 @@ class wxEditor(wxScrolledWindow):
|
||||
|
||||
def DrawSimpleCursor(self, xp, yp, dc = None, old=False):
|
||||
if not dc:
|
||||
dc = wxClientDC(self)
|
||||
dc = wx.ClientDC(self)
|
||||
|
||||
if old:
|
||||
xp = self.sco_x
|
||||
@@ -274,7 +286,7 @@ class wxEditor(wxScrolledWindow):
|
||||
szy = self.fh
|
||||
x = xp * szx
|
||||
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_y = yp
|
||||
|
||||
@@ -376,7 +388,7 @@ class wxEditor(wxScrolledWindow):
|
||||
self.EnableScrolling(False, False)
|
||||
self.nextScrollTime = 0
|
||||
self.SCROLLDELAY = 0.050 # seconds
|
||||
self.scrollTimer = wxTimer(self)
|
||||
self.scrollTimer = wx.Timer(self)
|
||||
self.scroller = Scroller(self)
|
||||
|
||||
def CanScroll(self):
|
||||
@@ -389,10 +401,10 @@ class wxEditor(wxScrolledWindow):
|
||||
def SetScrollTimer(self):
|
||||
oneShot = True
|
||||
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):
|
||||
screenX, screenY = wxGetMousePosition()
|
||||
screenX, screenY = wx.GetMousePosition()
|
||||
x, y = self.ScreenToClientXY(screenX, screenY)
|
||||
self.MouseToRow(y)
|
||||
self.MouseToCol(x)
|
||||
@@ -484,17 +496,17 @@ class wxEditor(wxScrolledWindow):
|
||||
def HorizScroll(self, event, eventType):
|
||||
maxLineLen = self.CalcMaxLineLen()
|
||||
|
||||
if eventType == wxEVT_SCROLLWIN_LINEUP:
|
||||
if eventType == wx.EVT_SCROLLWIN_LINEUP:
|
||||
self.sx -= 1
|
||||
elif eventType == wxEVT_SCROLLWIN_LINEDOWN:
|
||||
elif eventType == wx.EVT_SCROLLWIN_LINEDOWN:
|
||||
self.sx += 1
|
||||
elif eventType == wxEVT_SCROLLWIN_PAGEUP:
|
||||
elif eventType == wx.EVT_SCROLLWIN_PAGEUP:
|
||||
self.sx -= self.sw
|
||||
elif eventType == wxEVT_SCROLLWIN_PAGEDOWN:
|
||||
elif eventType == wx.EVT_SCROLLWIN_PAGEDOWN:
|
||||
self.sx += self.sw
|
||||
elif eventType == wxEVT_SCROLLWIN_TOP:
|
||||
elif eventType == wx.EVT_SCROLLWIN_TOP:
|
||||
self.sx = self.cx = 0
|
||||
elif eventType == wxEVT_SCROLLWIN_BOTTOM:
|
||||
elif eventType == wx.EVT_SCROLLWIN_BOTTOM:
|
||||
self.sx = maxLineLen - self.sw
|
||||
self.cx = maxLineLen
|
||||
else:
|
||||
@@ -503,17 +515,17 @@ class wxEditor(wxScrolledWindow):
|
||||
self.HorizBoundaries()
|
||||
|
||||
def VertScroll(self, event, eventType):
|
||||
if eventType == wxEVT_SCROLLWIN_LINEUP:
|
||||
if eventType == wx.EVT_SCROLLWIN_LINEUP:
|
||||
self.sy -= 1
|
||||
elif eventType == wxEVT_SCROLLWIN_LINEDOWN:
|
||||
elif eventType == wx.EVT_SCROLLWIN_LINEDOWN:
|
||||
self.sy += 1
|
||||
elif eventType == wxEVT_SCROLLWIN_PAGEUP:
|
||||
elif eventType == wx.EVT_SCROLLWIN_PAGEUP:
|
||||
self.sy -= self.sh
|
||||
elif eventType == wxEVT_SCROLLWIN_PAGEDOWN:
|
||||
elif eventType == wx.EVT_SCROLLWIN_PAGEDOWN:
|
||||
self.sy += self.sh
|
||||
elif eventType == wxEVT_SCROLLWIN_TOP:
|
||||
elif eventType == wx.EVT_SCROLLWIN_TOP:
|
||||
self.sy = self.cy = 0
|
||||
elif eventType == wxEVT_SCROLLWIN_BOTTOM:
|
||||
elif eventType == wx.EVT_SCROLLWIN_BOTTOM:
|
||||
self.sy = self.LinesInFile() - self.sh
|
||||
self.cy = self.LinesInFile()
|
||||
else:
|
||||
@@ -524,7 +536,7 @@ class wxEditor(wxScrolledWindow):
|
||||
def OnScroll(self, event):
|
||||
dir = event.GetOrientation()
|
||||
eventType = event.GetEventType()
|
||||
if dir == wxHORIZONTAL:
|
||||
if dir == wx.HORIZONTAL:
|
||||
self.HorizScroll(event, eventType)
|
||||
else:
|
||||
self.VertScroll(event, eventType)
|
||||
@@ -583,7 +595,7 @@ class wxEditor(wxScrolledWindow):
|
||||
self.JoinLines()
|
||||
self.TouchBuffer()
|
||||
else:
|
||||
wxBell()
|
||||
wx.Bell()
|
||||
|
||||
def Delete(self, event):
|
||||
t = self.GetTextLine(self.cy)
|
||||
@@ -625,7 +637,7 @@ class wxEditor(wxScrolledWindow):
|
||||
|
||||
def FindSelection(self):
|
||||
if self.SelectEnd is None or self.SelectBegin is None:
|
||||
wxBell()
|
||||
wx.Bell()
|
||||
return None
|
||||
(begin, end) = self.NormalizedSelect()
|
||||
(bRow, bCol) = begin
|
||||
@@ -654,11 +666,11 @@ class wxEditor(wxScrolledWindow):
|
||||
self.SelectOff()
|
||||
|
||||
def CopyToClipboard(self, linesOfText):
|
||||
do = wxTextDataObject()
|
||||
do = wx.TextDataObject()
|
||||
do.SetText(os.linesep.join(linesOfText))
|
||||
wxTheClipboard.Open()
|
||||
wxTheClipboard.SetData(do)
|
||||
wxTheClipboard.Close()
|
||||
wx.TheClipboard.Open()
|
||||
wx.TheClipboard.SetData(do)
|
||||
wx.TheClipboard.Close()
|
||||
|
||||
def SingleLineCopy(self, Row, bCol, eCol):
|
||||
Line = self.GetTextLine(Row)
|
||||
@@ -700,17 +712,17 @@ class wxEditor(wxScrolledWindow):
|
||||
self.lines[bRow:eRow + 1] = [ModLine]
|
||||
|
||||
def OnPaste(self, event):
|
||||
do = wxTextDataObject()
|
||||
wxTheClipboard.Open()
|
||||
success = wxTheClipboard.GetData(do)
|
||||
wxTheClipboard.Close()
|
||||
do = wx.TextDataObject()
|
||||
wx.TheClipboard.Open()
|
||||
success = wx.TheClipboard.GetData(do)
|
||||
wx.TheClipboard.Close()
|
||||
if success:
|
||||
pastedLines = LineSplitter(do.GetText())
|
||||
else:
|
||||
wxBell()
|
||||
wx.Bell()
|
||||
return
|
||||
if len(pastedLines) == 0:
|
||||
wxBell()
|
||||
wx.Bell()
|
||||
return
|
||||
elif len(pastedLines) == 1:
|
||||
self.SingleLineInsert(pastedLines[0])
|
||||
@@ -797,18 +809,18 @@ class wxEditor(wxScrolledWindow):
|
||||
#-------------- Key handler mapping tables
|
||||
|
||||
def SetMoveSpecialFuncs(self, action):
|
||||
action[WXK_DOWN] = self.MoveDown
|
||||
action[WXK_UP] = self.MoveUp
|
||||
action[WXK_LEFT] = self.MoveLeft
|
||||
action[WXK_RIGHT] = self.MoveRight
|
||||
action[WXK_NEXT] = self.MovePageDown
|
||||
action[WXK_PRIOR] = self.MovePageUp
|
||||
action[WXK_HOME] = self.MoveHome
|
||||
action[WXK_END] = self.MoveEnd
|
||||
action[wx.WXK_DOWN] = self.MoveDown
|
||||
action[wx.WXK_UP] = self.MoveUp
|
||||
action[wx.WXK_LEFT] = self.MoveLeft
|
||||
action[wx.WXK_RIGHT] = self.MoveRight
|
||||
action[wx.WXK_NEXT] = self.MovePageDown
|
||||
action[wx.WXK_PRIOR] = self.MovePageUp
|
||||
action[wx.WXK_HOME] = self.MoveHome
|
||||
action[wx.WXK_END] = self.MoveEnd
|
||||
|
||||
def SetMoveSpecialControlFuncs(self, action):
|
||||
action[WXK_HOME] = self.MoveStartOfFile
|
||||
action[WXK_END] = self.MoveEndOfFile
|
||||
action[wx.WXK_HOME] = self.MoveStartOfFile
|
||||
action[wx.WXK_END] = self.MoveEndOfFile
|
||||
|
||||
def SetAltFuncs(self, action):
|
||||
# subclass implements
|
||||
@@ -821,18 +833,18 @@ class wxEditor(wxScrolledWindow):
|
||||
action['x'] = self.OnCutSelection
|
||||
|
||||
def SetSpecialControlFuncs(self, action):
|
||||
action[WXK_INSERT] = self.OnCopySelection
|
||||
action[wx.WXK_INSERT] = self.OnCopySelection
|
||||
|
||||
def SetShiftFuncs(self, action):
|
||||
action[WXK_DELETE] = self.OnCutSelection
|
||||
action[WXK_INSERT] = self.OnPaste
|
||||
action[wx.WXK_DELETE] = self.OnCutSelection
|
||||
action[wx.WXK_INSERT] = self.OnPaste
|
||||
|
||||
def SetSpecialFuncs(self, action):
|
||||
action[WXK_BACK] = self.BackSpace
|
||||
action[WXK_DELETE] = self.Delete
|
||||
action[WXK_RETURN] = self.BreakLine
|
||||
action[WXK_ESCAPE] = self.Escape
|
||||
action[WXK_TAB] = self.TabKey
|
||||
action[wx.WXK_BACK] = self.BackSpace
|
||||
action[wx.WXK_DELETE] = self.Delete
|
||||
action[wx.WXK_RETURN] = self.BreakLine
|
||||
action[wx.WXK_ESCAPE] = self.Escape
|
||||
action[wx.WXK_TAB] = self.TabKey
|
||||
|
||||
##-------------- Logic for key handlers
|
||||
|
||||
@@ -886,7 +898,7 @@ class wxEditor(wxScrolledWindow):
|
||||
except:
|
||||
return False
|
||||
if not self.Dispatch(MappingFunc, key, event):
|
||||
wxBell()
|
||||
wx.Bell()
|
||||
return True
|
||||
|
||||
def ControlKey(self, event, key):
|
||||
@@ -899,7 +911,7 @@ class wxEditor(wxScrolledWindow):
|
||||
if not event.ControlDown():
|
||||
return False
|
||||
if not self.Dispatch(self.SetSpecialControlFuncs, key, event):
|
||||
wxBell()
|
||||
wx.Bell()
|
||||
return True
|
||||
|
||||
def ShiftKey(self, event, key):
|
||||
@@ -915,7 +927,7 @@ class wxEditor(wxScrolledWindow):
|
||||
if (key>31) and (key<256):
|
||||
self.InsertChar(chr(key))
|
||||
else:
|
||||
wxBell()
|
||||
wx.Bell()
|
||||
return
|
||||
self.UpdateView()
|
||||
self.AdjustScrollbars()
|
||||
|
@@ -1,17 +1,22 @@
|
||||
|
||||
# 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 wx
|
||||
|
||||
##----------- Common Functions
|
||||
|
||||
def GetBitmap(ImageData):
|
||||
return wxBitmapFromImage(GetImage(ImageData))
|
||||
return wx.BitmapFromImage(GetImage(ImageData))
|
||||
|
||||
def GetImage(ImageData):
|
||||
stream = cStringIO.StringIO(ImageData)
|
||||
return wxImageFromStream(stream)
|
||||
return wx.ImageFromStream(stream)
|
||||
|
||||
##----------- Image Data
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
True = 1
|
||||
False = 0
|
||||
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o 2.5 compatability update.
|
||||
#
|
||||
|
||||
def RestOfLine(sx, width, data, bool):
|
||||
if len(data) == 0 and sx == 0:
|
||||
|
@@ -11,6 +11,10 @@
|
||||
# Copyright: (c) 2003 by db-X Corporation
|
||||
# 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
|
||||
@@ -33,8 +37,8 @@ programmer to declare or track control ids or parent containers:
|
||||
This module is Python 2.1+ compatible.
|
||||
|
||||
"""
|
||||
from wxPython import wx
|
||||
import pubsub
|
||||
import wx
|
||||
import pubsub # publish / subscribe library
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
@@ -84,9 +88,11 @@ class EventManager:
|
||||
# the natural way of doing things.)
|
||||
if source is not None:
|
||||
id = source.GetId()
|
||||
|
||||
if win is None:
|
||||
# Some widgets do not function as their own windows.
|
||||
win = self._determineWindow(source)
|
||||
|
||||
topic = (event, win, id)
|
||||
|
||||
# Create an adapter from the PS system back to wxEvents, and
|
||||
@@ -143,9 +149,11 @@ class EventManager:
|
||||
"""
|
||||
win = self._determineWindow(win)
|
||||
topics = self.__getTopics(win)
|
||||
|
||||
if topics:
|
||||
for aTopic in topics:
|
||||
self.__deregisterTopic(aTopic)
|
||||
|
||||
del self.windowTopicLookup[win]
|
||||
|
||||
|
||||
@@ -160,13 +168,16 @@ class EventManager:
|
||||
|
||||
for topic in topicList:
|
||||
topicDict = self.messageAdapterDict[topic]
|
||||
|
||||
if topicDict.has_key(listener):
|
||||
topicDict[listener].Destroy()
|
||||
del topicDict[listener]
|
||||
|
||||
if len(topicDict) == 0:
|
||||
self.eventAdapterDict[topic].Destroy()
|
||||
del self.eventAdapterDict[topic]
|
||||
del self.messageAdapterDict[topic]
|
||||
|
||||
del self.listenerTopicLookup[listener]
|
||||
|
||||
|
||||
@@ -211,8 +222,8 @@ class EventManager:
|
||||
name = aWin.GetClassName()
|
||||
i = id(aWin)
|
||||
return '%s #%d' % (name, i)
|
||||
except wx.wxPyDeadObjectError:
|
||||
return '(dead wxObject)'
|
||||
except wx.PyDeadObjectError:
|
||||
return '(dead wx.Object)'
|
||||
|
||||
|
||||
def __topicString(self, aTopic):
|
||||
@@ -239,8 +250,10 @@ class EventManager:
|
||||
# This topic isn't valid. Probably because it was deleted
|
||||
# by listener.
|
||||
return
|
||||
|
||||
for messageAdapter in messageAdapterList:
|
||||
messageAdapter.Destroy()
|
||||
|
||||
self.eventAdapterDict[aTopic].Destroy()
|
||||
del self.messageAdapterDict[aTopic]
|
||||
del self.eventAdapterDict[aTopic]
|
||||
@@ -249,6 +262,7 @@ class EventManager:
|
||||
def __getTopics(self, win=None):
|
||||
if win is None:
|
||||
return self.messageAdapterDict.keys()
|
||||
|
||||
if win is not None:
|
||||
try:
|
||||
return self.windowTopicLookup[win]
|
||||
@@ -284,7 +298,7 @@ class EventManager:
|
||||
discovered, the implementation can be changed to a dictionary
|
||||
lookup along the lines of class : function-to-get-window.
|
||||
"""
|
||||
if isinstance(aComponent, wx.wxMenuItem):
|
||||
if isinstance(aComponent, wx.MenuItem):
|
||||
return aComponent.GetMenu()
|
||||
else:
|
||||
return aComponent
|
||||
@@ -429,7 +443,7 @@ class EventAdapter:
|
||||
try:
|
||||
if not self.disconnect():
|
||||
print 'disconnect failed'
|
||||
except wx.wxPyDeadObjectError:
|
||||
except wx.PyDeadObjectError:
|
||||
print 'disconnect failed: dead object' ##????
|
||||
|
||||
|
||||
@@ -481,12 +495,11 @@ eventManager = EventManager()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from wxPython.wx import wxPySimpleApp, wxFrame, wxToggleButton, wxBoxSizer, wxHORIZONTAL, EVT_MOTION, EVT_LEFT_DOWN, EVT_TOGGLEBUTTON, wxALL
|
||||
app = wxPySimpleApp()
|
||||
frame = wxFrame(None, -1, 'Event Test', size=(300,300))
|
||||
button = wxToggleButton(frame, -1, 'Listen for Mouse Events')
|
||||
sizer = wxBoxSizer(wxHORIZONTAL)
|
||||
sizer.Add(button, 0, 0 | wxALL, 10)
|
||||
app = wx.PySimpleApp()
|
||||
frame = wx.Frame(None, -1, 'Event Test', size=(300,300))
|
||||
button = wx.ToggleButton(frame, -1, 'Listen for Mouse Events')
|
||||
sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
sizer.Add(button, 0, 0 | wx.ALL, 10)
|
||||
frame.SetAutoLayout(1)
|
||||
frame.SetSizer(sizer)
|
||||
|
||||
@@ -502,16 +515,16 @@ if __name__ == '__main__':
|
||||
# Turn the output of mouse events on and off
|
||||
if event.IsChecked():
|
||||
print '\nEnabling mouse events...'
|
||||
eventManager.Register(printEvent, EVT_MOTION, frame)
|
||||
eventManager.Register(printEvent, EVT_LEFT_DOWN, frame)
|
||||
eventManager.Register(printEvent, wx.EVT_MOTION, frame)
|
||||
eventManager.Register(printEvent, wx.EVT_LEFT_DOWN, frame)
|
||||
else:
|
||||
print '\nDisabling mouse events...'
|
||||
eventManager.DeregisterWindow(frame)
|
||||
|
||||
# Send togglebutton events to both the on/off code as well
|
||||
# as the function that prints to stdout.
|
||||
eventManager.Register(printEvent, EVT_TOGGLEBUTTON, button)
|
||||
eventManager.Register(enableFrameEvents, EVT_TOGGLEBUTTON, button)
|
||||
eventManager.Register(printEvent, wx.EVT_TOGGLEBUTTON, button)
|
||||
eventManager.Register(enableFrameEvents, wx.EVT_TOGGLEBUTTON, button)
|
||||
|
||||
frame.CenterOnScreen()
|
||||
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 family="swiss" size="12">
|
||||
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>
|
||||
The End"""
|
||||
|
||||
# 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 math
|
||||
import sys
|
||||
|
||||
import wx
|
||||
import xml.parsers.expat
|
||||
|
||||
@@ -395,9 +403,9 @@ renderToDC = RenderToDC
|
||||
# Test Driver
|
||||
|
||||
def test():
|
||||
app = wx.PyApp()
|
||||
app = wx.PySimpleApp()
|
||||
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")
|
||||
sft = StaticFancyText(frame, -1, __doc__)
|
||||
box.Add(sft, 1, wx.EXPAND)
|
||||
|
@@ -11,13 +11,19 @@
|
||||
# Copyright: (c) 2000 by Total Control Software
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------
|
||||
# 12/02/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o 2.5 Compatability changes
|
||||
#
|
||||
|
||||
from wxPython.wx import *
|
||||
import os, types
|
||||
import os
|
||||
import types
|
||||
|
||||
import wx
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class FileBrowseButton(wxPanel):
|
||||
class FileBrowseButton(wx.Panel):
|
||||
""" A control to allow the user to type in a filename
|
||||
or browse with the standard file dialog to select file
|
||||
|
||||
@@ -40,8 +46,8 @@ class FileBrowseButton(wxPanel):
|
||||
browseButton -- pointer to button
|
||||
"""
|
||||
def __init__ (self, parent, id= -1,
|
||||
pos = wxDefaultPosition, size = wxDefaultSize,
|
||||
style = wxTAB_TRAVERSAL,
|
||||
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||
style = wx.TAB_TRAVERSAL,
|
||||
labelText= "File Entry:",
|
||||
buttonText= "Browse",
|
||||
toolTip= "Type filename or click browse to choose file",
|
||||
@@ -50,7 +56,7 @@ class FileBrowseButton(wxPanel):
|
||||
startDirectory = ".",
|
||||
initialValue = "",
|
||||
fileMask = "*.*",
|
||||
fileMode = wxOPEN,
|
||||
fileMode = wx.OPEN,
|
||||
# callback for when value changes (optional)
|
||||
changeCallback= lambda x:x
|
||||
):
|
||||
@@ -84,58 +90,57 @@ class FileBrowseButton(wxPanel):
|
||||
|
||||
def createDialog( self, parent, id, pos, size, style ):
|
||||
"""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:
|
||||
self.SetBackgroundColour(self._bc)
|
||||
except:
|
||||
pass
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box = wx.BoxSizer(wx.HORIZONTAL)
|
||||
|
||||
self.label = self.createLabel( )
|
||||
box.Add( self.label, 0, wxCENTER )
|
||||
box.Add( self.label, 0, wx.CENTER )
|
||||
|
||||
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()
|
||||
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
|
||||
outsidebox = wxBoxSizer(wxVERTICAL)
|
||||
outsidebox.Add(box, 1, wxEXPAND|wxALL, 3)
|
||||
outsidebox = wx.BoxSizer(wx.VERTICAL)
|
||||
outsidebox.Add(box, 1, wx.EXPAND|wx.ALL, 3)
|
||||
outsidebox.Fit(self)
|
||||
|
||||
self.SetAutoLayout(True)
|
||||
self.SetSizer( outsidebox )
|
||||
self.Layout()
|
||||
if type( size ) == types.TupleType:
|
||||
size = apply( wxSize, size)
|
||||
self.SetDimensions(-1, -1, size.width, size.height, wxSIZE_USE_EXISTING)
|
||||
size = apply( wx.Size, size)
|
||||
self.SetDimensions(-1, -1, size.width, size.height, wx.SIZE_USE_EXISTING)
|
||||
|
||||
# if size.width != -1 or size.height != -1:
|
||||
# self.SetSize(size)
|
||||
|
||||
def SetBackgroundColour(self,color):
|
||||
wxPanel.SetBackgroundColour(self,color)
|
||||
wx.Panel.SetBackgroundColour(self,color)
|
||||
self.label.SetBackgroundColour(color)
|
||||
|
||||
def createLabel( self ):
|
||||
"""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()
|
||||
w, h, d, e = self.GetFullTextExtent(self.labelText, font)
|
||||
label.SetSize(wxSize(w+5, h))
|
||||
label.SetSize((w+5, h))
|
||||
return label
|
||||
|
||||
def createTextControl( self):
|
||||
"""Create the text control"""
|
||||
ID = wxNewId()
|
||||
textControl = wxTextCtrl(self, ID)
|
||||
textControl = wx.TextCtrl(self, -1)
|
||||
textControl.SetToolTipString( self.toolTip )
|
||||
if self.changeCallback:
|
||||
EVT_TEXT(textControl, ID, self.OnChanged)
|
||||
EVT_COMBOBOX(textControl, ID, self.OnChanged)
|
||||
textControl.Bind(wx.EVT_TEXT, self.OnChanged)
|
||||
textControl.Bind(wx.EVT_COMBOBOX, self.OnChanged)
|
||||
return textControl
|
||||
|
||||
def OnChanged(self, evt):
|
||||
@@ -144,10 +149,9 @@ class FileBrowseButton(wxPanel):
|
||||
|
||||
def createBrowseButton( self):
|
||||
"""Create the browse-button control"""
|
||||
ID = wxNewId()
|
||||
button =wxButton(self, ID, self.buttonText)
|
||||
button =wx.Button(self, -1, self.buttonText)
|
||||
button.SetToolTipString( self.toolTip )
|
||||
EVT_BUTTON(button, ID, self.OnBrowse)
|
||||
button.Bind(wx.EVT_BUTTON, self.OnBrowse)
|
||||
return button
|
||||
|
||||
|
||||
@@ -163,9 +167,10 @@ class FileBrowseButton(wxPanel):
|
||||
directory = directory [0]
|
||||
else:
|
||||
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())
|
||||
dlg.Destroy()
|
||||
|
||||
@@ -210,7 +215,7 @@ class FileBrowseButtonWithHistory( FileBrowseButton ):
|
||||
If history is callable it will must return a list used
|
||||
for the history drop-down
|
||||
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
|
||||
will cause some systems to create two events for each Combobox
|
||||
selection. If you discover this condition, please report it!
|
||||
@@ -238,13 +243,12 @@ class FileBrowseButtonWithHistory( FileBrowseButton ):
|
||||
|
||||
def createTextControl( self):
|
||||
"""Create the text control"""
|
||||
ID = wxNewId()
|
||||
textControl = wxComboBox(self, ID, style = wxCB_DROPDOWN )
|
||||
textControl = wx.ComboBox(self, -1, style = wx.CB_DROPDOWN )
|
||||
textControl.SetToolTipString( self.toolTip )
|
||||
EVT_SET_FOCUS(textControl, self.OnSetFocus)
|
||||
textControl.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
|
||||
if self.changeCallback:
|
||||
EVT_TEXT(textControl, ID, self.changeCallback)
|
||||
EVT_COMBOBOX(textControl, ID, self.changeCallback)
|
||||
textControl.Bind(wx.EVT_TEXT, self.changeCallback)
|
||||
textControl.Bind(wx.EVT_COMBOBOX, self.changeCallback)
|
||||
if self.history:
|
||||
history=self.history
|
||||
self.history=None
|
||||
@@ -298,10 +302,10 @@ class FileBrowseButtonWithHistory( FileBrowseButton ):
|
||||
event.Skip()
|
||||
|
||||
|
||||
if wxPlatform == "__WXMSW__":
|
||||
if wx.Platform == "__WXMSW__":
|
||||
def SetValue (self, value, callBack=1):
|
||||
""" Convenient setting of text control value, works
|
||||
around limitation of wxComboBox """
|
||||
around limitation of wx.ComboBox """
|
||||
save = self.callCallback
|
||||
self.callCallback = callBack
|
||||
self.textControl.SetValue(value)
|
||||
@@ -321,15 +325,15 @@ class FileBrowseButtonWithHistory( FileBrowseButton ):
|
||||
|
||||
class DirBrowseButton(FileBrowseButton):
|
||||
def __init__(self, parent, id = -1,
|
||||
pos = wxDefaultPosition, size = wxDefaultSize,
|
||||
style = wxTAB_TRAVERSAL,
|
||||
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||
style = wx.TAB_TRAVERSAL,
|
||||
labelText = 'Select a directory:',
|
||||
buttonText = 'Browse',
|
||||
toolTip = 'Type directory name or browse to select',
|
||||
dialogTitle = '',
|
||||
startDirectory = '.',
|
||||
changeCallback = None,
|
||||
dialogClass = wxDirDialog):
|
||||
dialogClass = wx.DirDialog):
|
||||
FileBrowseButton.__init__(self, parent, id, pos, size, style,
|
||||
labelText, buttonText, toolTip,
|
||||
dialogTitle, startDirectory,
|
||||
@@ -341,7 +345,7 @@ class DirBrowseButton(FileBrowseButton):
|
||||
#
|
||||
def OnBrowse(self, ev = None):
|
||||
dialog = self._dirDialog
|
||||
if dialog.ShowModal() == wxID_OK:
|
||||
if dialog.ShowModal() == wx.ID_OK:
|
||||
self.SetValue(dialog.GetPath())
|
||||
#
|
||||
def __del__(self):
|
||||
@@ -359,17 +363,17 @@ if __name__ == "__main__":
|
||||
self.tag = tag
|
||||
def __call__( self, event ):
|
||||
print self.tag, event.GetString()
|
||||
class DemoFrame( wxFrame ):
|
||||
class DemoFrame( wx.Frame ):
|
||||
def __init__(self, parent):
|
||||
wxFrame.__init__(self, parent, 2400, "File entry with browse", size=(500,260) )
|
||||
EVT_CLOSE(self, self.OnCloseWindow)
|
||||
panel = wxPanel (self,-1)
|
||||
innerbox = wxBoxSizer(wxVERTICAL)
|
||||
wx.Frame.__init__(self, parent, -1, "File entry with browse", size=(500,260))
|
||||
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
||||
panel = wx.Panel (self,-1)
|
||||
innerbox = wx.BoxSizer(wx.VERTICAL)
|
||||
control = FileBrowseButton(
|
||||
panel,
|
||||
initialValue = "z:\\temp",
|
||||
)
|
||||
innerbox.Add( control, 0, wxEXPAND )
|
||||
innerbox.Add( control, 0, wx.EXPAND )
|
||||
middlecontrol = FileBrowseButtonWithHistory(
|
||||
panel,
|
||||
labelText = "With History",
|
||||
@@ -377,7 +381,7 @@ if __name__ == "__main__":
|
||||
history = ["c:\\temp", "c:\\tmp", "r:\\temp","z:\\temp"],
|
||||
changeCallback= SimpleCallback( "With History" ),
|
||||
)
|
||||
innerbox.Add( middlecontrol, 0, wxEXPAND )
|
||||
innerbox.Add( middlecontrol, 0, wx.EXPAND )
|
||||
middlecontrol = FileBrowseButtonWithHistory(
|
||||
panel,
|
||||
labelText = "History callback",
|
||||
@@ -385,25 +389,25 @@ if __name__ == "__main__":
|
||||
history = self.historyCallBack,
|
||||
changeCallback= SimpleCallback( "History callback" ),
|
||||
)
|
||||
innerbox.Add( middlecontrol, 0, wxEXPAND )
|
||||
innerbox.Add( middlecontrol, 0, wx.EXPAND )
|
||||
self.bottomcontrol = control = FileBrowseButton(
|
||||
panel,
|
||||
labelText = "With Callback",
|
||||
style = wxSUNKEN_BORDER|wxCLIP_CHILDREN ,
|
||||
style = wx.SUNKEN_BORDER|wx.CLIP_CHILDREN ,
|
||||
changeCallback= SimpleCallback( "With Callback" ),
|
||||
)
|
||||
innerbox.Add( control, 0, wxEXPAND)
|
||||
innerbox.Add( control, 0, wx.EXPAND)
|
||||
self.bottommostcontrol = control = DirBrowseButton(
|
||||
panel,
|
||||
labelText = "Simple dir browse button",
|
||||
style = wxSUNKEN_BORDER|wxCLIP_CHILDREN)
|
||||
innerbox.Add( control, 0, wxEXPAND)
|
||||
ID = wxNewId()
|
||||
innerbox.Add( wxButton( panel, ID,"Change Label", ), 1, wxEXPAND)
|
||||
EVT_BUTTON( self, ID, self.OnChangeLabel )
|
||||
ID = wxNewId()
|
||||
innerbox.Add( wxButton( panel, ID,"Change Value", ), 1, wxEXPAND)
|
||||
EVT_BUTTON( self, ID, self.OnChangeValue )
|
||||
style = wx.SUNKEN_BORDER|wx.CLIP_CHILDREN)
|
||||
innerbox.Add( control, 0, wx.EXPAND)
|
||||
ID = wx.NewId()
|
||||
innerbox.Add( wx.Button( panel, ID,"Change Label", ), 1, wx.EXPAND)
|
||||
self.Bind(wx.EVT_BUTTON, self.OnChangeLabel , id=ID)
|
||||
ID = wx.NewId()
|
||||
innerbox.Add( wx.Button( panel, ID,"Change Value", ), 1, wx.EXPAND)
|
||||
self.Bind(wx.EVT_BUTTON, self.OnChangeValue, id=ID )
|
||||
panel.SetAutoLayout(True)
|
||||
panel.SetSizer( innerbox )
|
||||
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):
|
||||
self.Destroy()
|
||||
|
||||
class DemoApp(wxApp):
|
||||
class DemoApp(wx.App):
|
||||
def OnInit(self):
|
||||
wxImage_AddHandler(wxJPEGHandler())
|
||||
wxImage_AddHandler(wxPNGHandler())
|
||||
wxImage_AddHandler(wxGIFHandler())
|
||||
frame = DemoFrame(NULL)
|
||||
#frame = RulesPanel(NULL )
|
||||
wx.InitAllImageHandlers()
|
||||
frame = DemoFrame(None)
|
||||
frame.Show(True)
|
||||
self.SetTopWindow(frame)
|
||||
return True
|
||||
|
@@ -6,6 +6,15 @@
|
||||
#
|
||||
# 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
|
||||
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
|
||||
"""
|
||||
|
||||
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
|
||||
#
|
||||
class wxFloatBar(wxToolBar):
|
||||
class wxFloatBar(wx.ToolBar):
|
||||
def __init__(self, parent, ID,
|
||||
pos = wxDefaultPosition,
|
||||
size = wxDefaultSize,
|
||||
pos = wx.DefaultPosition,
|
||||
size = wx.DefaultSize,
|
||||
style = 0,
|
||||
name = 'toolbar'):
|
||||
wxToolBar.__init__(self, parent, ID, pos, size,
|
||||
style|wxTB_DOCKABLE, name)
|
||||
wx.ToolBar.__init__(self, parent, ID, pos, size,
|
||||
style|wx.TB_DOCKABLE, name)
|
||||
|
||||
# these other methods just become no-ops
|
||||
def SetFloatable(self, float):
|
||||
@@ -45,7 +68,7 @@ if wxPlatform == '__WXGTK__':
|
||||
else:
|
||||
_DOCKTHRESHOLD = 25
|
||||
|
||||
class wxFloatBar(wxToolBar):
|
||||
class wxFloatBar(wx.ToolBar):
|
||||
"""
|
||||
wxToolBar subclass which can be dragged off its frame and later
|
||||
replaced there. Drag on the toolbar to release it, close it like
|
||||
@@ -62,7 +85,7 @@ else:
|
||||
user actions (i.e., dragging) can float the toolbar or not.
|
||||
"""
|
||||
args = (self,) + _args
|
||||
apply(wxToolBar.__init__, args, _kwargs)
|
||||
apply(wx.ToolBar.__init__, args, _kwargs)
|
||||
if _kwargs.has_key('floatable'):
|
||||
self.floatable = _kwargs['floatable']
|
||||
assert type(self.floatable) == type(0)
|
||||
@@ -74,8 +97,8 @@ else:
|
||||
assert type(self.title) == type("")
|
||||
else:
|
||||
self.title = ""
|
||||
EVT_MOUSE_EVENTS(self, self.OnMouse)
|
||||
self.parentframe = wxPyTypeCast(args[1], 'wxFrame')
|
||||
self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
|
||||
self.parentframe = args[1]
|
||||
|
||||
|
||||
def IsFloatable(self):
|
||||
@@ -86,9 +109,9 @@ else:
|
||||
self.floatable = float
|
||||
#Find the size of a title bar.
|
||||
if not hasattr(self, 'titleheight'):
|
||||
test = wxMiniFrame(NULL, -1, "TEST")
|
||||
test.SetClientSize(wxSize(0,0))
|
||||
self.titleheight = test.GetSizeTuple()[1]
|
||||
test = wx.MiniFrame(None, -1, "TEST")
|
||||
test.SetClientSize((0,0))
|
||||
self.titleheight = test.GetSize()[1]
|
||||
test.Destroy()
|
||||
|
||||
|
||||
@@ -97,7 +120,7 @@ else:
|
||||
|
||||
|
||||
def Realize(self):
|
||||
wxToolBar.Realize(self)
|
||||
wx.ToolBar.Realize(self)
|
||||
|
||||
|
||||
def GetTitle(self):
|
||||
@@ -119,7 +142,7 @@ else:
|
||||
## if hasattr(self, 'parentframe'):
|
||||
## return self.parentframe
|
||||
## else:
|
||||
## return wxPyTypeCast(self.GetParent(), 'wxFrame')
|
||||
## return (self.GetParent())
|
||||
|
||||
|
||||
## def SetHome(self, frame):
|
||||
@@ -133,7 +156,7 @@ else:
|
||||
## self.parentframe = frame
|
||||
## self.floatframe.Reparent(frame)
|
||||
## else:
|
||||
## parent = wxPyTypeCast(self.GetParent(), 'wxFrame')
|
||||
## parent = self.GetParent()
|
||||
## self.Reparent(frame)
|
||||
## parent.SetToolBar(None)
|
||||
## size = parent.GetSize()
|
||||
@@ -148,37 +171,37 @@ else:
|
||||
def Float(self, bool):
|
||||
"Floats or docks the toolbar programmatically."
|
||||
if bool:
|
||||
self.parentframe = wxPyTypeCast(self.GetParent(), 'wxFrame')
|
||||
self.parentframe = self.GetParent()
|
||||
print self.title
|
||||
if self.title:
|
||||
useStyle = wxDEFAULT_FRAME_STYLE
|
||||
useStyle = wx.DEFAULT_FRAME_STYLE
|
||||
else:
|
||||
useStyle = wxTHICK_FRAME
|
||||
self.floatframe = wxMiniFrame(self.parentframe, -1, self.title,
|
||||
useStyle = wx.THICK_FRAME
|
||||
self.floatframe = wx.MiniFrame(self.parentframe, -1, self.title,
|
||||
style = useStyle)
|
||||
|
||||
self.Reparent(self.floatframe)
|
||||
self.parentframe.SetToolBar(None)
|
||||
self.floating = 1
|
||||
psize = self.parentframe.GetSize()
|
||||
self.parentframe.SetSize(wxSize(0,0))
|
||||
self.parentframe.SetSize((0,0))
|
||||
self.parentframe.SetSize(psize)
|
||||
self.floatframe.SetToolBar(self)
|
||||
self.oldcolor = self.GetBackgroundColour()
|
||||
|
||||
w = psize.width
|
||||
h = self.GetSize().height
|
||||
w = psize[0]
|
||||
h = self.GetSize()[1]
|
||||
if self.title:
|
||||
h = h + self.titleheight
|
||||
self.floatframe.SetSize(wxSize(w,h))
|
||||
self.floatframe.SetSize((w,h))
|
||||
self.floatframe.SetClientSize(self.GetSize())
|
||||
newpos = self.parentframe.GetPosition()
|
||||
newpos.y = newpos.y + _DOCKTHRESHOLD * 2
|
||||
self.floatframe.SetPosition(newpos)
|
||||
self.floatframe.Show(True)
|
||||
|
||||
EVT_CLOSE(self.floatframe, self.OnDock)
|
||||
#EVT_MOVE(self.floatframe, self.OnMove)
|
||||
self.floatframe.Bind(wx.EVT_CLOSE, self.OnDock)
|
||||
#self.floatframe.Bind(wx.EVT_MOVE, self.OnMove)
|
||||
|
||||
else:
|
||||
self.Reparent(self.parentframe)
|
||||
@@ -187,7 +210,7 @@ else:
|
||||
self.floatframe.SetToolBar(None)
|
||||
self.floatframe.Destroy()
|
||||
size = self.parentframe.GetSize()
|
||||
self.parentframe.SetSize(wxSize(0,0))
|
||||
self.parentframe.SetSize((0,0))
|
||||
self.parentframe.SetSize(size)
|
||||
self.SetBackgroundColour(self.oldcolor)
|
||||
|
||||
@@ -199,7 +222,7 @@ else:
|
||||
|
||||
|
||||
def OnMove(self, e):
|
||||
homepos = self.parentframe.ClientToScreen(wxPoint(0,0))
|
||||
homepos = self.parentframe.ClientToScreen((0,0))
|
||||
floatpos = self.floatframe.GetPosition()
|
||||
if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and
|
||||
abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD):
|
||||
@@ -231,7 +254,7 @@ else:
|
||||
if e.ButtonUp():
|
||||
self.ReleaseMouse()
|
||||
if self.IsFloating():
|
||||
homepos = self.parentframe.ClientToScreen(wxPoint(0,0))
|
||||
homepos = self.parentframe.ClientToScreen((0,0))
|
||||
floatpos = self.floatframe.GetPosition()
|
||||
if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and
|
||||
abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD):
|
||||
@@ -245,7 +268,7 @@ else:
|
||||
else:
|
||||
if hasattr(self, 'oldpos'):
|
||||
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)
|
||||
|
||||
|
||||
@@ -255,17 +278,17 @@ else:
|
||||
if vis:
|
||||
if self.parentframe.GetToolBar() == None:
|
||||
if not hasattr(self, 'nullbar'):
|
||||
self.nullbar = wxToolBar(self.parentframe, -1)
|
||||
self.nullbar = wx.ToolBar(self.parentframe, -1)
|
||||
print "Adding fauxbar."
|
||||
self.nullbar.Reparent(self.parentframe)
|
||||
print "Reparented."
|
||||
self.parentframe.SetToolBar(self.nullbar)
|
||||
print "Set toolbar"
|
||||
col = wxNamedColour("GREY")
|
||||
col = wx.NamedColour("GREY")
|
||||
self.nullbar.SetBackgroundColour(col)
|
||||
print "Set color"
|
||||
size = self.parentframe.GetSize()
|
||||
self.parentframe.SetSize(wxSize(0,0))
|
||||
self.parentframe.SetSize((0,0))
|
||||
self.parentframe.SetSize(size)
|
||||
print "Set size"
|
||||
else:
|
||||
@@ -276,7 +299,7 @@ else:
|
||||
self.nullbar.Reparent(self.floatframe)
|
||||
self.parentframe.SetToolBar(None)
|
||||
size = self.parentframe.GetSize()
|
||||
self.parentframe.SetSize(wxSize(0,0))
|
||||
self.parentframe.SetSize((0,0))
|
||||
self.parentframe.SetSize(size)
|
||||
|
||||
|
||||
|
@@ -1,3 +1,7 @@
|
||||
# 12/07/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o 2.5 Compatability changes
|
||||
#
|
||||
|
||||
import wx
|
||||
from wx.lib.evtmgr import eventManager
|
||||
@@ -11,8 +15,8 @@ class FoldOutWindow(wx.PopupWindow):
|
||||
self.handlers={}
|
||||
self.InitColors()
|
||||
self.inWindow=False
|
||||
wx.EVT_ENTER_WINDOW(self,self.evEnter)
|
||||
wx.EVT_LEAVE_WINDOW(self,self.evLeave)
|
||||
self.Bind(wx.EVT_ENTER_WINDOW, self.evEnter)
|
||||
self.Bind(wx.EVT_LEAVE_WINDOW, self.evLeave)
|
||||
|
||||
def InitColors(self):
|
||||
faceClr = wx.SystemSettings_GetSystemColour(wx.SYS_COLOUR_WINDOW)
|
||||
@@ -22,11 +26,13 @@ class FoldOutWindow(wx.PopupWindow):
|
||||
id=wx.NewId()
|
||||
btn=wx.BitmapButton(self,id,bitmap)
|
||||
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.Layout()
|
||||
|
||||
if handler:
|
||||
self.handlers[id]=handler
|
||||
|
||||
return id
|
||||
|
||||
def Popup(self):
|
||||
@@ -35,8 +41,10 @@ class FoldOutWindow(wx.PopupWindow):
|
||||
|
||||
def OnBtnClick(self,event):
|
||||
id=event.GetEventObject().GetId()
|
||||
|
||||
if self.handlers.has_key(id):
|
||||
self.handlers[id](event)
|
||||
|
||||
self.Hide()
|
||||
self.inWindow=False
|
||||
event.Skip()
|
||||
@@ -50,6 +58,7 @@ class FoldOutWindow(wx.PopupWindow):
|
||||
if self.inWindow:
|
||||
if not self.rect.Inside(self.ClientToScreen(event.GetPosition())):
|
||||
self.Hide()
|
||||
|
||||
event.Skip()
|
||||
|
||||
|
||||
@@ -60,10 +69,12 @@ class FoldOutMenu(wx.BitmapButton):
|
||||
def __init__(self,parent,id,bitmap,pos = wx.DefaultPosition,
|
||||
size = wx.DefaultSize, style = wx.BU_AUTODRAW,
|
||||
validator = wx.DefaultValidator, name = "button"):
|
||||
|
||||
wx.BitmapButton.__init__(self, parent, id, bitmap, pos, size, style,
|
||||
validator, name)
|
||||
|
||||
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)
|
||||
|
||||
def AddButton(self,bitmap,handler=None):
|
||||
|
@@ -9,27 +9,31 @@
|
||||
# RCS-ID: $Id$
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------------
|
||||
# 12/07/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o 2.5 Compatability changes
|
||||
#
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.grid import wxGrid
|
||||
import wx
|
||||
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()
|
||||
wxEVT_COMMAND_GRID_ROW_MOVE = wxNewEventType()
|
||||
EVT_GRID_COL_MOVE = wx.PyEventBinder(wxEVT_COMMAND_GRID_COL_MOVE, 1)
|
||||
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):
|
||||
win.Connect(id, -1, wxEVT_COMMAND_GRID_ROW_MOVE, func)
|
||||
|
||||
|
||||
class wxGridColMoveEvent(wxPyCommandEvent):
|
||||
class wxGridColMoveEvent(wx.PyCommandEvent):
|
||||
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.moveColumn = dCol
|
||||
self.beforeColumn = bCol
|
||||
@@ -41,9 +45,9 @@ class wxGridColMoveEvent(wxPyCommandEvent):
|
||||
return self.beforeColumn
|
||||
|
||||
|
||||
class wxGridRowMoveEvent(wxPyCommandEvent):
|
||||
class wxGridRowMoveEvent(wx.PyCommandEvent):
|
||||
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.moveRow = dRow
|
||||
self.beforeRow = bRow
|
||||
@@ -65,12 +69,14 @@ def _ColToRect(self,col):
|
||||
rect = wxRect()
|
||||
rect.height = self.GetColLabelSize()
|
||||
rect.width = self.GetColSize(col)
|
||||
|
||||
for cCol in range(0,col):
|
||||
rect.x += self.GetColSize(cCol)
|
||||
|
||||
rect.y = self.GetGridColLabelWindow().GetPosition()[1]
|
||||
return rect
|
||||
|
||||
wxGrid.ColToRect = _ColToRect
|
||||
wx.grid.Grid.ColToRect = _ColToRect
|
||||
|
||||
|
||||
def _RowToRect(self,row):
|
||||
@@ -80,25 +86,27 @@ def _RowToRect(self,row):
|
||||
rect = wxRect()
|
||||
rect.width = self.GetRowLabelSize()
|
||||
rect.height = self.GetRowSize(row)
|
||||
|
||||
for cRow in range(0,row):
|
||||
rect.y += self.GetRowSize(cRow)
|
||||
|
||||
rect.x = self.GetGridRowLabelWindow().GetPosition()[0]
|
||||
return rect
|
||||
|
||||
wxGrid.RowToRect = _RowToRect
|
||||
wx.grid.Grid.RowToRect = _RowToRect
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
class ColDragWindow(wxWindow):
|
||||
class ColDragWindow(wx.Window):
|
||||
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.SetSize((self.image.GetWidth(),self.image.GetHeight()))
|
||||
self.ux = parent.GetScrollPixelsPerUnit()[0]
|
||||
self.moveColumn = dragCol
|
||||
|
||||
EVT_PAINT(self,self.OnPaint)
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
|
||||
def DisplayAt(self,pos,y):
|
||||
x = self.GetPositionTuple()[0]
|
||||
@@ -114,20 +122,24 @@ class ColDragWindow(wxWindow):
|
||||
parent = self.GetParent()
|
||||
sx = parent.GetViewStart()[0] * self.ux
|
||||
sx -= parent._rlSize
|
||||
x = self.GetPositionTuple()[0]
|
||||
w = self.GetSizeTuple()[0]
|
||||
x = self.GetPosition()[0]
|
||||
w = self.GetSize()[0]
|
||||
sCol = parent.XToCol(x + sx)
|
||||
eCol = parent.XToCol(x + w + sx)
|
||||
iPos = xPos = xCol = 99999
|
||||
centerPos = x + sx + (w / 2)
|
||||
|
||||
for col in range(sCol,eCol + 1):
|
||||
cx = parent.ColToRect(col)[0]
|
||||
|
||||
if abs(cx - centerPos) < iPos:
|
||||
iPos = abs(cx - centerPos)
|
||||
xCol = col
|
||||
xPos = cx
|
||||
|
||||
if xCol < 0 or xCol > parent.GetNumberCols():
|
||||
xCol = parent.GetNumberCols()
|
||||
|
||||
return (xPos - sx - x,xCol)
|
||||
|
||||
def GetInsertionColumn(self):
|
||||
@@ -137,11 +149,11 @@ class ColDragWindow(wxWindow):
|
||||
return self._GetInsertionInfo()[0]
|
||||
|
||||
def OnPaint(self,evt):
|
||||
dc = wxPaintDC(self)
|
||||
dc = wx.PaintDC(self)
|
||||
w,h = self.GetSize()
|
||||
dc.DrawBitmap(self.image, (0,0))
|
||||
dc.SetPen(wxPen(wxBLACK,1,wxSOLID))
|
||||
dc.SetBrush(wxTRANSPARENT_BRUSH)
|
||||
dc.SetPen(wx.Pen(wx.BLACK,1,wx.SOLID))
|
||||
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
||||
dc.DrawRectangle((0,0), (w,h))
|
||||
iPos = self.GetInsertionPos()
|
||||
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):
|
||||
wxWindow.__init__(self,parent,-1, style=wxSIMPLE_BORDER)
|
||||
wx.Window.__init__(self,parent,-1, style=wx.SIMPLE_BORDER)
|
||||
self.image = image
|
||||
self.SetSize((self.image.GetWidth(),self.image.GetHeight()))
|
||||
self.uy = parent.GetScrollPixelsPerUnit()[1]
|
||||
self.moveRow = dragRow
|
||||
|
||||
EVT_PAINT(self,self.OnPaint)
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
|
||||
def DisplayAt(self,x,pos):
|
||||
y = self.GetPositionTuple()[1]
|
||||
y = self.GetPosition()[1]
|
||||
if y == pos:
|
||||
self.Refresh() # Need to display insertion point
|
||||
else:
|
||||
@@ -173,20 +185,24 @@ class RowDragWindow(wxWindow):
|
||||
parent = self.GetParent()
|
||||
sy = parent.GetViewStart()[1] * self.uy
|
||||
sy -= parent._clSize
|
||||
y = self.GetPositionTuple()[1]
|
||||
h = self.GetSizeTuple()[1]
|
||||
y = self.GetPosition()[1]
|
||||
h = self.GetSize()[1]
|
||||
sRow = parent.YToRow(y + sy)
|
||||
eRow = parent.YToRow(y + h + sy)
|
||||
iPos = yPos = yRow = 99999
|
||||
centerPos = y + sy + (h / 2)
|
||||
|
||||
for row in range(sRow,eRow + 1):
|
||||
cy = parent.RowToRect(row)[1]
|
||||
|
||||
if abs(cy - centerPos) < iPos:
|
||||
iPos = abs(cy - centerPos)
|
||||
yRow = row
|
||||
yPos = cy
|
||||
|
||||
if yRow < 0 or yRow > parent.GetNumberRows():
|
||||
yRow = parent.GetNumberRows()
|
||||
|
||||
return (yPos - sy - y,yRow)
|
||||
|
||||
def GetInsertionRow(self):
|
||||
@@ -196,20 +212,20 @@ class RowDragWindow(wxWindow):
|
||||
return self._GetInsertionInfo()[0]
|
||||
|
||||
def OnPaint(self,evt):
|
||||
dc = wxPaintDC(self)
|
||||
dc = wx.PaintDC(self)
|
||||
w,h = self.GetSize()
|
||||
dc.DrawBitmap(self.image, (0,0))
|
||||
dc.SetPen(wxPen(wxBLACK,1,wxSOLID))
|
||||
dc.SetBrush(wxTRANSPARENT_BRUSH)
|
||||
dc.SetPen(wx.Pen(wx.BLACK,1,wx.SOLID))
|
||||
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
||||
dc.DrawRectangle((0,0), (w,h))
|
||||
iPos = self.GetInsertionPos()
|
||||
dc.DrawLine((w - 10,iPos), (w,iPos))
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
class wxGridColMover(wxEvtHandler):
|
||||
class wxGridColMover(wx.EvtHandler):
|
||||
def __init__(self,grid):
|
||||
wxEvtHandler.__init__(self)
|
||||
wx.EvtHandler.__init__(self)
|
||||
|
||||
self.grid = grid
|
||||
self.grid._rlSize = self.grid.GetRowLabelSize()
|
||||
@@ -222,37 +238,48 @@ class wxGridColMover(wxEvtHandler):
|
||||
self.didMove = False
|
||||
self.isDragging = False
|
||||
|
||||
EVT_MOTION(self,self.OnMouseMove)
|
||||
EVT_LEFT_DOWN(self,self.OnPress)
|
||||
EVT_LEFT_UP(self,self.OnRelease)
|
||||
self.Bind(wx.EVT_MOTION, self.OnMouseMove)
|
||||
self.Bind(wx.EVT_LEFT_DOWN, self.OnPress)
|
||||
self.Bind(wx.EVT_LEFT_UP, self.OnRelease)
|
||||
|
||||
def OnMouseMove(self,evt):
|
||||
if self.isDragging:
|
||||
if abs(self.startX - evt.m_x) >= 3:
|
||||
self.didMove = True
|
||||
sx,y = self.grid.GetViewStart()
|
||||
w,h = self.lwin.GetClientSizeTuple()
|
||||
w,h = self.lwin.GetClientSize()
|
||||
x = sx * self.ux
|
||||
|
||||
if (evt.m_x + x) < x:
|
||||
x = evt.m_x + x
|
||||
elif evt.m_x > w:
|
||||
x += evt.m_x - w
|
||||
|
||||
if x < 1: x = 0
|
||||
else: x /= self.ux
|
||||
|
||||
if x != sx:
|
||||
if wxPlatform == '__WXMSW__':
|
||||
if wx.Platform == '__WXMSW__':
|
||||
self.colWin.Show(False)
|
||||
|
||||
self.grid.Scroll(x,y)
|
||||
|
||||
x,y = self.lwin.ClientToScreenXY(evt.m_x,0)
|
||||
x,y = self.grid.ScreenToClientXY(x,y)
|
||||
|
||||
if not self.colWin.IsShown():
|
||||
self.colWin.Show(True)
|
||||
|
||||
px = x - self.cellX
|
||||
|
||||
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)
|
||||
return
|
||||
|
||||
evt.Skip()
|
||||
|
||||
def OnPress(self,evt):
|
||||
@@ -261,7 +288,8 @@ class wxGridColMover(wxEvtHandler):
|
||||
sx -= self.grid._rlSize
|
||||
px,py = self.lwin.ClientToScreenXY(evt.m_x,evt.m_y)
|
||||
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()
|
||||
return
|
||||
|
||||
@@ -270,7 +298,7 @@ class wxGridColMover(wxEvtHandler):
|
||||
col = self.grid.XToCol(px + sx)
|
||||
rect = self.grid.ColToRect(col)
|
||||
self.cellX = px + sx - rect.x
|
||||
size = self.lwin.GetSizeTuple()
|
||||
size = self.lwin.GetSize()
|
||||
rect.y = 0
|
||||
rect.x -= sx + self.grid._rlSize
|
||||
rect.height = size[1]
|
||||
@@ -284,37 +312,40 @@ class wxGridColMover(wxEvtHandler):
|
||||
self.lwin.ReleaseMouse()
|
||||
self.colWin.Show(False)
|
||||
self.isDragging = False
|
||||
|
||||
if not self.didMove:
|
||||
px = self.lwin.ClientToScreenXY(self.startX,0)[0]
|
||||
px = self.grid.ScreenToClientXY(px,0)[0]
|
||||
sx = self.grid.GetViewStart()[0] * self.ux
|
||||
sx -= self.grid._rlSize
|
||||
col = self.grid.XToCol(px+sx)
|
||||
if col != wxNOT_FOUND:
|
||||
|
||||
if col != wx.NOT_FOUND:
|
||||
self.grid.SelectCol(col,evt.m_controlDown)
|
||||
|
||||
return
|
||||
else:
|
||||
bCol = self.colWin.GetInsertionColumn()
|
||||
dCol = self.colWin.GetMoveColumn()
|
||||
wxPostEvent(self,wxGridColMoveEvent(self.grid.GetId(),
|
||||
dCol,bCol))
|
||||
wx.PostEvent(self,
|
||||
wxGridColMoveEvent(self.grid.GetId(), dCol, bCol))
|
||||
|
||||
self.colWin.Destroy()
|
||||
evt.Skip()
|
||||
|
||||
def _CaptureImage(self,rect):
|
||||
bmp = wxEmptyBitmap(rect.width,rect.height)
|
||||
memdc = wxMemoryDC()
|
||||
bmp = wx.EmptyBitmap(rect.width,rect.height)
|
||||
memdc = wx.MemoryDC()
|
||||
memdc.SelectObject(bmp)
|
||||
dc = wxWindowDC(self.lwin)
|
||||
dc = wx.WindowDC(self.lwin)
|
||||
memdc.Blit((0,0), rect.GetSize(), dc, rect.GetPosition())
|
||||
memdc.SelectObject(wxNullBitmap)
|
||||
memdc.SelectObject(wx.NullBitmap)
|
||||
return bmp
|
||||
|
||||
|
||||
|
||||
class wxGridRowMover(wxEvtHandler):
|
||||
class wxGridRowMover(wx.EvtHandler):
|
||||
def __init__(self,grid):
|
||||
wxEvtHandler.__init__(self)
|
||||
wx.EvtHandler.__init__(self)
|
||||
|
||||
self.grid = grid
|
||||
self.grid._clSize = self.grid.GetColLabelSize()
|
||||
@@ -327,9 +358,9 @@ class wxGridRowMover(wxEvtHandler):
|
||||
self.didMove = False
|
||||
self.isDragging = False
|
||||
|
||||
EVT_MOTION(self,self.OnMouseMove)
|
||||
EVT_LEFT_DOWN(self,self.OnPress)
|
||||
EVT_LEFT_UP(self,self.OnRelease)
|
||||
self.Bind(wx.EVT_MOTION, self.OnMouseMove)
|
||||
self.Bind(wx.EVT_LEFT_DOWN, self.OnPress)
|
||||
self.Bind(wx.EVT_LEFT_UP, self.OnRelease)
|
||||
|
||||
def OnMouseMove(self,evt):
|
||||
if self.isDragging:
|
||||
@@ -338,26 +369,40 @@ class wxGridRowMover(wxEvtHandler):
|
||||
x,sy = self.grid.GetViewStart()
|
||||
w,h = self.lwin.GetClientSizeTuple()
|
||||
y = sy * self.uy
|
||||
|
||||
if (evt.m_y + y) < y:
|
||||
y = evt.m_y + y
|
||||
elif 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 wxPlatform == '__WXMSW__':
|
||||
if wx.Platform == '__WXMSW__':
|
||||
self.rowWin.Show(False)
|
||||
|
||||
self.grid.Scroll(x,y)
|
||||
|
||||
x,y = self.lwin.ClientToScreenXY(0,evt.m_y)
|
||||
x,y = self.grid.ScreenToClientXY(x,y)
|
||||
|
||||
if not self.rowWin.IsShown():
|
||||
self.rowWin.Show(True)
|
||||
|
||||
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:
|
||||
py = h - self.rowWin.GetSizeTuple()[1] + self.grid._clSize
|
||||
|
||||
if py < 0 + 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)
|
||||
return
|
||||
|
||||
evt.Skip()
|
||||
|
||||
def OnPress(self,evt):
|
||||
@@ -366,7 +411,8 @@ class wxGridRowMover(wxEvtHandler):
|
||||
sy -= self.grid._clSize
|
||||
px,py = self.lwin.ClientToScreenXY(evt.m_x,evt.m_y)
|
||||
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()
|
||||
return
|
||||
|
||||
@@ -375,7 +421,7 @@ class wxGridRowMover(wxEvtHandler):
|
||||
row = self.grid.YToRow(py + sy)
|
||||
rect = self.grid.RowToRect(row)
|
||||
self.cellY = py + sy - rect.y
|
||||
size = self.lwin.GetSizeTuple()
|
||||
size = self.lwin.GetSize()
|
||||
rect.x = 0
|
||||
rect.y -= sy + self.grid._clSize
|
||||
rect.width = size[0]
|
||||
@@ -389,30 +435,34 @@ class wxGridRowMover(wxEvtHandler):
|
||||
self.lwin.ReleaseMouse()
|
||||
self.rowWin.Show(False)
|
||||
self.isDragging = False
|
||||
|
||||
if not self.didMove:
|
||||
py = self.lwin.ClientToScreenXY(0,self.startY)[1]
|
||||
py = self.grid.ScreenToClientXY(0,py)[1]
|
||||
sy = self.grid.GetViewStart()[1] * self.uy
|
||||
sy -= self.grid._clSize
|
||||
row = self.grid.YToRow(py + sy)
|
||||
if row != wxNOT_FOUND:
|
||||
|
||||
if row != wx.NOT_FOUND:
|
||||
self.grid.SelectRow(row,evt.m_controlDown)
|
||||
return
|
||||
else:
|
||||
bRow = self.rowWin.GetInsertionRow()
|
||||
dRow = self.rowWin.GetMoveRow()
|
||||
wxPostEvent(self,wxGridRowMoveEvent(self.grid.GetId(),
|
||||
dRow,bRow))
|
||||
|
||||
wx.PostEvent(self,
|
||||
wxGridRowMoveEvent(self.grid.GetId(), dRow, bRow))
|
||||
|
||||
self.rowWin.Destroy()
|
||||
evt.Skip()
|
||||
|
||||
def _CaptureImage(self,rect):
|
||||
bmp = wxEmptyBitmap(rect.width,rect.height)
|
||||
memdc = wxMemoryDC()
|
||||
bmp = wx.EmptyBitmap(rect.width,rect.height)
|
||||
memdc = wx.MemoryDC()
|
||||
memdc.SelectObject(bmp)
|
||||
dc = wxWindowDC(self.lwin)
|
||||
dc = wx.WindowDC(self.lwin)
|
||||
memdc.Blit((0,0), rect.GetSize(), dc, rect.GetPosition())
|
||||
memdc.SelectObject(wxNullBitmap)
|
||||
memdc.SelectObject(wx.NullBitmap)
|
||||
return bmp
|
||||
|
||||
|
||||
|
@@ -10,6 +10,10 @@
|
||||
# Copyright: (c) 1999 by Total Control Software
|
||||
# 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
|
||||
@@ -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
|
||||
that when the sizer changes size, the growable rows and colums are the
|
||||
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 wx
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class wxGridSizer(wxPySizer):
|
||||
class wxGridSizer(wx.PySizer):
|
||||
def __init__(self, rows=0, cols=0, hgap=0, vgap=0):
|
||||
wxPySizer.__init__(self)
|
||||
wx.PySizer.__init__(self)
|
||||
if rows == 0 and cols == 0:
|
||||
raise ValueError, "rows and cols cannot both be zero"
|
||||
|
||||
@@ -104,7 +105,7 @@ class wxGridSizer(wxPySizer):
|
||||
w = max(w, size.width)
|
||||
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)
|
||||
|
||||
|
||||
@@ -136,7 +137,9 @@ class wxGridSizer(wxPySizer):
|
||||
i = r * ncols + c
|
||||
if i < nitems:
|
||||
self.SetItemBounds(items[i], x, y, w, h)
|
||||
|
||||
y = y + h + self.vgap
|
||||
|
||||
x = x + w + self.hgap
|
||||
|
||||
|
||||
@@ -144,21 +147,21 @@ class wxGridSizer(wxPySizer):
|
||||
def SetItemBounds(self, item, x, y, w, h):
|
||||
# calculate the item's size and position within
|
||||
# its grid cell
|
||||
ipt = wxPoint(x, y)
|
||||
ipt = wx.Point(x, y)
|
||||
isz = item.CalcMin()
|
||||
flag = item.GetFlag()
|
||||
|
||||
if flag & wxEXPAND or flag & wxSHAPED:
|
||||
isz = wxSize(w, h)
|
||||
if flag & wx.EXPAND or flag & wx.SHAPED:
|
||||
isz = (w, h)
|
||||
else:
|
||||
if flag & wxALIGN_CENTER_HORIZONTAL:
|
||||
if flag & wx.ALIGN_CENTER_HORIZONTAL:
|
||||
ipt.x = x + (w - isz.width) / 2
|
||||
elif flag & wxALIGN_RIGHT:
|
||||
elif flag & wx.ALIGN_RIGHT:
|
||||
ipt.x = x + (w - isz.width)
|
||||
|
||||
if flag & wxALIGN_CENTER_VERTICAL:
|
||||
if flag & wx.ALIGN_CENTER_VERTICAL:
|
||||
ipt.y = y + (h - isz.height) / 2
|
||||
elif flag & wxALIGN_BOTTOM:
|
||||
elif flag & wx.ALIGN_BOTTOM:
|
||||
ipt.y = y + (h - isz.height)
|
||||
|
||||
item.SetDimension(ipt, isz)
|
||||
@@ -197,6 +200,7 @@ class wxFlexGridSizer(wxGridSizer):
|
||||
# Find the max width and height for any component.
|
||||
self.rowHeights = [0] * nrows
|
||||
self.colWidths = [0] * ncols
|
||||
|
||||
for i in range(len(items)):
|
||||
size = items[i].CalcMin()
|
||||
row = i / ncols
|
||||
@@ -208,7 +212,7 @@ class wxFlexGridSizer(wxGridSizer):
|
||||
cellsWidth = reduce(operator.__add__, self.colWidths)
|
||||
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)
|
||||
|
||||
|
||||
@@ -243,7 +247,7 @@ class wxFlexGridSizer(wxGridSizer):
|
||||
self.colWidths[idx] = self.colWidths[idx] + delta
|
||||
|
||||
# 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
|
||||
x = pt.x
|
||||
@@ -251,11 +255,14 @@ class wxFlexGridSizer(wxGridSizer):
|
||||
y = pt.y
|
||||
for r in range(nrows):
|
||||
i = r * ncols + c
|
||||
|
||||
if i < nitems:
|
||||
w = max(0, min(self.colWidths[c], sz.width - x))
|
||||
h = max(0, min(self.rowHeights[r], sz.height - y))
|
||||
self.SetItemBounds(items[i], x, y, w, h)
|
||||
|
||||
y = y + self.rowHeights[r] + self.vgap
|
||||
|
||||
x = x + self.colWidths[c] + self.hgap
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
@@ -8,17 +8,28 @@
|
||||
# Date: January 29, 2002
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# 1.0 Release
|
||||
# Create list of all available image file types
|
||||
# View "All Image" File Types as default filter
|
||||
# Sort the file list
|
||||
# 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
|
||||
from wxPython.wx import *
|
||||
import os
|
||||
import sys
|
||||
|
||||
import wx
|
||||
|
||||
dir_path = os.getcwd()
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
@@ -30,55 +41,37 @@ def ConvertBMP(file_nm):
|
||||
fl_fld = os.path.splitext(file_nm)
|
||||
ext = fl_fld[1]
|
||||
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
|
||||
|
||||
|
||||
def GetSize(file_nm): # for scaling image values
|
||||
image = ConvertBMP(file_nm)
|
||||
bmp = image.ConvertToBitmap()
|
||||
size = bmp.GetWidth(), bmp.GetHeight()
|
||||
return size
|
||||
|
||||
class ImageView(wxWindow):
|
||||
def __init__(self, parent, id=-1, pos=wxDefaultPosition, size=wxDefaultSize):
|
||||
wxWindow.__init__(self, parent, id, pos, size)
|
||||
|
||||
class ImageView(wx.Window):
|
||||
def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize):
|
||||
wx.Window.__init__(self, parent, id, pos, size)
|
||||
self.win = parent
|
||||
self.image = None
|
||||
self.back_color = 'WHITE'
|
||||
self.border_color = 'BLACK'
|
||||
|
||||
self.image_sizex = size.width
|
||||
self.image_sizey = size.height
|
||||
self.image_posx = pos.x
|
||||
self.image_posy = pos.y
|
||||
EVT_PAINT(self, self.OnPaint)
|
||||
|
||||
wxInitAllImageHandlers()
|
||||
# Changed API of wx uses tuples for size and pos now.
|
||||
self.image_sizex = size[0]
|
||||
self.image_sizey = size[1]
|
||||
self.image_posx = pos[0]
|
||||
self.image_posy = pos[1]
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
|
||||
def OnPaint(self, event):
|
||||
dc = wxPaintDC(self)
|
||||
dc = wx.PaintDC(self)
|
||||
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
|
||||
image = ConvertBMP(file_nm)
|
||||
@@ -86,10 +79,10 @@ class ImageView(wxWindow):
|
||||
self.Refresh()
|
||||
|
||||
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.SetPen(wxPen(wxNamedColour(self.border_color), 1))
|
||||
dc.DrawRectangle(0, 0, self.image_sizex, self.image_sizey)
|
||||
dc.SetPen(wx.Pen(wx.NamedColour(self.border_color), 1))
|
||||
dc.DrawRectangle((0, 0), (self.image_sizex, self.image_sizey))
|
||||
|
||||
def DrawImage(self, dc):
|
||||
try:
|
||||
@@ -98,6 +91,7 @@ class ImageView(wxWindow):
|
||||
return
|
||||
|
||||
self.DrawBorder(dc)
|
||||
|
||||
if image is None:
|
||||
return
|
||||
|
||||
@@ -119,12 +113,12 @@ class ImageView(wxWindow):
|
||||
image.Rescale(iwidth, iheight) # rescale to fit the window
|
||||
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):
|
||||
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.y_pos = 20
|
||||
@@ -145,9 +139,8 @@ class ImageDialog(wxDialog):
|
||||
|
||||
self.y_pos = self.y_pos + self.delta
|
||||
|
||||
mID = wxNewId()
|
||||
wxButton(self, mID, ' Set Directory ', wxPoint(self.x_pos, self.y_pos), size).SetDefault()
|
||||
EVT_BUTTON(self, mID, self.SetDirect)
|
||||
btn = wx.Button(self, -1, ' Set Directory ', (self.x_pos, self.y_pos), size).SetDefault()
|
||||
self.Bind(wx.EVT_BUTTON, self.SetDirect, btn)
|
||||
|
||||
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
|
||||
|
||||
# List of Labels
|
||||
mID = wxNewId()
|
||||
self.tb = tb = wxListBox(self, mID, wxPoint(self.x_pos, self.y_pos), wxSize(160, self.list_height), self.fl_list, wxLB_SINGLE)
|
||||
EVT_LISTBOX(self, mID, self.OnListClick)
|
||||
EVT_LISTBOX_DCLICK(self, mID, self.OnListDClick)
|
||||
self.tb = tb = wx.ListBox(self, -1, (self.x_pos, self.y_pos),
|
||||
(160, self.list_height), self.fl_list,
|
||||
wx.LB_SINGLE )
|
||||
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_posy = self.y_pos
|
||||
image_sizex = 150
|
||||
image_sizey = self.list_height
|
||||
|
||||
self.fl_types = ["All Images", "Bmp", "Gif", "Png", "Jpg", "Ico", "Pnm", "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.fl_types = [
|
||||
"All Images", "Bmp", "Gif", "Png", "Jpg", "Ico", "Pnm",
|
||||
"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.fl_ext = self.fl_ext_types[self.set_type]
|
||||
|
||||
mID = wxNewId()
|
||||
self.sel_type = wxComboBox(self, mID, self.set_type, wxPoint(image_posx , self.type_posy), wxSize(150, -1), self.fl_types, wxCB_DROPDOWN)
|
||||
EVT_COMBOBOX(self, mID, self.OnSetType)
|
||||
self.sel_type = wx.ComboBox(self, -1, self.set_type, (image_posx , self.type_posy),
|
||||
(150, -1), self.fl_types, wx.CB_DROPDOWN)
|
||||
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
|
||||
|
||||
mID = wxNewId()
|
||||
wxButton(self, mID, ' Select ', wxPoint(100, self.y_pos), size).SetDefault()
|
||||
EVT_BUTTON(self, mID, self.OnOk)
|
||||
btn = wx.Button(self, -1, ' Select ', (100, self.y_pos), size).SetDefault()
|
||||
self.Bind(wx.EVT_BUTTON, self.OnOk, btn)
|
||||
|
||||
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
|
||||
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.ResetFiles()
|
||||
@@ -200,11 +208,13 @@ class ImageDialog(wxDialog):
|
||||
def GetFiles(self): # get the file list using directory and extension values
|
||||
if self.fl_ext == "All":
|
||||
all_files = []
|
||||
|
||||
for ftypes in self.fl_types[1:-1]: # get list of all available image types
|
||||
filter = self.fl_ext_types[ftypes]
|
||||
print "filter = ", filter
|
||||
#print "filter = ", filter
|
||||
self.fl_val = FindFiles(self, self.set_dir, filter)
|
||||
all_files = all_files + self.fl_val.files # add to list of files
|
||||
|
||||
self.fl_list = all_files
|
||||
else:
|
||||
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
|
||||
|
||||
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):
|
||||
val = event.GetString() # get file type value
|
||||
@@ -233,22 +243,45 @@ class ImageDialog(wxDialog):
|
||||
self.image_view.SetValue(file_val)
|
||||
|
||||
def SetDirect(self, event): # set the new directory
|
||||
dlg = wxDirDialog(self)
|
||||
dlg = wx.DirDialog(self)
|
||||
dlg.SetPath(self.set_dir)
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
|
||||
if dlg.ShowModal() == wx.ID_OK:
|
||||
self.set_dir = dlg.GetPath()
|
||||
self.ResetFiles()
|
||||
|
||||
dlg.Destroy()
|
||||
|
||||
def ResetFiles(self): # refresh the display with files and initial image
|
||||
self.DisplayDir()
|
||||
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)
|
||||
|
||||
try:
|
||||
self.tb.SetSelection(0)
|
||||
self.SetListValue(0)
|
||||
except:
|
||||
self.image_view.SetValue(None)
|
||||
else:
|
||||
self.image_view.SetValue(None)
|
||||
|
||||
def GetFile(self):
|
||||
return self.set_file
|
||||
@@ -258,19 +291,22 @@ class ImageDialog(wxDialog):
|
||||
|
||||
def OnCancel(self, event):
|
||||
self.result = None
|
||||
self.EndModal(wxID_CANCEL)
|
||||
self.EndModal(wx.ID_CANCEL)
|
||||
|
||||
def OnOk(self, event):
|
||||
self.result = self.set_file
|
||||
self.EndModal(wxID_OK)
|
||||
self.EndModal(wx.ID_OK)
|
||||
|
||||
|
||||
def OnFileDlg(self):
|
||||
dlg = wxFileDialog(self, "Choose an Image File", ".", "", "Bmp (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg", wxOPEN)
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
dlg = wx.FileDialog(self, "Choose an Image File", ".", "",
|
||||
"Bmp (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg", wx.OPEN)
|
||||
|
||||
if dlg.ShowModal() == wx.ID_OK:
|
||||
path = dlg.GetPath()
|
||||
else:
|
||||
path = None
|
||||
|
||||
dlg.Destroy()
|
||||
return path
|
||||
|
||||
@@ -282,9 +318,11 @@ class FindFiles:
|
||||
self.file = ""
|
||||
mask = mask.upper()
|
||||
pattern = self.MakeRegex(mask)
|
||||
|
||||
for i in os.listdir(dir):
|
||||
if i == "." or i == "..":
|
||||
continue
|
||||
|
||||
path = os.path.join(dir, i)
|
||||
path = path.upper()
|
||||
value = i.upper()
|
||||
@@ -297,6 +335,7 @@ class FindFiles:
|
||||
def MakeRegex(self, pattern):
|
||||
import re
|
||||
f = "" # Set up a regex for file names
|
||||
|
||||
for ch in pattern:
|
||||
if ch == "*":
|
||||
f = f + ".*"
|
||||
@@ -306,6 +345,7 @@ class FindFiles:
|
||||
f = f + "."
|
||||
else:
|
||||
f = f + ch
|
||||
|
||||
return re.compile(f+'$')
|
||||
|
||||
def StripExt(self, file_nm):
|
||||
|
@@ -120,58 +120,57 @@ see the appropriate "stub" file in the wxPython demo.
|
||||
|
||||
"""
|
||||
|
||||
from wxPython.wx import *
|
||||
import sys, tempfile, os
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
class _MyStatusBar(wxStatusBar):
|
||||
import wx
|
||||
|
||||
class _MyStatusBar(wx.StatusBar):
|
||||
def __init__(self, parent, callbacks=None, useopenbutton=0):
|
||||
wxStatusBar.__init__(self, parent, -1, style=wxTAB_TRAVERSAL)
|
||||
wx.StatusBar.__init__(self, parent, -1, style=wx.TAB_TRAVERSAL)
|
||||
self.SetFieldsCount(3)
|
||||
|
||||
self.SetStatusText("",0)
|
||||
|
||||
ID = wxNewId()
|
||||
self.button1 = wxButton(self,ID,"Dismiss",
|
||||
style=wxTAB_TRAVERSAL)
|
||||
EVT_BUTTON(self,ID,self.OnButton1)
|
||||
self.button1 = wx.Button(self, -1, "Dismiss", style=wx.TAB_TRAVERSAL)
|
||||
self.Bind(wx.EVT_BUTTON, self.OnButton1, self.button1)
|
||||
|
||||
ID = wxNewId()
|
||||
if not useopenbutton:
|
||||
self.button2 = wxButton(self,ID,"Close File",
|
||||
style=wxTAB_TRAVERSAL)
|
||||
self.button2 = wx.Button(self, -1, "Close File", style=wx.TAB_TRAVERSAL)
|
||||
else:
|
||||
self.button2 = wxButton(self,ID,"Open New File",
|
||||
style=wxTAB_TRAVERSAL)
|
||||
EVT_BUTTON(self,ID,self.OnButton2)
|
||||
self.button2 = wx.Button(self, -1, "Open New File", style=wx.TAB_TRAVERSAL)
|
||||
|
||||
self.Bind(wx.EVT_BUTTON, self.OnButton2, self.button2)
|
||||
self.useopenbutton = useopenbutton
|
||||
self.callbacks = callbacks
|
||||
|
||||
# figure out how tall to make the status bar
|
||||
dc = wxClientDC(self)
|
||||
dc = wx.ClientDC(self)
|
||||
dc.SetFont(self.GetFont())
|
||||
(w,h) = dc.GetTextExtent('X')
|
||||
h = int(h * 1.8)
|
||||
self.SetSize(wxSize(100, h))
|
||||
self.SetSize((100, h))
|
||||
self.OnSize("dummy")
|
||||
EVT_SIZE(self,self.OnSize)
|
||||
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||
|
||||
# reposition things...
|
||||
def OnSize(self, event):
|
||||
self.CalculateSizes()
|
||||
rect = self.GetFieldRect(1)
|
||||
self.button1.SetPosition(wxPoint(rect.x+5, rect.y+2))
|
||||
self.button1.SetSize(wxSize(rect.width-10, rect.height-4))
|
||||
self.button1.SetPosition((rect.x+5, rect.y+2))
|
||||
self.button1.SetSize((rect.width-10, rect.height-4))
|
||||
rect = self.GetFieldRect(2)
|
||||
self.button2.SetPosition(wxPoint(rect.x+5, rect.y+2))
|
||||
self.button2.SetSize(wxSize(rect.width-10, rect.height-4))
|
||||
self.button2.SetPosition((rect.x+5, rect.y+2))
|
||||
self.button2.SetSize((rect.width-10, rect.height-4))
|
||||
|
||||
# widths........
|
||||
def CalculateSizes(self):
|
||||
dc = wxClientDC(self.button1)
|
||||
dc = wx.ClientDC(self.button1)
|
||||
dc.SetFont(self.button1.GetFont())
|
||||
(w1,h) = dc.GetTextExtent(self.button1.GetLabel())
|
||||
|
||||
dc = wxClientDC(self.button2)
|
||||
dc = wx.ClientDC(self.button2)
|
||||
dc.SetFont(self.button2.GetFont())
|
||||
(w2,h) = dc.GetTextExtent(self.button2.GetLabel())
|
||||
|
||||
@@ -185,6 +184,7 @@ class _MyStatusBar(wxStatusBar):
|
||||
self.button2.SetLabel ("Close File")
|
||||
elif self.callbacks[1] ():
|
||||
self.button2.SetLabel ("Open New File")
|
||||
|
||||
self.useopenbutton = 1 - self.useopenbutton
|
||||
self.OnSize("")
|
||||
self.button2.Refresh(True)
|
||||
@@ -217,6 +217,7 @@ class wxPyInformationalMessagesFrame:
|
||||
self.title = "%s %s" % (progname,text)
|
||||
self.parent = None # use the SetParent method if desired...
|
||||
self.softspace = 1 # of rather limited use
|
||||
|
||||
if dir:
|
||||
self.SetOutputDirectory(dir)
|
||||
|
||||
@@ -240,10 +241,14 @@ class wxPyInformationalMessagesFrame:
|
||||
|
||||
|
||||
def write(self, string):
|
||||
if not wxThread_IsMain():
|
||||
if not wx.Thread_IsMain():
|
||||
# Aquire the GUI mutex before making GUI calls. Mutex is released
|
||||
# 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.f:
|
||||
@@ -257,10 +262,11 @@ class wxPyInformationalMessagesFrame:
|
||||
move = 0
|
||||
|
||||
if not self.frame:
|
||||
self.frame = wxFrame(self.parent, -1, self.title, size=(450, 300),
|
||||
style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
|
||||
self.text = wxTextCtrl(self.frame, -1, "",
|
||||
style = wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH)
|
||||
self.frame = wx.Frame(self.parent, -1, self.title, size=(450, 300),
|
||||
style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
|
||||
|
||||
self.text = wx.TextCtrl(self.frame, -1, "",
|
||||
style = wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_RICH)
|
||||
|
||||
self.frame.sb = _MyStatusBar(self.frame,
|
||||
callbacks=[self.DisableOutput,
|
||||
@@ -270,7 +276,7 @@ class wxPyInformationalMessagesFrame:
|
||||
"nofile"))
|
||||
self.frame.SetStatusBar(self.frame.sb)
|
||||
self.frame.Show(True)
|
||||
EVT_CLOSE(self.frame, self.OnCloseWindow)
|
||||
self.frame.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
||||
|
||||
if hasattr(self,"nofile"):
|
||||
self.text.AppendText(
|
||||
@@ -284,6 +290,7 @@ class wxPyInformationalMessagesFrame:
|
||||
else:
|
||||
tempfile.tempdir = self.dir
|
||||
filename = os.path.abspath(tempfile.mktemp ())
|
||||
|
||||
self.text.AppendText(
|
||||
"Please close this window (or select the "
|
||||
"'Dismiss' button below) when desired. By "
|
||||
@@ -389,10 +396,10 @@ class wxPyInformationalMessagesFrame:
|
||||
|
||||
def OpenNewFile(self):
|
||||
self.CloseFile()
|
||||
dlg = wxFileDialog(self.frame,
|
||||
dlg = wx.FileDialog(self.frame,
|
||||
"Choose a new log file", self.dir,"","*",
|
||||
wxSAVE | wxHIDE_READONLY | wxOVERWRITE_PROMPT)
|
||||
if dlg.ShowModal() == wxID_CANCEL:
|
||||
wx.SAVE | wx.HIDE_READONLY | wx.OVERWRITE_PROMPT)
|
||||
if dlg.ShowModal() == wx.ID_CANCEL:
|
||||
dlg.Destroy()
|
||||
return 0
|
||||
else:
|
||||
@@ -434,7 +441,7 @@ class wxPyInformationalMessagesFrame:
|
||||
def flush(self):
|
||||
if self.text:
|
||||
self.text.SetInsertionPointEnd()
|
||||
wxYield()
|
||||
wx.Yield()
|
||||
|
||||
|
||||
def __call__(self,* args):
|
||||
|
@@ -24,16 +24,31 @@
|
||||
# wxIntCtrl also supports range limits, with the option of either
|
||||
# enforcing them or simply coloring the text of the control if the limits
|
||||
# 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
|
||||
MAXINT = maxint # (constants should be in upper case)
|
||||
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"
|
||||
# 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_V = (ord('V')+1) - ord('A')
|
||||
|
||||
|
||||
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):
|
||||
class wxIntUpdatedEvent(wx.PyCommandEvent):
|
||||
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.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
|
||||
prior to changing the value of the underlying wxTextCtrl.
|
||||
prior to changing the value of the underlying wx.TextCtrl.
|
||||
"""
|
||||
def __init__(self):
|
||||
wxPyValidator.__init__(self)
|
||||
EVT_CHAR(self, self.OnChar)
|
||||
wx.PyValidator.__init__(self)
|
||||
self.Bind(wx.EVT_CHAR, self.OnChar)
|
||||
|
||||
def Clone (self):
|
||||
return self.__class__()
|
||||
@@ -100,7 +108,7 @@ class wxIntValidator( wxPyValidator ):
|
||||
|
||||
|
||||
value = ctrl.GetValue()
|
||||
textval = wxTextCtrl.GetValue(ctrl)
|
||||
textval = wx.TextCtrl.GetValue(ctrl)
|
||||
allow_none = ctrl.IsNoneAllowed()
|
||||
|
||||
pos = ctrl.GetInsertionPoint()
|
||||
@@ -129,12 +137,12 @@ class wxIntValidator( wxPyValidator ):
|
||||
# Validate action, and predict resulting value, so we can
|
||||
# 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:
|
||||
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:]
|
||||
elif key == WXK_BACK and pos > 0:
|
||||
elif key == wx.WXK_BACK and pos > 0:
|
||||
new_text = textval[:pos-1] + textval[pos:]
|
||||
# (else value shouldn't change)
|
||||
|
||||
@@ -167,10 +175,12 @@ class wxIntValidator( wxPyValidator ):
|
||||
# size if ctrl limited to int. (if not,
|
||||
# disallow event.)
|
||||
new_value = ctrl._fromGUI(new_text)
|
||||
|
||||
if paste_text:
|
||||
paste_value = ctrl._fromGUI(paste_text)
|
||||
else:
|
||||
paste_value = 0
|
||||
|
||||
new_pos = sel_start + len(str(paste_value))
|
||||
|
||||
# if resulting value is 0, truncate and highlight value:
|
||||
@@ -184,13 +194,14 @@ class wxIntValidator( wxPyValidator ):
|
||||
and ( (value >= 0 and pos == 0)
|
||||
or (value < 0 and pos in [0,1]) ) ):
|
||||
allow_event = 0
|
||||
|
||||
paste = 1
|
||||
|
||||
except ValueError:
|
||||
allow_event = 0
|
||||
|
||||
|
||||
elif key < WXK_SPACE or key > 255:
|
||||
elif key < wx.WXK_SPACE or key > 255:
|
||||
pass # event ok
|
||||
|
||||
|
||||
@@ -254,19 +265,19 @@ class wxIntValidator( wxPyValidator ):
|
||||
# making this like "remove leading digits"
|
||||
|
||||
# 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) ):
|
||||
new_pos = new_pos - 1
|
||||
|
||||
wxCallAfter(ctrl.SetValue, new_value)
|
||||
wxCallAfter(ctrl.SetInsertionPoint, new_pos)
|
||||
wx.CallAfter(ctrl.SetValue, new_value)
|
||||
wx.CallAfter(ctrl.SetInsertionPoint, new_pos)
|
||||
internally_set = 1
|
||||
|
||||
elif paste:
|
||||
# Always do paste numerically, to remove
|
||||
# leading/trailing spaces
|
||||
wxCallAfter(ctrl.SetValue, new_value)
|
||||
wxCallAfter(ctrl.SetInsertionPoint, new_pos)
|
||||
wx.CallAfter(ctrl.SetValue, new_value)
|
||||
wx.CallAfter(ctrl.SetInsertionPoint, new_pos)
|
||||
internally_set = 1
|
||||
|
||||
elif (new_value == 0 and len(new_text) > 1 ):
|
||||
@@ -290,24 +301,24 @@ class wxIntValidator( wxPyValidator ):
|
||||
|
||||
if allow_event:
|
||||
if set_to_none:
|
||||
wxCallAfter(ctrl.SetValue, new_value)
|
||||
wx.CallAfter(ctrl.SetValue, new_value)
|
||||
|
||||
elif set_to_zero:
|
||||
# select to "empty" numeric value
|
||||
wxCallAfter(ctrl.SetValue, new_value)
|
||||
wxCallAfter(ctrl.SetInsertionPoint, 0)
|
||||
wxCallAfter(ctrl.SetSelection, 0, 1)
|
||||
wx.CallAfter(ctrl.SetValue, new_value)
|
||||
wx.CallAfter(ctrl.SetInsertionPoint, 0)
|
||||
wx.CallAfter(ctrl.SetSelection, 0, 1)
|
||||
|
||||
elif set_to_minus_one:
|
||||
wxCallAfter(ctrl.SetValue, new_value)
|
||||
wxCallAfter(ctrl.SetInsertionPoint, 1)
|
||||
wxCallAfter(ctrl.SetSelection, 1, 2)
|
||||
wx.CallAfter(ctrl.SetValue, new_value)
|
||||
wx.CallAfter(ctrl.SetInsertionPoint, 1)
|
||||
wx.CallAfter(ctrl.SetSelection, 1, 2)
|
||||
|
||||
elif not internally_set:
|
||||
event.Skip() # allow base wxTextCtrl to finish processing
|
||||
|
||||
elif not wxValidator_IsSilent():
|
||||
wxBell()
|
||||
elif not wx.Validator_IsSilent():
|
||||
wx.Bell()
|
||||
|
||||
|
||||
def TransferToWindow(self):
|
||||
@@ -316,7 +327,7 @@ class wxIntValidator( wxPyValidator ):
|
||||
The default implementation returns False, indicating that an error
|
||||
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):
|
||||
@@ -325,12 +336,12 @@ class wxIntValidator( wxPyValidator ):
|
||||
The default implementation returns False, indicating that an error
|
||||
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
|
||||
value, and provides bounds support and optional value limiting.
|
||||
@@ -401,33 +412,33 @@ class wxIntCtrl(wxTextCtrl):
|
||||
|
||||
def __init__ (
|
||||
self, parent, id=-1, value = 0,
|
||||
pos = wxDefaultPosition, size = wxDefaultSize,
|
||||
style = 0, validator = wxDefaultValidator,
|
||||
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||
style = 0, validator = wx.DefaultValidator,
|
||||
name = "integer",
|
||||
min=None, max=None,
|
||||
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:
|
||||
self.__min = None
|
||||
self.__max = None
|
||||
self.__limited = 0
|
||||
self.__default_color = wxBLACK
|
||||
self.__oob_color = wxRED
|
||||
self.__default_color = wx.BLACK
|
||||
self.__oob_color = wx.RED
|
||||
self.__allow_none = 0
|
||||
self.__allow_long = 0
|
||||
self.__oldvalue = None
|
||||
|
||||
if validator == wxDefaultValidator:
|
||||
if validator == wx.DefaultValidator:
|
||||
validator = wxIntValidator()
|
||||
|
||||
wxTextCtrl.__init__(
|
||||
wx.TextCtrl.__init__(
|
||||
self, parent, id, self._toGUI(0),
|
||||
pos, size, style, validator, name )
|
||||
|
||||
# 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
|
||||
|
||||
@@ -444,8 +455,8 @@ class wxIntCtrl(wxTextCtrl):
|
||||
"""
|
||||
Handles an event indicating that the text control's value
|
||||
has changed, and issue EVT_INT event.
|
||||
NOTE: using wxTextCtrl.SetValue() to change the control's
|
||||
contents from within a EVT_CHAR handler can cause double
|
||||
NOTE: using wx.TextCtrl.SetValue() to change the control's
|
||||
contents from within a wx.EVT_CHAR handler can cause double
|
||||
text events. So we check for actual changes to the text
|
||||
before passing the events on.
|
||||
"""
|
||||
@@ -465,7 +476,7 @@ class wxIntCtrl(wxTextCtrl):
|
||||
"""
|
||||
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):
|
||||
"""
|
||||
@@ -476,7 +487,7 @@ class wxIntCtrl(wxTextCtrl):
|
||||
A ValueError exception will be raised if an invalid value
|
||||
is specified.
|
||||
"""
|
||||
wxTextCtrl.SetValue( self, self._toGUI(value) )
|
||||
wx.TextCtrl.SetValue( self, self._toGUI(value) )
|
||||
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
|
||||
values. If the value currently exceeds the bounds, it will be
|
||||
@@ -770,13 +781,13 @@ class wxIntCtrl(wxTextCtrl):
|
||||
"""
|
||||
sel_start, sel_to = self.GetSelection()
|
||||
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])
|
||||
wxTheClipboard.Open()
|
||||
wxTheClipboard.SetData(do)
|
||||
wxTheClipboard.Close()
|
||||
wx.TheClipboard.Open()
|
||||
wx.TheClipboard.SetData(do)
|
||||
wx.TheClipboard.Close()
|
||||
if select_len == len(wxTextCtrl.GetValue(self)):
|
||||
if not self.IsNoneAllowed():
|
||||
self.SetValue(0)
|
||||
@@ -793,10 +804,10 @@ class wxIntCtrl(wxTextCtrl):
|
||||
"""
|
||||
Subroutine for getting the current contents of the clipboard.
|
||||
"""
|
||||
do = wxTextDataObject()
|
||||
wxTheClipboard.Open()
|
||||
success = wxTheClipboard.GetData(do)
|
||||
wxTheClipboard.Close()
|
||||
do = wx.TextDataObject()
|
||||
wx.TheClipboard.Open()
|
||||
success = wx.TheClipboard.GetData(do)
|
||||
wx.TheClipboard.Close()
|
||||
|
||||
if not success:
|
||||
return None
|
||||
@@ -815,7 +826,7 @@ class wxIntCtrl(wxTextCtrl):
|
||||
if paste_text:
|
||||
# (conversion will raise ValueError if paste isn't legal)
|
||||
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:]
|
||||
if new_text == '' and self.IsNoneAllowed():
|
||||
self.SetValue(None)
|
||||
@@ -823,7 +834,7 @@ class wxIntCtrl(wxTextCtrl):
|
||||
value = self._fromGUI(new_text)
|
||||
self.SetValue(value)
|
||||
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
|
||||
|
||||
class myDialog(wxDialog):
|
||||
class myDialog(wx.Dialog):
|
||||
def __init__(self, parent, id, title,
|
||||
pos = wxPyDefaultPosition, size = wxPyDefaultSize,
|
||||
style = wxDEFAULT_DIALOG_STYLE ):
|
||||
wxDialog.__init__(self, parent, id, title, pos, size, style)
|
||||
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||
style = wx.DEFAULT_DIALOG_STYLE ):
|
||||
wx.Dialog.__init__(self, parent, id, title, pos, size, style)
|
||||
|
||||
self.int_ctrl = wxIntCtrl(self, wxNewId(), size=(55,20))
|
||||
self.OK = wxButton( self, wxID_OK, "OK")
|
||||
self.Cancel = wxButton( self, wxID_CANCEL, "Cancel")
|
||||
self.int_ctrl = wxIntCtrl(self, wx.NewId(), size=(55,20))
|
||||
self.OK = wx.Button( self, wx.ID_OK, "OK")
|
||||
self.Cancel = wx.Button( self, wx.ID_CANCEL, "Cancel")
|
||||
|
||||
vs = wxBoxSizer( wxVERTICAL )
|
||||
vs.AddWindow( self.int_ctrl, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
hs = wxBoxSizer( wxHORIZONTAL )
|
||||
hs.AddWindow( self.OK, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
hs.AddWindow( self.Cancel, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
vs.AddSizer(hs, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
vs = wx.BoxSizer( wx.VERTICAL )
|
||||
vs.Add( self.int_ctrl, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
||||
hs = wx.BoxSizer( wx.HORIZONTAL )
|
||||
hs.Add( self.OK, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
||||
hs.Add( self.Cancel, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
||||
vs.Add(hs, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
||||
|
||||
self.SetAutoLayout( True )
|
||||
self.SetSizer( vs )
|
||||
vs.Fit( 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):
|
||||
print 'int now', event.GetValue()
|
||||
|
||||
class TestApp(wxApp):
|
||||
class TestApp(wx.App):
|
||||
def OnInit(self):
|
||||
try:
|
||||
self.frame = wxFrame(NULL, -1, "Test",
|
||||
wxPoint(20,20), wxSize(120,100) )
|
||||
self.panel = wxPanel(self.frame, -1)
|
||||
button = wxButton(self.panel, 10, "Push Me",
|
||||
wxPoint(20, 20))
|
||||
EVT_BUTTON(self, 10, self.OnClick)
|
||||
self.frame = wx.Frame(None, -1, "Test", (20,20), (120,100) )
|
||||
self.panel = wx.Panel(self.frame, -1)
|
||||
button = wx.Button(self.panel, 10, "Push Me", (20, 20))
|
||||
self.Bind(wx.EVT_BUTTON, self.OnClick, button)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
return False
|
||||
|
@@ -1,9 +1,12 @@
|
||||
from wxPython.wx import wxLayoutConstraints,\
|
||||
wxTop, wxLeft, wxBottom, wxRight, \
|
||||
wxHeight, wxWidth, wxCentreX, wxCentreY
|
||||
import re
|
||||
# 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o Updated for wx namespace
|
||||
#
|
||||
|
||||
class Layoutf(wxLayoutConstraints):
|
||||
import re
|
||||
import wx
|
||||
|
||||
class Layoutf(wx.LayoutConstraints):
|
||||
"""
|
||||
The class Layoutf(wxLayoutConstraints) presents a simplification
|
||||
of the wxLayoutConstraints syntax. The name Layoutf is choosen
|
||||
@@ -117,15 +120,15 @@ time of this writing not documented.
|
||||
op_d = { '=': 'SameAs', '%': 'PercentOf', '<': 'LeftOf',
|
||||
'>': 'RightOf', '^': 'Above', '_': 'Below',
|
||||
'!': 'Absolute', '?': 'Unconstrained', '*': 'AsIs' }
|
||||
cmp_d = { 't': 'wxTop', 'l': 'wxLeft', 'b': 'wxBottom',
|
||||
'r': 'wxRight', 'h': 'wxHeight', 'w': 'wxWidth',
|
||||
'x': 'wxCentreX', 'y': 'wxCentreY' }
|
||||
cmp_d = { 't': 'wx.Top', 'l': 'wx.Left', 'b': 'wx.Bottom',
|
||||
'r': 'wx.Right', 'h': 'wx.Height', 'w': 'wx.Width',
|
||||
'x': 'wx.CentreX', 'y': 'wx.CentreY' }
|
||||
|
||||
rexp1 = re.compile('^\s*([tlrbhwxy])\s*([!\?\*])\s*(\d*)\s*$')
|
||||
rexp2 = re.compile('^\s*([tlrbhwxy])\s*([=%<>^_])\s*([tlrbhwxy]?)\s*(\d*)\s*#(\d+)\s*$')
|
||||
|
||||
def __init__(self,pstr=None,winlist=None):
|
||||
wxLayoutConstraints.__init__(self)
|
||||
wx.LayoutConstraints.__init__(self)
|
||||
if pstr:
|
||||
self.pack(pstr,winlist)
|
||||
|
||||
@@ -194,62 +197,59 @@ time of this writing not documented.
|
||||
self.cmp_d[g[2]])
|
||||
|
||||
if __name__=='__main__':
|
||||
from wxPython.wx import *
|
||||
|
||||
class TestLayoutf(wxFrame):
|
||||
class TestLayoutf(wx.Frame):
|
||||
def __init__(self, parent):
|
||||
wxFrame.__init__(self, parent, -1, 'Test Layout Constraints',
|
||||
wxPyDefaultPosition, wxSize(500, 300))
|
||||
EVT_CLOSE(self, self.OnCloseWindow)
|
||||
wx.Frame.__init__(self, parent, -1, 'Test Layout Constraints',
|
||||
wx.DefaultPosition, (500, 300))
|
||||
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
||||
|
||||
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.SetBackgroundColour(wxBLUE)
|
||||
self.panelA = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
|
||||
self.panelA.SetBackgroundColour(wx.BLUE)
|
||||
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.SetBackgroundColour(wxRED)
|
||||
self.panelB = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
|
||||
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.panelC = wxWindow(self, -1, wxPyDefaultPosition, wxPyDefaultSize, wxSIMPLE_BORDER)
|
||||
self.panelC.SetBackgroundColour(wxWHITE)
|
||||
self.panelC = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
|
||||
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)))
|
||||
|
||||
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,)))
|
||||
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,)))
|
||||
|
||||
self.panelD = wxWindow(self.panelC, -1, wxPyDefaultPosition, wxPyDefaultSize, wxSIMPLE_BORDER)
|
||||
self.panelD.SetBackgroundColour(wxGREEN)
|
||||
self.panelD = wx.Window(self.panelC, -1, style=wx.SIMPLE_BORDER)
|
||||
self.panelD.SetBackgroundColour(wx.GREEN)
|
||||
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,)))
|
||||
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):
|
||||
self.Close(True)
|
||||
|
||||
def OnAbout(self, event):
|
||||
try:
|
||||
from dialogs import wxScrolledMessageDialog
|
||||
msg = wxScrolledMessageDialog(self, Layoutf.__doc__, "about")
|
||||
import wx.lib.dialogs
|
||||
msg = wx.lib.dialogs.wxScrolledMessageDialog(self, Layoutf.__doc__, "about")
|
||||
msg.ShowModal()
|
||||
except:
|
||||
print msg
|
||||
msg.Destroy()
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
|
||||
class TestApp(wxApp):
|
||||
class TestApp(wx.App):
|
||||
def OnInit(self):
|
||||
frame = TestLayoutf(NULL)
|
||||
frame = TestLayoutf(None)
|
||||
frame.Show(1)
|
||||
self.SetTopWindow(frame)
|
||||
return 1
|
||||
|
@@ -6,6 +6,10 @@
|
||||
# RCS-ID: $Id$
|
||||
# License: wxWindows license
|
||||
#----------------------------------------------------------------------------
|
||||
# 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o Updated for wx namespace (minor)
|
||||
#
|
||||
|
||||
"""<html><body>
|
||||
<P>
|
||||
@@ -47,9 +51,9 @@ their own demo pages and interface descriptions.
|
||||
</body></html>
|
||||
"""
|
||||
|
||||
from wxPython.lib.maskededit import wxMaskedTextCtrl, wxMaskedComboBox, wxIpAddrCtrl
|
||||
from wxPython.lib.maskednumctrl import wxMaskedNumCtrl
|
||||
from wxPython.lib.timectrl import wxTimeCtrl
|
||||
from wx.lib.maskededit import wxMaskedTextCtrl, wxMaskedComboBox, wxIpAddrCtrl
|
||||
from wx.lib.maskednumctrl import wxMaskedNumCtrl
|
||||
from wx.lib.timectrl import wxTimeCtrl
|
||||
|
||||
|
||||
# "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
|
||||
# is derived from wxMaskedTextCtrl. As such, it supports a limited range
|
||||
# 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>
|
||||
<P>
|
||||
<B>wxMaskedNumCtrl:</B>
|
||||
@@ -344,32 +350,32 @@ the field values on entry.
|
||||
</body></html>
|
||||
"""
|
||||
|
||||
from wxPython.wx import *
|
||||
import types, string, copy
|
||||
import copy
|
||||
import string
|
||||
import types
|
||||
|
||||
import wx
|
||||
|
||||
from sys import maxint
|
||||
MAXINT = maxint # (constants should be in upper case)
|
||||
MININT = -maxint-1
|
||||
|
||||
from wxPython.tools.dbg import Logger
|
||||
from wxPython.lib.maskededit import wxMaskedEditMixin, wxMaskedTextCtrl, Field
|
||||
from wx.tools.dbg import Logger
|
||||
from wx.lib.maskededit import wxMaskedEditMixin, wxMaskedTextCtrl, Field
|
||||
|
||||
dbg = Logger()
|
||||
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):
|
||||
"""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):
|
||||
class wxMaskedNumNumberUpdatedEvent(wx.PyCommandEvent):
|
||||
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.SetEventObject(object)
|
||||
@@ -408,8 +414,8 @@ class wxMaskedNumCtrl(wxMaskedTextCtrl):
|
||||
|
||||
def __init__ (
|
||||
self, parent, id=-1, value = 0,
|
||||
pos = wxDefaultPosition, size = wxDefaultSize,
|
||||
style = wxTE_PROCESS_TAB, validator = wxDefaultValidator,
|
||||
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||
style = wx.TE_PROCESS_TAB, validator = wx.DefaultValidator,
|
||||
name = "maskednum",
|
||||
**kwargs ):
|
||||
|
||||
@@ -493,13 +499,13 @@ class wxMaskedNumCtrl(wxMaskedTextCtrl):
|
||||
validFunc=self.IsInBounds,
|
||||
setupEventHandling = False)
|
||||
|
||||
EVT_SET_FOCUS( self, self._OnFocus ) ## defeat automatic full selection
|
||||
EVT_KILL_FOCUS( self, self._OnKillFocus ) ## run internal validator
|
||||
EVT_LEFT_DCLICK(self, self._OnDoubleClick) ## select field under cursor on dclick
|
||||
EVT_RIGHT_UP(self, self._OnContextMenu ) ## bring up an appropriate context menu
|
||||
EVT_KEY_DOWN( self, self._OnKeyDown ) ## capture control events not normally seen, eg ctrl-tab.
|
||||
EVT_CHAR( self, self._OnChar ) ## handle each keypress
|
||||
EVT_TEXT( self, self.GetId(), self.OnTextChange ) ## color control appropriately & keep
|
||||
self.Bind(wx.EVT_SET_FOCUS, self._OnFocus ) ## defeat automatic full selection
|
||||
self.Bind(wx.EVT_KILL_FOCUS, self._OnKillFocus ) ## run internal validator
|
||||
self.Bind(wx.EVT_LEFT_DCLICK, self._OnDoubleClick) ## select field under cursor on dclick
|
||||
self.Bind(wx.EVT_RIGHT_UP, self._OnContextMenu ) ## bring up an appropriate context menu
|
||||
self.Bind(wx.EVT_KEY_DOWN, self._OnKeyDown ) ## capture control events not normally seen, eg ctrl-tab.
|
||||
self.Bind(wx.EVT_CHAR, self._OnChar ) ## handle each keypress
|
||||
self.Bind(wx.EVT_TEXT, self.OnTextChange ) ## color control appropriately & keep
|
||||
## track of previous value for undo
|
||||
|
||||
# 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:
|
||||
text = text.replace(old_decimalchar, self._decimalChar)
|
||||
if text != self._GetValue():
|
||||
wxTextCtrl.SetValue(self, text)
|
||||
wx.TextCtrl.SetValue(self, text)
|
||||
|
||||
value = self.GetValue()
|
||||
|
||||
@@ -783,12 +789,12 @@ class wxMaskedNumCtrl(wxMaskedTextCtrl):
|
||||
# limited and -1 is out of bounds
|
||||
if self._typedSign:
|
||||
self._isNeg = False
|
||||
if not wxValidator_IsSilent():
|
||||
wxBell()
|
||||
if not wx.Validator_IsSilent():
|
||||
wx.Bell()
|
||||
sel_start, sel_to = self._GetSelection()
|
||||
dbg('queuing reselection of (%d, %d)' % (sel_start, sel_to))
|
||||
wxCallAfter(self.SetInsertionPoint, sel_start) # preserve current selection/position
|
||||
wxCallAfter(self.SetSelection, sel_start, sel_to)
|
||||
wx.CallAfter(self.SetInsertionPoint, sel_start) # preserve current selection/position
|
||||
wx.CallAfter(self.SetSelection, sel_start, sel_to)
|
||||
|
||||
def _SetValue(self, value):
|
||||
"""
|
||||
@@ -888,12 +894,12 @@ class wxMaskedNumCtrl(wxMaskedTextCtrl):
|
||||
# is attempting to insert a digit in the middle of the control
|
||||
# resulting in something like " 3 45". Disallow such actions:
|
||||
dbg('>>>>>>>>>>>>>>>> "%s" does not convert to a long!' % int)
|
||||
if not wxValidator_IsSilent():
|
||||
wxBell()
|
||||
if not wx.Validator_IsSilent():
|
||||
wx.Bell()
|
||||
sel_start, sel_to = self._GetSelection()
|
||||
dbg('queuing reselection of (%d, %d)' % (sel_start, sel_to))
|
||||
wxCallAfter(self.SetInsertionPoint, sel_start) # preserve current selection/position
|
||||
wxCallAfter(self.SetSelection, sel_start, sel_to)
|
||||
wx.CallAfter(self.SetInsertionPoint, sel_start) # preserve current selection/position
|
||||
wx.CallAfter(self.SetSelection, sel_start, sel_to)
|
||||
dbg(indent=0)
|
||||
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_to = sel_start + len(str(abs(replacement)))
|
||||
dbg('queuing selection of (%d, %d)' %(sel_start, sel_to))
|
||||
wxCallAfter(self.SetInsertionPoint, sel_start)
|
||||
wxCallAfter(self.SetSelection, sel_start, sel_to)
|
||||
wx.CallAfter(self.SetInsertionPoint, sel_start)
|
||||
wx.CallAfter(self.SetSelection, sel_start, sel_to)
|
||||
dbg(indent=0)
|
||||
return
|
||||
|
||||
@@ -942,7 +948,7 @@ class wxMaskedNumCtrl(wxMaskedTextCtrl):
|
||||
wxMaskedTextCtrl._SetValue(self, adjvalue)
|
||||
# After all actions so far scheduled, check that resulting cursor
|
||||
# position is appropriate, and move if not:
|
||||
wxCallAfter(self._CheckInsertionPoint)
|
||||
wx.CallAfter(self._CheckInsertionPoint)
|
||||
|
||||
dbg('finished wxMaskedNumCtrl::_SetValue', indent=0)
|
||||
|
||||
@@ -975,7 +981,7 @@ class wxMaskedNumCtrl(wxMaskedTextCtrl):
|
||||
value = wxMaskedTextCtrl.GetValue(self)
|
||||
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 sel_start > 0 and sel_start < len(self._mask) and value[sel_start:sel_to] == self._groupChar:
|
||||
self.SetInsertionPoint(sel_start-1)
|
||||
@@ -986,7 +992,7 @@ class wxMaskedNumCtrl(wxMaskedTextCtrl):
|
||||
self.SetInsertionPoint(sel_start-2)
|
||||
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)
|
||||
and sel_start == sel_to
|
||||
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
|
||||
control with this function.
|
||||
"""
|
||||
return wxTextCtrl.GetValue(self)
|
||||
return wx.TextCtrl.GetValue(self)
|
||||
|
||||
|
||||
def GetValue(self):
|
||||
@@ -1438,41 +1444,39 @@ if __name__ == '__main__':
|
||||
|
||||
import traceback
|
||||
|
||||
class myDialog(wxDialog):
|
||||
class myDialog(wx.Dialog):
|
||||
def __init__(self, parent, id, title,
|
||||
pos = wxPyDefaultPosition, size = wxPyDefaultSize,
|
||||
style = wxDEFAULT_DIALOG_STYLE ):
|
||||
wxDialog.__init__(self, parent, id, title, pos, size, style)
|
||||
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||
style = wx.DEFAULT_DIALOG_STYLE ):
|
||||
wx.Dialog.__init__(self, parent, id, title, pos, size, style)
|
||||
|
||||
self.int_ctrl = wxMaskedNumCtrl(self, wxNewId(), size=(55,20))
|
||||
self.OK = wxButton( self, wxID_OK, "OK")
|
||||
self.Cancel = wxButton( self, wxID_CANCEL, "Cancel")
|
||||
self.int_ctrl = wxMaskedNumCtrl(self, wx.NewId(), size=(55,20))
|
||||
self.OK = wx.Button( self, wx.ID_OK, "OK")
|
||||
self.Cancel = wx.Button( self, wx.ID_CANCEL, "Cancel")
|
||||
|
||||
vs = wxBoxSizer( wxVERTICAL )
|
||||
vs.AddWindow( self.int_ctrl, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
hs = wxBoxSizer( wxHORIZONTAL )
|
||||
hs.AddWindow( self.OK, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
hs.AddWindow( self.Cancel, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
vs.AddSizer(hs, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
vs = wx.BoxSizer( wx.VERTICAL )
|
||||
vs.Add( self.int_ctrl, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
||||
hs = wx.BoxSizer( wx.HORIZONTAL )
|
||||
hs.Add( self.OK, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
||||
hs.Add( self.Cancel, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
||||
vs.Add(hs, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
|
||||
|
||||
self.SetAutoLayout( True )
|
||||
self.SetSizer( vs )
|
||||
vs.Fit( 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):
|
||||
print 'value now', event.GetValue()
|
||||
|
||||
class TestApp(wxApp):
|
||||
class TestApp(wx.App):
|
||||
def OnInit(self):
|
||||
try:
|
||||
self.frame = wxFrame(NULL, -1, "Test",
|
||||
wxPoint(20,20), wxSize(120,100) )
|
||||
self.panel = wxPanel(self.frame, -1)
|
||||
button = wxButton(self.panel, 10, "Push Me",
|
||||
wxPoint(20, 20))
|
||||
EVT_BUTTON(self, 10, self.OnClick)
|
||||
self.frame = wx.Frame(None, -1, "Test", (20,20), (120,100) )
|
||||
self.panel = wx.Panel(self.frame, -1)
|
||||
button = wx.Button(self.panel, -1, "Push Me", (20, 20))
|
||||
self.Bind(wx.EVT_BUTTON, self.OnClick, button)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
return False
|
||||
|
@@ -9,6 +9,10 @@
|
||||
# Copyright: (c) 2001 by Total Control Software
|
||||
# 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
|
||||
# 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):
|
||||
self.__enableEdit = 0
|
||||
wx.EVT_IDLE(self, self.__OnIdle)
|
||||
grid.EVT_GRID_SELECT_CELL(self, self.__OnSelectCell)
|
||||
self.Bind(wx.EVT_IDLE, self.__OnIdle)
|
||||
self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.__OnSelectCell)
|
||||
|
||||
|
||||
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
|
||||
#
|
||||
# Author: Robin Dunn
|
||||
@@ -9,8 +9,13 @@
|
||||
# Copyright: (c) 2001 by Total Control Software
|
||||
# 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):
|
||||
self.__size = size or self.DEFAULTICONSIZE
|
||||
self.__magicImageList = wxImageList (self.__size,self.__size)
|
||||
self.__magicImageList = wx.ImageList (self.__size,self.__size)
|
||||
self.__magicImageListMapping = {}
|
||||
self.SetImageList (
|
||||
self.__magicImageList, {
|
||||
16:wxIMAGE_LIST_SMALL,
|
||||
32:wxIMAGE_LIST_NORMAL,
|
||||
16:wx.IMAGE_LIST_SMALL,
|
||||
32:wx.IMAGE_LIST_NORMAL,
|
||||
}[self.__size]
|
||||
)
|
||||
for image in images:
|
||||
@@ -46,20 +51,20 @@ class MagicImageList:
|
||||
|
||||
|
||||
### 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'''
|
||||
index = self.__magicImageListMapping.get (id (icon))
|
||||
if index is None:
|
||||
if isinstance( icon, wxIconPtr ):
|
||||
index = self.__magicImageList.AddIcon( icon )
|
||||
elif isinstance( icon, wxBitmapPtr ):
|
||||
if isinstance( mask, wxColour ):
|
||||
elif isinstance( icon, wx.BitmapPtr ):
|
||||
if isinstance( mask, wx.Colour ):
|
||||
index = self.__magicImageList.AddWithColourMask( icon, mask )
|
||||
else:
|
||||
index = self.__magicImageList.Add( icon, mask )
|
||||
else:
|
||||
raise ValueError("Unexpected icon object %s, "
|
||||
"expected wxIcon or wxBitmap" % (icon))
|
||||
"expected wx.Icon or wx.Bitmap" % (icon))
|
||||
self.__magicImageListMapping [id (icon)] = index
|
||||
return index
|
||||
|
||||
|
@@ -9,22 +9,27 @@
|
||||
# Copyright: (c) 2001 by Total Control Software
|
||||
# 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 wx
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
|
||||
There are a few requirments needed in order for this to work genericly:
|
||||
|
||||
1. The combined class must have a GetListCtrl method that
|
||||
returns the wxListCtrl to be sorted, and the list control
|
||||
must exist at the time the wxColumnSorterMixin.__init__
|
||||
returns the wx.ListCtrl to be sorted, and the list control
|
||||
must exist at the time the wx.ColumnSorterMixin.__init__
|
||||
method is called because it uses GetListCtrl.
|
||||
|
||||
2. Items in the list control must have a unique data value set
|
||||
@@ -43,8 +48,8 @@ class wxColumnSorterMixin:
|
||||
self.SetColumnCount(numColumns)
|
||||
list = self.GetListCtrl()
|
||||
if not list:
|
||||
raise ValueError, "No wxListCtrl available"
|
||||
EVT_LIST_COL_CLICK(list, list.GetId(), self.__OnColClick)
|
||||
raise ValueError, "No wx.ListCtrl available"
|
||||
self.Bind(wx.EVT_LIST_COL_CLICK, self.__OnColClick, list)
|
||||
|
||||
|
||||
def SetColumnCount(self, newNumColumns):
|
||||
@@ -141,15 +146,15 @@ class wxColumnSorterMixin:
|
||||
|
||||
class wxListCtrlAutoWidthMixin:
|
||||
""" 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
|
||||
necessary) or empty space to the right of the last column.
|
||||
|
||||
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
|
||||
_OnResize method is called.
|
||||
|
||||
@@ -160,8 +165,8 @@ class wxListCtrlAutoWidthMixin:
|
||||
"""
|
||||
self._lastColMinWidth = None
|
||||
|
||||
EVT_SIZE(self, self._onResize)
|
||||
EVT_LIST_COL_END_DRAG(self, self.GetId(), self._onResize)
|
||||
self.Bind(wx.EVT_SIZE, self._onResize)
|
||||
self.Bind(wx.EVT_LIST_COL_END_DRAG, self._onResize, self)
|
||||
|
||||
|
||||
def resizeLastColumn(self, minWidth):
|
||||
@@ -171,7 +176,7 @@ class wxListCtrlAutoWidthMixin:
|
||||
a horizontal scrollbar. Otherwise, we expand the right-most column
|
||||
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
|
||||
be resized appropriately (eg, when adding, removing or resizing
|
||||
columns).
|
||||
@@ -186,11 +191,11 @@ class wxListCtrlAutoWidthMixin:
|
||||
# =====================
|
||||
|
||||
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.
|
||||
"""
|
||||
wxCallAfter(self._doResize)
|
||||
wx.CallAfter(self._doResize)
|
||||
event.Skip()
|
||||
|
||||
|
||||
@@ -216,9 +221,9 @@ class wxListCtrlAutoWidthMixin:
|
||||
# NOTE: on GTK, the scrollbar is included in the client size, but on
|
||||
# Windows it is not included
|
||||
listWidth = self.GetClientSize().width
|
||||
if wxPlatform != '__WXMSW__':
|
||||
if wx.Platform != '__WXMSW__':
|
||||
if self.GetItemCount() > self.GetCountPerPage():
|
||||
scrollWidth = wxSystemSettings_GetMetric(wxSYS_VSCROLL_X)
|
||||
scrollWidth = wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
|
||||
listWidth = listWidth - scrollWidth
|
||||
|
||||
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):
|
||||
"""Ensures the item the mouse is pointing at is selected before a popup.
|
||||
|
||||
@@ -251,36 +256,39 @@ def selectBeforePopup(event):
|
||||
if isinstance(ctrl, wxListCtrl):
|
||||
n, flags = ctrl.HitTest(event.GetPosition())
|
||||
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()):
|
||||
ctrl.SetItemState(i, 0, SEL_FOC)
|
||||
#for i in getListCtrlSelection(ctrl, SEL_FOC):
|
||||
# ctrl.SetItemState(i, 0, 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) """
|
||||
res = []
|
||||
idx = -1
|
||||
while 1:
|
||||
idx = listctrl.GetNextItem(idx, wxLIST_NEXT_ALL, state)
|
||||
idx = listctrl.GetNextItem(idx, wx.LIST_NEXT_ALL, state)
|
||||
if idx == -1:
|
||||
break
|
||||
res.append(idx)
|
||||
return res
|
||||
|
||||
wxEVT_DOPOPUPMENU = wx.NewEventType()
|
||||
EVT_DOPOPUPMENU = wx.PyEventBinder(wxEVT_DOPOPUPMENU, 0)
|
||||
|
||||
class ListCtrlSelectionManagerMix:
|
||||
"""Mixin that defines a platform independent selection policy
|
||||
|
||||
As selection single and multi-select list return the item index or a
|
||||
list of item indexes respectively.
|
||||
"""
|
||||
wxEVT_DOPOPUPMENU = wxNewId()
|
||||
_menu = None
|
||||
|
||||
def __init__(self):
|
||||
EVT_RIGHT_DOWN(self, self.OnLCSMRightDown)
|
||||
self.Connect(-1, -1, self.wxEVT_DOPOPUPMENU, self.OnLCSMDoPopup)
|
||||
self.Bind(wx.EVT_RIGHT_DOWN, self.OnLCSMRightDown)
|
||||
self.Bind(EVT_DOPOPUPMENU, self.OnLCSMDoPopup)
|
||||
# self.Connect(-1, -1, self.wxEVT_DOPOPUPMENU, self.OnLCSMDoPopup)
|
||||
|
||||
def getPopupMenu(self):
|
||||
""" Override to implement dynamic menus (create) """
|
||||
@@ -296,7 +304,7 @@ class ListCtrlSelectionManagerMix:
|
||||
|
||||
def getSelection(self):
|
||||
res = getListCtrlSelection(self)
|
||||
if self.GetWindowStyleFlag() & wxLC_SINGLE_SEL:
|
||||
if self.GetWindowStyleFlag() & wx.LC_SINGLE_SEL:
|
||||
if res:
|
||||
return res[0]
|
||||
else:
|
||||
@@ -309,11 +317,11 @@ class ListCtrlSelectionManagerMix:
|
||||
event.Skip()
|
||||
menu = self.getPopupMenu()
|
||||
if menu:
|
||||
evt = wxPyEvent()
|
||||
evt.SetEventType(self.wxEVT_DOPOPUPMENU)
|
||||
evt = wx.PyEvent()
|
||||
evt.SetEventType(wxEVT_DOPOPUPMENU)
|
||||
evt.menu = menu
|
||||
evt.pos = event.GetPosition()
|
||||
wxPostEvent(self, evt)
|
||||
wx.PostEvent(self, evt)
|
||||
|
||||
def OnLCSMDoPopup(self, event):
|
||||
self.PopupMenu(event.menu, event.pos)
|
||||
|
@@ -9,13 +9,19 @@
|
||||
# Copyright: (c) 2002 by db-X Corporation
|
||||
# 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.
|
||||
"""
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
import wx
|
||||
|
||||
#
|
||||
# Some miscellaneous mathematical and geometrical functions
|
||||
@@ -125,8 +131,9 @@ class RubberBand:
|
||||
self.currentBox = None
|
||||
self.__enabled = 1
|
||||
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):
|
||||
self.__enabled = enabled
|
||||
@@ -143,19 +150,19 @@ class RubberBand:
|
||||
Return True if the current cursor is one used to
|
||||
mean moving the rubberband.
|
||||
"""
|
||||
return self.__currentCursor == wxCURSOR_HAND
|
||||
return self.__currentCursor == wx.CURSOR_HAND
|
||||
|
||||
def __isSizingCursor(self):
|
||||
"""
|
||||
Return True if the current cursor is one of the ones
|
||||
I may use to signify sizing.
|
||||
"""
|
||||
sizingCursors = [wxCURSOR_SIZENESW,
|
||||
wxCURSOR_SIZENS,
|
||||
wxCURSOR_SIZENWSE,
|
||||
wxCURSOR_SIZEWE,
|
||||
wxCURSOR_SIZING,
|
||||
wxCURSOR_CROSS]
|
||||
sizingCursors = [wx.CURSOR_SIZENESW,
|
||||
wx.CURSOR_SIZENS,
|
||||
wx.CURSOR_SIZENWSE,
|
||||
wx.CURSOR_SIZEWE,
|
||||
wx.CURSOR_SIZING,
|
||||
wx.CURSOR_CROSS]
|
||||
try:
|
||||
sizingCursors.index(self.__currentCursor)
|
||||
return 1
|
||||
@@ -177,7 +184,7 @@ class RubberBand:
|
||||
# First make sure we have started a box.
|
||||
if self.currentBox == None and not event.LeftDown():
|
||||
# No box started yet. Set cursor to the initial kind.
|
||||
self.__setCursor(wxCURSOR_CROSS)
|
||||
self.__setCursor(wx.CURSOR_CROSS)
|
||||
return
|
||||
|
||||
if event.LeftDown():
|
||||
@@ -228,9 +235,9 @@ class RubberBand:
|
||||
# Implement the correct behavior for dragging a side
|
||||
# of the box: Only change one dimension.
|
||||
if not self.aspectRatio:
|
||||
if self.__currentCursor == wxCURSOR_SIZENS:
|
||||
if self.__currentCursor == wx.CURSOR_SIZENS:
|
||||
x = None
|
||||
elif self.__currentCursor == wxCURSOR_SIZEWE:
|
||||
elif self.__currentCursor == wx.CURSOR_SIZEWE:
|
||||
y = None
|
||||
|
||||
x0,y0,w0,h0 = self.currentBox
|
||||
@@ -274,18 +281,18 @@ class RubberBand:
|
||||
if pointOnBox(x, y, self.currentBox, thickness=self.__THICKNESS):
|
||||
position = getCursorPosition(x, y, self.currentBox, thickness=self.__THICKNESS)
|
||||
cursor = [
|
||||
wxCURSOR_SIZENWSE,
|
||||
wxCURSOR_SIZENS,
|
||||
wxCURSOR_SIZENESW,
|
||||
wxCURSOR_SIZEWE,
|
||||
wxCURSOR_SIZENWSE,
|
||||
wxCURSOR_SIZENS,
|
||||
wxCURSOR_SIZENESW,
|
||||
wxCURSOR_SIZEWE
|
||||
wx.CURSOR_SIZENWSE,
|
||||
wx.CURSOR_SIZENS,
|
||||
wx.CURSOR_SIZENESW,
|
||||
wx.CURSOR_SIZEWE,
|
||||
wx.CURSOR_SIZENWSE,
|
||||
wx.CURSOR_SIZENS,
|
||||
wx.CURSOR_SIZENESW,
|
||||
wx.CURSOR_SIZEWE
|
||||
] [position]
|
||||
self.__setCursor(cursor)
|
||||
elif pointInBox(x, y, self.currentBox):
|
||||
self.__setCursor(wxCURSOR_HAND)
|
||||
self.__setCursor(wx.CURSOR_HAND)
|
||||
else:
|
||||
self.__setCursor()
|
||||
|
||||
@@ -295,9 +302,9 @@ class RubberBand:
|
||||
"""
|
||||
if self.__currentCursor != id: # Avoid redundant calls
|
||||
if id:
|
||||
self.drawingSurface.SetCursor(wxStockCursor(id))
|
||||
self.drawingSurface.SetCursor(wx.StockCursor(id))
|
||||
else:
|
||||
self.drawingSurface.SetCursor(wxNullCursor)
|
||||
self.drawingSurface.SetCursor(wx.NullCursor)
|
||||
self.__currentCursor = id
|
||||
|
||||
def __moveCenterTo(self, x, y):
|
||||
@@ -320,14 +327,17 @@ class RubberBand:
|
||||
"""
|
||||
Draw one box shape and possibly erase another.
|
||||
"""
|
||||
dc = wxClientDC(self.drawingSurface)
|
||||
dc = wx.ClientDC(self.drawingSurface)
|
||||
dc.BeginDrawing()
|
||||
dc.SetPen(wxPen(wxWHITE, 1, wxDOT))
|
||||
dc.SetBrush(wxTRANSPARENT_BRUSH)
|
||||
dc.SetLogicalFunction(wxXOR)
|
||||
dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT))
|
||||
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
||||
dc.SetLogicalFunction(wx.XOR)
|
||||
if boxToErase:
|
||||
dc.DrawRectangle(*boxToErase)
|
||||
dc.DrawRectangle(*boxToDraw)
|
||||
r = wx.Rect(*boxToErase)
|
||||
dc.DrawRectangleRect(r)
|
||||
|
||||
r = wx.Rect(*boxToDraw)
|
||||
dc.DrawRectangleRect(r)
|
||||
dc.EndDrawing()
|
||||
|
||||
def __dumpMouseEvent(self, event):
|
||||
@@ -369,12 +379,12 @@ class RubberBand:
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = wxPySimpleApp()
|
||||
frame = wxFrame(None, -1, title='RubberBand Test', size=(300,300))
|
||||
app = wx.PySimpleApp()
|
||||
frame = wx.Frame(None, -1, title='RubberBand Test', size=(300,300))
|
||||
|
||||
# Add a panel that the rubberband will work on.
|
||||
panel = wxPanel(frame, -1)
|
||||
panel.SetBackgroundColour(wxBLUE)
|
||||
panel = wx.Panel(frame, -1)
|
||||
panel.SetBackgroundColour(wx.BLUE)
|
||||
|
||||
# Create the rubberband
|
||||
frame.rubberBand = RubberBand(drawingSurface=panel)
|
||||
@@ -383,13 +393,13 @@ if __name__ == '__main__':
|
||||
# Add a button that creates a new rubberband
|
||||
def __newRubberBand(event):
|
||||
frame.rubberBand.reset()
|
||||
button = wxButton(frame, 100, 'Reset Rubberband')
|
||||
EVT_BUTTON(frame, 100, __newRubberBand)
|
||||
button = wx.Button(frame, 100, 'Reset Rubberband')
|
||||
frame.Bind(wx.EVT_BUTTON, __newRubberBand, button)
|
||||
|
||||
# Layout the frame
|
||||
sizer = wxBoxSizer(wxVERTICAL)
|
||||
sizer.Add(panel, 1, wxEXPAND | wxALL, 5)
|
||||
sizer.Add(button, 0, wxALIGN_CENTER | wxALL, 5)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(panel, 1, wx.EXPAND | wx.ALL, 5)
|
||||
sizer.Add(button, 0, wx.ALIGN_CENTER | wx.ALL, 5)
|
||||
frame.SetAutoLayout(1)
|
||||
frame.SetSizer(sizer)
|
||||
frame.Show(1)
|
||||
|
@@ -9,8 +9,12 @@
|
||||
# RCS-ID: $Id$
|
||||
# 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_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):
|
||||
apply(wxWindow.__init__,(self,) + _args,_kwargs)
|
||||
apply(wx.Window.__init__,(self,) + _args,_kwargs)
|
||||
self._defChild = EmptyChild
|
||||
self.child = wxMultiSplit(self,self,wxPoint(0,0),self.GetSize())
|
||||
EVT_SIZE(self,self.OnMultiSize)
|
||||
self.child = wxMultiSplit(self,self,(0,0),self.GetSize())
|
||||
self.Bind(wx.EVT_SIZE,self.OnMultiSize)
|
||||
|
||||
def SetDefaultChildClass(self,childCls):
|
||||
self._defChild = childCls
|
||||
@@ -39,7 +43,7 @@ class wxMultiSash(wxWindow):
|
||||
|
||||
def Clear(self):
|
||||
old = self.child
|
||||
self.child = wxMultiSplit(self,self,wxPoint(0,0),self.GetSize())
|
||||
self.child = wxMultiSplit(self,self,(0,0),self.GetSize())
|
||||
old.Destroy()
|
||||
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):
|
||||
wxWindow.__init__(self,id = -1,parent = parent,pos = pos,size = size,
|
||||
style = wxCLIP_CHILDREN)
|
||||
wx.Window.__init__(self,id = -1,parent = parent,pos = pos,size = size,
|
||||
style = wx.CLIP_CHILDREN)
|
||||
self.multiView = multiView
|
||||
self.view2 = None
|
||||
if view1:
|
||||
@@ -77,10 +81,10 @@ class wxMultiSplit(wxWindow):
|
||||
self.view1.MoveXY(0,0)
|
||||
else:
|
||||
self.view1 = wxMultiViewLeaf(self.multiView,self,
|
||||
wxPoint(0,0),self.GetSize())
|
||||
(0,0),self.GetSize())
|
||||
self.direction = None
|
||||
|
||||
EVT_SIZE(self,self.OnSize)
|
||||
self.Bind(wx.EVT_SIZE,self.OnSize)
|
||||
|
||||
def GetSaveData(self):
|
||||
saveData = {}
|
||||
@@ -93,10 +97,10 @@ class wxMultiSplit(wxWindow):
|
||||
if isinstance(self.view2,wxMultiSplit):
|
||||
saveData['view2IsSplit'] = 1
|
||||
saveData['direction'] = self.direction
|
||||
v1,v2 = self.GetPositionTuple()
|
||||
v1,v2 = self.GetPosition()
|
||||
saveData['x'] = v1
|
||||
saveData['y'] = v2
|
||||
v1,v2 = self.GetSizeTuple()
|
||||
v1,v2 = self.GetSize()
|
||||
saveData['w'] = v1
|
||||
saveData['h'] = v2
|
||||
return saveData
|
||||
@@ -110,10 +114,10 @@ class wxMultiSplit(wxWindow):
|
||||
old = self.view1
|
||||
if isSplit:
|
||||
self.view1 = wxMultiSplit(self.multiView,self,
|
||||
wxPoint(0,0),self.GetSize())
|
||||
(0,0),self.GetSize())
|
||||
else:
|
||||
self.view1 = wxMultiViewLeaf(self.multiView,self,
|
||||
wxPoint(0,0),self.GetSize())
|
||||
(0,0),self.GetSize())
|
||||
self.view1.SetSaveData(v1Data)
|
||||
if old:
|
||||
old.Destroy()
|
||||
@@ -123,10 +127,10 @@ class wxMultiSplit(wxWindow):
|
||||
old = self.view2
|
||||
if isSplit:
|
||||
self.view2 = wxMultiSplit(self.multiView,self,
|
||||
wxPoint(0,0),self.GetSize())
|
||||
(0,0),self.GetSize())
|
||||
else:
|
||||
self.view2 = wxMultiViewLeaf(self.multiView,self,
|
||||
wxPoint(0,0),self.GetSize())
|
||||
(0,0),self.GetSize())
|
||||
self.view2.SetSaveData(v2Data)
|
||||
if old:
|
||||
old.Destroy()
|
||||
@@ -161,7 +165,7 @@ class wxMultiSplit(wxWindow):
|
||||
self.view2.AddLeaf(direction,caller,pos)
|
||||
else:
|
||||
self.direction = direction
|
||||
w,h = self.GetSizeTuple()
|
||||
w,h = self.GetSize()
|
||||
if direction == MV_HOR:
|
||||
x,y = (pos,0)
|
||||
w1,h1 = (w-pos,h)
|
||||
@@ -170,9 +174,8 @@ class wxMultiSplit(wxWindow):
|
||||
x,y = (0,pos)
|
||||
w1,h1 = (w,h-pos)
|
||||
w2,h2 = (w,pos)
|
||||
self.view2 = wxMultiViewLeaf(self.multiView,self,
|
||||
wxPoint(x,y),wxSize(w1,h1))
|
||||
self.view1.SetSize(wxSize(w2,h2))
|
||||
self.view2 = wxMultiViewLeaf(self.multiView, self, (x,y), (w1,h1))
|
||||
self.view1.SetSize((w2,h2))
|
||||
self.view2.OnSize(None)
|
||||
|
||||
def DestroyLeaf(self,caller):
|
||||
@@ -191,8 +194,8 @@ class wxMultiSplit(wxWindow):
|
||||
self.view1.SetSize(self.GetSize())
|
||||
self.view1.Move(self.GetPosition())
|
||||
else:
|
||||
w,h = self.GetSizeTuple()
|
||||
x,y = self.GetPositionTuple()
|
||||
w,h = self.GetSize()
|
||||
x,y = self.GetPosition()
|
||||
if caller == self.view1:
|
||||
if self == parent.view1:
|
||||
parent.view1 = self.view2
|
||||
@@ -230,7 +233,7 @@ class wxMultiSplit(wxWindow):
|
||||
if not (self.view1 and self.view2):
|
||||
return
|
||||
if pos < 10: return
|
||||
w,h = self.GetSizeTuple()
|
||||
w,h = self.GetSize()
|
||||
if side == MV_HOR:
|
||||
if pos > w - 10: return
|
||||
else:
|
||||
@@ -247,11 +250,11 @@ class wxMultiSplit(wxWindow):
|
||||
self.view1.SetSize(self.GetSize())
|
||||
self.view1.OnSize(None)
|
||||
return
|
||||
v1w,v1h = self.view1.GetSizeTuple()
|
||||
v2w,v2h = self.view2.GetSizeTuple()
|
||||
v1x,v1y = self.view1.GetPositionTuple()
|
||||
v2x,v2y = self.view2.GetPositionTuple()
|
||||
w,h = self.GetSizeTuple()
|
||||
v1w,v1h = self.view1.GetSize()
|
||||
v2w,v2h = self.view2.GetSize()
|
||||
v1x,v1y = self.view1.GetPosition()
|
||||
v2x,v2y = self.view2.GetPosition()
|
||||
w,h = self.GetSize()
|
||||
|
||||
if v1x != v2x:
|
||||
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):
|
||||
wxWindow.__init__(self,id = -1,parent = parent,pos = pos,size = size,
|
||||
style = wxCLIP_CHILDREN)
|
||||
wx.Window.__init__(self,id = -1,parent = parent,pos = pos,size = size,
|
||||
style = wx.CLIP_CHILDREN)
|
||||
self.multiView = multiView
|
||||
|
||||
self.sizerHor = MultiSizer(self,MV_HOR)
|
||||
@@ -291,7 +294,7 @@ class wxMultiViewLeaf(wxWindow):
|
||||
self.detail = MultiClient(self,multiView._defChild)
|
||||
self.closer = MultiCloser(self)
|
||||
|
||||
EVT_SIZE(self,self.OnSize)
|
||||
self.Bind(wx.EVT_SIZE,self.OnSize)
|
||||
|
||||
def GetSaveData(self):
|
||||
saveData = {}
|
||||
@@ -302,10 +305,10 @@ class wxMultiViewLeaf(wxWindow):
|
||||
dData = attr()
|
||||
if dData:
|
||||
saveData['detail'] = dData
|
||||
v1,v2 = self.GetPositionTuple()
|
||||
v1,v2 = self.GetPosition()
|
||||
saveData['x'] = v1
|
||||
saveData['y'] = v2
|
||||
v1,v2 = self.GetSizeTuple()
|
||||
v1,v2 = self.GetSize()
|
||||
saveData['w'] = v1
|
||||
saveData['h'] = v2
|
||||
return saveData
|
||||
@@ -335,7 +338,7 @@ class wxMultiViewLeaf(wxWindow):
|
||||
|
||||
def AddLeaf(self,direction,pos):
|
||||
if pos < 10: return
|
||||
w,h = self.GetSizeTuple()
|
||||
w,h = self.GetSize()
|
||||
if direction == MV_VER:
|
||||
if pos > h - 10: return
|
||||
else:
|
||||
@@ -362,20 +365,20 @@ class wxMultiViewLeaf(wxWindow):
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
class MultiClient(wxWindow):
|
||||
class MultiClient(wx.Window):
|
||||
def __init__(self,parent,childCls):
|
||||
w,h = self.CalcSize(parent)
|
||||
wxWindow.__init__(self,id = -1,parent = parent,
|
||||
pos = wxPoint(0,0),
|
||||
size = wxSize(w,h),
|
||||
style = wxCLIP_CHILDREN | wxSUNKEN_BORDER)
|
||||
wx.Window.__init__(self,id = -1,parent = parent,
|
||||
pos = (0,0),
|
||||
size = (w,h),
|
||||
style = wx.CLIP_CHILDREN | wx.SUNKEN_BORDER)
|
||||
self.child = childCls(self)
|
||||
self.child.MoveXY(2,2)
|
||||
self.normalColour = self.GetBackgroundColour()
|
||||
self.selected = False
|
||||
|
||||
EVT_SET_FOCUS(self,self.OnSetFocus)
|
||||
EVT_CHILD_FOCUS(self,self.OnChildFocus)
|
||||
self.Bind(wx.EVT_SET_FOCUS,self.OnSetFocus)
|
||||
self.Bind(wx.EVT_CHILD_FOCUS,self.OnChildFocus)
|
||||
|
||||
def UnSelect(self):
|
||||
if self.selected:
|
||||
@@ -386,11 +389,11 @@ class MultiClient(wxWindow):
|
||||
def Select(self):
|
||||
self.GetParent().multiView.UnSelect()
|
||||
self.selected = True
|
||||
self.SetBackgroundColour(wxColour(255,255,0)) # Yellow
|
||||
self.SetBackgroundColour(wx.Colour(255,255,0)) # Yellow
|
||||
self.Refresh()
|
||||
|
||||
def CalcSize(self,parent):
|
||||
w,h = parent.GetSizeTuple()
|
||||
w,h = parent.GetSize()
|
||||
w -= SH_SIZE
|
||||
h -= SH_SIZE
|
||||
return (w,h)
|
||||
@@ -398,8 +401,8 @@ class MultiClient(wxWindow):
|
||||
def OnSize(self,evt):
|
||||
w,h = self.CalcSize(self.GetParent())
|
||||
self.SetDimensions(0,0,w,h)
|
||||
w,h = self.GetClientSizeTuple()
|
||||
self.child.SetSize(wxSize(w-4,h-4))
|
||||
w,h = self.GetClientSize()
|
||||
self.child.SetSize((w-4,h-4))
|
||||
|
||||
def SetNewChildCls(self,childCls):
|
||||
if self.child:
|
||||
@@ -415,34 +418,34 @@ class MultiClient(wxWindow):
|
||||
self.OnSetFocus(evt)
|
||||
## from Funcs import FindFocusedChild
|
||||
## 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):
|
||||
self.side = side
|
||||
x,y,w,h = self.CalcSizePos(parent)
|
||||
wxWindow.__init__(self,id = -1,parent = parent,
|
||||
pos = wxPoint(x,y),
|
||||
size = wxSize(w,h),
|
||||
style = wxCLIP_CHILDREN)
|
||||
wx.Window.__init__(self,id = -1,parent = parent,
|
||||
pos = (x,y),
|
||||
size = (w,h),
|
||||
style = wx.CLIP_CHILDREN)
|
||||
|
||||
self.px = None # Previous X
|
||||
self.py = None # Previous Y
|
||||
self.isDrag = False # In Dragging
|
||||
self.dragTarget = None # View being sized
|
||||
|
||||
EVT_LEAVE_WINDOW(self,self.OnLeave)
|
||||
EVT_ENTER_WINDOW(self,self.OnEnter)
|
||||
EVT_MOTION(self,self.OnMouseMove)
|
||||
EVT_LEFT_DOWN(self,self.OnPress)
|
||||
EVT_LEFT_UP(self,self.OnRelease)
|
||||
self.Bind(wx.EVT_LEAVE_WINDOW,self.OnLeave)
|
||||
self.Bind(wx.EVT_ENTER_WINDOW,self.OnEnter)
|
||||
self.Bind(wx.EVT_MOTION,self.OnMouseMove)
|
||||
self.Bind(wx.EVT_LEFT_DOWN,self.OnPress)
|
||||
self.Bind(wx.EVT_LEFT_UP,self.OnRelease)
|
||||
|
||||
def CalcSizePos(self,parent):
|
||||
pw,ph = parent.GetSizeTuple()
|
||||
pw,ph = parent.GetSize()
|
||||
if self.side == MV_HOR:
|
||||
x = CR_SIZE + 2
|
||||
y = ph - SH_SIZE
|
||||
@@ -460,15 +463,15 @@ class MultiSizer(wxWindow):
|
||||
self.SetDimensions(x,y,w,h)
|
||||
|
||||
def OnLeave(self,evt):
|
||||
self.SetCursor(wxStockCursor(wxCURSOR_ARROW))
|
||||
self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
|
||||
|
||||
def OnEnter(self,evt):
|
||||
if not self.GetParent().CanSize(not self.side):
|
||||
return
|
||||
if self.side == MV_HOR:
|
||||
self.SetCursor(wxStockCursor(wxCURSOR_SIZENS))
|
||||
self.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS))
|
||||
else:
|
||||
self.SetCursor(wxStockCursor(wxCURSOR_SIZEWE))
|
||||
self.SetCursor(wx.StockCursor(wx.CURSOR_SIZEWE))
|
||||
|
||||
def OnMouseMove(self,evt):
|
||||
if self.isDrag:
|
||||
@@ -508,28 +511,28 @@ class MultiSizer(wxWindow):
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
class MultiCreator(wxWindow):
|
||||
class MultiCreator(wx.Window):
|
||||
def __init__(self,parent,side):
|
||||
self.side = side
|
||||
x,y,w,h = self.CalcSizePos(parent)
|
||||
wxWindow.__init__(self,id = -1,parent = parent,
|
||||
pos = wxPoint(x,y),
|
||||
size = wxSize(w,h),
|
||||
style = wxCLIP_CHILDREN)
|
||||
wx.Window.__init__(self,id = -1,parent = parent,
|
||||
pos = (x,y),
|
||||
size = (w,h),
|
||||
style = wx.CLIP_CHILDREN)
|
||||
|
||||
self.px = None # Previous X
|
||||
self.py = None # Previous Y
|
||||
self.isDrag = False # In Dragging
|
||||
|
||||
EVT_LEAVE_WINDOW(self,self.OnLeave)
|
||||
EVT_ENTER_WINDOW(self,self.OnEnter)
|
||||
EVT_MOTION(self,self.OnMouseMove)
|
||||
EVT_LEFT_DOWN(self,self.OnPress)
|
||||
EVT_LEFT_UP(self,self.OnRelease)
|
||||
EVT_PAINT(self,self.OnPaint)
|
||||
self.Bind(wx.EVT_LEAVE_WINDOW,self.OnLeave)
|
||||
self.Bind(wx.EVT_ENTER_WINDOW,self.OnEnter)
|
||||
self.Bind(wx.EVT_MOTION,self.OnMouseMove)
|
||||
self.Bind(wx.EVT_LEFT_DOWN,self.OnPress)
|
||||
self.Bind(wx.EVT_LEFT_UP,self.OnRelease)
|
||||
self.Bind(wx.EVT_PAINT,self.OnPaint)
|
||||
|
||||
def CalcSizePos(self,parent):
|
||||
pw,ph = parent.GetSizeTuple()
|
||||
pw,ph = parent.GetSize()
|
||||
if self.side == MV_HOR:
|
||||
x = 2
|
||||
y = ph - SH_SIZE
|
||||
@@ -547,13 +550,13 @@ class MultiCreator(wxWindow):
|
||||
self.SetDimensions(x,y,w,h)
|
||||
|
||||
def OnLeave(self,evt):
|
||||
self.SetCursor(wxStockCursor(wxCURSOR_ARROW))
|
||||
self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
|
||||
|
||||
def OnEnter(self,evt):
|
||||
if self.side == MV_HOR:
|
||||
self.SetCursor(wxStockCursor(wxCURSOR_HAND))
|
||||
self.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
|
||||
else:
|
||||
self.SetCursor(wxStockCursor(wxCURSOR_POINT_LEFT))
|
||||
self.SetCursor(wx.StockCursor(wx.CURSOR_POINT_LEFT))
|
||||
|
||||
def OnMouseMove(self,evt):
|
||||
if self.isDrag:
|
||||
@@ -588,14 +591,14 @@ class MultiCreator(wxWindow):
|
||||
evt.Skip()
|
||||
|
||||
def OnPaint(self,evt):
|
||||
dc = wxPaintDC(self)
|
||||
dc.SetBackground(wxBrush(self.GetBackgroundColour(),wxSOLID))
|
||||
dc = wx.PaintDC(self)
|
||||
dc.SetBackground(wx.Brush(self.GetBackgroundColour(),wx.SOLID))
|
||||
dc.Clear()
|
||||
|
||||
highlight = wxPen(wxSystemSettings_GetColour(wxSYS_COLOUR_BTNHIGHLIGHT), 1, wxSOLID)
|
||||
shadow = wxPen(wxSystemSettings_GetColour(wxSYS_COLOUR_BTNSHADOW), 1, wxSOLID)
|
||||
black = wxPen(wxBLACK,1,wxSOLID)
|
||||
w,h = self.GetSizeTuple()
|
||||
highlight = wx.Pen(wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT), 1, wx.SOLID)
|
||||
shadow = wx.Pen(wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNSHADOW), 1, wx.SOLID)
|
||||
black = wx.Pen(wx.BLACK,1,wx.SOLID)
|
||||
w,h = self.GetSize()
|
||||
w -= 1
|
||||
h -= 1
|
||||
|
||||
@@ -612,29 +615,29 @@ class MultiCreator(wxWindow):
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
class MultiCloser(wxWindow):
|
||||
class MultiCloser(wx.Window):
|
||||
def __init__(self,parent):
|
||||
x,y,w,h = self.CalcSizePos(parent)
|
||||
wxWindow.__init__(self,id = -1,parent = parent,
|
||||
pos = wxPoint(x,y),
|
||||
size = wxSize(w,h),
|
||||
style = wxCLIP_CHILDREN)
|
||||
wx.Window.__init__(self,id = -1,parent = parent,
|
||||
pos = (x,y),
|
||||
size = (w,h),
|
||||
style = wx.CLIP_CHILDREN)
|
||||
|
||||
self.down = False
|
||||
self.entered = False
|
||||
|
||||
EVT_LEFT_DOWN(self,self.OnPress)
|
||||
EVT_LEFT_UP(self,self.OnRelease)
|
||||
EVT_PAINT(self,self.OnPaint)
|
||||
EVT_LEAVE_WINDOW(self,self.OnLeave)
|
||||
EVT_ENTER_WINDOW(self,self.OnEnter)
|
||||
self.Bind(wx.EVT_LEFT_DOWN,self.OnPress)
|
||||
self.Bind(wx.EVT_LEFT_UP,self.OnRelease)
|
||||
self.Bind(wx.EVT_PAINT,self.OnPaint)
|
||||
self.Bind(wx.EVT_LEAVE_WINDOW,self.OnLeave)
|
||||
self.Bind(wx.EVT_ENTER_WINDOW,self.OnEnter)
|
||||
|
||||
def OnLeave(self,evt):
|
||||
self.SetCursor(wxStockCursor(wxCURSOR_ARROW))
|
||||
self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
|
||||
self.entered = False
|
||||
|
||||
def OnEnter(self,evt):
|
||||
self.SetCursor(wxStockCursor(wxCURSOR_BULLSEYE))
|
||||
self.SetCursor(wx.StockCursor(wx.CURSOR_BULLSEYE))
|
||||
self.entered = True
|
||||
|
||||
def OnPress(self,evt):
|
||||
@@ -649,12 +652,12 @@ class MultiCloser(wxWindow):
|
||||
self.down = False
|
||||
|
||||
def OnPaint(self,evt):
|
||||
dc = wxPaintDC(self)
|
||||
dc.SetBackground(wxBrush(wxRED,wxSOLID))
|
||||
dc = wx.PaintDC(self)
|
||||
dc.SetBackground(wx.Brush(wx.RED,wx.SOLID))
|
||||
dc.Clear()
|
||||
|
||||
def CalcSizePos(self,parent):
|
||||
pw,ph = parent.GetSizeTuple()
|
||||
pw,ph = parent.GetSize()
|
||||
x = pw - SH_SIZE
|
||||
w = SH_SIZE
|
||||
h = SH_SIZE + 2
|
||||
@@ -669,19 +672,19 @@ class MultiCloser(wxWindow):
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
class EmptyChild(wxWindow):
|
||||
class EmptyChild(wx.Window):
|
||||
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):
|
||||
dc = wxScreenDC()
|
||||
dc = wx.ScreenDC()
|
||||
dc.StartDrawingOnTopWin(win)
|
||||
bmp = wxEmptyBitmap(8,8)
|
||||
bdc = wxMemoryDC()
|
||||
bmp = wx.EmptyBitmap(8,8)
|
||||
bdc = wx.MemoryDC()
|
||||
bdc.SelectObject(bmp)
|
||||
bdc.DrawRectangle((-1,-1), (10,10))
|
||||
for i in range(8):
|
||||
@@ -689,13 +692,13 @@ def DrawSash(win,x,y,direction):
|
||||
if ((i + j) & 1):
|
||||
bdc.DrawPoint((i,j))
|
||||
|
||||
brush = wxBrush(wxColour(0,0,0))
|
||||
brush = wx.Brush(wx.Colour(0,0,0))
|
||||
brush.SetStipple(bmp)
|
||||
|
||||
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:
|
||||
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
|
||||
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, sys, traceback
|
||||
import os
|
||||
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:
|
||||
@@ -132,11 +156,11 @@ class Painter:
|
||||
"""
|
||||
def __init__(self, tree):
|
||||
self.tree = tree
|
||||
self.textcolor = wxNamedColour("BLACK")
|
||||
self.bgcolor = wxNamedColour("WHITE")
|
||||
self.fgcolor = wxNamedColour("BLUE")
|
||||
self.linecolor = wxNamedColour("GREY")
|
||||
self.font = wxFont(9, wxDEFAULT, wxNORMAL, wxNORMAL, False)
|
||||
self.textcolor = wx.NamedColour("BLACK")
|
||||
self.bgcolor = wx.NamedColour("WHITE")
|
||||
self.fgcolor = wx.NamedColour("BLUE")
|
||||
self.linecolor = wx.NamedColour("GREY")
|
||||
self.font = wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False)
|
||||
self.bmp = None
|
||||
|
||||
def GetFont(self):
|
||||
@@ -155,26 +179,26 @@ class Painter:
|
||||
return self.textcolor
|
||||
def SetTextColour(self, color):
|
||||
self.textcolor = color
|
||||
self.textbrush = wxBrush(color)
|
||||
self.textpen = wxPen(color, 1, wxSOLID)
|
||||
self.textbrush = wx.Brush(color)
|
||||
self.textpen = wx.Pen(color, 1, wx.SOLID)
|
||||
def GetBackgroundColour(self):
|
||||
return self.bgcolor
|
||||
def SetBackgroundColour(self, color):
|
||||
self.bgcolor = color
|
||||
self.bgbrush = wxBrush(color)
|
||||
self.bgpen = wxPen(color, 1, wxSOLID)
|
||||
self.bgbrush = wx.Brush(color)
|
||||
self.bgpen = wx.Pen(color, 1, wx.SOLID)
|
||||
def GetForegroundColour(self):
|
||||
return self.fgcolor
|
||||
def SetForegroundColour(self, color):
|
||||
self.fgcolor = color
|
||||
self.fgbrush = wxBrush(color)
|
||||
self.fgpen = wxPen(color, 1, wxSOLID)
|
||||
self.fgbrush = wx.Brush(color)
|
||||
self.fgpen = wx.Pen(color, 1, wx.SOLID)
|
||||
def GetLineColour(self):
|
||||
return self.linecolor
|
||||
def SetLineColour(self, color):
|
||||
self.linecolor = color
|
||||
self.linebrush = wxBrush(color)
|
||||
self.linepen = wxPen( color, 1, wxSOLID)
|
||||
self.linebrush = wx.Brush(color)
|
||||
self.linepen = wx.Pen( color, 1, wx.SOLID)
|
||||
def GetForegroundPen(self):
|
||||
return self.fgpen
|
||||
def GetBackgroundPen(self):
|
||||
@@ -348,9 +372,9 @@ class FileEditor(Editor):
|
||||
self.editcomp.SetSelection(0, len(node.fileName))
|
||||
self.editcomp.SetFocus()
|
||||
self.treenode = treenode
|
||||
# EVT_KEY_DOWN(self.editcomp, self._key)
|
||||
EVT_KEY_UP(self.editcomp, self._key)
|
||||
EVT_LEFT_DOWN(self.editcomp, self._mdown)
|
||||
# self.editcomp.Bind(wx.EVT_KEY_DOWN, self._key)
|
||||
self.editcomp.Bind(wx.EVT_KEY_UP, self._key)
|
||||
self.editcomp.Bind(wx.EVT_LEFT_DOWN, self._mdown)
|
||||
self.editcomp.CaptureMouse()
|
||||
|
||||
def CanEdit(self, node):
|
||||
@@ -373,18 +397,18 @@ class FileEditor(Editor):
|
||||
|
||||
|
||||
def _key(self, evt):
|
||||
if evt.KeyCode() == WXK_RETURN:
|
||||
if evt.KeyCode() == wx.WXK_RETURN:
|
||||
self.EndEdit(True)
|
||||
elif evt.KeyCode() == WXK_ESCAPE:
|
||||
elif evt.KeyCode() == wx.WXK_ESCAPE:
|
||||
self.EndEdit(False)
|
||||
else:
|
||||
evt.Skip()
|
||||
|
||||
def _mdown(self, evt):
|
||||
if evt.IsButton():
|
||||
pos = evt.GetPosition()
|
||||
edsize = self.editcomp.GetSize()
|
||||
if pos.x < 0 or pos.y < 0 or pos.x > edsize.width or pos.y > edsize.height:
|
||||
x, y = evt.GetPosition()
|
||||
w, h = self.editcomp.GetSize()
|
||||
if x < 0 or y < 0 or x > w or y > h:
|
||||
self.EndEdit(False)
|
||||
|
||||
|
||||
@@ -555,36 +579,36 @@ class TreePainter(Painter):
|
||||
for i in range(25):
|
||||
self.charWidths.append(dc.GetTextExtent("D")[0] * i)
|
||||
self.charHeight = dc.GetTextExtent("D")[1]
|
||||
self.textpen = wxPen(self.GetTextColour(), 1, wxSOLID)
|
||||
self.fgpen = wxPen(self.GetForegroundColour(), 1, wxSOLID)
|
||||
self.bgpen = wxPen(self.GetBackgroundColour(), 1, wxSOLID)
|
||||
self.linepen = wxPen(self.GetLineColour(), 1, wxSOLID)
|
||||
self.dashpen = wxPen(self.GetLineColour(), 1, wxDOT)
|
||||
self.textbrush = wxBrush(self.GetTextColour(), wxSOLID)
|
||||
self.fgbrush = wxBrush(self.GetForegroundColour(), wxSOLID)
|
||||
self.bgbrush = wxBrush(self.GetBackgroundColour(), wxSOLID)
|
||||
self.linebrush = wxPen(self.GetLineColour(), 1, wxSOLID)
|
||||
self.textpen = wx.Pen(self.GetTextColour(), 1, wx.SOLID)
|
||||
self.fgpen = wx.Pen(self.GetForegroundColour(), 1, wx.SOLID)
|
||||
self.bgpen = wx.Pen(self.GetBackgroundColour(), 1, wx.SOLID)
|
||||
self.linepen = wx.Pen(self.GetLineColour(), 1, wx.SOLID)
|
||||
self.dashpen = wx.Pen(self.GetLineColour(), 1, wx.DOT)
|
||||
self.textbrush = wx.Brush(self.GetTextColour(), wx.SOLID)
|
||||
self.fgbrush = wx.Brush(self.GetForegroundColour(), wx.SOLID)
|
||||
self.bgbrush = wx.Brush(self.GetBackgroundColour(), wx.SOLID)
|
||||
self.linebrush = wx.Pen(self.GetLineColour(), 1, wx.SOLID)
|
||||
treesize = self.tree.GetSize()
|
||||
size = self.tree.transform.GetSize()
|
||||
size = (max(treesize.width, size[0]+50), max(treesize.height, size[1]+50))
|
||||
dc.BeginDrawing()
|
||||
if doubleBuffered:
|
||||
mem_dc = wxMemoryDC()
|
||||
mem_dc = wx.MemoryDC()
|
||||
if not self.GetBuffer():
|
||||
self.knobs = []
|
||||
self.rectangles = []
|
||||
self.bmp = wxEmptyBitmap(size[0], size[1])
|
||||
self.bmp = wx.EmptyBitmap(size[0], size[1])
|
||||
mem_dc.SelectObject(self.GetBuffer())
|
||||
mem_dc.SetPen(self.GetBackgroundPen())
|
||||
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())
|
||||
self.paintWalk(node, mem_dc)
|
||||
else:
|
||||
mem_dc.SelectObject(self.GetBuffer())
|
||||
xstart, ystart = self.tree.CalcUnscrolledPosition(0,0)
|
||||
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:
|
||||
if node == self.tree.currentRoot:
|
||||
self.knobs = []
|
||||
@@ -593,7 +617,7 @@ class TreePainter(Painter):
|
||||
dc.SetBrush(self.GetBackgroundBrush())
|
||||
dc.SetFont(self.tree.GetFont())
|
||||
if paintBackground:
|
||||
dc.DrawRectangle(0, 0, size[0], size[1])
|
||||
dc.DrawRectangle((0, 0), (size[0], size[1]))
|
||||
if node:
|
||||
#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.
|
||||
@@ -606,7 +630,7 @@ class TreePainter(Painter):
|
||||
|
||||
def 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):
|
||||
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)):
|
||||
dc.SetPen(self.linepen)
|
||||
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)) )
|
||||
dc.SetPen(self.textpen)
|
||||
if not kid.expanded:
|
||||
dc.DrawLine(px, py -2, px, py + 3)
|
||||
dc.DrawLine(px -2, py, px + 3, py)
|
||||
dc.DrawLine((px, py -2), (px, py + 3))
|
||||
dc.DrawLine((px -2, py), (px + 3, py))
|
||||
if node == self.tree.currentRoot:
|
||||
px = (node.projx - self.tree.layout.NODE_STEP) + 5
|
||||
py = node.projy + node.height/2
|
||||
dc.SetPen(self.linepen)
|
||||
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)) )
|
||||
dc.SetPen(self.textpen)
|
||||
if not node.expanded:
|
||||
dc.DrawLine(px, py -2, px, py + 3)
|
||||
dc.DrawLine(px -2, py, px + 3, py)
|
||||
dc.DrawLine((px, py -2), (px, py + 3))
|
||||
dc.DrawLine((px -2, py), (px + 3, py))
|
||||
return True
|
||||
|
||||
def OnMouse(self, evt):
|
||||
@@ -652,15 +676,15 @@ class TreeNodePainter(NodePainter):
|
||||
if node.selected:
|
||||
dc.SetPen(self.painter.GetLinePen())
|
||||
dc.SetBrush(self.painter.GetForegroundBrush())
|
||||
dc.SetTextForeground(wxNamedColour("WHITE"))
|
||||
dc.DrawRectangle(node.projx -1, node.projy -1, node.width + 3, node.height + 3)
|
||||
dc.SetTextForeground(wx.NamedColour("WHITE"))
|
||||
dc.DrawRectangle((node.projx -1, node.projy -1), (node.width + 3, node.height + 3))
|
||||
else:
|
||||
if drawRects:
|
||||
dc.SetBrush(self.painter.GetBackgroundBrush())
|
||||
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.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)))
|
||||
|
||||
class TreeLinePainter(LinePainter):
|
||||
@@ -672,59 +696,41 @@ class TreeLinePainter(LinePainter):
|
||||
py = child.projy + self.painter.tree.layout.NODE_HEIGHT/2 -2
|
||||
cx = child.projx
|
||||
cy = py
|
||||
dc.DrawLine(px, py, cx, cy)
|
||||
dc.DrawLine((px, py), (cx, cy))
|
||||
else:
|
||||
px = parent.projx + 5
|
||||
py = parent.projy + parent.height
|
||||
cx = child.projx -5
|
||||
cy = child.projy + self.painter.tree.layout.NODE_HEIGHT/2 -3
|
||||
dc.DrawLine(px, py, px, cy)
|
||||
dc.DrawLine(px, cy, cx, cy)
|
||||
dc.DrawLine((px, py), (px, 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.
|
||||
wxEVT_MVCTREE_END_EDIT = 20205 #Stop editing. Vetoable.
|
||||
wxEVT_MVCTREE_DELETE_ITEM = 20206 #Item removed from model.
|
||||
wxEVT_MVCTREE_ITEM_EXPANDED = 20209
|
||||
wxEVT_MVCTREE_ITEM_EXPANDING = 20210
|
||||
wxEVT_MVCTREE_ITEM_COLLAPSED = 20211
|
||||
wxEVT_MVCTREE_ITEM_COLLAPSING = 20212
|
||||
wxEVT_MVCTREE_SEL_CHANGED = 20213
|
||||
wxEVT_MVCTREE_SEL_CHANGING = 20214 #Vetoable.
|
||||
wxEVT_MVCTREE_KEY_DOWN = 20215
|
||||
wxEVT_MVCTREE_ADD_ITEM = 20216 #Item added to model.
|
||||
EVT_MVCTREE_SEL_CHANGED = wx.PyEventBinder(wxEVT_MVCTREE_SEL_CHANGED, 1)
|
||||
EVT_MVCTREE_SEL_CHANGING = wx.PyEventBinder(wxEVT_MVCTREE_SEL_CHANGING, 1)
|
||||
EVT_MVCTREE_ITEM_EXPANDED = wx.PyEventBinder(wxEVT_MVCTREE_ITEM_EXPANDED, 1)
|
||||
EVT_MVCTREE_ITEM_EXPANDING = wx.PyEventBinder(wxEVT_MVCTREE_ITEM_EXPANDING, 1)
|
||||
EVT_MVCTREE_ITEM_COLLAPSED = wx.PyEventBinder(wxEVT_MVCTREE_ITEM_COLLAPSED, 1)
|
||||
EVT_MVCTREE_ITEM_COLLAPSING = wx.PyEventBinder(wxEVT_MVCTREE_ITEM_COLLAPSING, 1)
|
||||
EVT_MVCTREE_ADD_ITEM = wx.PyEventBinder(wxEVT_MVCTREE_ADD_ITEM, 1)
|
||||
EVT_MVCTREE_DELETE_ITEM = wx.PyEventBinder(wxEVT_MVCTREE_DELETE_ITEM, 1)
|
||||
EVT_MVCTREE_KEY_DOWN = wx.PyEventBinder(wxEVT_MVCTREE_KEY_DOWN, 1)
|
||||
|
||||
def EVT_MVCTREE_SEL_CHANGED(win, id, func):
|
||||
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):
|
||||
class wxMVCTreeEvent(wx.PyCommandEvent):
|
||||
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.nodes = nodes
|
||||
self.keyEvent = keyEvent
|
||||
@@ -738,17 +744,17 @@ class wxMVCTreeEvent(wxPyCommandEvent):
|
||||
class wxMVCTreeNotifyEvent(wxMVCTreeEvent):
|
||||
def __init__(self, type, id, node = None, nodes = None, **kwargs):
|
||||
apply(wxMVCTreeEvent.__init__, (self, type, id, node, nodes), kwargs)
|
||||
self.notify = wxNotifyEvent(type, id)
|
||||
self.notify = wx.NotifyEvent(type, id)
|
||||
def getNotifyEvent(self):
|
||||
return self.notify
|
||||
|
||||
class wxMVCTree(wxScrolledWindow):
|
||||
class wxMVCTree(wx.ScrolledWindow):
|
||||
"""
|
||||
The main mvc tree class.
|
||||
"""
|
||||
def __init__(self, parent, id, model = None, layout = None, transform = None,
|
||||
painter = None, *args, **kwargs):
|
||||
apply(wxScrolledWindow.__init__, (self, parent, id), kwargs)
|
||||
apply(wx.ScrolledWindow.__init__, (self, parent, id), kwargs)
|
||||
self.nodemap = {}
|
||||
self._multiselect = False
|
||||
self._selections = []
|
||||
@@ -771,19 +777,19 @@ class wxMVCTree(wxScrolledWindow):
|
||||
if not painter:
|
||||
painter = TreePainter(self)
|
||||
self.painter = painter
|
||||
self.SetFont(wxFont(9, wxDEFAULT, wxNORMAL, wxNORMAL, False))
|
||||
EVT_MOUSE_EVENTS(self, self.OnMouse)
|
||||
EVT_KEY_DOWN(self, self.OnKeyDown)
|
||||
self.SetFont(wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False))
|
||||
self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
|
||||
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
|
||||
self.doubleBuffered = True
|
||||
EVT_SIZE(self, self.OnSize)
|
||||
EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
|
||||
EVT_PAINT(self, self.OnPaint)
|
||||
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
|
||||
|
||||
def Refresh(self):
|
||||
if self.doubleBuffered:
|
||||
self.painter.ClearBuffer()
|
||||
wxScrolledWindow.Refresh(self, False)
|
||||
wx.ScrolledWindow.Refresh(self, False)
|
||||
|
||||
def GetPainter(self):
|
||||
return self.painter
|
||||
@@ -821,7 +827,7 @@ class wxMVCTree(wxScrolledWindow):
|
||||
|
||||
def SetFont(self, font):
|
||||
self.painter.SetFont(font)
|
||||
dc = wxClientDC(self)
|
||||
dc = wx.ClientDC(self)
|
||||
dc.SetFont(font)
|
||||
self.layout.SetHeight(dc.GetTextExtent("")[1] + 18)
|
||||
self.painter.ClearBuffer()
|
||||
@@ -1042,7 +1048,7 @@ class wxMVCTree(wxScrolledWindow):
|
||||
changeparents.append(treenode)
|
||||
e = wxMVCTreeEvent(wxEVT_MVCTREE_SEL_CHANGED, self.GetId(), nodeTuple[0], nodes = nodeTuple)
|
||||
self.GetEventHandler().ProcessEvent(e)
|
||||
dc = wxClientDC(self)
|
||||
dc = wx.ClientDC(self)
|
||||
self.PrepareDC(dc)
|
||||
for node in changeparents:
|
||||
if node:
|
||||
@@ -1060,7 +1066,7 @@ class wxMVCTree(wxScrolledWindow):
|
||||
treenode.selected = False
|
||||
e = wxMVCTreeEvent(wxEVT_MVCTREE_SEL_CHANGED, self.GetId(), node, nodes = nodeTuple)
|
||||
self.GetEventHandler().ProcessEvent(e)
|
||||
dc = wxClientDC(self)
|
||||
dc = wx.ClientDC(self)
|
||||
self.PrepareDC(dc)
|
||||
for node in changeparents:
|
||||
if node:
|
||||
@@ -1072,22 +1078,22 @@ class wxMVCTree(wxScrolledWindow):
|
||||
if hasattr(self, 'painter') and self.painter:
|
||||
return self.painter.GetBackgroundColour()
|
||||
else:
|
||||
return wxWindow.GetBackgroundColour(self)
|
||||
return wx.Window.GetBackgroundColour(self)
|
||||
def SetBackgroundColour(self, color):
|
||||
if hasattr(self, 'painter') and self.painter:
|
||||
self.painter.SetBackgroundColour(color)
|
||||
else:
|
||||
wxWindow.SetBackgroundColour(self, color)
|
||||
wx.Window.SetBackgroundColour(self, color)
|
||||
def GetForegroundColour(self):
|
||||
if hasattr(self, 'painter') and self.painter:
|
||||
return self.painter.GetForegroundColour()
|
||||
else:
|
||||
return wxWindow.GetBackgroundColour(self)
|
||||
return wx.Window.GetBackgroundColour(self)
|
||||
def SetForegroundColour(self, color):
|
||||
if hasattr(self, 'painter') and self.painter:
|
||||
self.painter.SetForegroundColour(color)
|
||||
else:
|
||||
wxWindow.SetBackgroundColour(self, color)
|
||||
wx.Window.SetBackgroundColour(self, color)
|
||||
|
||||
def SetAssumeChildren(self, bool):
|
||||
self._assumeChildren = bool
|
||||
@@ -1113,15 +1119,15 @@ class wxMVCTree(wxScrolledWindow):
|
||||
tsize = list(self.transform.GetSize())
|
||||
tsize[0] = tsize[0] + 50
|
||||
tsize[1] = tsize[1] + 50
|
||||
size = self.GetSizeTuple()
|
||||
if tsize[0] > size[0] or tsize[1] > size[1]:
|
||||
w, h = self.GetSize()
|
||||
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]):
|
||||
self._oldsize = tsize
|
||||
oldstart = self.ViewStart()
|
||||
oldstart = self.GetViewStart()
|
||||
self._lastPhysicalSize = self.GetSize()
|
||||
self.SetScrollbars(10, 10, tsize[0]/10, tsize[1]/10)
|
||||
self.Scroll(oldstart[0], oldstart[1])
|
||||
dc = wxPaintDC(self)
|
||||
dc = wx.PaintDC(self)
|
||||
self.PrepareDC(dc)
|
||||
dc.SetFont(self.GetFont())
|
||||
self.painter.Paint(dc, self.currentRoot, self.doubleBuffered)
|
||||
@@ -1130,12 +1136,3 @@ class wxMVCTree(wxScrolledWindow):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -9,38 +9,42 @@
|
||||
# RCS-ID: $Id$
|
||||
# License: wxWindows license
|
||||
#----------------------------------------------------------------------
|
||||
# 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o 2.5 compatability update.
|
||||
#
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.buttons import wxGenButtonEvent
|
||||
import wx
|
||||
from wx.lib.buttons import GenButtonEvent
|
||||
|
||||
|
||||
class PopButton(wxPyControl):
|
||||
class PopButton(wx.PyControl):
|
||||
def __init__(self,*_args,**_kwargs):
|
||||
apply(wxPyControl.__init__,(self,) + _args,_kwargs)
|
||||
apply(wx.PyControl.__init__,(self,) + _args,_kwargs)
|
||||
|
||||
self.up = True
|
||||
self.didDown = False
|
||||
|
||||
self.InitColours()
|
||||
|
||||
EVT_LEFT_DOWN(self, self.OnLeftDown)
|
||||
EVT_LEFT_UP(self, self.OnLeftUp)
|
||||
EVT_MOTION(self, self.OnMotion)
|
||||
EVT_PAINT(self, self.OnPaint)
|
||||
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
|
||||
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
|
||||
self.Bind(wx.EVT_MOTION, self.OnMotion)
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
|
||||
def InitColours(self):
|
||||
faceClr = wxSystemSettings_GetColour(wxSYS_COLOUR_BTNFACE)
|
||||
faceClr = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE)
|
||||
self.faceDnClr = faceClr
|
||||
self.SetBackgroundColour(faceClr)
|
||||
|
||||
shadowClr = wxSystemSettings_GetColour(wxSYS_COLOUR_BTNSHADOW)
|
||||
highlightClr = wxSystemSettings_GetColour(wxSYS_COLOUR_BTNHIGHLIGHT)
|
||||
self.shadowPen = wxPen(shadowClr, 1, wxSOLID)
|
||||
self.highlightPen = wxPen(highlightClr, 1, wxSOLID)
|
||||
self.blackPen = wxPen(wxBLACK, 1, wxSOLID)
|
||||
shadowClr = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNSHADOW)
|
||||
highlightClr = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT)
|
||||
self.shadowPen = wx.Pen(shadowClr, 1, wx.SOLID)
|
||||
self.highlightPen = wx.Pen(highlightClr, 1, wx.SOLID)
|
||||
self.blackPen = wx.Pen(wx.BLACK, 1, wx.SOLID)
|
||||
|
||||
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.SetButtonObj(self)
|
||||
evt.SetEventObject(self)
|
||||
@@ -76,8 +80,8 @@ class PopButton(wxPyControl):
|
||||
return
|
||||
if event.LeftIsDown():
|
||||
if self.didDown:
|
||||
x,y = event.GetPositionTuple()
|
||||
w,h = self.GetClientSizeTuple()
|
||||
x,y = event.GetPosition()
|
||||
w,h = self.GetClientSize()
|
||||
if self.up and x<w and x>=0 and y<h and y>=0:
|
||||
self.up = False
|
||||
self.Refresh()
|
||||
@@ -108,9 +112,9 @@ class PopButton(wxPyControl):
|
||||
dc.DrawLine((x2-i, y1+i), (x2-i, y2))
|
||||
|
||||
def DrawArrow(self,dc):
|
||||
size = self.GetSize()
|
||||
mx = size.width / 2
|
||||
my = size.height / 2
|
||||
w, h = self.GetSize()
|
||||
mx = w / 2
|
||||
my = h / 2
|
||||
dc.SetPen(self.highlightPen)
|
||||
dc.DrawLine((mx-5,my-5), (mx+5,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))
|
||||
|
||||
def OnPaint(self, event):
|
||||
width, height = self.GetClientSizeTuple()
|
||||
width, height = self.GetClientSize()
|
||||
x1 = y1 = 0
|
||||
x2 = width - 1
|
||||
y2 = height - 1
|
||||
dc = wxBufferedPaintDC(self)
|
||||
dc = wx.BufferedPaintDC(self)
|
||||
if self.up:
|
||||
dc.SetBackground(wxBrush(self.GetBackgroundColour(), wxSOLID))
|
||||
dc.SetBackground(wx.Brush(self.GetBackgroundColour(), wx.SOLID))
|
||||
else:
|
||||
dc.SetBackground(wxBrush(self.faceDnClr, wxSOLID))
|
||||
dc.SetBackground(wx.Brush(self.faceDnClr, wx.SOLID))
|
||||
dc.Clear()
|
||||
self.DrawBezel(dc, x1, y1, x2, y2)
|
||||
self.DrawArrow(dc)
|
||||
@@ -138,12 +142,12 @@ class PopButton(wxPyControl):
|
||||
|
||||
|
||||
# Tried to use wxPopupWindow but the control misbehaves on MSW
|
||||
class wxPopupDialog(wxDialog):
|
||||
class wxPopupDialog(wx.Dialog):
|
||||
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.win = wxWindow(self,-1,pos = wxPoint(0,0),style = 0)
|
||||
self.win = wx.Window(self,-1,pos = (0,0),style = 0)
|
||||
|
||||
if content:
|
||||
self.SetContent(content)
|
||||
@@ -157,7 +161,7 @@ class wxPopupDialog(wxDialog):
|
||||
|
||||
def Display(self):
|
||||
pos = self.ctrl.ClientToScreen( (0,0) )
|
||||
dSize = wxGetDisplaySize()
|
||||
dSize = wx.GetDisplaySize()
|
||||
selfSize = self.GetSize()
|
||||
tcSize = self.ctrl.GetSize()
|
||||
|
||||
@@ -173,7 +177,7 @@ class wxPopupDialog(wxDialog):
|
||||
if pos.y < 0:
|
||||
pos.y = 0
|
||||
|
||||
self.MoveXY(pos.x,pos.y)
|
||||
self.Move(pos)
|
||||
|
||||
self.ctrl.FormatContent()
|
||||
|
||||
@@ -183,29 +187,29 @@ class wxPopupDialog(wxDialog):
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class wxPopupControl(wxPyControl):
|
||||
class wxPopupControl(wx.PyControl):
|
||||
def __init__(self,*_args,**_kwargs):
|
||||
if _kwargs.has_key('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.pop = None
|
||||
self.content = None
|
||||
self.OnSize(None)
|
||||
|
||||
EVT_SIZE(self,self.OnSize)
|
||||
EVT_BUTTON(self.bCtrl,self.bCtrl.GetId(),self.OnButton)
|
||||
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||
self.bCtrl.Bind(wx.EVT_BUTTON, self.OnButton, self.bCtrl)
|
||||
# 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):
|
||||
self.textCtrl.SetFocus()
|
||||
evt.Skip()
|
||||
|
||||
def OnSize(self,evt):
|
||||
w,h = self.GetClientSizeTuple()
|
||||
w,h = self.GetClientSize()
|
||||
self.textCtrl.SetDimensions(0,0,w-17,h)
|
||||
self.bCtrl.SetDimensions(w-17,0,17,h)
|
||||
|
||||
@@ -220,7 +224,7 @@ class wxPopupControl(wxPyControl):
|
||||
self.pop.Display()
|
||||
|
||||
def Enable(self,flag):
|
||||
wxPyControl.Enable(self,flag)
|
||||
wx.PyControl.Enable(self,flag)
|
||||
self.textCtrl.Enable(flag)
|
||||
self.bCtrl.Enable(flag)
|
||||
|
||||
|
@@ -14,36 +14,41 @@
|
||||
# fixed bug for string wider than print region
|
||||
# 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 os
|
||||
import sys
|
||||
|
||||
import wx
|
||||
|
||||
class PrintBase:
|
||||
def SetPrintFont(self, font): # set the DC font parameters
|
||||
fattr = font["Attr"]
|
||||
if fattr[0] == 1:
|
||||
weight = wxBOLD
|
||||
weight = wx.BOLD
|
||||
else:
|
||||
weight = wxNORMAL
|
||||
weight = wx.NORMAL
|
||||
|
||||
if fattr[1] == 1:
|
||||
set_style = wxITALIC
|
||||
set_style = wx.ITALIC
|
||||
else:
|
||||
set_style = wxNORMAL
|
||||
set_style = wx.NORMAL
|
||||
|
||||
underline = fattr[2]
|
||||
fcolour = self.GetFontColour(font)
|
||||
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"])
|
||||
self.DC.SetFont(setfont)
|
||||
|
||||
def GetFontColour(self, font):
|
||||
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):
|
||||
textlines = textout.split('\n')
|
||||
@@ -54,19 +59,19 @@ class PrintBase:
|
||||
vout, remain = self.SetFlow(text, self.region)
|
||||
if self.draw == True and txtdraw == True:
|
||||
test_out = self.TestFull(vout)
|
||||
if self.align == wxALIGN_LEFT:
|
||||
self.DC.DrawText(test_out, self.indent+self.pcell_left_margin, y)
|
||||
if self.align == wx.ALIGN_LEFT:
|
||||
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)
|
||||
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)
|
||||
self.DC.DrawText(test_out, self.indent+diff, y)
|
||||
self.DC.DrawText(test_out, (self.indent+diff, y))
|
||||
|
||||
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
|
||||
y = y + self.space
|
||||
return y - self.space + self.pt_space_after
|
||||
@@ -142,19 +147,19 @@ class PrintBase:
|
||||
vout, remain = self.SetFlow(text, pagew)
|
||||
if self.draw == True and txtdraw == True:
|
||||
test_out = vout
|
||||
if align == wxALIGN_LEFT:
|
||||
self.DC.DrawText(test_out, indent, y)
|
||||
if align == wx.ALIGN_LEFT:
|
||||
self.DC.DrawText(test_out, (indent, y))
|
||||
|
||||
elif align == wxALIGN_CENTRE:
|
||||
elif align == wx.ALIGN_CENTRE:
|
||||
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)
|
||||
self.DC.DrawText(test_out, indent+diff, y)
|
||||
self.DC.DrawText(test_out, (indent+diff, y))
|
||||
|
||||
else:
|
||||
self.DC.DrawText(test_out, indent, y_out)
|
||||
self.DC.DrawText(test_out, (indent, y_out))
|
||||
text = remain
|
||||
y = y + y_line
|
||||
return y - y_line
|
||||
@@ -168,7 +173,7 @@ class PrintBase:
|
||||
return date + ' ' + time
|
||||
|
||||
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()
|
||||
date = flds[0]
|
||||
time = flds[1]
|
||||
@@ -195,7 +200,7 @@ class PrintBase:
|
||||
return self.sizeh
|
||||
|
||||
|
||||
class PrintTableDraw(wxScrolledWindow, PrintBase):
|
||||
class PrintTableDraw(wx.ScrolledWindow, PrintBase):
|
||||
def __init__(self, parent, DC, size):
|
||||
self.parent = parent
|
||||
self.DC = DC
|
||||
@@ -297,7 +302,7 @@ class PrintTableDraw(wxScrolledWindow, PrintBase):
|
||||
try:
|
||||
align = set_column_align[col] # check if custom column alignment
|
||||
except:
|
||||
align = wxALIGN_LEFT
|
||||
align = wx.ALIGN_LEFT
|
||||
self.column_align.append(align)
|
||||
|
||||
try:
|
||||
@@ -316,7 +321,7 @@ class PrintTableDraw(wxScrolledWindow, PrintBase):
|
||||
col = col + 1
|
||||
|
||||
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)
|
||||
f.SetFaceName(self.text_font["Name"])
|
||||
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.indent = self.column[self.col]
|
||||
|
||||
self.align = wxALIGN_LEFT
|
||||
self.align = wx.ALIGN_LEFT
|
||||
|
||||
max_out = self.OutTextRegion(vtxt, True)
|
||||
if max_out > max_y:
|
||||
@@ -488,10 +493,11 @@ class PrintTableDraw(wxScrolledWindow, PrintBase):
|
||||
|
||||
|
||||
def LabelColorRow(self, colour):
|
||||
brush = wxBrush(colour, wxSOLID)
|
||||
brush = wx.Brush(colour, wx.SOLID)
|
||||
self.DC.SetBrush(brush)
|
||||
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):
|
||||
if self.draw == False:
|
||||
@@ -503,16 +509,16 @@ class PrintTableDraw(wxScrolledWindow, PrintBase):
|
||||
if cellcolour is not None:
|
||||
colour = cellcolour
|
||||
|
||||
brush = wxBrush(colour, wxSOLID)
|
||||
brush = wx.Brush(colour, wx.SOLID)
|
||||
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]
|
||||
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
|
||||
|
||||
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.pt_space_before = self.text_pt_space_before # set the point spacing
|
||||
@@ -576,11 +582,11 @@ class PrintTableDraw(wxScrolledWindow, PrintBase):
|
||||
except:
|
||||
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 + 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):
|
||||
if self.draw == True:
|
||||
@@ -598,15 +604,15 @@ class PrintTableDraw(wxScrolledWindow, PrintBase):
|
||||
|
||||
indent = val
|
||||
|
||||
self.DC.SetPen(wxPen(colour, size))
|
||||
self.DC.DrawLine(indent, self.y_start, indent, self.y)
|
||||
self.DC.SetPen(wx.Pen(colour, size))
|
||||
self.DC.DrawLine((indent, self.y_start), (indent, self.y))
|
||||
col = col + 1
|
||||
|
||||
def DrawText(self):
|
||||
self.DoRefresh()
|
||||
|
||||
def DoDrawing(self, DC):
|
||||
size = DC.GetSizeTuple()
|
||||
size = DC.GetSize()
|
||||
self.DC = DC
|
||||
|
||||
DC.BeginDrawing()
|
||||
@@ -638,7 +644,7 @@ class PrintTable:
|
||||
self.parentFrame = parentFrame
|
||||
self.SetPreviewSize()
|
||||
|
||||
self.printData = wxPrintData()
|
||||
self.printData = wx.PrintData()
|
||||
self.scale = 1.0
|
||||
|
||||
self.SetParms()
|
||||
@@ -652,11 +658,11 @@ class PrintTable:
|
||||
self.SetMargins()
|
||||
self.SetPortrait()
|
||||
|
||||
def SetPreviewSize(self, position = wxPoint(0, 0), size="Full"):
|
||||
def SetPreviewSize(self, position = wx.Point(0, 0), size="Full"):
|
||||
if size == "Full":
|
||||
r = wxGetClientDisplayRect()
|
||||
self.preview_frame_size = wxSize(r.width, r.height)
|
||||
self.preview_frame_pos = wxPoint(r.x, r.y)
|
||||
r = wx.GetClientDisplayRect()
|
||||
self.preview_frame_size = r.GetSize()
|
||||
self.preview_frame_pos = r.GetPosition()
|
||||
else:
|
||||
self.preview_frame_size = size
|
||||
self.preview_frame_pos = position
|
||||
@@ -668,14 +674,14 @@ class PrintTable:
|
||||
self.printData.SetOrientation(orient)
|
||||
|
||||
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.column_def_line_colour = wxNamedColour('BLACK')
|
||||
self.column_def_line_colour = wx.NamedColour('BLACK')
|
||||
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):
|
||||
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):
|
||||
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_align = wxALIGN_CENTRE
|
||||
self.header_align = wx.ALIGN_CENTRE
|
||||
self.header_indent = 0
|
||||
self.header_type = "Text"
|
||||
|
||||
def SetFooterValue(self):
|
||||
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_align = wxALIGN_CENTRE
|
||||
self.footer_align = wx.ALIGN_CENTRE
|
||||
self.footer_indent = 0
|
||||
self.footer_type = "Pageof"
|
||||
|
||||
@@ -724,13 +730,13 @@ class PrintTable:
|
||||
self.cell_right_margin = 0.1
|
||||
|
||||
def SetPortrait(self):
|
||||
self.printData.SetPaperId(wxPAPER_LETTER)
|
||||
self.printData.SetOrientation(wxPORTRAIT)
|
||||
self.printData.SetPaperId(wx.PAPER_LETTER)
|
||||
self.printData.SetOrientation(wx.PORTRAIT)
|
||||
self.page_width = 8.5
|
||||
self.page_height = 11.0
|
||||
|
||||
def SetLandscape(self):
|
||||
self.printData.SetOrientation(wxLANDSCAPE)
|
||||
self.printData.SetOrientation(wx.LANDSCAPE)
|
||||
self.page_width = 11.0
|
||||
self.page_height = 8.5
|
||||
|
||||
@@ -746,7 +752,7 @@ class PrintTable:
|
||||
self.default_font_name = "Arial"
|
||||
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
|
||||
|
||||
def SetColBackgroundColour(self, col, colour):
|
||||
@@ -866,14 +872,14 @@ class PrintTable:
|
||||
def Preview(self):
|
||||
printout = 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():
|
||||
wxMessageBox("There was a problem printing!", "Printing", wxOK)
|
||||
wxMessageBox("There was a problem printing!", "Printing", wx.OK)
|
||||
return
|
||||
|
||||
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()
|
||||
if self.parentFrame:
|
||||
@@ -882,18 +888,18 @@ class PrintTable:
|
||||
frame.Show(True)
|
||||
|
||||
def Print(self):
|
||||
pdd = wxPrintDialogData()
|
||||
pdd = wx.PrintDialogData()
|
||||
pdd.SetPrintData(self.printData)
|
||||
printer = wxPrinter(pdd)
|
||||
printer = wx.Printer(pdd)
|
||||
printout = SetPrintout(self)
|
||||
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:
|
||||
self.printData = printer.GetPrintDialogData().GetPrintData()
|
||||
printout.Destroy()
|
||||
|
||||
def DoDrawing(self, DC):
|
||||
size = DC.GetSizeTuple()
|
||||
size = DC.GetSize()
|
||||
DC.BeginDrawing()
|
||||
|
||||
table = PrintTableDraw(self, DC, size)
|
||||
@@ -1008,9 +1014,9 @@ class PrintGrid:
|
||||
self.table.Print()
|
||||
|
||||
|
||||
class SetPrintout(wxPrintout):
|
||||
class SetPrintout(wx.Printout):
|
||||
def __init__(self, canvas):
|
||||
wxPrintout.__init__(self)
|
||||
wx.Printout.__init__(self)
|
||||
self.canvas = canvas
|
||||
self.end_pg = 1000
|
||||
|
||||
@@ -1049,7 +1055,7 @@ class SetPrintout(wxPrintout):
|
||||
else:
|
||||
self.pixelsPerInch = self.GetPPIPrinter()
|
||||
|
||||
(w, h) = dc.GetSizeTuple()
|
||||
(w, h) = dc.GetSize()
|
||||
scaleX = float(w) / 1000
|
||||
scaleY = float(h) / 1000
|
||||
self.printUserScale = min(scaleX, scaleY)
|
||||
@@ -1066,7 +1072,7 @@ class SetPrintout(wxPrintout):
|
||||
|
||||
def OnPrintPage(self, page):
|
||||
dc = self.GetDC()
|
||||
(w, h) = dc.GetSizeTuple()
|
||||
(w, h) = dc.GetSize()
|
||||
scaleX = float(w) / 1000
|
||||
scaleY = float(h) / 1000
|
||||
self.printUserScale = min(scaleX, scaleY)
|
||||
|
@@ -10,6 +10,11 @@
|
||||
# Copyright: (c) 2000 by Total Control Software
|
||||
# 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
|
||||
@@ -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
|
||||
|
||||
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
|
||||
|
||||
if wxPlatform == '__WXMSW__':
|
||||
if wx.Platform == '__WXMSW__':
|
||||
_defaultSize = 8
|
||||
else:
|
||||
_defaultSize = 10
|
||||
@@ -77,11 +97,11 @@ _trace_style = 17
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
|
||||
def __init__(self, parent, ID, pos=wxDefaultPosition,
|
||||
size=wxDefaultSize, style=0,
|
||||
class PyShellWindow(stc.StyledTextCtrl, InteractiveInterpreter):
|
||||
def __init__(self, parent, ID, pos=wx.DefaultPosition,
|
||||
size=wx.DefaultSize, style=0,
|
||||
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)
|
||||
|
||||
self.lastPromptPos = 0
|
||||
@@ -110,9 +130,9 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
|
||||
self.Prompt()
|
||||
|
||||
# Event handlers
|
||||
EVT_KEY_DOWN(self, self.OnKey)
|
||||
EVT_STC_UPDATEUI(self, ID, self.OnUpdateUI)
|
||||
#EVT_STC_STYLENEEDED(self, ID, self.OnStyle)
|
||||
self.Bind(wx.EVT_KEY_DOWN, self.OnKey)
|
||||
self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI, id=ID)
|
||||
#self.Bind(stc.EVT_STC_STYLENEEDED, self.OnStyle, id=ID)
|
||||
|
||||
|
||||
def GetLocals(self): return self.locals
|
||||
@@ -131,7 +151,7 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
|
||||
"""
|
||||
p = self.props
|
||||
|
||||
#self.SetEdgeMode(wxSTC_EDGE_LINE)
|
||||
#self.SetEdgeMode(stc.STC_EDGE_LINE)
|
||||
#self.SetEdgeColumn(80)
|
||||
|
||||
|
||||
@@ -140,25 +160,25 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
|
||||
self.SetMargins(p['marginWidth'], p['marginWidth'])
|
||||
|
||||
# styles
|
||||
self.StyleSetSpec(wxSTC_STYLE_DEFAULT, p['default'])
|
||||
self.StyleSetSpec(stc.STC_STYLE_DEFAULT, p['default'])
|
||||
self.StyleClearAll()
|
||||
self.StyleSetSpec(_stdout_style, p['stdout'])
|
||||
self.StyleSetSpec(_stderr_style, p['stderr'])
|
||||
self.StyleSetSpec(_trace_style, p['trace'])
|
||||
|
||||
self.StyleSetSpec(wxSTC_STYLE_BRACELIGHT, p['bracegood'])
|
||||
self.StyleSetSpec(wxSTC_STYLE_BRACEBAD, p['bracebad'])
|
||||
self.StyleSetSpec(wxSTC_P_COMMENTLINE, p['comment'])
|
||||
self.StyleSetSpec(wxSTC_P_NUMBER, p['number'])
|
||||
self.StyleSetSpec(wxSTC_P_STRING, p['string'])
|
||||
self.StyleSetSpec(wxSTC_P_CHARACTER, p['char'])
|
||||
self.StyleSetSpec(wxSTC_P_WORD, p['keyword'])
|
||||
self.StyleSetSpec(wxSTC_P_TRIPLE, p['triple'])
|
||||
self.StyleSetSpec(wxSTC_P_TRIPLEDOUBLE, p['tripledouble'])
|
||||
self.StyleSetSpec(wxSTC_P_CLASSNAME, p['class'])
|
||||
self.StyleSetSpec(wxSTC_P_DEFNAME, p['def'])
|
||||
self.StyleSetSpec(wxSTC_P_OPERATOR, p['operator'])
|
||||
self.StyleSetSpec(wxSTC_P_COMMENTBLOCK, p['comment'])
|
||||
self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, p['bracegood'])
|
||||
self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, p['bracebad'])
|
||||
self.StyleSetSpec(stc.STC_P_COMMENTLINE, p['comment'])
|
||||
self.StyleSetSpec(stc.STC_P_NUMBER, p['number'])
|
||||
self.StyleSetSpec(stc.STC_P_STRING, p['string'])
|
||||
self.StyleSetSpec(stc.STC_P_CHARACTER, p['char'])
|
||||
self.StyleSetSpec(stc.STC_P_WORD, p['keyword'])
|
||||
self.StyleSetSpec(stc.STC_P_TRIPLE, p['triple'])
|
||||
self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, p['tripledouble'])
|
||||
self.StyleSetSpec(stc.STC_P_CLASSNAME, p['class'])
|
||||
self.StyleSetSpec(stc.STC_P_DEFNAME, p['def'])
|
||||
self.StyleSetSpec(stc.STC_P_OPERATOR, p['operator'])
|
||||
self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, p['comment'])
|
||||
|
||||
|
||||
# used for writing to stdout, etc.
|
||||
@@ -169,7 +189,7 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
|
||||
self.StartStyling(pos, 0xFF)
|
||||
self.SetStyling(len(text), style)
|
||||
self.EnsureCaretVisible()
|
||||
wxYield()
|
||||
wx.Yield()
|
||||
|
||||
write = _write
|
||||
|
||||
@@ -197,7 +217,7 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
|
||||
|
||||
def OnKey(self, evt):
|
||||
key = evt.KeyCode()
|
||||
if key == WXK_RETURN:
|
||||
if key == wx.WXK_RETURN:
|
||||
pos = self.GetCurrentPos()
|
||||
lastPos = self.GetTextLength()
|
||||
|
||||
@@ -237,7 +257,7 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
|
||||
# Only style from the prompt pos to the end
|
||||
lastPos = self.GetTextLength()
|
||||
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.Colourise(self.lastPromptPos, lastPos)
|
||||
@@ -256,14 +276,14 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
|
||||
styleBefore = self.GetStyleAt(caretPos - 1)
|
||||
|
||||
# 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
|
||||
|
||||
# check after
|
||||
if braceAtCaret < 0:
|
||||
charAfter = self.GetCharAt(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
|
||||
|
||||
if braceAtCaret >= 0:
|
||||
@@ -319,7 +339,7 @@ class FauxFile:
|
||||
# test code
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = wxPyWidgetTester(size = (640, 480))
|
||||
app = wx.PyWidgetTester(size = (640, 480))
|
||||
app.SetWidget(PyShellWindow, -1)
|
||||
app.MainLoop()
|
||||
|
||||
|
@@ -9,6 +9,11 @@
|
||||
# Copyright: (c) 2002 by Total Control Software
|
||||
# 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
|
||||
@@ -17,24 +22,41 @@ specified by row and col, and row/col spanning is supported.
|
||||
|
||||
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 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
|
||||
col_w = 10
|
||||
row_h = 22
|
||||
|
||||
def __init__(self):
|
||||
wxPySizer.__init__(self)
|
||||
wx.PySizer.__init__(self)
|
||||
self.growableRows = []
|
||||
self.growableCols = []
|
||||
|
||||
@@ -64,9 +86,9 @@ class RowColSizer(wxPySizer):
|
||||
|
||||
# Do I really want to do this? Probably not...
|
||||
#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))
|
||||
|
||||
#AddWindow = Add
|
||||
@@ -85,7 +107,7 @@ class RowColSizer(wxPySizer):
|
||||
assert row != -1, "Row 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))
|
||||
|
||||
#--------------------------------------------------
|
||||
@@ -116,12 +138,12 @@ class RowColSizer(wxPySizer):
|
||||
|
||||
items = self.GetChildren()
|
||||
if not items:
|
||||
return wxSize(10, 10)
|
||||
return wx.Size(10, 10)
|
||||
|
||||
for item in items:
|
||||
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) )
|
||||
return size
|
||||
|
||||
@@ -129,12 +151,9 @@ class RowColSizer(wxPySizer):
|
||||
#--------------------------------------------------
|
||||
def RecalcSizes( self ):
|
||||
# save current dimensions, etc.
|
||||
curWidth = self.GetSize().width
|
||||
curHeight = self.GetSize().height
|
||||
px = self.GetPosition().x
|
||||
py = self.GetPosition().y
|
||||
minWidth = self.CalcMin().width
|
||||
minHeight = self.CalcMin().height
|
||||
curWidth, curHeight = self.GetSize()
|
||||
px, py = self.GetPosition()
|
||||
minWidth, minHeight = self.CalcMin()
|
||||
|
||||
# Check for growables
|
||||
if self.growableRows and curHeight > minHeight:
|
||||
@@ -176,21 +195,21 @@ class RowColSizer(wxPySizer):
|
||||
def SetItemBounds(self, item, x, y, w, h):
|
||||
# calculate the item's actual size and position within
|
||||
# its grid cell
|
||||
ipt = wxPoint(x, y)
|
||||
ipt = wx.Point(x, y)
|
||||
isz = item.CalcMin()
|
||||
flag = item.GetFlag()
|
||||
|
||||
if flag & wxEXPAND or flag & wxSHAPED:
|
||||
isz = wxSize(w, h)
|
||||
if flag & wx.EXPAND or flag & wx.SHAPED:
|
||||
isz = wx.Size(w, h)
|
||||
else:
|
||||
if flag & wxALIGN_CENTER_HORIZONTAL:
|
||||
if flag & wx.ALIGN_CENTER_HORIZONTAL:
|
||||
ipt.x = x + (w - isz.width) / 2
|
||||
elif flag & wxALIGN_RIGHT:
|
||||
elif flag & wx.ALIGN_RIGHT:
|
||||
ipt.x = x + (w - isz.width)
|
||||
|
||||
if flag & wxALIGN_CENTER_VERTICAL:
|
||||
if flag & wx.ALIGN_CENTER_VERTICAL:
|
||||
ipt.y = y + (h - isz.height) / 2
|
||||
elif flag & wxALIGN_BOTTOM:
|
||||
elif flag & wx.ALIGN_BOTTOM:
|
||||
ipt.y = y + (h - isz.height)
|
||||
|
||||
item.SetDimension(ipt, isz)
|
||||
|
@@ -11,6 +11,11 @@
|
||||
# Copyright: (c) 2001 by Total Control Software
|
||||
# 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
|
||||
@@ -34,23 +39,40 @@ Ubera Servicios Inform
|
||||
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):
|
||||
wxTextCtrl.__init__(self, parent, id, *args, **kwargs)
|
||||
EVT_KILL_FOCUS(self, self.OnKillFocus)
|
||||
EVT_PAINT(self, self.OnPaint)
|
||||
wx.TextCtrl.__init__(self, parent, id, *args, **kwargs)
|
||||
self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
|
||||
def OnPaint(self, event):
|
||||
dc = wxPaintDC(self)
|
||||
dc = wx.PaintDC(self)
|
||||
dc.SetFont(self.GetFont())
|
||||
dc.Clear()
|
||||
text = self.GetValue()
|
||||
textwidth, textheight = dc.GetTextExtent(text)
|
||||
dcwidth, dcheight = self.GetClientSizeTuple()
|
||||
dcwidth, dcheight = self.GetClientSize()
|
||||
|
||||
y = (dcheight - textheight) / 2
|
||||
x = dcwidth - textwidth - 2
|
||||
@@ -58,21 +80,22 @@ class wxRightTextCtrl(wxTextCtrl):
|
||||
if self.IsEnabled():
|
||||
fclr = self.GetForegroundColour()
|
||||
else:
|
||||
fclr = wxSystemSettings_GetColour(wxSYS_COLOUR_GRAYTEXT)
|
||||
fclr = wx.SystemSettings_GetColour(wx.SYS_COLOUR_GRAYTEXT)
|
||||
|
||||
dc.SetTextForeground(fclr)
|
||||
|
||||
dc.SetClippingRegionXY(0, 0, dcwidth, dcheight)
|
||||
dc.DrawText(text, x, y)
|
||||
dc.SetClippingRegion(0, 0, dcwidth, dcheight)
|
||||
dc.DrawText(text, (x, y))
|
||||
|
||||
if x < 0:
|
||||
toofat = '...'
|
||||
markwidth = dc.GetTextExtent(toofat)[0]
|
||||
dc.SetPen(wxPen(dc.GetBackground().GetColour(), 1, wxSOLID ))
|
||||
dc.DrawRectangle(0,0, markwidth, dcheight)
|
||||
dc.SetPen(wxPen(wxRED, 1, wxSOLID ))
|
||||
dc.SetBrush(wxTRANSPARENT_BRUSH)
|
||||
dc.DrawRectangle(1, 1, dcwidth-2, dcheight-2)
|
||||
dc.DrawText(toofat, 1, y)
|
||||
dc.SetPen(wx.Pen(dc.GetBackground().GetColour(), 1, wx.SOLID ))
|
||||
dc.DrawRectangle((0,0), (markwidth, dcheight))
|
||||
dc.SetPen(wx.Pen(wx.RED, 1, wx.SOLID ))
|
||||
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
||||
dc.DrawRectangle((1, 1), (dcwidth-2, dcheight-2))
|
||||
dc.DrawText(toofat, (1, y))
|
||||
|
||||
|
||||
def OnKillFocus(self, event):
|
||||
|
@@ -17,6 +17,11 @@
|
||||
# Copyright: (c) 2000, 2001 by Greg Landrum and Rational Discovery LLC
|
||||
# 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
|
||||
|
||||
@@ -68,12 +73,14 @@
|
||||
|
||||
"""
|
||||
|
||||
from wxPython.wx import *
|
||||
import xmlrpcserver,xmlrpclib
|
||||
import threading
|
||||
import SocketServer
|
||||
import new
|
||||
import SocketServer
|
||||
import sys
|
||||
import threading
|
||||
import xmlrpclib
|
||||
import xmlrpcserver
|
||||
|
||||
import wx
|
||||
|
||||
rpcPENDING = 0
|
||||
rpcDONE = 1
|
||||
@@ -85,14 +92,16 @@ class RPCRequest:
|
||||
result = None
|
||||
|
||||
# here's the ID for external events
|
||||
wxEVT_EXTERNAL_EVENT = 25015
|
||||
class ExternalEvent(wxPyEvent):
|
||||
wxEVT_EXTERNAL_EVENT = wx.NewEventType()
|
||||
EVT_EXTERNAL_EVENT = wx.PyEventBinder(wxEVT_EXTERNAL_EVENT, 0)
|
||||
|
||||
class ExternalEvent(wx.PyEvent):
|
||||
"""The custom event class used to pass xmlrpc calls from
|
||||
the server thread into the GUI thread
|
||||
|
||||
"""
|
||||
def __init__(self,method,args):
|
||||
wxPyEvent.__init__(self)
|
||||
wx.PyEvent.__init__(self)
|
||||
self.SetEventType(wxEVT_EXTERNAL_EVENT)
|
||||
self.method = method
|
||||
self.args = args
|
||||
@@ -107,9 +116,6 @@ class ExternalEvent(wxPyEvent):
|
||||
self.rpcStatusLock = None
|
||||
self.rpcondVar = None
|
||||
|
||||
def EVT_EXTERNAL_EVENT(win,func):
|
||||
win.Connect(-1,-1,wxEVT_EXTERNAL_EVENT,func)
|
||||
|
||||
class Handler(xmlrpcserver.RequestHandler):
|
||||
"""The handler class that the xmlrpcserver actually calls
|
||||
when a request comes in.
|
||||
@@ -145,7 +151,7 @@ class Handler(xmlrpcserver.RequestHandler):
|
||||
|
||||
evt.rpcCondVar.acquire()
|
||||
# dispatch the event to the GUI
|
||||
wxPostEvent(self._app,evt)
|
||||
wx.PostEvent(self._app,evt)
|
||||
|
||||
# wait for the GUI to finish
|
||||
while evt.rpcStatus.status == rpcPENDING:
|
||||
@@ -227,14 +233,14 @@ class rpcMixin:
|
||||
if port == -1:
|
||||
port = self.defPort
|
||||
self.verbose=verbose
|
||||
EVT_EXTERNAL_EVENT(self,self.OnExternal)
|
||||
self.Bind(EVT_EXTERNAL_EVENT,self.OnExternal)
|
||||
if hasattr(self,'OnClose'):
|
||||
self._origOnClose = self.OnClose
|
||||
self.Disconnect(-1,-1,wxEVT_CLOSE_WINDOW)
|
||||
self.Disconnect(-1,-1,wx.EVT_CLOSE_WINDOW)
|
||||
else:
|
||||
self._origOnClose = None
|
||||
self.OnClose = self.RPCOnClose
|
||||
EVT_CLOSE(self,self.RPCOnClose)
|
||||
self.Bind(wx.EVT_CLOSE,self.RPCOnClose)
|
||||
|
||||
tClass = new.classobj('Handler%d'%(port),(Handler,),{})
|
||||
tClass._app = self
|
||||
@@ -342,7 +348,7 @@ if __name__ == '__main__':
|
||||
else:
|
||||
port = 8023
|
||||
|
||||
class rpcFrame(wxFrame,rpcMixin):
|
||||
class rpcFrame(wx.Frame,rpcMixin):
|
||||
"""A simple wxFrame with the rpcMixin functionality added
|
||||
"""
|
||||
def __init__(self,*args,**kwargs):
|
||||
@@ -360,10 +366,10 @@ if __name__ == '__main__':
|
||||
mixinArgs['portScan'] = kwargs['rpcPortScan']
|
||||
del kwargs['rpcPortScan']
|
||||
|
||||
apply(wxFrame.__init__,(self,)+args,kwargs)
|
||||
apply(wx.Frame.__init__,(self,)+args,kwargs)
|
||||
apply(rpcMixin.__init__,(self,),mixinArgs)
|
||||
|
||||
EVT_CHAR(self,self.OnChar)
|
||||
self.Bind(wx.EVT_CHAR,self.OnChar)
|
||||
|
||||
def TestFunc(self,args):
|
||||
"""a demo method"""
|
||||
@@ -382,11 +388,10 @@ if __name__ == '__main__':
|
||||
|
||||
|
||||
|
||||
class MyApp(wxApp):
|
||||
class MyApp(wx.App):
|
||||
def OnInit(self):
|
||||
self.frame = rpcFrame(NULL, -1, "wxPython RPCDemo", wxDefaultPosition,
|
||||
wxSize(300,300),
|
||||
rpcHost='localhost',rpcPort=port)
|
||||
self.frame = rpcFrame(None, -1, "wxPython RPCDemo", wx.DefaultPosition,
|
||||
(300,300), rpcHost='localhost',rpcPort=port)
|
||||
self.frame.Show(True)
|
||||
return True
|
||||
|
||||
|
@@ -6,13 +6,16 @@
|
||||
# RCS-ID: $Id$
|
||||
# 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,
|
||||
providing automatic scrollbar and scrolling behavior and the tab traversal
|
||||
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.)
|
||||
"""
|
||||
def __init__(self, parent, id=-1,
|
||||
pos = wxDefaultPosition, size = wxDefaultSize,
|
||||
style = wxTAB_TRAVERSAL, name = "scrolledpanel"):
|
||||
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||
style = wx.TAB_TRAVERSAL, name = "scrolledpanel"):
|
||||
|
||||
wxScrolledWindow.__init__(self, parent, -1,
|
||||
wx.ScrolledWindow.__init__(self, parent, -1,
|
||||
pos=pos, size=size,
|
||||
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):
|
||||
@@ -56,7 +59,7 @@ as a proper class (and the demo is now converted to just use it.)
|
||||
self.SetVirtualSizeHints( w, h )
|
||||
|
||||
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):
|
||||
@@ -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:
|
||||
new_vs_y = vs_y + (cpos.y / sppu_y)
|
||||
|
||||
clntsz = self.GetClientSize()
|
||||
|
||||
# is it past the right edge ?
|
||||
if cpos.x + csz.width > self.GetClientSize().width and sppu_x > 0:
|
||||
diff = (cpos.x + csz.width - self.GetClientSize().width) / sppu_x
|
||||
if cpos.x + csz.width > clntsz.width and sppu_x > 0:
|
||||
diff = (cpos.x + csz.width - clntsz.width) / sppu_x
|
||||
new_vs_x = vs_x + diff + 1
|
||||
|
||||
# is it below the bottom ?
|
||||
if cpos.y + csz.height > self.GetClientSize().height and sppu_y > 0:
|
||||
diff = (cpos.y + csz.height - self.GetClientSize().height) / sppu_y
|
||||
if cpos.y + csz.height > clntsz.height and sppu_y > 0:
|
||||
diff = (cpos.y + csz.height - clntsz.height) / sppu_y
|
||||
new_vs_y = vs_y + diff + 1
|
||||
|
||||
# if we need to adjust
|
||||
|
@@ -2,42 +2,48 @@
|
||||
# CSheet - A wxPython spreadsheet class.
|
||||
# This is free software. Feel free to adapt it as you like.
|
||||
# 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 wx
|
||||
import wx.grid
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
class CTextCellEditor(wxTextCtrl):
|
||||
class CTextCellEditor(wx.TextCtrl):
|
||||
""" Custom text control for cell editing """
|
||||
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
|
||||
EVT_CHAR(self, self.OnChar)
|
||||
self.Bind(wx.EVT_CHAR, self.OnChar)
|
||||
|
||||
def OnChar(self, evt): # Hook OnChar for custom behavior
|
||||
"""Customizes char events """
|
||||
key = evt.GetKeyCode()
|
||||
if key == WXK_DOWN:
|
||||
if key == wx.WXK_DOWN:
|
||||
self._grid.DisableCellEditControl() # Commit the edit
|
||||
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.MoveCursorUp(False) # Change the current cell
|
||||
elif key == WXK_LEFT:
|
||||
elif key == wx.WXK_LEFT:
|
||||
self._grid.DisableCellEditControl() # Commit the edit
|
||||
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.MoveCursorRight(False) # Change the current cell
|
||||
|
||||
evt.Skip() # Continue event
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
class CCellEditor(wxPyGridCellEditor):
|
||||
class CCellEditor(wx.grid.PyGridCellEditor):
|
||||
""" Custom cell editor """
|
||||
def __init__(self, grid):
|
||||
wxPyGridCellEditor.__init__(self)
|
||||
wx.grid.PyGridCellEditor.__init__(self)
|
||||
self._grid = grid # Save a reference to the grid
|
||||
|
||||
def Create(self, parent, id, evtHandler):
|
||||
@@ -106,7 +112,7 @@ class CCellEditor(wxPyGridCellEditor):
|
||||
and will always start the editor.
|
||||
"""
|
||||
return (not (evt.ControlDown() or evt.AltDown())
|
||||
and evt.GetKeyCode() != WXK_SHIFT)
|
||||
and evt.GetKeyCode() != wx.WXK_SHIFT)
|
||||
|
||||
def StartingKey(self, evt):
|
||||
""" 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
|
||||
ch = None # Handle num pad keys
|
||||
if key in [WXK_NUMPAD0, WXK_NUMPAD1, WXK_NUMPAD2, WXK_NUMPAD3, WXK_NUMPAD4,
|
||||
WXK_NUMPAD5, WXK_NUMPAD6, WXK_NUMPAD7, WXK_NUMPAD8, WXK_NUMPAD9]:
|
||||
ch = chr(ord('0') + key - WXK_NUMPAD0)
|
||||
if key in [ wx.WXK_NUMPAD0, wx.WXK_NUMPAD1, wx.WXK_NUMPAD2, wx.WXK_NUMPAD3,
|
||||
wx.WXK_NUMPAD4, wx.WXK_NUMPAD5, wx.WXK_NUMPAD6, wx.WXK_NUMPAD7,
|
||||
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 = ""
|
||||
# Handle normal keys
|
||||
elif key < 256 and key >= 0 and chr(key) in string.printable:
|
||||
@@ -147,36 +154,36 @@ class CCellEditor(wxPyGridCellEditor):
|
||||
return CCellEditor()
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
class CSheet(wxGrid):
|
||||
class CSheet(wx.grid.Grid):
|
||||
def __init__(self, parent):
|
||||
wxGrid.__init__(self, parent, -1)
|
||||
wx.grid.Grid.__init__(self, parent, -1)
|
||||
|
||||
# Init variables
|
||||
self._lastCol = -1 # Init last cell column clicked
|
||||
self._lastRow = -1 # Init last cell row clicked
|
||||
self._selected = None # Init range currently selected
|
||||
# Map string datatype to default renderer/editor
|
||||
self.RegisterDataType(wxGRID_VALUE_STRING,
|
||||
wxGridCellStringRenderer(),
|
||||
self.RegisterDataType(wx.grid.GRID_VALUE_STRING,
|
||||
wx.grid.GridCellStringRenderer(),
|
||||
CCellEditor(self))
|
||||
|
||||
self.CreateGrid(4, 3) # By default start with a 4 x 3 grid
|
||||
self.SetColLabelSize(18) # Default sizes and alignment
|
||||
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(1, 75)
|
||||
self.SetColSize(2, 75)
|
||||
|
||||
# Sink events
|
||||
EVT_GRID_CELL_LEFT_CLICK( self, self.OnLeftClick)
|
||||
EVT_GRID_CELL_RIGHT_CLICK( self, self.OnRightClick)
|
||||
EVT_GRID_CELL_LEFT_DCLICK( self, self.OnLeftDoubleClick)
|
||||
EVT_GRID_RANGE_SELECT( self, self.OnRangeSelect)
|
||||
EVT_GRID_ROW_SIZE( self, self.OnRowSize)
|
||||
EVT_GRID_COL_SIZE( self, self.OnColSize)
|
||||
EVT_GRID_CELL_CHANGE( self, self.OnCellChange)
|
||||
EVT_GRID_SELECT_CELL( self, self.OnGridSelectCell)
|
||||
self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnLeftClick)
|
||||
self.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.OnRightClick)
|
||||
self.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.OnLeftDoubleClick)
|
||||
self.Bind(wx.grid.EVT_GRID_RANGE_SELECT, self.OnRangeSelect)
|
||||
self.Bind(wx.grid.EVT_GRID_ROW_SIZE, self.OnRowSize)
|
||||
self.Bind(wx.grid.EVT_GRID_COL_SIZE, self.OnColSize)
|
||||
self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnCellChange)
|
||||
self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnGridSelectCell)
|
||||
|
||||
def OnGridSelectCell(self, event):
|
||||
""" Track cell selections """
|
||||
@@ -247,18 +254,18 @@ class CSheet(wxGrid):
|
||||
s += crlf
|
||||
|
||||
# Put the string on the clipboard
|
||||
if wxTheClipboard.Open():
|
||||
wxTheClipboard.Clear()
|
||||
wxTheClipboard.SetData(wxTextDataObject(s))
|
||||
wxTheClipboard.Close()
|
||||
if wx.TheClipboard.Open():
|
||||
wx.TheClipboard.Clear()
|
||||
wx.TheClipboard.SetData(wx.TextDataObject(s))
|
||||
wx.TheClipboard.Close()
|
||||
|
||||
def Paste(self):
|
||||
""" Paste the contents of the clipboard into the currently selected cells """
|
||||
# (Is there a better way to do this?)
|
||||
if wxTheClipboard.Open():
|
||||
td = wxTextDataObject()
|
||||
success = wxTheClipboard.GetData(td)
|
||||
wxTheClipboard.Close()
|
||||
if wx.TheClipboard.Open():
|
||||
td = wx.TextDataObject()
|
||||
success = wx.TheClipboard.GetData(td)
|
||||
wx.TheClipboard.Close()
|
||||
if not success: return # Exit on failure
|
||||
s = td.GetText() # Get the text
|
||||
|
||||
|
@@ -1,4 +1,11 @@
|
||||
# shell.py
|
||||
#----------------------------------------------------------------------
|
||||
# 12/10/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o 2.5 compatability update.
|
||||
# o Added deprecation warning.
|
||||
#
|
||||
|
||||
"""wxPython interactive shell
|
||||
|
||||
Copyright (c) 1999 SIA "ANK"
|
||||
@@ -29,12 +36,30 @@ History:
|
||||
__version__ ="$Revision$"
|
||||
# $RCSfile$
|
||||
|
||||
import sys, code, traceback
|
||||
from wxPython.wx import *
|
||||
from wxPython.html import *
|
||||
import code
|
||||
import sys
|
||||
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
|
||||
|
||||
"""
|
||||
@@ -48,22 +73,22 @@ class PyShellInput(wxPanel):
|
||||
and shell.output is used for output
|
||||
(print's go to overridden stdout)
|
||||
"""
|
||||
wxPanel.__init__(self, parent, id)
|
||||
wx.Panel.__init__(self, parent, id)
|
||||
self.shell =shell
|
||||
# make a private copy of class attrs
|
||||
self.PS1 =PyShellInput.PS1
|
||||
self.PS2 =PyShellInput.PS2
|
||||
# create controls
|
||||
self.label =wxStaticText(self, -1, self.PS1)
|
||||
tid =wxNewId()
|
||||
self.entry =wxTextCtrl(self, tid, style = wxTE_MULTILINE)
|
||||
EVT_CHAR(self.entry, self.OnChar)
|
||||
self.entry.SetFont(wxFont(9, wxMODERN, wxNORMAL, wxNORMAL, False))
|
||||
sizer =wxBoxSizer(wxVERTICAL)
|
||||
sizer.AddMany([(self.label, 0, wxEXPAND), (self.entry, 1, wxEXPAND)])
|
||||
self.label =wx.StaticText(self, -1, self.PS1)
|
||||
tid =wx.NewId()
|
||||
self.entry =wx.TextCtrl(self, tid, style = wx.TE_MULTILINE)
|
||||
self.entry.Bind(wx.EVT_CHAR, self.OnChar)
|
||||
self.entry.SetFont(wx.Font(9, wx.MODERN, wx.NORMAL, wx.NORMAL, False))
|
||||
sizer =wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.AddMany([(self.label, 0, wx.EXPAND), (self.entry, 1, wx.EXPAND)])
|
||||
self.SetSizer(sizer)
|
||||
self.SetAutoLayout(True)
|
||||
EVT_SET_FOCUS(self, self.OnSetFocus)
|
||||
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
|
||||
# when in "continuation" mode,
|
||||
# two consecutive newlines are required
|
||||
# to avoid execution of unfinished block
|
||||
@@ -84,7 +109,7 @@ class PyShellInput(wxPanel):
|
||||
def OnChar(self, event):
|
||||
"""called on CHARevent. executes input on newline"""
|
||||
# print "On Char:", event.__dict__.keys()
|
||||
if event.KeyCode() !=WXK_RETURN:
|
||||
if event.KeyCode() !=wx.WXK_RETURN:
|
||||
# not of our business
|
||||
event.Skip()
|
||||
return
|
||||
@@ -110,7 +135,7 @@ class PyShellInput(wxPanel):
|
||||
else:
|
||||
self.Clear()
|
||||
|
||||
class PyShellOutput(wxPanel):
|
||||
class PyShellOutput(wx.Panel):
|
||||
"""PyShell output window
|
||||
|
||||
for now, it is based on simple wxTextCtrl,
|
||||
@@ -128,7 +153,7 @@ class PyShellOutput(wxPanel):
|
||||
# entity references
|
||||
erefs =(("&", "&"), (">", ">"), ("<", "<"), (" ", " "))
|
||||
def __init__(self, parent, id=-1):
|
||||
wxPanel.__init__(self, parent, id)
|
||||
wx.Panel.__init__(self, parent, id)
|
||||
# make a private copy of class attrs
|
||||
self.in_style =PyShellOutput.in_style
|
||||
self.out_style =PyShellOutput.out_style
|
||||
@@ -139,17 +164,17 @@ class PyShellOutput(wxPanel):
|
||||
if self.html_debug:
|
||||
# this was used in html debugging,
|
||||
# but i don't want to delete it; it's funny
|
||||
splitter =wxSplitterWindow(self, -1)
|
||||
self.view =wxTextCtrl(splitter, -1,
|
||||
style = wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL)
|
||||
self.html =wxHtmlWindow(splitter)
|
||||
splitter =wx.SplitterWindow(self, -1)
|
||||
self.view =wx.TextCtrl(splitter, -1,
|
||||
style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
|
||||
self.html =wx.html.HtmlWindow(splitter)
|
||||
splitter.SplitVertically(self.view, self.html)
|
||||
splitter.SetSashPosition(40)
|
||||
splitter.SetMinimumPaneSize(3)
|
||||
self.client =splitter
|
||||
else:
|
||||
self.view =None
|
||||
self.html =wxHtmlWindow(self)
|
||||
self.html =wx.html.HtmlWindow(self)
|
||||
self.client =self.html # used in OnSize()
|
||||
self.text =self.intro
|
||||
self.html.SetPage(self.text)
|
||||
@@ -158,8 +183,8 @@ class PyShellOutput(wxPanel):
|
||||
# refreshes are annoying
|
||||
self.in_batch =0
|
||||
self.dirty =0
|
||||
EVT_SIZE(self, self.OnSize)
|
||||
EVT_IDLE(self, self.OnIdle)
|
||||
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||
self.Bind(wx.EVT_IDLE, self.OnIdle)
|
||||
|
||||
def OnSize(self, event):
|
||||
self.client.SetSize(self.GetClientSize())
|
||||
@@ -232,18 +257,18 @@ class PyShellOutput(wxPanel):
|
||||
if style ==None: style =self.exc_style
|
||||
self.AddText(str, style)
|
||||
|
||||
class PyShell(wxPanel):
|
||||
class PyShell(wx.Panel):
|
||||
"""interactive Python shell with wxPython interface
|
||||
|
||||
"""
|
||||
def __init__(self, parent, globals=globals(), locals={},
|
||||
id=-1, pos=wxDefaultPosition, size=wxDefaultSize,
|
||||
style=wxTAB_TRAVERSAL, name="shell"):
|
||||
id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize,
|
||||
style=wx.TAB_TRAVERSAL, name="shell"):
|
||||
"""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.locals =locals
|
||||
splitter =wxSplitterWindow(self, -1)
|
||||
splitter =wx.SplitterWindow(self, -1)
|
||||
self.output =PyShellOutput(splitter)
|
||||
self.input =PyShellInput(splitter, self)
|
||||
self.input.SetFocus()
|
||||
@@ -251,8 +276,8 @@ class PyShell(wxPanel):
|
||||
splitter.SetSashPosition(100)
|
||||
splitter.SetMinimumPaneSize(20)
|
||||
self.splitter =splitter
|
||||
EVT_SET_FOCUS(self, self.OnSetFocus)
|
||||
EVT_SIZE(self, self.OnSize)
|
||||
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
|
||||
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||
|
||||
def OnSetFocus(self, event):
|
||||
self.input.SetFocus()
|
||||
@@ -317,14 +342,14 @@ class PyShell(wxPanel):
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
class MyFrame(wxFrame):
|
||||
class MyFrame(wx.Frame):
|
||||
"""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"):
|
||||
wxFrame.__init__(self, parent, id, title)
|
||||
wx.Frame.__init__(self, parent, id, title)
|
||||
self.shell =PyShell(self)
|
||||
|
||||
class MyApp(wxApp):
|
||||
class MyApp(wx.App):
|
||||
"""Demonstrates usage of both default and customized shells"""
|
||||
def OnInit(self):
|
||||
frame = MyFrame()
|
||||
|
@@ -10,6 +10,11 @@
|
||||
# Copyright: (c) 1999 by Total Control Software
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------
|
||||
# 12/11/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o 2.5 compatability update.
|
||||
# o Untested.
|
||||
#
|
||||
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
|
||||
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",
|
||||
style=wxSIMPLE_BORDER|wxSTAY_ON_TOP,
|
||||
style=wx.SIMPLE_BORDER|wx.STAY_ON_TOP,
|
||||
duration=1500, bitmapfile="bitmaps/splashscreen.bmp",
|
||||
callback = None):
|
||||
'''
|
||||
parent, ID, title, style -- see wxFrame
|
||||
parent, ID, title, style -- see wx.Frame
|
||||
duration -- milliseconds to display the splash screen
|
||||
bitmapfile -- absolute or relative pathname to image file
|
||||
callback -- if specified, is called when timer completes, callback is
|
||||
responsible for closing the splash screen
|
||||
'''
|
||||
### 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...
|
||||
size = (bmp.GetWidth(), bmp.GetHeight())
|
||||
|
||||
# size of screen
|
||||
width = wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_X)
|
||||
height = wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_Y)
|
||||
width = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
|
||||
height = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)
|
||||
pos = ((width-size[0])/2, (height-size[1])/2)
|
||||
|
||||
# check for overflow...
|
||||
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:
|
||||
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)
|
||||
EVT_LEFT_DOWN(self, self.OnMouseClick)
|
||||
EVT_CLOSE(self, self.OnCloseWindow)
|
||||
EVT_PAINT(self, self.OnPaint)
|
||||
EVT_ERASE_BACKGROUND(self, self.OnEraseBG)
|
||||
wx.Frame.__init__(self, parent, ID, title, pos, size, style)
|
||||
self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseClick)
|
||||
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBG)
|
||||
|
||||
self.Show(True)
|
||||
|
||||
|
||||
class SplashTimer(wxTimer):
|
||||
class SplashTimer(wx.Timer):
|
||||
def __init__(self, targetFunction):
|
||||
self.Notify = targetFunction
|
||||
wxTimer.__init__(self)
|
||||
wx.Timer.__init__(self)
|
||||
|
||||
if callback is None:
|
||||
callback = self.OnSplashExitDefault
|
||||
@@ -72,8 +92,8 @@ class SplashScreen(wxFrame):
|
||||
self.timer.Start(duration, 1) # one-shot only
|
||||
|
||||
def OnPaint(self, event):
|
||||
dc = wxPaintDC(self)
|
||||
dc.DrawBitmap(self.bitmap, 0,0, False)
|
||||
dc = wx.PaintDC(self)
|
||||
dc.DrawBitmap(self.bitmap, (0,0), False)
|
||||
|
||||
def OnEraseBG(self, event):
|
||||
pass
|
||||
@@ -94,12 +114,10 @@ class SplashScreen(wxFrame):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
class DemoApp(wxApp):
|
||||
class DemoApp(wx.App):
|
||||
def OnInit(self):
|
||||
wxImage_AddHandler(wxJPEGHandler())
|
||||
wxImage_AddHandler(wxPNGHandler())
|
||||
wxImage_AddHandler(wxGIFHandler())
|
||||
self.splash = SplashScreen(NULL, bitmapfile="splashscreen.jpg", callback=self.OnSplashExit)
|
||||
wx.InitAllImageHandlers()
|
||||
self.splash = SplashScreen(None, bitmapfile="splashscreen.jpg", callback=self.OnSplashExit)
|
||||
self.splash.Show(True)
|
||||
self.SetTopWindow(self.splash)
|
||||
return True
|
||||
|
@@ -11,9 +11,11 @@
|
||||
# Copyright: (c) 2002 by Total Control Software
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
"""
|
||||
"""
|
||||
# 12/12/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o 2.5 compatability update.
|
||||
# o Untested.
|
||||
#
|
||||
|
||||
import wx
|
||||
|
||||
@@ -52,8 +54,8 @@ class GenStaticText(wx.PyControl):
|
||||
if rh == -1: rh = bh
|
||||
self.SetSize(wx.Size(rw, rh))
|
||||
|
||||
wx.EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
|
||||
wx.EVT_PAINT(self, self.OnPaint)
|
||||
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
|
||||
|
||||
def SetLabel(self, label):
|
||||
|
@@ -16,6 +16,11 @@ can continue unencumbered.
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# 12/12/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o 2.5 compatability update.
|
||||
#
|
||||
|
||||
|
||||
import os
|
||||
import wx
|
||||
@@ -23,8 +28,7 @@ import wx
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
THROBBER_EVENT = wx.NewEventType()
|
||||
def EVT_UPDATE_THROBBER(win, func):
|
||||
win.Connect(-1, -1, THROBBER_EVENT, func)
|
||||
EVT_UPDATE_THROBBER = wx.PyEventBinder(THROBBER_EVENT, 0)
|
||||
|
||||
class UpdateThrobberEvent(wx.PyEvent):
|
||||
def __init__(self):
|
||||
@@ -119,10 +123,10 @@ class Throbber(wx.Panel):
|
||||
timerID = wx.NewId()
|
||||
self.timer = wx.Timer(self, timerID)
|
||||
|
||||
EVT_UPDATE_THROBBER(self, self.Rotate)
|
||||
wx.EVT_PAINT(self, self.OnPaint)
|
||||
wx.EVT_TIMER(self, timerID, self.OnTimer)
|
||||
wx.EVT_WINDOW_DESTROY(self, self.OnDestroyWindow)
|
||||
self.Bind(EVT_UPDATE_THROBBER, self.Rotate)
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
|
||||
self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroyWindow)
|
||||
|
||||
|
||||
def OnTimer(self, event):
|
||||
|
@@ -29,6 +29,13 @@
|
||||
# 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
|
||||
# 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>
|
||||
@@ -239,10 +246,14 @@ value to fall within the current bounds.
|
||||
</body></html>
|
||||
"""
|
||||
|
||||
import string, copy, types
|
||||
from wxPython.wx import *
|
||||
from wxPython.tools.dbg import Logger
|
||||
from wxPython.lib.maskededit import wxMaskedTextCtrl, Field
|
||||
import copy
|
||||
import string
|
||||
import types
|
||||
|
||||
import wx
|
||||
|
||||
from wx.tools.dbg import Logger
|
||||
from wx.lib.maskededit import wxMaskedTextCtrl, Field
|
||||
|
||||
dbg = Logger()
|
||||
dbg(enable=0)
|
||||
@@ -254,14 +265,12 @@ except ImportError:
|
||||
accept_mx = False
|
||||
|
||||
# This class of event fires whenever the value of the time changes in the control:
|
||||
wxEVT_TIMEVAL_UPDATED = wxNewId()
|
||||
def EVT_TIMEUPDATE(win, id, func):
|
||||
"""Used to trap events indicating that the current time has been changed."""
|
||||
win.Connect(id, -1, wxEVT_TIMEVAL_UPDATED, func)
|
||||
wxEVT_TIMEVAL_UPDATED = wx.NewEventType()
|
||||
EVT_TIMEUPDATE = wx.PyEventBinder(wxEVT_TIMEVAL_UPDATED, 1)
|
||||
|
||||
class TimeUpdatedEvent(wxPyCommandEvent):
|
||||
class TimeUpdatedEvent(wx.PyCommandEvent):
|
||||
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
|
||||
def GetValue(self):
|
||||
"""Retrieve the value of the time control at the time this event was generated"""
|
||||
@@ -281,11 +290,11 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
||||
|
||||
def __init__ (
|
||||
self, parent, id=-1, value = '12:00:00 AM',
|
||||
pos = wxDefaultPosition, size = wxDefaultSize,
|
||||
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||
fmt24hr=False,
|
||||
spinButton = None,
|
||||
style = wxTE_PROCESS_TAB,
|
||||
validator = wxDefaultValidator,
|
||||
style = wx.TE_PROCESS_TAB,
|
||||
validator = wx.DefaultValidator,
|
||||
name = "time",
|
||||
**kwargs ):
|
||||
|
||||
@@ -369,7 +378,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
||||
maskededit_kwargs['useFixedWidthFont'] = self.__useFixedWidthFont
|
||||
|
||||
# allow for explicit size specification:
|
||||
if size != wxDefaultSize:
|
||||
if size != wx.DefaultSize:
|
||||
# override (and remove) "autofit" autoformat code in standard time formats:
|
||||
maskededit_kwargs['formatcodes'] = 'T!'
|
||||
|
||||
@@ -389,8 +398,8 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
||||
|
||||
|
||||
# This makes the up/down keys act like spin button controls:
|
||||
self._SetKeycodeHandler(WXK_UP, self.__OnSpinUp)
|
||||
self._SetKeycodeHandler(WXK_DOWN, self.__OnSpinDown)
|
||||
self._SetKeycodeHandler(wx.WXK_UP, self.__OnSpinUp)
|
||||
self._SetKeycodeHandler(wx.WXK_DOWN, self.__OnSpinDown)
|
||||
|
||||
|
||||
# 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
|
||||
# EVT_TIMEUPDATE events on changes:
|
||||
|
||||
EVT_SET_FOCUS( self, self._OnFocus ) ## defeat automatic full selection
|
||||
EVT_KILL_FOCUS( self, self._OnKillFocus ) ## run internal validator
|
||||
EVT_LEFT_UP(self, self.__LimitSelection) ## limit selections to single field
|
||||
EVT_LEFT_DCLICK(self, self._OnDoubleClick ) ## select field under cursor on dclick
|
||||
EVT_KEY_DOWN( self, 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_SET_FOCUS, self._OnFocus ) ## defeat automatic full selection
|
||||
self.Bind(wx.EVT_KILL_FOCUS, self._OnKillFocus ) ## run internal validator
|
||||
self.Bind(wx.EVT_LEFT_UP, self.__LimitSelection) ## limit selections to single field
|
||||
self.Bind(wx.EVT_LEFT_DCLICK, self._OnDoubleClick ) ## select field under cursor on dclick
|
||||
self.Bind(wx.EVT_KEY_DOWN, self._OnKeyDown ) ## capture control events not normally seen, eg ctrl-tab.
|
||||
self.Bind(wx.EVT_CHAR, self.__OnChar ) ## remove "shift" attribute from colon key event,
|
||||
## then call wxMaskedTextCtrl._OnChar with
|
||||
## 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
|
||||
@@ -438,8 +447,8 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
||||
self.__spinButton = sb
|
||||
if self.__spinButton:
|
||||
# bind event handlers to spin ctrl
|
||||
EVT_SPIN_UP(self.__spinButton, self.__spinButton.GetId(), self.__OnSpinUp)
|
||||
EVT_SPIN_DOWN(self.__spinButton, self.__spinButton.GetId(), self.__OnSpinDown)
|
||||
self.__spinButton.Bind(wx.EVT_SPIN_UP, self.__OnSpinUp, self.__spinButton)
|
||||
self.__spinButton.Bind(wx.EVT_SPIN_DOWN, self.__OnSpinDown, self.__spinButton)
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
@@ -478,7 +487,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
||||
elif as_mxDateTime:
|
||||
value = DateTime.DateTime(1970, 1, 1, value.GetHour(), value.GetMinute(), value.GetSecond())
|
||||
elif as_wxTimeSpan:
|
||||
value = wxTimeSpan(value.GetHour(), value.GetMinute(), value.GetSecond())
|
||||
value = wx.TimeSpan(value.GetHour(), value.GetMinute(), value.GetSecond())
|
||||
elif as_mxDateTimeDelta:
|
||||
value = DateTime.DateTimeDelta(0, value.GetHour(), value.GetMinute(), value.GetSecond())
|
||||
else:
|
||||
@@ -524,7 +533,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
||||
if type(value) == types.StringType:
|
||||
|
||||
# Construct constant wxDateTime, then try to parse the string:
|
||||
wxdt = wxDateTimeFromDMY(1, 0, 1970)
|
||||
wxdt = wx.DateTimeFromDMY(1, 0, 1970)
|
||||
dbg('attempting conversion')
|
||||
value = value.strip() # (parser doesn't like leading spaces)
|
||||
checkTime = wxdt.ParseTime(value)
|
||||
@@ -536,9 +545,9 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
||||
raise ValueError('cannot convert string "%s" to valid time' % value)
|
||||
|
||||
else:
|
||||
if isinstance(value, wxDateTime):
|
||||
if isinstance(value, wx.DateTime):
|
||||
hour, minute, second = value.GetHour(), value.GetMinute(), value.GetSecond()
|
||||
elif isinstance(value, wxTimeSpan):
|
||||
elif isinstance(value, wx.TimeSpan):
|
||||
totalseconds = value.GetSeconds()
|
||||
hour = totalseconds / 3600
|
||||
minute = totalseconds / 60 - (hour * 60)
|
||||
@@ -557,7 +566,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
||||
dbg(indent=0, suspend=0)
|
||||
raise ValueError(error)
|
||||
|
||||
wxdt = wxDateTimeFromDMY(1, 0, 1970)
|
||||
wxdt = wx.DateTimeFromDMY(1, 0, 1970)
|
||||
wxdt.SetHour(hour)
|
||||
wxdt.SetMinute(minute)
|
||||
wxdt.SetSecond(second)
|
||||
@@ -772,9 +781,9 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
||||
|
||||
# Note: relies on min and max and value date portions
|
||||
# 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, # minutes
|
||||
interval.GetSeconds() / 2, # seconds
|
||||
@@ -782,7 +791,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
||||
|
||||
if value < min: # min is on next day, so use value on
|
||||
# "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
|
||||
cmp_value = value
|
||||
|
||||
@@ -850,7 +859,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
||||
min = self.GetMin()
|
||||
max = self.GetMax()
|
||||
|
||||
midnight = wxDateTimeFromDMY(1, 0, 1970)
|
||||
midnight = wx.DateTimeFromDMY(1, 0, 1970)
|
||||
if min <= max: # they don't span midnight
|
||||
ret = min <= value <= max
|
||||
|
||||
@@ -993,7 +1002,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
||||
This is the key handler for '!' and 'c'; this allows the user to
|
||||
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
|
||||
return keep_processing
|
||||
|
||||
@@ -1028,7 +1037,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
||||
dbg('field: ', field._index)
|
||||
start, end = field._extent
|
||||
slice = text[start:end]
|
||||
if key == WXK_UP: increment = 1
|
||||
if key == wx.WXK_UP: increment = 1
|
||||
else: increment = -1
|
||||
|
||||
if slice in ('A', 'P'):
|
||||
@@ -1040,7 +1049,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
||||
# 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:
|
||||
# (Use a fixed date not subject to DST variations:)
|
||||
converter = wxDateTimeFromDMY(1, 0, 1970)
|
||||
converter = wx.DateTimeFromDMY(1, 0, 1970)
|
||||
dbg('text: "%s"' % text)
|
||||
converter.ParseTime(text.strip())
|
||||
currenthour = converter.GetHour()
|
||||
@@ -1059,8 +1068,8 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
||||
self.SetValue(newvalue)
|
||||
|
||||
except ValueError: # must not be in bounds:
|
||||
if not wxValidator_IsSilent():
|
||||
wxBell()
|
||||
if not wx.Validator_IsSilent():
|
||||
wx.Bell()
|
||||
dbg(indent=0)
|
||||
|
||||
|
||||
@@ -1111,30 +1120,30 @@ class wxTimeCtrl(wxMaskedTextCtrl):
|
||||
if __name__ == '__main__':
|
||||
import traceback
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
class TestPanel(wx.Panel):
|
||||
def __init__(self, parent, id,
|
||||
pos = wxPyDefaultPosition, size = wxPyDefaultSize,
|
||||
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||
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.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)
|
||||
|
||||
sizer = wxBoxSizer( wxHORIZONTAL )
|
||||
sizer.AddWindow( self.tc, 0, wxALIGN_CENTRE|wxLEFT|wxTOP|wxBOTTOM, 5 )
|
||||
sizer.AddWindow( sb, 0, wxALIGN_CENTRE|wxRIGHT|wxTOP|wxBOTTOM, 5 )
|
||||
sizer = wx.BoxSizer( wx.HORIZONTAL )
|
||||
sizer.Add( self.tc, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.TOP|wx.BOTTOM, 5 )
|
||||
sizer.Add( sb, 0, wx.ALIGN_CENTRE|wx.RIGHT|wx.TOP|wx.BOTTOM, 5 )
|
||||
|
||||
self.SetAutoLayout( True )
|
||||
self.SetSizer( sizer )
|
||||
sizer.Fit( self )
|
||||
sizer.SetSizeHints( self )
|
||||
|
||||
EVT_TIMEUPDATE(self, self.tc.GetId(), self.OnTimeChange)
|
||||
self.Bind(EVT_TIMEUPDATE, self.OnTimeChange, self.tc)
|
||||
|
||||
def OnTimeChange(self, event):
|
||||
dbg('OnTimeChange: value = ', event.GetValue())
|
||||
@@ -1145,14 +1154,14 @@ if __name__ == '__main__':
|
||||
dbg('mxdt =', mxdt.hour, mxdt.minute, mxdt.second)
|
||||
|
||||
|
||||
class MyApp(wxApp):
|
||||
class MyApp(wx.App):
|
||||
def OnInit(self):
|
||||
import sys
|
||||
fmt24hr = '24' in sys.argv
|
||||
test_mx = 'mx' in sys.argv
|
||||
try:
|
||||
frame = wxFrame(NULL, -1, "wxTimeCtrl Test", wxPoint(20,20), wxSize(100,100) )
|
||||
panel = TestPanel(frame, -1, wxPoint(-1,-1), fmt24hr=fmt24hr, test_mx = test_mx)
|
||||
frame = wx.Frame(None, -1, "wxTimeCtrl Test", (20,20), (100,100) )
|
||||
panel = TestPanel(frame, -1, (-1,-1), fmt24hr=fmt24hr, test_mx = test_mx)
|
||||
frame.Show(True)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
|
@@ -18,8 +18,28 @@ Original comment follows below:
|
||||
# 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...
|
||||
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
|
||||
information on downloading source or binaries."""
|
||||
|
||||
if wx.wxPlatform == '__WXMSW__':
|
||||
d = wx.wxMessageDialog(wx.NULL, msg, "Numeric not found")
|
||||
if d.ShowModal() == wx.wxID_CANCEL:
|
||||
d = wx.wxMessageDialog(wx.NULL, "I kid you not! Pressing Cancel won't help you!", "Not a joke", wx.wxOK)
|
||||
if wx.Platform == '__WXMSW__':
|
||||
d = wx.MessageDialog(None, msg, "Numeric not found")
|
||||
if d.ShowModal() == wx.ID_CANCEL:
|
||||
d = wx.MessageDialog(None, "I kid you not! Pressing Cancel won't help you!", "Not a joke", wx.OK)
|
||||
d.ShowModal()
|
||||
else:
|
||||
print msg
|
||||
@@ -75,7 +95,7 @@ class PolyLine(PolyPoints):
|
||||
color = self.attributes['color']
|
||||
width = self.attributes['width']
|
||||
arguments = []
|
||||
dc.SetPen(wx.wxPen(wx.wxNamedColour(color), width))
|
||||
dc.SetPen(wx.Pen(wx.NamedColour(color), width))
|
||||
dc.DrawLines(map(tuple,self.scaled))
|
||||
|
||||
|
||||
@@ -89,7 +109,7 @@ class PolyMarker(PolyPoints):
|
||||
'width': 1,
|
||||
'fillcolor': None,
|
||||
'size': 2,
|
||||
'fillstyle': wx.wxSOLID,
|
||||
'fillstyle': wx.SOLID,
|
||||
'outline': 'black',
|
||||
'marker': 'circle'}
|
||||
|
||||
@@ -101,11 +121,11 @@ class PolyMarker(PolyPoints):
|
||||
fillstyle = self.attributes['fillstyle']
|
||||
marker = self.attributes['marker']
|
||||
|
||||
dc.SetPen(wx.wxPen(wx.wxNamedColour(color),width))
|
||||
dc.SetPen(wx.Pen(wx.NamedColour(color),width))
|
||||
if fillcolor:
|
||||
dc.SetBrush(wx.wxBrush(wx.wxNamedColour(fillcolor),fillstyle))
|
||||
dc.SetBrush(wx.Brush(wx.NamedColour(fillcolor),fillstyle))
|
||||
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)
|
||||
|
||||
@@ -115,7 +135,7 @@ class PolyMarker(PolyPoints):
|
||||
f(dc, xc, yc, size)
|
||||
|
||||
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):
|
||||
dc.DrawPoint(xc,yc)
|
||||
@@ -134,12 +154,12 @@ class PolyMarker(PolyPoints):
|
||||
(0.0,0.577350*size*5)],xc,yc)
|
||||
|
||||
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):
|
||||
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-2.5*size,yc), (xc+2.5*size,yc))
|
||||
dc.DrawLine((xc,yc-2.5*size,xc), (yc+2.5*size))
|
||||
|
||||
class PlotGraphics:
|
||||
|
||||
@@ -169,29 +189,29 @@ class PlotGraphics:
|
||||
return self.objects[item]
|
||||
|
||||
|
||||
class PlotCanvas(wx.wxWindow):
|
||||
class PlotCanvas(wx.Window):
|
||||
|
||||
def __init__(self, parent, id=-1,
|
||||
pos = wx.wxDefaultPosition, size = wx.wxDefaultSize,
|
||||
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||
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.SetClientSizeWH(400,400)
|
||||
self.SetBackgroundColour(wx.wxNamedColour("white"))
|
||||
self.SetClientSize((400,400))
|
||||
self.SetBackgroundColour("white")
|
||||
|
||||
wx.EVT_SIZE(self,self.reconfigure)
|
||||
wx.EVT_PAINT(self, self.OnPaint)
|
||||
self.Bind(wx.EVT_SIZE,self.reconfigure)
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
self._setsize()
|
||||
self.last_draw = None
|
||||
# self.font = self._testFont(font)
|
||||
|
||||
def OnPaint(self, event):
|
||||
pdc = wx.wxPaintDC(self)
|
||||
pdc = wx.PaintDC(self)
|
||||
if self.last_draw is not None:
|
||||
apply(self.draw, self.last_draw + (pdc,))
|
||||
|
||||
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:
|
||||
return
|
||||
self._setsize()
|
||||
@@ -209,14 +229,14 @@ class PlotCanvas(wx.wxWindow):
|
||||
return font
|
||||
|
||||
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])
|
||||
xo = 0.5*(self.width-self.plotbox_size[0])
|
||||
yo = self.height-0.5*(self.height+self.plotbox_size[1])
|
||||
self.plotbox_origin = Numeric.array([xo, yo])
|
||||
|
||||
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.Clear()
|
||||
self.last_draw = (graphics, xaxis, yaxis)
|
||||
@@ -291,19 +311,19 @@ class PlotCanvas(wx.wxWindow):
|
||||
|
||||
def _drawAxes(self, dc, xaxis, yaxis,
|
||||
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:
|
||||
lower, upper = xaxis
|
||||
text = 1
|
||||
for y, d in [(bb1[1], -3), (bb2[1], 3)]:
|
||||
p1 = scale*Numeric.array([lower, 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:
|
||||
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:
|
||||
dc.DrawText(label,p[0],p[1])
|
||||
dc.DrawText(label, (p[0],p[1]))
|
||||
text = 0
|
||||
|
||||
if yaxis is not None:
|
||||
@@ -313,13 +333,13 @@ class PlotCanvas(wx.wxWindow):
|
||||
for x, d in [(bb1[0], -3), (bb2[0], 3)]:
|
||||
p1 = scale*Numeric.array([x, lower])+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:
|
||||
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:
|
||||
dc.DrawText(label,p[0]-dc.GetTextExtent(label)[0],
|
||||
p[1]-0.5*h)
|
||||
dc.DrawText(label,
|
||||
(p[0]-dc.GetTextExtent(label)[0], p[1]-0.5*h))
|
||||
text = 0
|
||||
|
||||
def _ticks(self, lower, upper):
|
||||
@@ -389,33 +409,33 @@ if __name__ == '__main__':
|
||||
return PlotGraphics([markers1, lines, markers2])
|
||||
|
||||
|
||||
class AppFrame(wx.wxFrame):
|
||||
class AppFrame(wx.Frame):
|
||||
def __init__(self, parent, id, title):
|
||||
wx.wxFrame.__init__(self, parent, id, title,
|
||||
wx.wxPyDefaultPosition, wx.wxSize(400, 400))
|
||||
wx.Frame.__init__(self, parent, id, title,
|
||||
wx.DefaultPosition, (400, 400))
|
||||
|
||||
# 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')
|
||||
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!')
|
||||
wx.EVT_MENU(self, 209, self.OnFileExit)
|
||||
self.Bind(wx.EVT_MENU, self.OnFileExit, id=209)
|
||||
self.mainmenu.Append(menu, '&File')
|
||||
|
||||
menu = wx.wxMenu()
|
||||
menu = wx.Menu()
|
||||
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')
|
||||
wx.EVT_MENU(self,211,self.OnPlotRedraw)
|
||||
self.Bind(wx.EVT_MENU,self.OnPlotRedraw, id=211)
|
||||
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')
|
||||
|
||||
menu = wx.wxMenu()
|
||||
menu = wx.Menu()
|
||||
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.SetMenuBar(self.mainmenu)
|
||||
@@ -426,11 +446,11 @@ if __name__ == '__main__':
|
||||
self.client = PlotCanvas(self)
|
||||
|
||||
def OnFilePrint(self, event):
|
||||
d = wx.wxMessageDialog(self,
|
||||
d = wx.MessageDialog(self,
|
||||
"""As of this writing, printing support in wxPython is shaky at best.
|
||||
Are you sure you want to do this?""", "Danger!", wx.wxYES_NO)
|
||||
if d.ShowModal() == wx.wxID_YES:
|
||||
psdc = wx.wxPostScriptDC("out.ps", wx.True, self)
|
||||
Are you sure you want to do this?""", "Danger!", wx.YES_NO)
|
||||
if d.ShowModal() == wx.ID_YES:
|
||||
psdc = wx.PostScriptDC("out.ps", True, self)
|
||||
self.client.redraw(psdc)
|
||||
|
||||
def OnFileExit(self, event):
|
||||
@@ -444,21 +464,21 @@ Are you sure you want to do this?""", "Danger!", wx.wxYES_NO)
|
||||
|
||||
def OnPlotClear(self,event):
|
||||
self.client.last_draw = None
|
||||
dc = wx.wxClientDC(self.client)
|
||||
dc = wx.ClientDC(self.client)
|
||||
dc.Clear()
|
||||
|
||||
def OnHelpAbout(self, event):
|
||||
about = wx.wxMessageDialog(self, __doc__, "About...", wx.wxOK)
|
||||
about = wx.MessageDialog(self, __doc__, "About...", wx.OK)
|
||||
about.ShowModal()
|
||||
|
||||
|
||||
|
||||
class MyApp(wx.wxApp):
|
||||
class MyApp(wx.App):
|
||||
def OnInit(self):
|
||||
frame = AppFrame(wx.NULL, -1, "wxPlotCanvas")
|
||||
frame.Show(wx.True)
|
||||
frame = AppFrame(None, -1, "wxPlotCanvas")
|
||||
frame.Show(True)
|
||||
self.SetTopWindow(frame)
|
||||
return wx.True
|
||||
return True
|
||||
|
||||
|
||||
app = MyApp(0)
|
||||
|
@@ -10,6 +10,10 @@
|
||||
# Copyright: (c) 1999 by Total Control Software
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------
|
||||
# 12/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o Updated for V2.5 compatability
|
||||
#
|
||||
|
||||
'''
|
||||
wxPython.lib.wxpTag
|
||||
@@ -69,9 +73,9 @@ be converted from strings to alternate datatypes. They are:
|
||||
|
||||
An example:
|
||||
|
||||
<wxp module="" class="wxButton">
|
||||
<wxp module="wx" class="Button">
|
||||
<param name="label" value="Click here">
|
||||
<param name="id" value="wxID_OK">
|
||||
<param name="id" value="ID_OK">
|
||||
</wxp>
|
||||
|
||||
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 wx
|
||||
import wx.html
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
WXPTAG = 'WXP'
|
||||
@@ -98,9 +102,9 @@ PARAMTAG = 'PARAM'
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class wxpTagHandler(wxHtmlWinTagHandler):
|
||||
class wxpTagHandler(wx.html.HtmlWinTagHandler):
|
||||
def __init__(self):
|
||||
wxHtmlWinTagHandler.__init__(self)
|
||||
wx.html.HtmlWinTagHandler.__init__(self)
|
||||
self.ctx = None
|
||||
|
||||
def GetSupportedTags(self):
|
||||
@@ -128,7 +132,7 @@ class wxpTagHandler(wxHtmlWinTagHandler):
|
||||
if modName:
|
||||
self.ctx.classMod = _my_import(modName)
|
||||
else:
|
||||
self.ctx.classMod = wxPython.wx
|
||||
self.ctx.classMod = wx
|
||||
|
||||
# find and verify the class
|
||||
if not tag.HasParam('CLASS'):
|
||||
@@ -151,7 +155,7 @@ class wxpTagHandler(wxHtmlWinTagHandler):
|
||||
width = int(width)
|
||||
if tag.HasParam('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.
|
||||
self.ParseInner(tag)
|
||||
@@ -165,7 +169,7 @@ class wxpTagHandler(wxHtmlWinTagHandler):
|
||||
obj.Show(True)
|
||||
|
||||
# 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
|
||||
|
||||
return True
|
||||
@@ -198,13 +202,13 @@ class wxpTagHandler(wxHtmlWinTagHandler):
|
||||
except:
|
||||
value = saveVal
|
||||
|
||||
# convert to wxColour
|
||||
# convert to wx.Colour
|
||||
elif value[0] == '#':
|
||||
try:
|
||||
red = int('0x'+value[1:3], 16)
|
||||
green = int('0x'+value[3:5], 16)
|
||||
blue = int('0x'+value[5:], 16)
|
||||
value = wxColor(red, green, blue)
|
||||
value = wx.Color(red, green, blue)
|
||||
except:
|
||||
pass
|
||||
|
||||
@@ -267,4 +271,4 @@ def _param2dict(param):
|
||||
|
||||
|
||||
|
||||
wxHtmlWinParser_AddTagHandler(wxpTagHandler)
|
||||
wx.html.HtmlWinParser_AddTagHandler(wxpTagHandler)
|
||||
|
Reference in New Issue
Block a user