4
__version__ = "$Revision: 1.1 $"
5
__date__ = "$Date: 2004/09/28 21:23:55 $"
8
from PythonCard import clipboard, dialog, graphic, model
14
# minimalist panel that works like PageBackground
15
# for testing purposes
16
class MyPanel(wx.Panel):
17
def __init__(self, aParent, size, name):
18
wx.Panel.__init__(self, aParent,
23
self.panel = wx.Panel(self, -1,
24
style=wx.TAB_TRAVERSAL | wx.NO_FULL_REPAINT_ON_RESIZE)
26
self.field1 = wx.TextCtrl(self, -1, 'Hello World')
28
self._sizer = wx.BoxSizer(wx.VERTICAL)
29
self._sizer.Add(self.panel, True, wx.EXPAND)
31
self._sizer.SetSizeHints(self)
32
self.SetSizer(self._sizer)
35
class TestSplitter(model.SplitterBackground):
37
def on_initialize(self, event):
38
# the splitter code is adapted from the wxPython demo Main.py
40
# I was having to do RemoveChild with Background
41
# but SplitterBackground seems okay
42
## self.RemoveChild(self.panel)
45
splitter = wx.SplitterWindow(self, -1, style=wx.CLIP_CHILDREN | wx.SP_LIVE_UPDATE | wx.SP_3D)
46
splitter2 = wx.SplitterWindow(splitter, -1, style=wx.CLIP_CHILDREN | wx.SP_LIVE_UPDATE | wx.SP_3D)
47
self.splitter = splitter
48
self.splitter2 = splitter2
50
win1 = MyPanel(splitter, (100, 50), 'win1')
51
#win1 = model.childWindow(splitter, doodle.Doodle)
52
win1 = model.childWindow(splitter, minimal.Minimal)
53
#win2 = model.childWindow(splitter, minimal.Minimal)
54
#win2 = MyPanel(splitter, (100, 50), 'win2')
55
win2 = model.childWindow(splitter2, doodle.Doodle)
56
#win2 = model.childWindow(splitter2, minimal.Minimal)
57
win3 = model.childWindow(splitter2, doodle.Doodle)
63
# add the windows to the splitter and split it.
64
splitter2.SplitHorizontally(win2, win3, 160)
65
splitter.SplitVertically(win1, splitter2, 200)
66
#splitter.SplitVertically(win1, win2, 150)
68
splitter.SetMinimumPaneSize(20)
69
splitter2.SetMinimumPaneSize(20)
70
self.size = (600, 400)
72
# Make the splitter on the right expand the top window when resized
73
def SplitterOnSize(evt):
74
splitter = evt.GetEventObject()
75
sz = splitter.GetSize()
76
splitter.SetSashPosition(sz.height - 160, False)
79
#splitter2.Bind(wx.EVT_SIZE, SplitterOnSize)
86
MAJOR UNRESOLVED ISSUES
88
just like top-level event handlers and methods
89
when dealing with a Notebook
90
how do we want these kinds of methods to work with a SplitterBackground?
91
if the event handlers and methods such as openFile are defined in the
92
top-level parent then they will be found, but rather than references
93
such as self.components.bufOff they would have to make specific
94
references to the child such as self.win3.components.bufOff
96
this makes sense from the standpoint that the associated menus
97
also have to be specified in the top-level Background resource
98
but it would seem to reduce reusability
100
so could we and should we bind and dispatch events such that
101
a child could add menus and menu items from its resource
102
during the initLayout call or something like that?
103
depending on the focus context, events would be directed
104
at the appropriate child.
105
i'm not even sure that is doable.
107
needless to say the containers introduced with Notebook
108
and SplitterBackground are making me worry about PythonCard
109
becoming even more of a confusing hack job than it already is.
113
win = self.findFocus()
115
result = dialog.openFileDialog(None, "Import which file?")
117
path = result.paths[0]
118
os.chdir(os.path.dirname(path))
120
bmp = graphic.Bitmap(self.filename)
121
#self.components.bufOff.drawBitmap(bmp, (0, 0))
122
self.win3.components.bufOff.drawBitmap(bmp, (0, 0))
124
def on_menuFileOpen_select(self, event):
127
def on_menuFileSaveAs_select(self, event):
128
if self.filename is None:
132
path, filename = os.path.split(self.filename)
133
result = dialog.saveFileDialog(None, "Save As", path, filename)
135
path = result.paths[0]
136
fileType = graphic.bitmapType(path)
139
#bmp = self.components.bufOff.getBitmap()
140
bmp = self.win3.components.bufOff.getBitmap()
141
bmp.SaveFile(path, fileType)
148
def on_menuEditCopy_select(self, event):
149
#clipboard.setClipboard(self.components.bufOff.getBitmap())
150
clipboard.setClipboard(self.win3.components.bufOff.getBitmap())
152
def on_menuEditPaste_select(self, event):
153
bmp = clipboard.getClipboard()
154
if isinstance(bmp, wx.Bitmap):
155
#self.components.bufOff.drawBitmap(bmp)
156
self.win3.components.bufOff.drawBitmap(bmp)
158
def on_editClear_command(self, event):
159
#self.components.bufOff.clear()
160
self.win3.components.bufOff.clear()
163
if __name__ == '__main__':
164
app = model.Application(TestSplitter)