overview questions
play

Overview/Questions Creating a GUI application which uses multiple - PDF document

CS108 Lecture 31: Graphical User Interface: Multiple Window GUIs Aaron Stevens 17 April 2009 1 Overview/Questions Creating a GUI application which uses multiple windows working together. Developing a parent/child relationship


  1. CS108 Lecture 31: Graphical User Interface: Multiple Window GUIs Aaron Stevens 17 April 2009 1 Overview/Questions – Creating a GUI application which uses multiple windows working together. – Developing a parent/child relationship between windows. – Sending data between windows. 2 1

  2. Main Concepts Multiple GUI windows in an application are arranged in a hierarchy: – A main window launches when the application starts. – A child window is launched by another window. – A window can have any number of child windows. – A child window can also have other child windows (an endless hierarchy) 3 Main Concepts Each GUI window is a resource created by Layout Editor ( .rsrc.py ), and each has its own code file (.py ). IMPORTANT: By default, PythonCard uses a class name of Background. However, with multiple GUIs, each one needs its own class name. 4 2

  3. Modal vs. non-Modal Recall that a modal window is a non- optional window, which must be deal with before returning to the main window. To create a modal window, the class for the child window must be changed to inherit from model.CustomDialog instead of model.Backgroud . 5 Working Example We will continue/expand our counter/click button example from last week, and make it work in multiple windows. – class Counter (the main window) – class Display (the child window) 6 3

  4. Creating the Child Window Once the GUIs are developed, the main window’s class will launch the child window. – The main window’s code must import the appropriate module which contains the child window. – Create child window(s) in the on_initialize event handler. – Use the PythonCard function model.childWindow(self,<child-class>) to create the child window. 7 Creating the Child Window Example: creating a child window whose class is called Display : class Counter(model.Background): def on_initialize(self, event): self.displayWindow = model.childWindow(self, display.Display) Notice: the child window is saved into a member variable called self.displayWindow . 8 4

  5. How to Talk to your Child Each window is an object, an instance of its class definition. Communication between objects happens by setting variables and calling methods. The main window can talk to its child window by using the variable it set up at the time the child window was created, e.g.: self.displayWindow.<some-action-here> 9 Eres tu mi mamá? It will be handy to have a way for the child window to communicate with its parent window. This method call (in the child’s on_initialize event) set up a variable called self.parent : def on_initialize(self, event): # hold a reference to parent object: self.parent = self.getParent() 10 5

  6. Setting Visibility By default, any window created is visible. This can be changed using the visible property on the window’s object: # hide it: self.displayWindow.visible = False # show it: self.displayWindow.visible = True 11 Start Up Visibility By default, any window created is visible at startup. To turn this off, look for a property in Layout Editor under the Edit / BackgroundInfo menu called “Visible at Startup”. 12 6

  7. Take-Away Points – Multiple windows in one GUI application are organized in a parent-child relationship. – Parent window creates the child window. – The windows communicate as objects, making method calls and setting data to each other using object reference variables. 13 Student To-Dos – MONDAY 4/20 is a holiday -- no class  Class next week on WED, THU, FRI – HW13 due TUESDAY 4/21 – QUIZ 6 on FRIDAY 4/24  GUI, PythonCard, Dialogs, Selection Widgets, etc. – Final HW due THURSDAY 4/30 @ Noon  bonus if you’re done/can show it to me MON 4/27  we’ll spend a lot of next week working on the project, bring your questions! 14 7

Recommend


More recommend