[Wnd-commit] wnd/wnd/sample-guis gui_mdiframe.py,NONE,1.1 gui_propertysheet.py,NONE,1.1 _HelloWorld.
Status: Alpha
Brought to you by:
jurner
|
From: jürgen u. <cer...@us...> - 2005-07-23 19:31:33
|
Update of /cvsroot/wnd/wnd/wnd/sample-guis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31457 Modified Files: _HelloWorld.py gui_dobjview.py Added Files: gui_mdiframe.py gui_propertysheet.py Log Message: bit of this and a bit of that Index: gui_dobjview.py =================================================================== RCS file: /cvsroot/wnd/wnd/wnd/sample-guis/gui_dobjview.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** gui_dobjview.py 2 Jul 2005 09:20:38 -0000 1.1 --- gui_dobjview.py 23 Jul 2005 19:31:23 -0000 1.2 *************** *** 2,16 **** """simple DataObject viewer Displays information for either the DataObject currently on th eclipboard ! or for the DataObject dropped. """ import wnd - from wnd.controls.listview import Listview - from wnd.controls.menu import Menu from wnd.api import clipboard, msgbox from wnd.api.ole import dragdrop #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ! ## GUI class window(wnd.Window): --- 2,33 ---- """simple DataObject viewer Displays information for either the DataObject currently on th eclipboard ! or the DataObject dropped """ import wnd from wnd.api import clipboard, msgbox from wnd.api.ole import dragdrop + from wnd.controls.menu import Menu + from wnd.controls.listview import Listview #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ! ## menu IDs ! IDM_FILE = 1000 ! IDM_FILE_EXIT = 1001 ! ! idNext = IDM_FILE_EXIT + 1 ! ! IDM_CLIPBOARD = idNext ! IDM_CLIPBOARD_GET_DO = IDM_CLIPBOARD + 1 ! IDM_CLIPBOARD_CLEAR = IDM_CLIPBOARD + 2 ! ! idNext = IDM_CLIPBOARD_CLEAR + 1 ! ! IDM_VIEW = idNext ! IDM_VIEW_CLEAR = IDM_VIEW + 1 ! ! ! #********************************************************** ! #********************************************************** class window(wnd.Window): *************** *** 20,24 **** wnd.Window.__init__(self, 'wnd_dobjview', self.title, None, None, None, None, 'sysmenu', 'sizebox') ! # setup a listview self.lv = Listview(self, 0, 0, 0, 0, 'report', 'border', 'fullrowselect', 'showselalways', 'gridlines') self.lv.Column('get/set') --- 37,52 ---- wnd.Window.__init__(self, 'wnd_dobjview', self.title, None, None, None, None, 'sysmenu', 'sizebox') ! # setup menu ! self.menu= Menu() ! pop= self.menu.Popup('&File', IDM_FILE) ! pop.Item('E&xit', IDM_FILE_EXIT) ! pop= self.menu.Popup('&Clipboard', IDM_CLIPBOARD) ! pop.Item('&Get DataObject', IDM_CLIPBOARD_GET_DO) ! pop.Item('&Clear Clipboard', IDM_CLIPBOARD_CLEAR) ! pop= self.menu.Popup('&View', IDM_VIEW) ! pop.Item('&Clar View', IDM_VIEW_CLEAR) ! self.menu.Set(self) ! ! # setup listview self.lv = Listview(self, 0, 0, 0, 0, 'report', 'border', 'fullrowselect', 'showselalways', 'gridlines') self.lv.Column('get/set') *************** *** 28,51 **** self.lv.Column('index') ! # setup drag drop stuff self.drag= dragdrop.DragDrop(self.lv.Hwnd) self.drag.onMSG= self.on_dragdrop dragdrop.Register(self.lv.Hwnd, self.drag) - - # setup a menu - self.m= Menu() - p1= self.m.Popup('&File', 1000) - p1.Item('E&xit', 1001) - p2= self.m.Popup('&Clipboard', 2000) - p2.Item('&Get DataObject', 2001) - p2.Item('&Clear Clipboard', 2002) - p3= self.m.Popup('&View', 3000) - p3.Item('&Clar View', 3001) - self.m.Set(self) - ! ## helper method to print clipformats of a DataObject to the listview def lv_PrintDataObject(self, dataobject): def tmp_setdata(fmt, get=True): s= str(fmt).split('{') if get: --- 56,72 ---- self.lv.Column('index') ! # register listview as drop target self.drag= dragdrop.DragDrop(self.lv.Hwnd) self.drag.onMSG= self.on_dragdrop dragdrop.Register(self.lv.Hwnd, self.drag) ! ! # helper methods --------------------------------------------------------------------- ! def lv_PrintDataObject(self, dataobject): + ## helper method to print clipformats of a DataObject to the listview + def tmp_setdata(fmt, get=True): + # simply format the string representation of the clipboard format s= str(fmt).split('{') if get: *************** *** 75,108 **** def error(self, msg): msgbox.Msg(self.Hwnd, msg, 'DataObject viewer', 'ok', 'systemmodal') ! # menu message handler def menu_HandleMessage(self, hwnd, msg, wp, lp): ! if msg=="menu choice": ! if lp[0]==1001: self.Close() ! elif lp[0]==2001: try: self.lv_PrintDataObject(clipboard.GetDataObject()) except: ! self.error('error! \n failed to retrieve DataObject') ! elif lp[0]==2002: clipboard.Clear() ! elif lp[0]==3001: self.lv.Clear() ! ! # drag and drop message handler def on_dragdrop(self, hwnd, msg, wp, lp): ! if msg=="dragdrop": ! if wp=="drop": try: self.lv_PrintDataObject(lp[0]) except: ! self.error('error! \n failed to retrieve DataObject') ! return False ## reject DataObject ! ! # GUI message handler def onMSG(self, hwnd, msg, wp, lp): ! if msg=="size": self.lv.SetWindowPosAndSize(*lp) w= lp[2]/5 --- 96,139 ---- def error(self, msg): + # throws a messagebox + msgbox.Msg(self.Hwnd, msg, 'DataObject viewer', 'ok', 'systemmodal') ! # message handlers -------------------------------------------------------------- ! def menu_HandleMessage(self, hwnd, msg, wp, lp): ! # menu handler ! ! if msg=='menu choice': ! if lp[0]==IDM_FILE_EXIT: ! self.Close() ! elif lp[0]==IDM_CLIPBOARD_GET_DO: try: self.lv_PrintDataObject(clipboard.GetDataObject()) except: ! self.error("error! \n failed to retrieve DataObject") ! elif lp[0]==IDM_CLIPBOARD_CLEAR: ! clipboard.Clear() ! elif lp[0]==IDM_VIEW_CLEAR: ! self.lv.Clear() ! def on_dragdrop(self, hwnd, msg, wp, lp): ! # drag and drop handler ! ! if msg=='dragdrop': ! if wp=='drop': try: self.lv_PrintDataObject(lp[0]) except: ! self.error("error! \n failed to retrieve DataObject") ! return False ## reject drop anyway ! def onMSG(self, hwnd, msg, wp, lp): ! # GUI message handler ! ! if msg=='size': self.lv.SetWindowPosAndSize(*lp) w= lp[2]/5 *************** *** 113,125 **** self.lv.SetColumnWidth(4, w) ! elif msg in ("menu choice", "menu open", "menu popup"): self.menu_HandleMessage(hwnd, msg, wp, lp) ! elif msg=="destroy": try: dragdrop.Revoke(self.lv.Hwnd) except: pass ! #************************************ w = window() --- 144,157 ---- self.lv.SetColumnWidth(4, w) ! elif msg in ('menu choice', 'menu open', 'menu popup'): self.menu_HandleMessage(hwnd, msg, wp, lp) ! elif msg=='close': try: dragdrop.Revoke(self.lv.Hwnd) except: pass ! #********************************************************** ! #********************************************************** w = window() --- NEW FILE: gui_mdiframe.py --- """simple MDIFrame sample""" import wnd from wnd import gdi from wnd.controls.tab import Tab from wnd.controls.menu import Menu from wnd.controls.editbox import Editbox from wnd.controls.static import StaticHorz from wnd.controls.mdiframe import MDIFrame #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ## setup menu IDs, all IDs should be > MDIFrame.MIN_MENU_ID IDM_FILE = MDIFrame.MIN_MENU_ID + 1 IDM_FILE_NEW = IDM_FILE + 1 IDM_FILE_EXIT = IDM_FILE + 2 idNext = IDM_FILE_EXIT +1 IDM_WINDOW = idNext IDM_WINDOW_NEXT = IDM_WINDOW + 1 IDM_WINDOW_PREV = IDM_WINDOW + 2 IDM_WINDOW_TILEHORZ = IDM_WINDOW +3 IDM_WINDOW_TILEVERT = IDM_WINDOW + 4 IDM_WINDOW_CASCADE = IDM_WINDOW + 5 IDM_WINDOW_MINIMIZE = IDM_WINDOW + 6 IDM_WINDOW_RESTORE = IDM_WINDOW + 7 IDM_WINDOW_CLOSE = IDM_WINDOW + 8 IDM_WINDOW_ICONARANGE = IDM_WINDOW + 9 class MyWindow(MDIFrame): def __init__(self): self.n= 0 ## just a counter self.controls= {} ## hwnd MDI child --> associated control instance ## NOTE ## still a problem with ctypes. Cached controls ## leave pretty much garbage behind when destroyed ## and removed from the cache selftabH= 0 ## height of a tab button self.tabOffs= 0 ## vert offset inbetween buttons self.staticH= 0 ## calculate static divider height MDIFrame.__init__(self, 'MDI test', None, None, None, None, 'overlappedwindow') rc= self.GetClientRect() ## init menu self.mnu= Menu() popMdi= self.mnu.Popup('&File', IDM_FILE) popMdi.Item('&new MDI child', IDM_FILE_NEW) popMdi.Separator(0) popMdi.Item('&Exit', IDM_FILE_EXIT) pop= self.mnu.Popup('&Window', IDM_WINDOW) pop.Item('&Next', IDM_WINDOW_NEXT) pop.Item('&Previous', IDM_WINDOW_PREV) pop.Separator(0) pop.Item('Tile &Horizontally', IDM_WINDOW_TILEHORZ) pop.Item('Tile &Vertically', IDM_WINDOW_TILEVERT) pop.Item('&Cascade', IDM_WINDOW_CASCADE) pop.Separator(0) pop.Item('&Minimize All', IDM_WINDOW_MINIMIZE) pop.Item('&Restore All', IDM_WINDOW_RESTORE) pop.Item('&Close All', IDM_WINDOW_CLOSE) pop.Separator(0) pop.Item('&Arrange Icons', IDM_WINDOW_ICONARANGE) self.mnu.Set(self) ## static divider above the tab control self.st= StaticHorz(self, 0, 0, 100) self.staticH= self.st.GetWindowRect().ToSize()[3] ## setup tab control ## TODO: some cusromdrawing could help to make the buttons look better self.tab= Tab(self, 0, 0, 0, 0, 'buttons', 'flatseparators', 'fixedwidth', 'flatbuttons') self.tab.onMSG= self.on_tab self.tab.SetStyle('multiline') self.tabH, self.tabOffs= self.calculate_tab_metrics() self.tab.SetWindowSize(rc.right-rc.left, selftabH+1) ## setup MDIClient self.mdi= self.MDIClient(0, 0, 0, 0, 'clientedge', hMenu=popMdi.handle) self.mdi.onMSG= self.on_mdi ## all MDI client windows will be created dynamically from menu command ## helper methods ---------------------------------------------------------------- def calculate_tab_metrics(self): ## helper method ## calculates self.tabH and self.tabOffs ## required to adjust the tab control dynamically ## 1. !! the tab control has to fit exactly the parents with ## 3. calculate the tab button height ## 2. calculate the offset inbetween tab buttons ## ## TODO: ## - check if we have to readjust tab metrics on fontchanges ## n= len(self.tab) if n < 2: ## enshure at least two buttons are avaiable self.tab.Item('foo') if n==0: self.tab.Item('foo') ## calculate button size tabH= self.tab.GetItemRect(0).ToSize()[3] ## force tab to show multiple lines of tabs w, h= self.tab.GetWindowRect().ToSize()[2:] self.tab.SetWindowSize(0, 0) ## calculate the offset inbetween buttons rc1= self.tab.GetItemRect(0) rc2= self.tab.GetItemRect(1) if self.tab.GetRowCount()==1: ## fallback, not corect for 'flatbuttons' tabOffs= rc2.left-rc1.right else: tabOffs= rc2.top-rc1.bottom self.tab.SetWindowSize(w, h) if n < 2: self.tab.RemoveItem(1) if n==0: self.tab.RemoveItem(0) return tabH, tabOffs def size_controls(self, size= None): ## helper method ## handles resizing of controls if size==None: w, h= self.GetClientRect().ToSize()[2:] else: w, h= size[2:] ## adjust tab height to filt tab rowcount n= self.tab.GetRowCount() self.tab.SetWindowSize(w, (n*self.tabH) + (n*self.tabOffs)) tabW, tabH= self.tab.GetWindowRect().ToSize()[2:] self.DeferWindows( (self.st, None, None, w, self.staticH), (self.tab, 0, 0+self.staticH, w, tabH), (self.mdi, 0, 0+tabH+self.staticH, w, h-tabH-self.staticH) ) ## message handlers ---------------------------------------------------------------- def HandleMenuMsg(self, hwnd, msg, wp, lp): if msg=="menu choice": if lp[0]== IDM_FILE_NEW: ## create a new MDI child and place a simple editbox upon it n1= self.tab.GetRowCount() self.n += 1 w, h= self.mdi.GetClientRect().ToSize()[2:] ico= gdi.FileIcon('*.txt') mdi= self.mdi.NewChild('child-%s' % self.n, 0, 0, w/2, h/2, icon=ico) w, h= mdi.GetClientRect().ToSize()[2:] self.controls[mdi.Hwnd]= Editbox(mdi, 'sample text', 0, 0, w, h, 'autovscroll', 'autohscroll', 'wantreturn', 'vscroll', 'hscroll') ## adjust tab height to filt rowcount n2= self.tab.GetRowCount() if n1 != n2: self.size_controls() elif lp[0]==IDM_FILE_EXIT: self.Close() elif lp[0]==IDM_WINDOW_NEXT: self.mdi.ActivateNext() elif lp[0]==IDM_WINDOW_PREV: self.mdi.ActivatePrevious() elif lp[0]==IDM_WINDOW_TILEHORZ: self.mdi.Tile('horizontal') elif lp[0]==IDM_WINDOW_TILEVERT: self.mdi.Tile('verticalal') elif lp[0]==IDM_WINDOW_CASCADE: self.mdi.Cascade() elif lp[0]==IDM_WINDOW_MINIMIZE: for i in self.mdi: self.mdi.Minimize(i) elif lp[0]==IDM_WINDOW_RESTORE: for i in self.mdi: self.mdi.Restore(i) elif lp[0]==IDM_WINDOW_CLOSE: self.mdi.Clear() elif lp[0]==IDM_WINDOW_ICONARANGE: self.mdi.IconArrange() def on_tab(self, hwnd, msg, wp, lp): if msg=="selchanged": ## this is what happens when a tab is selected hwndMdi= self.tab.GetItemLparam(wp) if self.mdi.IsMinimized(hwndMdi): self.mdi.Restore(hwndMdi) self.mdi.Activate(hwndMdi) ## message handler of the MDI client window def on_mdi(self, hwnd, msg, wp, lp): if msg=="childsizing": ## control may not yet be available if 'size' is send in ## response to creating a MDI child if wp in self.controls: mdi= self.mdi.GetChild(wp) w, h= mdi.GetClientRect().ToSize()[2:] ctl= self.controls[wp] ctl.SetWindowSize(w, h) elif msg=="childcreated": ## create a tab for the MDI child ctl= self.mdi.GetChild(wp) self.tab.Item(ctl.GetText(), lp=wp) elif msg=="childdestroyed": ## remove tab ++ control from the cache i= self.tab.FindLparam(wp) if i != None: n1= self.tab.GetRowCount() self.tab.RemoveItem(i) self.controls[wp].Close() del self.controls[wp] ## collect garbage. See notes import gc gc.collect() ## adjust tab height to filt rowcount n2= self.tab.GetRowCount() if n1 != n2: self.size_controls() elif msg=="childactivated": ## select the associated tab i= self.tab.FindLparam(wp) if i != None: self.tab.Select(i) ## message handler of the MDI frame window def onMSG(self, hwnd, msg, wp, lp): if msg=="size": self.size_controls(lp) elif msg in ('menu open', 'menu popup', 'menu choice'): self.HandleMenuMsg(hwnd, msg, wp, lp) elif msg=="open": pass if msg=="close": pass #************************************************************* #************************************************************** w = MyWindow() w.Run() #wnd.Debug('leaks') ## hopefully None --- NEW FILE: gui_propertysheet.py --- """property sheet and witzard sample, bit lame currently Quite civilized in comparison to the tons of aource code piling up behind the scenes""" import gc import wnd from wnd import gdi from wnd.wintypes import BYTE from wnd.controls import dialog from wnd.controls import propertysheet from wnd.controls import button #********************************************************************* # dummy dialogs for property sheet and wizard #********************************************************************* ## DialogFromTemplate is more flexible when it comes to font sizes class dlg1(dialog.Dialog): def __init__(self, propsheet): self.propsheet= propsheet dialog.Dialog.__init__(self, 'dialog-1', 0, 0,propertysheet.PROP_MED_CXDLG, propertysheet.PROP_MED_CYDLG) def onINIT(self, hwnd, msg, wp, lp): self.bt= button.Button(self, 'Test', 20, 20, 60, 50) class dlg2(dialog.Dialog): def __init__(self, propsheet): self.propsheet= propsheet dialog.Dialog.__init__(self, 'dialog-2', 0, 0, propertysheet.PROP_MED_CXDLG, propertysheet.PROP_MED_CYDLG) def onINIT(self, hwnd, msg, wp, lp): self.bt= button.Button(self, 'Test-1', 40, 20, 60, 50) self.bt2= button.Button(self, 'Test-2', 120, 20, 60, 50) self.bt.onMSG=self.on_bt def on_bt(self, hwnd, msg, wp, lp): if msg=='command': self.propsheet.QuerySiblings(1, 222) pass def onMSG(self, hwnd, msg, wp, lp): #print self.Hwnd pass #********************************************************************* # property sheet #********************************************************************* class _property_sheet(propertysheet.PropertySheet): def __init__(self): propertysheet.PropertySheet.__init__(self, 'foo', None, 'proptitle', 'hashelp', startPage=0) self.d1= dlg1(self) self.d2= dlg2(self) self.Page(self.d1) self.Page(self.d2) def onMSG(self, hwnd, msg, wp, lp): if msg=='destroy': ## have to run a full collect here gc.collect() prop= _property_sheet() #********************************************************************* # wizard dialog #********************************************************************* class _wizard(propertysheet.PropertySheet): def __init__(self): ## dummmy bitmap for the header background pat= (BYTE*1)(0xFF) self.bm= gdi.BitmapFromBytes(1, 1, 1, 1, pat) propertysheet.PropertySheet.__init__(self, 'my wizard', None, 'wizard97', startPage=0, bmpWatermark=self.bm) self.d1= dlg1(self) self.d2= dlg2(self) self.Page(self.d1, title='wizard page 1', headerTitle='Header Title 1', headerSubTitle='Some usefull text here as subtitle') self.Page(self.d2, title='wizard page 2', headerTitle='Header Title 2', headerSubTitle='Some usefull text here as subtitle on the second page') def onMSG(self, hwnd, msg, wp, lp): if msg=='setactive': if wp==self.d1.Hwnd: pass self.SetWizardButtons('next') elif wp==self.d2.Hwnd: pass self.SetFinishText('finish') elif msg=='destroy': ## have to run a full collect here gc.collect() wizard= _wizard() #********************************************************************* # main window #********************************************************************* class window(wnd.Window): def __init__(self): wnd.Window.__init__(self, 'propsheet sample', 'Prpertysheet Sample', None, None, None, None, 'sysmenu', 'sizebox', 'dialoglike') self.bt= button.Button(self, 'prop sheet...', 40, 20, 120, 50, 'tabstop') self.bt2= button.Button(self, 'wizard...', 40, 90, 120, 50, 'tabstop') self.bt.onMSG= self.bt2.onMSG= self.on_bt def on_bt(self, hwnd, msg, wp, lp): if msg=='command': if hwnd== self.bt.Hwnd: try: r=prop.Run() except: pass elif hwnd==self.bt2.Hwnd: try: r= wizard.Run() except: pass def onMSG(self, hwnd, msg, wp, lp): pass w= window() w.Run() #wnd.Debug('leaks') Index: _HelloWorld.py =================================================================== RCS file: /cvsroot/wnd/wnd/wnd/sample-guis/_HelloWorld.py,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** _HelloWorld.py 29 Apr 2005 15:24:58 -0000 1.1.1.1 --- _HelloWorld.py 23 Jul 2005 19:31:23 -0000 1.2 *************** *** 6,10 **** class MyWindow(wnd.Window): def __init__(self): ! wnd.Window.__init__(self, 'hello World', 'Hello World', 50, 50, 180, 100, 'sysmenu') self.button1=Button(self, 'Hello', 20, 20, 60, 30) --- 6,10 ---- class MyWindow(wnd.Window): def __init__(self): ! wnd.Window.__init__(self, 'hello World', 'Hello World!', 50, 50, 180, 100, 'sysmenu') self.button1=Button(self, 'Hello', 20, 20, 60, 30) |