Fedora Linux Support Community & Resources Center
  #1  
Old 8th July 2012, 10:59 PM
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 5,685
linuxfedorafirefox
Programming challenge: Create a GUI window

I got this idea from this thread about how to create graphical applications in Linux. I think it could be a lot of fun to see how many ways this can be done!

So for consistency the requirements for the GUI window are based on what was done in that thread, namely:
  1. The window's size should be 400x150.
  2. The window should contain a text label that is centered horizontally and near the top of the window, saying "Welcome!" (without the quotes). The text should be colored white and size 32pt. If 32pt is not possible, then make the size as close to 32pt as you can.
  3. The window should contain a button that is centered horizontally and near the bottom of the window, with the word "OK" (without the quotes) on the button. The button should close the window and kill the application when clicked.
  4. The background of the window and label should be DarkSlateBlue (RGB: 72,61,139; HEX: #483D8B).
  5. The window should have a title of the form "<toolkit> Window Example" (without the quotes). For instance: PyQt Window Example
An example of what the window should (roughly) look like is shown at the bottom of this post.

I propose the following structure for how to post the code:
  1. State the programming language/GUI toolkit being used (e.g. PyQt, Perl/Tk). Some toolkits have multiple language bindings, so in that case be clear on which underlying language is being used, so that we don't get duplicates. For example, GTK+ has C and C++ bindings , so those would not be duplicates.
  2. Give the code listing. Enclose the code between [code]...[/code] tags so it's easier to read.
  3. (Optional) State any special instructions on how to compile or run the code. For scripting languages this isn't necessary; it's more useful for compiled languages.
  4. Show a screenshot of the window. You can use "Manage Attachments" under "Additional Options" for this.
It was interesting and educational for me to see the different ways that other people came up with in the other thread. So far we have the following entries:
  1. Tcl/Tk: http://forums.fedoraforum.org/showpo...94&postcount=4
  2. Perl/Tk: http://forums.fedoraforum.org/showpo...68&postcount=5
  3. Python/Tkinter: http://forums.fedoraforum.org/showpo...93&postcount=6
  4. Ruby/Tk: http://forums.fedoraforum.org/showpo...31&postcount=8
  5. PyQt: http://forums.fedoraforum.org/showpo...9&postcount=11
  6. Java Swing: http://forums.fedoraforum.org/showpo...0&postcount=12
  7. XForms (uses C): http://forums.fedoraforum.org/showpo...6&postcount=14
  8. GNUstep (uses Objective-C): http://forums.fedoraforum.org/showpo...3&postcount=16
If the people who wrote those want to repost them here, that's fine with me. I'm curious to see how to do this with other GUI toolkits that I've never coded in (e.g. GTK+, plain Qt with C++, FLTK) or, even better, some obscure toolkit I've never heard of. Let's have some fun with this! And no, text-based interfaces like ncurses or S-Lang don't count!

So to add to the above entries, here is a version using Motif, based on the C language. For this, I prefer to use OpenMotif instead of Lesstif (if anyone's curious I can explain why). It's in the RPMFusion non-free repo (yum install openmotif-devel).
Code:
#include <Xm/Xm.h>
#include <Xm/PushB.h>
#include <Xm/Label.h>
#include <Xm/BulletinB.h>
#include <stdlib.h>

void okCB(Widget w, XtPointer client_data, XtPointer call_data) {
   XmPushButtonCallbackStruct *cbs = (XmPushButtonCallbackStruct *) call_data;
   exit(0);
}

void main(int argc, char *argv[]) {
   XtAppContext app;
   XmStringCharSet char_set = XmSTRING_DEFAULT_CHARSET;
   Widget toplevel, bb, msg, ok;
   Display *display;
   Colormap cmap;
   XColor back, fore, spare;
   Arg al[6];
   int ac;
   XFontStruct *font = NULL;
   XmFontList fontlist = NULL;
   char *namestring = NULL;

   toplevel = XtAppInitialize(&app,"",NULL,0,&argc,argv,NULL,NULL,0);
   XtVaSetValues(toplevel,XmNtitle,"Motif Window Example",NULL);
   ac = 0;
   XtSetArg(al[ac],XmNwidth,400); ac++;
   XtSetArg(al[ac],XmNheight,150); ac++;
   XtSetValues(toplevel,al,ac);

   cmap = DefaultColormapOfScreen(XtScreen(toplevel));
   display = XtDisplay(toplevel);
   XAllocNamedColor(display,cmap,"dark slate blue",&back,&spare);
   XAllocNamedColor(display,cmap,"white",&fore,&spare);

   ac = 0;
   bb = XmCreateBulletinBoard(toplevel,"bb",al,ac);
   XtManageChild(bb);
   ac = 0;
   XtSetArg(al[ac],XmNbackground,back.pixel); ac++;
   XtSetArg(al[ac],XmNshadowThickness,0); ac++;
   XtSetValues(bb,al,ac);

   ac = 0;
   XtSetArg(al[ac],XmNlabelString,XmStringCreate("Welcome!",char_set)); ac++;
   msg = XmCreateLabel(bb,"label",al,ac);
   XtManageChild(msg);
   namestring = "*-lucida-medium-r-normal-sans-34-*";
   font = XLoadQueryFont(XtDisplay(msg),namestring);
   fontlist = XmFontListCreate(font,char_set);
   ac = 0;
   XtSetArg(al[ac],XmNx,120); ac++;
   XtSetArg(al[ac],XmNy,20); ac++;
   XtSetArg(al[ac],XmNbackground,back.pixel); ac++;
   XtSetArg(al[ac],XmNforeground,fore.pixel); ac++;
   XtSetArg(al[ac],XmNfontList,fontlist); ac++;
   XtSetValues(msg,al,ac);

   ac = 0;
   XtSetArg(al[ac],XmNlabelString,XmStringCreate(" OK ",char_set)); ac++;
   ok = XmCreatePushButton(bb,"button",al,ac);
   XtManageChild(ok);
   XtAddCallback(ok,XmNactivateCallback,okCB,NULL);
   ac = 0;
   XtSetArg(al[ac],XmNx,180); ac++;
   XtSetArg(al[ac],XmNy,110); ac++;
   XtSetValues(ok,al,ac);

   XtRealizeWidget(toplevel);
   XtAppMainLoop(app);
}
Save the above code in a file called mwindow.c, and compile like this:
Code:
$ gcc -o mwindow mwindow.c -lXm -lXt -lSM -lICE -lX11 -I/usr/include/openmotif -L/usr/lib64/openmotif
If you use Lesstif instead of OpenMotif, then you won't need the -I/usr/include/openmotif and -L/usr/lib64/openmotif parts.

Screenshot:
Attached Thumbnails
Click image for larger version

Name:	motifwindow.png
Views:	425
Size:	3.7 KB
ID:	23387  
__________________
OS: Fedora 20 x86_64 | Machine: HP Pavilion a6130n | CPU: AMD 64 X2 Dual-Core 5000+ 2.6GHz | RAM: 5GB PC5300 DDR2 | Disk: 400GB SATA | Video: ATI Radeon HD 4350 512MB | Sound: Realtek ALC888S | Ethernet: Realtek RTL8201N

Last edited by RupertPupkin; 14th July 2012 at 07:27 PM.
Reply With Quote
  #2  
Old 9th July 2012, 09:15 AM
ah7013 Offline
Registered "Cashew" User
 
Join Date: May 2010
Location: Adelaide, Australia
Age: 20
Posts: 671
linuxfirefox
Re: Programming challenge: Create a GUI window

Here is another Perl one from me. This one uses wxPerl (Perl + Wx) and requires the perl-Wx package (yum install perl-Wx). Have been learning about wxPerl so this is a good learning experience for me. Anyway here's the code:
Code:
#!/usr/bin/perl

use Wx;

use Wx::Event qw(EVT_BUTTON);

my $wxapp = Wx::SimpleApp->new;
my $mw = Wx::Frame->new(undef, -1, "wxPerl Window Example", [0, 0], [400, 150]);
$mw->CentreOnScreen(&Wx::wxBOTH);
my $backcolor = Wx::Colour->new('#483D8B');
my $textcolor = Wx::Colour->new('#FFFFFF');
my $sizer = Wx::BoxSizer->new(&Wx::wxVERTICAL);
my $panel = Wx::Panel->new($mw);
$panel->SetSizer($sizer);
$panel->SetBackgroundColour($backcolor);
my $font = Wx::Font->new(32);
my $msg = Wx::StaticText->new($panel, -1, "Welcome!");
$msg->SetFont($font);
$msg->SetForegroundColour($textcolor);
$sizer->AddSpacer(15);
$sizer->Add($msg, 0, &Wx::wxCENTER);
$sizer->AddSpacer(30);
my $ok = Wx::Button->new($panel, 1, "OK", [-1, -1], [50, 30]);
EVT_BUTTON($panel, 1, sub { $mw->Close(1) });
$sizer->Add($ok, 0, &Wx::wxCENTER);
$mw->Show;
$wxapp->MainLoop;
And here is the screenshot:
Attached Thumbnails
Click image for larger version

Name:	snapshot2.png
Views:	321
Size:	10.1 KB
ID:	23392  

Last edited by ah7013; 9th July 2012 at 09:20 AM.
Reply With Quote
  #3  
Old 9th July 2012, 08:08 PM
Pitfall Offline
Registered User
 
Join Date: Nov 2011
Location: the Netherlands
Posts: 67
linuxfirefox
Re: Programming challenge: Create a GUI window

Done. However, the button is a bit simple. But you get the idea.

Framework: Qt
Language: C++
Markup: QML
Tool: Qt Creator

QML is used for building the UI and handling the button event. The back is programmed in C++.

Code for the UI:
Code:
import QtQuick 1.0

Rectangle {
    width: 400
    height: 150
    color: "#483D8B"

    Text {
        text: "Welcome!"
        anchors.horizontalCenter: parent.horizontalCenter
        font.pointSize: 32
        color: "#FFFFFF"
    }

    Rectangle {
        id: btnOk
        SystemPalette { id: palette; colorGroup: SystemPalette.Active }
        width: 100
        height: 20
        color: palette.button
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 10
        anchors.horizontalCenter: parent.horizontalCenter

        signal clicked()
        onClicked: {
            Qt.quit()
        }

        Text {
            anchors.centerIn: parent
            text: "OK"
            color: palette.buttonText
        }

        MouseArea {
            anchors.fill: parent
            onClicked: btnOk.clicked()
        }
    }
}
Window:
Click image for larger version

Name:	fedoraScreen.png
Views:	228
Size:	11.7 KB
ID:	23394

Note that not everything is posted. The 'main.cpp', 'qmlapplicationviewer' and some other files are missing. The only thing I altered in the 'qmlapplicationviewer' is that the Window Title is set correctly.

If you want to test it: create a new Qt Quick project and replace your QML code with mine, or PM me and I will send you the full project.


We should have more challenges!
__________________
Desktop: i3 540, GT430, Fedora 17 x86_64 KDE
Netbook: E-450, HD 6230, Fedora 17 x86_64 KDE
Reply With Quote
  #4  
Old 9th July 2012, 09:23 PM
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 5,685
linuxfedorafirefox
Re: Programming challenge: Create a GUI window

@ah7013: Nice! I had forgotten all about wxWidgets. I like the rounded corners on the button.

@Pitfall: Finally some C++! I'll try out QT Creator, but I'd be interested in how to do all that in a single .cpp file.

I just remembered an old programming language called Icon, which has built-in graphics capabilities. You can get Icon here: http://www.cs.arizona.edu/icon/
So here's the Icon version:
Code:
#!/usr/local/bin/icon
link button
procedure main()
   local w
   w := WOpen("size=400,150","label=Icon Window Example","bg=darkslateblue","fg=white","font=serif,42")
   CenterString(200,40,"Welcome!")
   WAttrib("font=fixed","bg=gray","fg=black")
   button(w,"OK",quit,&null,180,110,40,20)
   evmux(w)
end
procedure quit()
   exit()
end
It can be run as a script; just change the first line to point to wherever the icon binary is installed.

Here's the screenshot:
Attached Thumbnails
Click image for larger version

Name:	iconwindow.png
Views:	279
Size:	3.6 KB
ID:	23395  
__________________
OS: Fedora 20 x86_64 | Machine: HP Pavilion a6130n | CPU: AMD 64 X2 Dual-Core 5000+ 2.6GHz | RAM: 5GB PC5300 DDR2 | Disk: 400GB SATA | Video: ATI Radeon HD 4350 512MB | Sound: Realtek ALC888S | Ethernet: Realtek RTL8201N

Last edited by RupertPupkin; 10th July 2012 at 03:50 AM. Reason: Misspelled capabilities :)
Reply With Quote
  #5  
Old 9th July 2012, 09:23 PM
beaker_ Offline
Registered User
 
Join Date: Nov 2008
Location: Canada
Posts: 2,398
linuxfirefox
Re: Programming challenge: Create a GUI window

What, no examples in Assembly? Wimps
Reply With Quote
  #6  
Old 10th July 2012, 12:15 AM
ah7013 Offline
Registered "Cashew" User
 
Join Date: May 2010
Location: Adelaide, Australia
Age: 20
Posts: 671
linuxfirefox
Re: Programming challenge: Create a GUI window

Quote:
Originally Posted by RupertPupkin View Post
@ah7013: Nice! I had forgotten all about wxWidgets. I like the rounded corners on the button.
Thanks!

Here is another one in Perl. This one uses the PRIMA GUI toolkit. I couldn't find a package for it on the repos so you will most likely have to it from the source on the website. Here is the code:
Code:
#!/usr/bin/perl

use Prima qw(Application Label Buttons);

my $mw = Prima::MainWindow->create(size => [400, 150], text => "Perl/Prima Window Example", backColor => 0x483D8B);
$mw->set(centered => 1);
my $msg = $mw->insert(Label => font => {size => 32}, text => "Welcome!", alignment => ta::Center, height => 45, pack => { pady => 30 }, color => 0xFFFFFF);
my $ok = $mw->insert(Button => text => "OK", alignment => ta::Center, width => 50, height => 25, pack => { pady => 50 }, onClick => sub { $mw->close() });
run Prima;
And the screenshot:
Attached Thumbnails
Click image for larger version

Name:	snapshot3.png
Views:	303
Size:	9.9 KB
ID:	23396  
Reply With Quote
  #7  
Old 10th July 2012, 10:09 PM
Pitfall Offline
Registered User
 
Join Date: Nov 2011
Location: the Netherlands
Posts: 67
linuxfirefox
Re: Programming challenge: Create a GUI window

Here is the one-file GUI.

Framework: Qt
Language: C++
Markup: none
Tool: Qt Creator

main.cpp
Code:
#include <QApplication>
#include <QWidget>
#include <QPalette>
#include <QLabel>
#include <QPushButton>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QWidget *window = new QWidget();

    QPalette windowPalette(a.palette());
    windowPalette.setColor(QPalette::Background, QColor::fromRgb(72, 61, 139));
    windowPalette.setColor(QPalette::WindowText, QColor::fromRgb(255, 255, 255));

    window->setAutoFillBackground(TRUE);
    window->setPalette(windowPalette);
    window->resize(400, 150);
    window->setWindowTitle("Qt Window Example");

    QLabel *lblWelcome = new QLabel(window);

    QFont font;
    font.setPointSize(32);

    lblWelcome->setFont(font);
    lblWelcome->setText("Welcome!");
    lblWelcome->adjustSize();
    lblWelcome->move(87, 0);

    QPushButton *btnOk = new QPushButton(window);
    btnOk->setText("OK");
    btnOk->resize(50, 30);
    btnOk->move(175, 120);
    btnOk->connect(btnOk, SIGNAL(clicked()), qApp, SLOT(quit()));

    window->show();

    return a.exec();
}
How to run (assuming that your working directory has the name 'foo'):
Code:
qmake-qt4 -project
qmake-qt4 foo.pro
make
./foo
Window:
Click image for larger version

Name:	fedoraScreen2.png
Views:	187
Size:	19.0 KB
ID:	23399

Note: you must have installed qt-devel in order to compile it.
__________________
Desktop: i3 540, GT430, Fedora 17 x86_64 KDE
Netbook: E-450, HD 6230, Fedora 17 x86_64 KDE

Last edited by Pitfall; 10th July 2012 at 10:11 PM.
Reply With Quote
  #8  
Old 11th July 2012, 08:42 AM
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 5,685
linuxfedorafirefox
Re: Programming challenge: Create a GUI window

@ah7013: Wow, I think you are now in the lead for Most Obscure GUI Toolkit! I never heard of PRIMA before. It has kind of an old-school SGI 4Dwm-ish look to it. Cool!

@Pitfall: Nice, I got your single-file Qt C++ example working!

I've been playing around with Haskell, and found out that it has GTK+ bindings. So I made a Haskell/GTK version of the app. To try it out you'll need to install the ghc-gtk-devel package from the Fedora repos:
Code:
yum install ghc-gtk-devel
Here's the code, save it in a file called hgtkwindow.hs:
Code:
import Graphics.UI.Gtk

main :: IO ()
main = do
   initGUI
   win <- windowNew
   vbox <- vBoxNew False 40
   set win [ windowTitle := "Haskell/GTK Example Window", containerBorderWidth := 15,
            containerChild := vbox, windowDefaultWidth := 400, windowDefaultHeight := 150 ]
   widgetModifyBg win StateNormal (Color 18504 15677 35723)
   msg <- labelNew (Just "Welcome!")
   msgFont <- fontDescriptionFromString "Sans 32"
   widgetModifyFont msg (Just msgFont)
   widgetModifyFg msg StateNormal (Color 65535 65535 65535)
   boxPackStart vbox msg PackNatural 0
   okBox <- hBoxNew False 0
   boxPackStart vbox okBox PackRepel 0
   ok <- buttonNewWithLabel "OK"
   boxPackStart okBox ok PackRepel 0
   onClicked ok mainQuit
   onDestroy win mainQuit
   widgetShowAll win
   mainGUI
Compile and run it like this:
Code:
ghc --make hgtkwindow.hs -o hgtkwindow
./hgtkwindow
Here's the screenshot:
Attached Thumbnails
Click image for larger version

Name:	hgtkwindow.png
Views:	250
Size:	8.4 KB
ID:	23400  
__________________
OS: Fedora 20 x86_64 | Machine: HP Pavilion a6130n | CPU: AMD 64 X2 Dual-Core 5000+ 2.6GHz | RAM: 5GB PC5300 DDR2 | Disk: 400GB SATA | Video: ATI Radeon HD 4350 512MB | Sound: Realtek ALC888S | Ethernet: Realtek RTL8201N
Reply With Quote
  #9  
Old 12th July 2012, 06:00 PM
cyborg Offline
Registered User
 
Join Date: Apr 2004
Location: Brackley, England
Age: 23
Posts: 203
linuxfirefox
Re: Programming challenge: Create a GUI window

A very quick attempt in Python (have to show its goodness). No formatting yet, but the foundation is there.

Code:
#!/bin/env python
import gtk

popUp = gtk.Dialog(title="PyGTK Window Example")
popUp.add_buttons(gtk.STOCK_OK, 1)

label = gtk.Label('Welcome!')
label.show()
popUp.vbox.pack_start(label)

popUp.run()
popUp.destroy()
__________________
[joe@host]

Last edited by cyborg; 12th July 2012 at 06:02 PM.
Reply With Quote
  #10  
Old 12th July 2012, 08:21 PM
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 5,685
linuxfedorafirefox
Re: Programming challenge: Create a GUI window

Quote:
Originally Posted by cyborg View Post
No formatting yet, but the foundation is there.
Many languages have convenience functions (such as the gtk.Dialog in your PyGTK example) that produce a ready-made dialog window with a message and exit button. That's fine for this challenge as long as you can change the formatting of that dialog to meet the requirements. A big part of this challenge is to provide a chance for others to see how that kind of stuff is done in different toolkits: e.g. how to use colors, how to set font characteristics, how to position widgets. I have an XView example (uses C) that I haven't posted yet because I can't get the colors working right.

There have been 2 Python examples so far (using PyQt and Tkinter -- see the links in the first post), but I'd like to see a full PyGTK example. So if you could expand your example to include the formatting that'd be great.
__________________
OS: Fedora 20 x86_64 | Machine: HP Pavilion a6130n | CPU: AMD 64 X2 Dual-Core 5000+ 2.6GHz | RAM: 5GB PC5300 DDR2 | Disk: 400GB SATA | Video: ATI Radeon HD 4350 512MB | Sound: Realtek ALC888S | Ethernet: Realtek RTL8201N
Reply With Quote
  #11  
Old 13th July 2012, 02:06 AM
ah7013 Offline
Registered "Cashew" User
 
Join Date: May 2010
Location: Adelaide, Australia
Age: 20
Posts: 671
linuxfirefox
Re: Programming challenge: Create a GUI window

Quote:
Originally Posted by RupertPupkin View Post
@ah7013: Wow, I think you are now in the lead for Most Obscure GUI Toolkit! I never heard of PRIMA before. It has kind of an old-school SGI 4Dwm-ish look to it. Cool!
Thanks!

I'm trying to do one in Perl+GTK at the moment but am having some issues with the text formatting. Once I get it all sorted out i'll post it.
Reply With Quote
  #12  
Old 13th July 2012, 04:22 AM
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 5,685
linuxfedorafirefox
Re: Programming challenge: Create a GUI window

I made a version using FOX, a C++-based toolkit. There's no Fedora package for FOX, so I compiled it from source (version 1.7.33). The libraries and headers were installed under /usr/local/lib and /usr/local/include/fox-1.7, respectively. I already have /usr/local/lib in my /etc/ld.so.conf.d/local.conf file, so I did this to make it easier to compile stuff:
Code:
ln -s /usr/local/include/fox-1.7 /usr/local/include/fox
ln -s /usr/local/lib/libFOX-1.7.so /usr/local/lib/libFOX.so
ldconfig
Here's the code (Foxwindow.cpp) for the example:
Code:
#include <fox/fx.h>

int main(int argc, char *argv[]) {
   FXApp application("Foxwindow", "FoxTest");
   application.init(argc, argv);
   FXMainWindow *main = new FXMainWindow(&application, "FOX Example Window", 
                                         NULL, NULL, DECOR_ALL, 0, 0, 400, 150);
   main->setBackColor(FXRGB(72,61,139));
   FXLabel *msg = new FXLabel(main, "Welcome!", NULL, LAYOUT_CENTER_X, 0, 0, 0, 0, 0, 0, 15, 40);
   msg->setBackColor(FXRGB(72,61,139));
   msg->setTextColor(FXRGB(255,255,255));
   FXFont *font = new FXFont(&application, "Sans,320");
   msg->setFont(font);
   FXButton *ok = new FXButton(main, "OK", NULL, &application, FXApp::ID_QUIT,
                               LAYOUT_CENTER_X|BUTTON_NORMAL, 0, 0, 0, 0, 10, 10, 5, 5);
   application.create();
   main->show(PLACEMENT_SCREEN);
   return application.run();
}
Here's how I compiled it:
Code:
g++ -o Foxwindow Foxwindow.cpp -I/usr/local/include -L/usr/local/lib -lFOX
Here's the screenshot:
Attached Thumbnails
Click image for larger version

Name:	foxwindow.png
Views:	213
Size:	7.6 KB
ID:	23418  
__________________
OS: Fedora 20 x86_64 | Machine: HP Pavilion a6130n | CPU: AMD 64 X2 Dual-Core 5000+ 2.6GHz | RAM: 5GB PC5300 DDR2 | Disk: 400GB SATA | Video: ATI Radeon HD 4350 512MB | Sound: Realtek ALC888S | Ethernet: Realtek RTL8201N
Reply With Quote
  #13  
Old 14th July 2012, 07:21 PM
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 5,685
linuxfedorafirefox
Re: Programming challenge: Create a GUI window

Here's another C++ entry, using the FLTK toolkit (yum install fltk-devel):
Code:
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Button.H>

void ok_cb(Fl_Widget* obj, void*) {
   exit(0);
}

int main(int argc, char *argv[]) {
   Fl_Window* win = new Fl_Window(400, 150, "FLTK Example Window");
   win->color(0x483D8B00);
   Fl_Box *msg = new Fl_Box(110, 20, 180, 50, "Welcome!");
   msg->labelsize(32);
   msg->labelcolor(FL_WHITE);
   Fl_Button* ok = new Fl_Button(180, 100, 40, 30, "OK");
   ok->callback(ok_cb);
   win->end();
   win->show(argc, argv);
   return Fl::run();
}
Save that in a file called fltkwindow.cpp and compile it like this:
Code:
g++ -o fltkwindow fltkwindow.cpp -lfltk
Here's the screenshot:
Attached Thumbnails
Click image for larger version

Name:	fltkwindow.png
Views:	237
Size:	6.8 KB
ID:	23429  
__________________
OS: Fedora 20 x86_64 | Machine: HP Pavilion a6130n | CPU: AMD 64 X2 Dual-Core 5000+ 2.6GHz | RAM: 5GB PC5300 DDR2 | Disk: 400GB SATA | Video: ATI Radeon HD 4350 512MB | Sound: Realtek ALC888S | Ethernet: Realtek RTL8201N
Reply With Quote
  #14  
Old 15th July 2012, 10:54 PM
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 5,685
linuxfedorafirefox
Re: Programming challenge: Create a GUI window

Here's another Qt version, this time using the Qt Jambi bindings for Java. Yes, you can write Java apps with a native Qt GUI!
Code:
import com.trolltech.qt.gui.*;
import com.trolltech.qt.core.*;

public class qtjambiwindow {
 public static void main(String[] args) {
   QApplication app = new QApplication(args);
   app.setStyleSheet("QMainWindow, QLabel { background-color: #483D8B; color: white }");
   QMainWindow win = new QMainWindow();
   win.setWindowTitle("QtJambi Example Window");
   win.resize(400, 150);
   QLabel msg = new QLabel("Welcome!", win);
   QFont font = new QFont();
   font.setPointSize(32);
   msg.setFont(font);
   msg.setGeometry(110, 20, 180, 50);
   msg.setAlignment(Qt.AlignmentFlag.AlignHCenter);
   QPushButton ok = new QPushButton("OK", win);
   ok.setStyle(new QCleanlooksStyle());
   ok.setGeometry(175, 100, 50, 30);
   ok.clicked.connect(app, "quit()");
   win.show();
   app.exec();
 }
}
Save that in a file called qtjambiwindow.java than compile it and run it like this:
Code:
javac qtjambiwindow.java
java  -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true qtjambiwindow
Here's the screenshot:
Attached Thumbnails
Click image for larger version

Name:	qtjambiwindow.png
Views:	233
Size:	4.1 KB
ID:	23433  
__________________
OS: Fedora 20 x86_64 | Machine: HP Pavilion a6130n | CPU: AMD 64 X2 Dual-Core 5000+ 2.6GHz | RAM: 5GB PC5300 DDR2 | Disk: 400GB SATA | Video: ATI Radeon HD 4350 512MB | Sound: Realtek ALC888S | Ethernet: Realtek RTL8201N
Reply With Quote
  #15  
Old 16th July 2012, 02:55 AM
ah7013 Offline
Registered "Cashew" User
 
Join Date: May 2010
Location: Adelaide, Australia
Age: 20
Posts: 671
linuxfirefox
Re: Programming challenge: Create a GUI window

Quote:
Originally Posted by ah7013 View Post
I'm trying to do one in Perl+GTK at the moment but am having some issues with the text formatting. Once I get it all sorted out i'll post it.
OK, finally sorted it all out . This one requires the perl-Gtk2 package and I think it may require the perl-Pango package too. Here's the code:
Code:
#!/usr/bin/perl
use Gtk2 '-init';
use Pango;

my $mw = Gtk2::Window->new;
$mw->set_title("Perl/Gtk2 Window Example");
$mw->signal_connect(destroy => sub { Gtk2->main_quit });
$mw->set_default_size(400, 150);
my $vbox = Gtk2::VBox->new;
$mw->add($vbox);
my $msg = Gtk2::Label->new("Welcome!");
my $font = Pango::FontDescription->from_string("Times New Roman 32");
$msg->modify_fg('normal', Gtk2::Gdk::Color->parse("#FFFFFF"));
$msg->modify_font($font);
$vbox->pack_start($msg, 1, 0, 0);
my $ok = Gtk2::Button->new("OK");
$ok->signal_connect(clicked => sub { Gtk2->main_quit });
$ok->set_size_request(60, 30);
my $hbox = Gtk2::HBox->new;
$hbox->pack_start($ok, 1, 0, 0);
$vbox->pack_start($hbox, 1, 0, 0);
$mw->modify_bg('normal', Gtk2::Gdk::Color->parse("#483D8B"));
$mw->set_position(GTK_WIN_POS_CENTER);
$mw->show_all;
Gtk2->main;
And the screenshot:
Attached Thumbnails
Click image for larger version

Name:	snapshot7.png
Views:	210
Size:	10.9 KB
ID:	23434  
Reply With Quote
Reply

Tags
challenge, create, gui, programming, window

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you create your own programming language hmm? Mepoe Programming & Packaging 7 23rd April 2012 12:16 AM
How does KDE 3.7 create popup window on detection of USB drives. Brian1 Using Fedora 0 22nd November 2007 11:12 PM
Which Window Manager are you using for programming ? michaeleekk Programming & Packaging 11 29th July 2007 08:45 AM
gtk programming ~ how to link to another window after button is clicked? yan612 Programming & Packaging 2 3rd October 2006 09:10 AM
Automatic daily login script *Programming Challenge* SickFreak Programming & Packaging 4 23rd November 2005 10:45 PM


Current GMT-time: 11:44 (Thursday, 23-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Magomeni Photos - Hazaribag Photos on Instagram - Seoni Malwa