programming - electronic visualization laboratory · wxwidgets • wxwidgets lets developers create...
TRANSCRIPT
ProgrammingCS422
1
FLTK: Fast Light Toolkit
• http://www.fltk.org
• FLTK is a cross-platform C++ GUI toolkit for UNIX®/Linux® (X11), Microsoft® Windows®, and MacOS® X
• FLTK provides modern GUI functionality without the bloat and supports 3D graphics via OpenGL® and its built-in GLUT emulation.
• FLTK is designed to be small and modular enough to be statically linked, but works fine as a shared library.
• FLTK also includes an UI builder called FLUID that can be used to create applications
2
FLTK
3
Program#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
int main(int argc, char **argv) {
Fl_Window *window = new Fl_Window(300,180);
Fl_Box *box = new Fl_Box(20,40,260,100,"Hello, World!");
box->box(FL_UP_BOX);
box->labelsize(36);
box->labelfont(FL_BOLD+FL_ITALIC);
box->labeltype(FL_SHADOW_LABEL);
window->end();
window->show(argc, argv);
return Fl::run();
}
4
CXXFLAGS=`fltk-config --cxxflags`LDLIBS=`fltk-config --ldflags`
Swing
• Java language
• JFC is short for Java Foundation Classes, which encompass a group of features for building graphical user interfaces (GUIs) and adding rich graphics functionality and interactivity to Java applications. It is defined as containing the features shown in the table below
• Swing GUI, Look-and-Feel, Accessibility API, Java 2D API, Drag-and-Drop Support, Internationalization, ...
5
Swing
6
import javax.swing.*;
public class HelloWorldSwing {
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
JFrame frame = new JFrame("HelloWorldSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add the ubiquitous "Hello World" label.
JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
} });
} }
Run: javac SwingApplication.java java SwingApplication
wxWidgets
• wxWidgets lets developers create applications for Win32, Mac OS X, GTK+, X11, Motif, WinCE, and more using one codebase
• It can be used from languages such as C++, Python, Perl, and C#/.NET
• wxWidgets applications look and feel native. This is because wxWidgets uses the platform's own native controls rather than emulating them
• It's also extensive, free, open-source, and matures
• http://wxwidgets.org/
7
C++
8
#include "wx/wx.h"
class MyApp: public wxApp{ virtual bool OnInit();};
class MyFrame: public wxFrame{public: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
void OnQuit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event);
DECLARE_EVENT_TABLE()};
enum{ ID_Quit = 1, ID_About,};
BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(ID_Quit, MyFrame::OnQuit) EVT_MENU(ID_About, MyFrame::OnAbout)END_EVENT_TABLE()
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit(){ MyFrame *frame = new MyFrame( "Hello World", ...); frame->Show(TRUE); SetTopWindow(frame); return TRUE;}
MyFrame::MyFrame(const wxString& title, ...){ wxMenu *menuFile = new wxMenu; menuFile->Append( ID_About, "&About..." ); menuFile->AppendSeparator(); menuFile->Append( ID_Quit, "E&xit" ); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append( menuFile, "&File" ); SetMenuBar( menuBar ); CreateStatusBar(); SetStatusText( "Welcome to wxWindows!" );}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)){ Close(TRUE);}
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)){ wxMessageBox("This is a wxWindows Hello world sample", "About Hello World", wxOK | wxICON_INFORMATION, this);}
C++
• CXXFLAGS=`wx-config --cxxflags`
• LDFLAGS=`wx-config --libs`
9
Python
10
import wx
ID_ABOUT = 101ID_EXIT = 102
class MyFrame(wx.Frame): def __init__(self, parent, ID, title): wx.Frame.__init__(self, parent, ID, title, wx.DefaultPosition, wx.Size(200, 150)) self.CreateStatusBar() self.SetStatusText("This is the statusbar")
menu = wx.Menu() menu.Append(ID_ABOUT, "&About", "More information about this program") menu.AppendSeparator() menu.Append(ID_EXIT, "E&xit",
"Terminate the program")
menuBar = wx.MenuBar() menuBar.Append(menu, "&File");
self.SetMenuBar(menuBar)
class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, -1, "Hello from wxPython") frame.Show(True) self.SetTopWindow(frame) return True
app = MyApp
Run:python app.py
Qt
• Qt sets the standard for high-performance, cross-platform application development
• It includes a C++ class library and tools for cross-platform development and internationalization
• Native looks
• Open Source and commercial licenses
• Linux, Mac, Win, embedded OS, ...
• http://www.trolltech.com/products/qt/
11
Applications
• K Desktop Environment
• Photoshop Elements
• Google Earth
12
Qt• Compile
• pkg-config --libs qt-mt
• pkg-config --cflags qt-mt
13
#include <qapplication.h>#include <qpushbutton.h>
int main( int argc, char **argv ){ QApplication a( argc, argv );
QPushButton hello( "Hello world!", 0 ); hello.resize( 100, 30 );
a.setMainWidget( &hello ); hello.show(); return a.exec();}