~toolpart/+junk/pythoncard

« back to all changes in this revision

Viewing changes to samples/testSplitter/testSplitter.py

  • Committer: Bazaar Package Importer
  • Author(s): Mohammed Adnène Trojette
  • Date: 2006-11-12 17:52:13 UTC
  • mfrom: (2.1.5 feisty)
  • Revision ID: james.westby@ubuntu.com-20061112175213-tv8bnl6rtpa2qw1o
Tags: 0.8.1-8.1
* Non-maintainer upload.
* Fix path to findfiles, codeEditor and resourceEditor:
   + patch from Ernest ter Kuile <ernestjw@xs4all.nl>. (Closes: #397018)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
"""
 
4
__version__ = "$Revision: 1.1 $"
 
5
__date__ = "$Date: 2004/09/28 21:23:55 $"
 
6
"""
 
7
 
 
8
from PythonCard import clipboard, dialog, graphic, model
 
9
import wx
 
10
import os
 
11
import minimal
 
12
import doodle
 
13
 
 
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,
 
19
                            -1, 
 
20
                            size=size,
 
21
                            name=name)
 
22
                            
 
23
        self.panel = wx.Panel(self, -1, 
 
24
            style=wx.TAB_TRAVERSAL | wx.NO_FULL_REPAINT_ON_RESIZE)
 
25
        
 
26
        self.field1 = wx.TextCtrl(self, -1, 'Hello World')
 
27
 
 
28
        self._sizer = wx.BoxSizer(wx.VERTICAL)
 
29
        self._sizer.Add(self.panel, True, wx.EXPAND)
 
30
        self._sizer.Fit(self)
 
31
        self._sizer.SetSizeHints(self)
 
32
        self.SetSizer(self._sizer)
 
33
        self.Layout()
 
34
 
 
35
class TestSplitter(model.SplitterBackground):
 
36
 
 
37
    def on_initialize(self, event):
 
38
        # the splitter code is adapted from the wxPython demo Main.py
 
39
        
 
40
        # I was having to do RemoveChild with Background
 
41
        # but SplitterBackground seems okay
 
42
##        self.RemoveChild(self.panel)
 
43
##        self.panel = None
 
44
 
 
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
 
49
 
 
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)
 
58
 
 
59
        self.win1 = win1
 
60
        self.win2 = win2
 
61
        self.win3 = win3
 
62
       
 
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)
 
67
 
 
68
        splitter.SetMinimumPaneSize(20)
 
69
        splitter2.SetMinimumPaneSize(20)
 
70
        self.size = (600, 400)
 
71
 
 
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)
 
77
            evt.Skip()
 
78
 
 
79
        #splitter2.Bind(wx.EVT_SIZE, SplitterOnSize)
 
80
 
 
81
 
 
82
 
 
83
    """
 
84
    Doodle methods
 
85
    
 
86
    MAJOR UNRESOLVED ISSUES
 
87
    
 
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
 
95
 
 
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
 
99
    
 
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.
 
106
    
 
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.
 
110
    """
 
111
    
 
112
    def openFile(self):
 
113
        win = self.findFocus()
 
114
        print win
 
115
        result = dialog.openFileDialog(None, "Import which file?")
 
116
        if result.accepted:
 
117
            path = result.paths[0]
 
118
            os.chdir(os.path.dirname(path))
 
119
            self.filename = path
 
120
            bmp = graphic.Bitmap(self.filename)
 
121
            #self.components.bufOff.drawBitmap(bmp, (0, 0))
 
122
            self.win3.components.bufOff.drawBitmap(bmp, (0, 0))
 
123
 
 
124
    def on_menuFileOpen_select(self, event):
 
125
        self.openFile()
 
126
 
 
127
    def on_menuFileSaveAs_select(self, event):
 
128
        if self.filename is None:
 
129
            path = ''
 
130
            filename = ''
 
131
        else:
 
132
            path, filename = os.path.split(self.filename)
 
133
        result = dialog.saveFileDialog(None, "Save As", path, filename)
 
134
        if result.accepted:
 
135
            path = result.paths[0]
 
136
            fileType = graphic.bitmapType(path)
 
137
            print fileType, path
 
138
            try:
 
139
                #bmp = self.components.bufOff.getBitmap()
 
140
                bmp = self.win3.components.bufOff.getBitmap()
 
141
                bmp.SaveFile(path, fileType)
 
142
                return 1
 
143
            except:
 
144
                return 0
 
145
        else:
 
146
            return 0
 
147
 
 
148
    def on_menuEditCopy_select(self, event):
 
149
        #clipboard.setClipboard(self.components.bufOff.getBitmap())
 
150
        clipboard.setClipboard(self.win3.components.bufOff.getBitmap())
 
151
 
 
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)
 
157
 
 
158
    def on_editClear_command(self, event):
 
159
        #self.components.bufOff.clear()
 
160
        self.win3.components.bufOff.clear()
 
161
 
 
162
 
 
163
if __name__ == '__main__':
 
164
    app = model.Application(TestSplitter)
 
165
    app.MainLoop()