From: Kevin A. <ka...@us...> - 2005-12-25 12:56:31
|
Update of /cvsroot/pythoncard/PythonCard/docs/html In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19091 Modified Files: walkthrough3.html Log Message: changed code blocks to use <pre> Index: walkthrough3.html =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/docs/html/walkthrough3.html,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** walkthrough3.html 18 Sep 2004 16:55:59 -0000 1.8 --- walkthrough3.html 25 Dec 2005 12:56:23 -0000 1.9 *************** *** 49,53 **** <h2>model.Background</h2> <p>This is the standard class definition for a PythonCard app:</p> ! <p class="code"> class Minimal(model.Background):</p> <p>One of the most important concepts when dealing with child windows in PythonCard is the background. The background is unique to PythonCard and it --- 49,55 ---- <h2>model.Background</h2> <p>This is the standard class definition for a PythonCard app:</p> ! <pre> ! class Minimal(model.Background): ! </pre> <p>One of the most important concepts when dealing with child windows in PythonCard is the background. The background is unique to PythonCard and it *************** *** 110,115 **** current background.</p> <p>In addition to the standard imports for Counter, we'll import minimal:</p> ! <p class="code">from PythonCard import model<br /> ! import minimal</p> <p>Next we'll add an event handler to be executed when the Counter application is started. This handler acts something like autoexec.bat on a PC or .login --- 112,119 ---- current background.</p> <p>In addition to the standard imports for Counter, we'll import minimal:</p> ! <pre> ! from PythonCard import model ! import minimal ! </pre> <p>Next we'll add an event handler to be executed when the Counter application is started. This handler acts something like autoexec.bat on a PC or .login *************** *** 119,126 **** applications.) Here is the class declaration of our Counter application with on_initialize added:</p> ! <p class="code">class Counter(model.Background):<br /> ! def on_initialize(self, event):</p> <p>and here is the code that we will add to the on_initialize method:</p> ! <p class="code"> self.minimalWindow = model.childWindow(self, minimal.Minimal)</p> <p>We create a minimal window object uisng the <span class="code">childWindow </span> function and give it the name minimalWindow by passing two parameters --- 123,134 ---- applications.) Here is the class declaration of our Counter application with on_initialize added:</p> ! <pre> ! class Counter(model.Background): ! def on_initialize(self, event): ! </pre> <p>and here is the code that we will add to the on_initialize method:</p> ! <pre> ! self.minimalWindow = model.childWindow(self, minimal.Minimal) ! </pre> <p>We create a minimal window object uisng the <span class="code">childWindow </span> function and give it the name minimalWindow by passing two parameters *************** *** 132,139 **** <p>Continuing in the on_initialize handler, we make calls to set the position and visibility of the new window:</p> ! <p class="code"> ! # override resource position<br /> ! self.minimalWindow.position = (200, 5)<br /> ! self.minimalWindow.visible = True</p> <p>We now have a window that is an attribute of our main background, just like any of the menus or buttons that are already a part of Counter.</p> --- 140,148 ---- <p>Continuing in the on_initialize handler, we make calls to set the position and visibility of the new window:</p> ! <pre> ! # override resource position ! self.minimalWindow.position = (200, 5) ! self.minimalWindow.visible = True ! </pre> <p>We now have a window that is an attribute of our main background, just like any of the menus or buttons that are already a part of Counter.</p> *************** *** 143,158 **** window minimalWindow, we simply add one more call to update the control in that window as well (the new lines are in bold type):</p> ! <p class="code"> ! def on_incrBtn_mouseClick(self, event):<br /> ! startValue = int(self.components.field1.text)<br /> ! endValue = startValue + 1<br /> ! self.components.field1.text = str(endValue)<br /> ! <strong>self.minimalWindow.components.field1.text = str(endValue)</strong><br /> ! <br /> ! def on_decrBtn_mouseClick(self, event):<br /> ! startValue = int(self.components.field1.text)<br /> ! endValue = startValue - 1<br /> ! self.components.field1.text = str(endValue)<br /> ! <strong>self.minimalWindow.components.field1.text = str(endValue)</strong></p> <p>Notice that we reference components in the child window by a collection of objects starting with the main application (self) and then pointing first to --- 152,168 ---- window minimalWindow, we simply add one more call to update the control in that window as well (the new lines are in bold type):</p> ! <pre> ! def on_incrBtn_mouseClick(self, event): ! startValue = int(self.components.field1.text) ! endValue = startValue + 1 ! self.components.field1.text = str(endValue) ! <strong>self.minimalWindow.components.field1.text = str(endValue)</strong> ! ! def on_decrBtn_mouseClick(self, event): ! startValue = int(self.components.field1.text) ! endValue = startValue - 1 ! self.components.field1.text = str(endValue) ! <strong>self.minimalWindow.components.field1.text = str(endValue)</strong> ! </pre> <p>Notice that we reference components in the child window by a collection of objects starting with the main application (self) and then pointing first to *************** *** 174,183 **** added to the minimal application above. Add the following code to minimal.py</p> ! <p class="code"> ! def on_initialize(self, event):<br /> ! self.parent = self.getParent()<br /> ! <br /> ! def on_btnReset_mouseClick(self, event): ! self.parent.components.field1.text = "0"</p> <p>When our child window it initialized, it calls getParent() to get a reference to its parent window, and then stores that reference. We place the --- 184,194 ---- added to the minimal application above. Add the following code to minimal.py</p> ! <pre> ! def on_initialize(self, event): ! self.parent = self.getParent() ! ! def on_btnReset_mouseClick(self, event): ! self.parent.components.field1.text = "0" ! </pre> <p>When our child window it initialized, it calls getParent() to get a reference to its parent window, and then stores that reference. We place the *************** *** 208,221 **** function that sets the counter's field1 to an arbitrary value just to confirm the connection between the two windows visibly:</p> ! <p class="code"> ! def doExit(self):<br /> ! self.parent.components.field1.text = "99"<br /> ! <br /> ! def on_close(self, event):<br /> ! self.doExit()<br /> ! self.visible = False<br /> ! <br /> ! def on_menuFileExit_select(self, event):<br /> ! self.close() </p> <p>As the above code shows, the File->Exit menu item just calls the close() to close the window. That is the same as clicking the --- 219,233 ---- function that sets the counter's field1 to an arbitrary value just to confirm the connection between the two windows visibly:</p> ! <pre> ! def doExit(self): ! self.parent.components.field1.text = "99" ! ! def on_close(self, event): ! self.doExit() ! self.visible = False ! ! def on_menuFileExit_select(self, event): ! self.close() ! </pre> <p>As the above code shows, the File->Exit menu item just calls the close() to close the window. That is the same as clicking the *************** *** 223,227 **** is called. We placed the work to be done when the document is closing in the doExit method. In this case it just sets the counter field in the parent to ! "99".</p> <p>In addition, in doExit() you could modify some properties of the parent window to keep track of the state of your child window. For example, assuming --- 235,239 ---- is called. We placed the work to be done when the document is closing in the doExit method. In this case it just sets the counter field in the parent to ! "99".</p> <p>In addition, in doExit() you could modify some properties of the parent window to keep track of the state of your child window. For example, assuming *************** *** 229,234 **** could use doExit() to check or uncheck the 'View Minimal Window' menu item on the parent. The code would look something like this:</p> ! <p class="code"> ! self.parent.menuBar.setChecked('menuViewMinimalWindow', False)</p> <?php include "footer.php" ?> <p>$Revision$ : $Author$ : Last update $Date$</p> --- 241,247 ---- could use doExit() to check or uncheck the 'View Minimal Window' menu item on the parent. The code would look something like this:</p> ! <pre> ! self.parent.menuBar.setChecked('menuViewMinimalWindow', False) ! </pre> <?php include "footer.php" ?> <p>$Revision$ : $Author$ : Last update $Date$</p> |