Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.

Slides:



Advertisements
Similar presentations
First Steps with Qt Julien Finet Kitware Inc. Jan. 05 th 2010.
Advertisements

Lecture 4: Embedded Application Framework Qt Tutorial Cheng-Liang (Paul) Hsieh ECE 424 Embedded Systems Design.
QT GUI Programming CS340 – Software Design © 2009 – Jason Leigh University of Illinois at Chicago.
QT – Introduction C++ GUI Programming with Qt 4 Blanchette and Summerfield, Ch. 1 Miller, 2004.
The Web Warrior Guide to Web Design Technologies
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
A Simple Motif Widget The basic steps involved in creating and displaying this or any other Motif widget are essentially the same. This is a shell widget.
L8: Qt4 Concept Qt Module QObject QObject Model Signal and Slot Qt Event Loop.
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
Qt Igor November 8, 2002 Friday’s HENP Group Meeting.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Blanchette and Summerfield, Ch. 2
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
FLTK Tutorial.
INTRODUCTION TO ANDROID. Slide 2 Application Components An Android application is made of up one or more of the following components Activities We will.
FLTK Help Session By Richard Yu Gu CS 638 -Graphics Fall, 1999.
C H A P T E R T E N Event-Driven Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Object Oriented Software Development 9. Creating Graphical User Interfaces.
Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like.
Dale Roberts GUI Programming using Java - Event Handling Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Dale Roberts GUI Programming using Java - Introduction Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 13 : Swing I King Fahd University of Petroleum & Minerals College of Computer Science.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Python Programming Graphical User Interfaces Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 15: GUIs 1.
Lection №5 Modern integrated development environment.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Applications Development
Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
Build-A-Button Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, October 8, 2003.
-1- National Alliance for Medical Image Computing First Steps with Qt Julien Finet Kitware Inc. Jan. 05 th 2010.
Comp 248 Introduction to Programming Chapter 4 & 5 Defining Classes Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Object Oriented Programming.  Interface  Event Handling.
Introduction to visual programming C#. Learning Outcomes In this chapter, you will learn about :  Event-Based Programming  The Event Based Model  Application.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
QT Programming QT Programming Ruku Roychowdhury. Background QT is a cross platform application framework. Widely used to develop GUI applications. Originally.
Framework for Interactive Applications Matthew Korchinsky Advisor: Aaron Cass Senior Project – Computer Engineering – 2006 Abstract The Java language was.
July Doxygen A Code Documentation System Doxygen generates documentation directly from the structure and comments in the code –Browsable HTML documentation.
GUIs Basic Concepts. GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components.
QT – Introduction C++ GUI Programming with Qt 4
Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 14 Event-Driven Programming with Graphical User Interfaces.
Dale Roberts Programming with Qt Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science,
12-Jun-16 Event loops. 2 Programming in prehistoric times Earliest programs were all “batch” processing There was no interaction with the user Input Output.
Lesson 1 – Getting Started with App Inventor
July FLTK The Fast Light Toolkit • A C++ graphical user interface toolkit • Can be used under X, Windows, MacOS • Supports OpenGL • Provides: – Interactive.
1 Visual Basic: An Object Oriented Approach 7 – The User interface.
1. 2 Qt Toolkit ● C++ toolkit for cross-platform GUI application development – GUI functions (GUI = graphical user interface) – Data access components,
Java FX: Scene Builder.
Mobile Application Development with MeeGo™ - Touch Apps & UI Design
GUI Programming using Java - Key Events
HCI/CHI: Computer-Human Interaction
Event Driven Programming Dick Steflik
QT graphical user interface framework
Chapter 2: GUI API Chapter 2.
Fundamentals of Python: From First Programs Through Data Structures
Event Driven Programming
User Interface Software Look under the hood
GTK + Programming.
Event loops 17-Jan-19.
Tonga Institute of Higher Education
Presentation transcript:

Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School of Science, IUPUI

Dale Roberts Event-driven Programming Event-driven programming is the standard approach to creating graphical user interfaces (GUIs) An event-driven program is object-oriented Object-oriented programming was originally developed to implement graphical objects within GUI operating systems Although object-oriented, flow-of-control is sufficiently different that we are going to classify it as a different paradigm that extends OOP. However, top-level control is expressed differently The user is the top-level loop Think of Word, or a game program Every action in your program is a reaction to the user Decompose program in terms of “what will I do if the user does…” User inaction may trigger background actions (e.g. games)

Dale Roberts Detecting Asynchronous Events Polling Repeatedly read input devices in an infinite loop Interrupt-driven Hardware-triggered context-switching in response to user- events Event-driven Explicit event waiting Invokes functions in response to user events Note that function invocations are asynchronous Qt uses event-driven processing.

Dale Roberts Method #1 Polling Interaction is governed by a simple loop: Loop forever: { read input respond to input } What limitations does this have? Does it have any advantages?

Dale Roberts Method #2 Interrupt-driven Processing Enable device, then proceed with “background” processing until an interrupt is received, at which point Save state (context-switch) Respond to input Restore state and go to step #2. What advantages/disadvantages does this have?

Dale Roberts Method #3: Event-driven Processing Interaction is once again governed by a loop: Loop forever: { if (event) then respond else do (one unit of) background processing or go to sleep (for one unit) }

Dale Roberts Events / Messages / Signals Any event-driven graphics package has devices that can signal events In old standards, this was limited to hardware devices In newer packages (e.g. Qt), any widget can signal events; the (hardware) mouse is the same as a (software) slider or button. Generally, the event tells you Which device/widget signaled the event Some “measure” giving the new state E.g., whether a mouse button was depressed or released Warning: old systems tend to use the term “events” while newer systems may call them messages or signals

Dale Roberts Event handlers Event handlers are functions invoked in response to an event. Predominant approach is through the use of “call-back” functions. Functions are registered with the event Signature of function most conform with language standard for the event

Dale Roberts Pick Correlation Events are originally detected by the operating system, and then routed to application through “Pick Correlation”. The application may continue to your the event to one of its children widgets. The principle is to encapsulate the event by routing it to the lowest level object. (10, 20) (40, 80) (600, 700) “click” Coordinates are relative to (0,0) in the upper-left corner of desktop/windows/widget.. (0, 0)

Dale Roberts Call-back function: Motif quit = XtVaCreateManagedWidget(……); tAddCallback( quit, XmNactivateCallback, QuitCallback, NULL); void QuitCallback( Widget w, XtPointer, clientData, XtPointer callData);

Dale Roberts Call-back function: Java btnJava.addActionListener(this); btnWishJava.addActionListener(this); btnNoJava.addActionListener(this); public void actionPerformed(ActionEvent e) { Object source = e.getSource(); lblInstructionLabel.setText("Got it!"); if (btnJava.equals(source)) lblFeedback.setText("Yes"); else if (btnWishJava.equals(source)) lblFeedback.setText("No"); else if (btnNoJava.equals(source)) lblFeedback.setText("Maybe so"); }//end action performed

Dale Roberts Event Handling QT's new approach: signals and slots A widget sends out various signals Object methods can be declared as slots Compatible signals and slots can be connected or plugged together like a telephone switchboard (parameter types must match) Strict separation This strict separation between UI components and program elements lends itself to component-based programming Goal: separate UI from program logic

Dale Roberts Signals and Slots All that is required to connect signals and slots is that the signatures match. Developers may use predefined or user- defined member functions as signals and slots. clicked_method ()

Dale Roberts Making Connections in Qt #include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QPushButton *button = new QPushButton("Quit", 0); QObject::connect(button, SIGNAL(clicked()), &app, SLOT(quit())); app.setMainWidget(button); button->show(); return app.exec(); } Note that the connect function is a static member function of QOBJECT. How do you know? quit.exe (requires qt-mtnc321.dll)qt-mtnc321.dll

Dale Roberts qmake The qmake utility is typically invoked with the following three commands] qmake –project qmake make (or nmake under Windows) Rules: Be sure to place code in its own directory. qmake scans all subdirectories for dependencies. Do not place archive version under a “save” subdirectory. If you reorganize your files, like adding a new.h, delete all the.pro and other working files, then start over.

Dale Roberts Making Connections with Qt 1. #include 1. #include 2. #include 2. #include 3. #include 3. #include 4. #include 4. #include 5. int main(int argc, char *argv[]) 6. { 7. QApplication app(argc, argv); 8. QHBox *hbox = new QHBox(0); 9. hbox->setCaption("Enter Your Age"); 10. hbox->setMargin(6); 11. hbox->setSpacing(6); 12. QSpinBox *spinBox = new QSpinBox(hbox); 13. QSlider *slider = new QSlider(Qt::Horizontal, hbox); 14. spinBox->setRange(0, 130); 15. slider->setRange(0, 130); 16. QObject::connect(spinBox, SIGNAL(valueChanged(int)), 17. slider, SLOT(setValue(int))); 18. QObject::connect(slider, SIGNAL(valueChanged(int)), 19. spinBox, SLOT(setValue(int))); 20. spinBox->setValue(35); 21. app.setMainWidget(hbox); 22. hbox->show(); 23. return app.exec(); 24. } Lines 1 – 4: You must include header files for each Qt object referenced in this file. Line 5 - 7: Declaring argc and argv and passing it through to the QApplication constructor is standard procedure. This allows all Qt programs to specificy the presentation style on the command line. Examples are age –style=windows, age –style=motif, and age –style=cde. Lines 8 – 11: Declare a Layout Manager. QHBox automatically arranged controls horizontally from left to right. Layout managers are used to alleviate the need for programmers to calculate actual coordinates for each control in the window. setCaption set the Title Bar. setMargin controls spacing around and in between child widgets. Lines 12 – 13: Create a spin box and slider with QHBox as the parent. Lines 14 – 15: Set the valid range for the spin box and the slider. Lines 16 – 19: Ensure that the spin box and slider are sychronized. Changing one always changes the other. Line 20 – Sets the initial value of the spin box to 35. Note that this causes the spin box to emit a valueChanged(int) signal, which is connected to slider’s setValue(int) slot. The slider will emit a valueChanged(int) signal, which is connected to the spin box’s setValue(int) slot. Since the value is already 35, the spin box does not emit another valueChanged(int) signal and avoids and infinite recursion loop. Lines 21 – 23: Sets the main widget to the hbox, makes the hbox visible, and starts the window’s main event loop. age.exe (requires qt-mtnc321.dll)qt-mtnc321.dll

Dale Roberts Widget Styles Qt supports dynamic widget styles because of it’s GUI emulation approach. age –style=windows age –style=motif age –style=cde age –style=platinum The Windows XP and Mac styles are platform specific because they rely on the platform’s theme engine. Enabled via argc and argv.

Dale Roberts Acknowledgements Some of the slides were originally written by J. Ross Beveridge, updated by Dale Roberts. Code examples are from Blanchette, Jasmin and Summerfield, Mark. C++ GUI Programming With Qt3.