|
From: Kevin A. <ka...@us...> - 2004-09-16 16:11:44
|
Update of /cvsroot/pythoncard/PythonCard/samples/testNotebook In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1381 Modified Files: testNotebook.py testNotebook.rsrc.py Added Files: doodle.py doodle.rsrc.py Log Message: made sample resizeable and added doodle as a sizer test --- NEW FILE: doodle.py --- #!/usr/bin/python """ __version__ = "$Revision: 1.1 $" __date__ = "$Date: 2004/09/16 16:11:34 $" """ from PythonCard import clipboard, dialog, graphic, model import wx import os class Doodle(model.PageBackground): def on_initialize(self, event): self.x = 0 self.y = 0 self.filename = None sizer1 = wx.BoxSizer(wx.VERTICAL) comp = self.components flags = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.ALIGN_BOTTOM # Mac wxButton needs 7 pixels on bottom and right macPadding = 7 sizer1.Add(comp.btnColor, 0, flags, macPadding) sizer1.Add(comp.bufOff, 1, wx.EXPAND) sizer1.Fit(self) sizer1.SetSizeHints(self) self.panel.SetSizer(sizer1) self.panel.SetAutoLayout(1) self.panel.Layout() def on_bufOff_mouseEnter(self, event): self.x, self.y = event.position def on_bufOff_mouseDown(self, event): self.x, self.y = event.position event.target.drawLine((self.x, self.y), (self.x + 1, self.y + 1)) def on_bufOff_mouseDrag(self, event): x, y = event.position event.target.drawLine((self.x, self.y), (x, y)) self.x = x self.y = y def on_btnColor_mouseClick(self, event): result = dialog.colorDialog(self) if result.accepted: self.components.bufOff.foregroundColor = result.color event.target.backgroundColor = result.color def openFile(self): result = dialog.openFileDialog(None, "Import which file?") if result.accepted: path = result.paths[0] os.chdir(os.path.dirname(path)) self.filename = path bmp = graphic.Bitmap(self.filename) self.components.bufOff.drawBitmap(bmp, (0, 0)) def on_menuFileOpen_select(self, event): self.openFile() def on_menuFileSaveAs_select(self, event): if self.filename is None: path = '' filename = '' else: path, filename = os.path.split(self.filename) result = dialog.saveFileDialog(None, "Save As", path, filename) if result.accepted: path = result.paths[0] fileType = graphic.bitmapType(path) print fileType, path try: bmp = self.components.bufOff.getBitmap() bmp.SaveFile(path, fileType) return 1 except: return 0 else: return 0 def on_menuEditCopy_select(self, event): clipboard.setClipboard(self.components.bufOff.getBitmap()) def on_menuEditPaste_select(self, event): bmp = clipboard.getClipboard() if isinstance(bmp, wx.Bitmap): self.components.bufOff.drawBitmap(bmp) def on_editClear_command(self, event): self.components.bufOff.clear() if __name__ == '__main__': app = model.Application(Doodle) app.MainLoop() --- NEW FILE: doodle.rsrc.py --- { 'application':{ 'type':'Application', 'name':'Doodle', 'backgrounds': [ { 'type':'Background', 'name':'bgDoodle', 'title':'Doodle PythonCard Application', 'size':( 310, 300 ), 'style':['resizeable'], 'menubar': { 'type':'MenuBar', 'menus': [ { 'type':'Menu', 'name':'menuFile', 'label':'&File', 'items': [ { 'type':'MenuItem', 'name':'menuFileOpen', 'label':'&Open...\tCtrl+O' }, { 'type':'MenuItem', 'name':'menuFileSaveAs', 'label':'Save &As...' }, { 'type':'MenuItem', 'name':'fileSep1', 'label':'-' }, { 'type':'MenuItem', 'name':'menuFileExit', 'label':'E&xit\tAlt+X', 'command':'exit' } ] }, { 'type':'Menu', 'name':'menuEdit', 'label':'&Edit', 'items': [ { 'type':'MenuItem', 'name':'menuEditCopy', 'label':'&Copy\tCtrl+C'}, { 'type':'MenuItem', 'name':'menuEditPaste', 'label':'&Paste\tCtrl+V'}, { 'type':'MenuItem', 'name':'editSep1', 'label':'-' }, { 'type':'MenuItem', 'name':'menuEditClear', 'label':'&Clear', 'command':'editClear'} ] } ] }, 'components': [ { 'type':'Button', 'name':'btnColor', 'position':(0, 0), 'label':'Color' }, { 'type':'BitmapCanvas', 'name':'bufOff', 'position':(0, 30), 'size':(300, 230) }, ] } ] } } Index: testNotebook.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/testNotebook/testNotebook.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** testNotebook.py 16 Sep 2004 04:42:30 -0000 1.5 --- testNotebook.py 16 Sep 2004 16:11:34 -0000 1.6 *************** *** 11,18 **** --- 11,26 ---- import minimal import widgets + import doodle class TestNotebook(model.Background): def on_initialize(self, event): + # KEA 2004-09-16 + # if we don't set a min size then the window is + # very small. this may not be the correct way to + # solve the problem... + self.components.notebook.SetMinSize(self.components.notebook.size) + self.singleItemExpandingSizerLayout() + panel = wx.Panel(self.components.notebook, -1) panel.text1 = wx.TextCtrl(panel, -1, 'Hello Notebook', (5, 5)) *************** *** 56,59 **** --- 64,84 ---- self.components.notebook.AddPage(win2, 'widgets', True) + win3 = model.childWindow(self.components.notebook, doodle.Doodle) + self.components.notebook.AddPage(win3, 'doodle', True) + page = self.components.notebook.getPage(3) + # it appears that since on_initialize hasn't run yet + # after adding the page, the sizer code in doodle + # in on_initialize hasn't been run so the page size + # below is what we want but after the sizer code runs it + # will be (300, 260) + # if the user resizes the window, the sizer works as expected + # but if the window hasn't been resized, then when you click + # on the doodle tab the page doesn't fill the whole window + # I don't know what the correct solution is yet, but this seems + # to work. i have to use a method with CallAfter + # so that's why we aren't just using the attribute + size = page.size + wx.CallAfter(page.SetSize, size) + print "number of pages:", self.components.notebook.getPageCount() print "last page text: %s\n" % \ Index: testNotebook.rsrc.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/testNotebook/testNotebook.rsrc.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** testNotebook.rsrc.py 14 Sep 2004 17:28:46 -0000 1.1 --- testNotebook.rsrc.py 16 Sep 2004 16:11:34 -0000 1.2 *************** *** 9,12 **** --- 9,13 ---- 'title':'Notebook Test', 'size':( 800, 600 ), + 'style':['resizeable'], 'menubar': |