CS-260
E N D
Presentation Transcript
CS-260 Event Driven Programming Dick Steflik
What is it? • Program execution is determined by user or sensor generated events rather than the old linear (begining to end) execution of command line programs. • Execution is non-linear
Embedded Systems • Interrupts – these are usually sensor generated asynchronous real-world events. • Usually handled by an ISS (Interrupt Servicing Subroutine) that gains control via a hardware controlled vector (automatic hardware branch). • Ex. A microcontroller based humidifier that has a low water interrupt that automatically puts the device into a non-damaging state when it runs out of water and displays a low water message.
Event Handling • The IBM Series 1 (circa 1980s) process control computer was one of the first event driven computers, it responded to external sensor generated events and was used to control industrial processes. • Programmed via EDL (Event Driven Language). • For each possible event a handler was provided, a typical program would initialize the environment then enter a do forever loop. When an event occurred, program control would transfer from the loop to the appropriate handler, execute the handler then return to the loop.
GUI Event Processing • With the advent of the personal computer and the modern day Graphical User Interface the model used for Event Processing in process control applications was extended to the GUI. • Initialize the environmentregister the event generatorsloop forever (wait for an event) • when an even occurs, put it into the event queue • the dispatcher will examine the next event in the queue and invoke the correct handler
Initializing the Environment • Mask off all events (don’t allow events) • Register all of the widgets that create events • what they are, where they are, names • Register the event handlers • bind the various events to their handlers • Unmask the events (allow them to happen.
Event Queues • most systems enqueue events before dispatching • a queue may be a simple fifo but more likely a priority queue, that way some events can be dispatched before others
GUI Events • Keyboard Events • Mouse Events • Screen Events (touch screens) • Pen Events
Cross Platform GUI Toolkits • Tcl/Tk – The Tk GUI toolkit • Tkinter: python wrappers for Tk; open source • GTK+ (Gimp Toolkit) • PyGTK : Python wrappers for the GTK+; open source • wxWidgets • wxPython: Python bindings for wxWidgets; open source • Qt • PyQt: Python bindings for Qt; PyQt is a licensed product (as is Qt)
Tkinter : Tk Interface • a Python binding to the Tk GUI toolkit • de-facto GUI standard for Python • written by Fredrik Lundh • Python wrapper around a Tcl interpreter embedded in the Python interpretor; this lets you mix Python and Tcl in the same program. • “themed Tk” - Tk widgets can be themed to look like the hosting OS.
Previous Slide • The previous slide shows the relationships on UNIX and LINUX systems where the toolkits are based on X11, remember X11 is a client-server display system where the app is an X-client and makes calls to xlib to send commands to an display things and uses an x-server to display them. This is very different than the way it is done on Windows
X11 Architecture Example deployment of X server: the X server receives input from a local keyboard and mouse and displays to a screen. A web browser and a terminal emulator run on the user's workstation and a software update application runs on a remote computer but is controlled and monitored from the user's machine