Lecture 3. GUI Programming part 1: GTK

Similar documents
Creating GNOME Applications with Glade. Part I: Introduction

Lesson 2: GTK+ Basics

Programming with Clutter. Murray Cumming

C Libraries. Using GLib. Ph. D. Eng. Lucjan Miękina upel.agh.edu.pl/wimir/login/ Department of Robotics and Mechatronics 1/31

Open source MySQL Browser for Open Innovation

The FFI Reference Manual

OO for GUI Design (contd.) Questions:

Maemo Diablo Reference Manual for maemo 4.1. Application Development

Lecture 2. Software Development on Linux Platforms (Cygwin( Cygwin,, etc.) INTRODUCTION TO DESIGN AUTOMATION. Guoyong Shi, PhD

COMP 2400 UNIX Tools

UNIVERSITÀ DEGLI STUDI DI MILANO Facoltà di Scienze Matematiche, Fisiche e Naturali Dipartimento di Scienze della Terra ALLEGATI ALLA TESI DI LAUREA

C SCI The X Window System Stewart Weiss

EE495K Slides by Avi Kak: OO for GUI Design (contd.)

t GTK+ Object # widget, [ W< z< sl. y Widget E / Xlib E 8 Csq ;, #,., $ Gtk widget object GWuS vv q. A o. # widget x C widget # X L. B #, D #( *), " #

Gjs/GTK+ 3 Tutorial Documentation

Container Widgets and Packing

COMP s1 Lecture 1

Automatically generated type-safe GTK+ binding for Dylan

PRINCIPLES OF OPERATING SYSTEMS

Course organization. Course introduction ( Week 1)

Cake: a tool for adaptation of object code

Chapter 11 Introduction to Programming in C

Martin Brunner, Jonas Pfoh Sept. 6, Sept. 24, 2010

Linux system programming - About this course

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

Object-Oriented Programming

Slide Set 9. for ENCM 335 in Fall Steve Norman, PhD, PEng

Chapter 11 Introduction to Programming in C

Exercise Session 2 Systems Programming and Computer Architecture

Chapter 11 Introduction to Programming in C

High Performance Computing MPI and C-Language Seminars 2009

Introduction: Before start doing any code, there is some terms that one should be familiar with:

Maemo Diablo Source code for the LibOSSO RPC examples Training Material

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

CMPT 300. Operating Systems. Brief Intro to UNIX and C

Introduction to C. CS2023 Winter 2004

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

15213 Recitation Section C

Software Development With Emacs: The Edit-Compile-Debug Cycle

Chapter 11 Introduction to Programming in C

OpenGL Introduction Computer Graphics and Visualization

HomeScope : an open microscope with an XY stage

Chapter 11 Introduction to Programming in C

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Recitation 2/18/2012

C Introduction. Comparison w/ Java, Memory Model, and Pointers

Armide Documentation. Release Kyle Mayes

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

CSE 333 Lecture 6 - data structures

What's new in GTK+ 2.6

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3

Fundamentals of Programming Session 12

CSE 303: Concepts and Tools for Software Development

Slide Set 3. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Final CSE 131B Spring 2004

Chapter 11 Introduction to Programming in C

Topics Introduction to Microprocessors

CSCI-243 Exam 2 Review February 22, 2015 Presented by the RIT Computer Science Community

INFORMATION SOCIETY TECHNOLOGIES (IST) PROGRAMME. Project IST MoWGLI. Report n. D4.a MathML Rendering/Browsing Engine

CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014)

Deep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems

CpSc 1111 Lab 4 Formatting and Flow Control

GStreamer for Tiny Devices Olivier Crête

Creating a Shell or Command Interperter Program CSCI411 Lab

Introduction to Lablgtk (from its internals) Adrien Nader - OCaml Users in PariS 1/34

ENCM 339 Fall 2017 Tutorial for Week 8

CSE 374 Programming Concepts & Tools

Reviewing gcc, make, gdb, and Linux Editors 1

Programming the DMCC in C

Debugging Techniques. CEFET Engineering Week

Intermediate Programming, Spring 2017*

Abstract Data Types. Lecture 05 Summary. Abstract Data Types Structures in C 1/26/2009. Slides by Mark Hancock (adapted from notes by Craig Schock)

Slide Set 3. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

CSE 333 SECTION 3. POSIX I/O Functions

SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar)

G52CPP C++ Programming Lecture 3. Dr Jason Atkin

CS61C : Machine Structures

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Lecture 10 Topics in Configuration Managements

Last lecture. 1. Problems facing SE

WebKit and Blink: Bridging the Gap Between the Kernel and the HTML5 Revolution. Juan J. Sánchez LinuxCon Japan 2014, Tokyo

CSE 333 Lecture 5 - data structures & modules

Algorithms, Data Structures, and Problem Solving

C / C++ Coding Rules

Two s Complement Review. Two s Complement Review. Agenda. Agenda 6/21/2011

ENCM 335 Fall 2018 Tutorial for Week 13

Lecture 2 outline. Lecture 2 outline. B16 Software Engineering Structured Programming Lecture 2: Control flow, variables, procedures, and modules

Dynamic Memory Allocation and Command-line Arguments

Announcements OpenGL. Computer Graphics. Spring CS4815

Scientific Visualization A Programming Guide using Fltk and Visual Studio

Programming in C - Part 2

Installing and Using Dev-C++

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

FUNCTIONS POINTERS. Pointers. Functions

CPS109 Lab 1. i. To become familiar with the Ryerson Computer Science laboratory environment.

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

CS240: Programming in C

Number review... Lecture 3 Introduction to the C Programming Language (pt 1) Has there been an update to ANSI C?

Programming in C week 1 meeting Tiina Niklander

Transcription:

INTRODUCTION TO DESIGN AUTOMATION Lecture 3. GUI Programming part 1: GTK Guoyong Shi, PhD shiguoyong@ic.sjtu.edu.cn School of Microelectronics Shanghai Jiao Tong University Fall 2010 2010-9-15 Slide 1

Outline Introduce basic GUI programming in Gtk. Learn the concept of widget, event and signal, and callback, etc. Learn to create menu, open file, edit text, and display figures, etc. slide 2

GTK vs Qt GTK is a toolkit for C programming. Also possible for C++, but requiring programming skills. Qt is mainly for C++ programming. slide 3

Make a Simple Window (1) gui_drill01.c #include <stdio.h> #include <gtk/gtk.h> (for GTK lib) int main( int argc, char *argv[] ) { int win_w0 = 400, win_h0 = 300; /* initial window size */ slide 4

Make a Simple Window (2) gtk_init (&argc, &argv); /* initialized GTK */ /* Create an initial window */ GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_set_size_request (GTK_WIDGET (window), \ win_w0, win_h0); gtk_window_set_title (GTK_WINDOW (window), "GUI-DRILL01"); g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL); close window height width slide 5

vbox for holding a menu /* Make a vbox to hold a menu-bar and other gui layouts. */ GtkWidget *vbox = gtk_vbox_new (FALSE, 0); /* <gboolean homogeneous = FALSE>; controls whether each object in the box * has the same size */ gtk_container_add (GTK_CONTAINER (window), vbox); gtk_widget_show (vbox); vbox slide 6

Make a menu bar /* Create a menu-bar for showing all menu titles. */ GtkWidget *menu_bar = gtk_menu_bar_new (); gtk_box_pack_start (GTK_BOX (vbox), menu_bar, FALSE, FALSE, 2); gtk_widget_show (menu_bar); GtkWidget *menu = gtk_menu_new (); put the menu_bar in vbox vbox slide 7

Make the 1 st menu item /* (1) Create the 1st menu-item with a name. */ GtkWidget *menu_item = gtk_menu_item_new_with_label("open File..."); /* (1) Append the entry to the menu. */ gtk_menu_shell_append (GTK_MENU_SHELL(menu), menu_item); /* (1) Define callback for each menu entry. */ g_signal_connect_swapped (G_OBJECT(menu_item), "activate", G_CALLBACK(menuitem_response), (gpointer) g_strdup("open File...") ); /* (1) Show the 1st menu item. */ gtk_widget_show (menu_item); callback function message passed to callback slide 8

Make the 2 nd menu item /* (2) Create the 2nd menu-item with a name. */ menu_item = gtk_menu_item_new_with_label("save"); /* (2) Append the entry to the menu. */ gtk_menu_shell_append (GTK_MENU_SHELL(menu), menu_item); /* (2) Define callback for each menu entry. */ g_signal_connect_swapped (G_OBJECT(menu_item), "activate", G_CALLBACK(menuitem_response), (gpointer) g_strdup("save") ); /* (2) Show the 2nd menu item. */ gtk_widget_show (menu_item); slide 9

Hook up the menu /* Define the menu label */ GtkWidget *menu_head = gtk_menu_item_new_with_label ("File"); gtk_widget_show (menu_head); /* Hook up the "menu-items" to the "menu_head" */ gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_head), menu); /* Append the menu title to the menu_bar. */ gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), menu_head); /* Show the window */ gtk_widget_show (window); gtk_main (); /* enter the gtk display loop until the window is destroyed */ return 0; } /* END OF THE MAIN CODE */ slide 10

The callback function static void menuitem_response( gchar *string ) { printf ("%s\n", string); } slide 11

The final window The GTK window generated * Your SPICE simulator should have a window for functionalities and displaying. slide 12

Use makefile CC = gcc PROGRAM = gui_drill01 all: $(PROGRAM) $(PROGRAM): $(PROGRAM).c $(CC) $< -o $@ \ `pkg-config gtk+-2.0 --cflags --libs` (needed for linking to the GTK libraries) Important: Learn to write makefile for compiling your project and for multiple-task programming. slide 13

Choose a file to open... The Choose file widget provided by Gtk. slide 14

A scribble window You can program to do handdrawing. You also can program to display coordinates and simulation waveforms. slide 15

How to make a command window? GTK does not provide a widget for use as a command window. User can type in text and do text editing in the command window. You can use the text widget to program a command window. slide 16

Command Window A command window is not purely a text editor. You need a command parser to recognize the commands. Programming a text widget into a simple command window is not hard (exercise). Programming a sophisticated command window (like the one in MATLAB) requires great programming skills: symbol table; parser; grammar; etc. slide 17

Summary Introduced 5 programming drills in this lecture: 1. A simple window with a simple menu. 2. A simple window with a menu system. 3. A window with two menu items working: one for opening a text file, the other for popping up a drawing window. 4. Modify 3 so that multiple text files can be opened in tabs. 5. Create a simple command window (but command line not parsed). slide 18

References GTK+ Reference Manual GTK+ 2.0 Tutorial GDK Reference Manual GIMP Drawing Kit (APIs for drawing and windowing) All available online slide 19

Programming Kickoff How to write professional programs? Divide your project into modules Learn multiple-file programming Compile using makefile After exercising Gtk/Qt for a while, every team must decide on using one GUI toolkit. slide 20

Assignment 1 This assignment contains the following parts: Learn GTK and run some examples. Write a simple GUI window containing 1. a menu system; 2. a text editor; 3. a drawing popup window; 4. a simple command window. (see the requirements next...) slide 21

Requirement 1 On the menu system: The following menu system is for your reference. Make your menu system easily modifiable. Your menu system always changes as your project proceeds. So you should not hard-code your menu; rather, think about clever programming to make the menu change easy. File Edit Tools Simulate Window Help Open Netlist... Save Save As... Exit Delete Undelete Copy Floorplan Placement Route Extraction Spice Digital Mixed-Signal New Window Arrange All Cascade Help & Support About... Contact Developer slide 22

Requirement 2 Add the following two functions to your menu 1. Open a text file editor 2. Pop up a window for hand drawing You can use the GTK examples in the GTK package you download. Understand the examples and put the separated code together in one GUI program. slide 23

Assignment Due The rule for due through out the course is: Submit your finished assignment (including code and documents) to Moodle in one week after the lecture is finished. Your turn-in must include: A text report describing the programming details; Your source code must be well-commented; Must have a makefile. Don t use any automatically generated makefile. slide 24