Fedora Linux Support Community & Resources Center
  #121  
Old 26th November 2014, 03:33 AM
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 6,584
linuxfedorafirefox
Re: Programming challenge: Create a GUI window

A while ago rclark posted an example with Pascal using GTK+. It used the Lazarus IDE for Free Pascal to create the form and other project files. I managed to get that example working thanks to his instructions. For anyone (like me) who prefers command-line compiling without an IDE, here's a single-file example of Pascal with GTK+, which requires the fpc package from the Fedora repos.
Code:
program pasgtk;
{$mode objfpc}{$H+}
uses Glib2, Gdk2, Gtk2;

procedure destroy(Widget: PGtkWidget; Data: gpointer); cdecl;
begin
   gtk_main_quit;
end;

var win, vbox, lbl, hbox, btn: PGtkWidget; bgcolor : TGdkColor;
begin
   gtk_init(@argc, @argv);
   win := gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title(GTK_WINDOW(win), 'Pascal/GTK Window Example');
   gdk_color_parse('darkslateblue', @bgcolor);
   gtk_widget_modify_bg(GTK_WIDGET(win), GTK_STATE_NORMAL, @bgcolor);
   g_signal_connect(G_OBJECT(win), 'delete_event', G_CALLBACK(@destroy), NULL);
   vbox := gtk_vbox_new(FALSE, 0);
   lbl := gtk_label_new(NULL);
   gtk_label_set_markup(GTK_LABEL(lbl), '<span foreground="white" size="32000">Welcome!</span>');
   gtk_box_pack_start(GTK_BOX(vbox), lbl, TRUE, TRUE, 0);
   hbox := gtk_hbox_new(TRUE, 0);
   btn := gtk_button_new_from_stock(GTK_STOCK_OK);
   g_signal_connect(G_OBJECT(btn), 'clicked', G_CALLBACK(@destroy), NULL);
   gtk_box_pack_start(GTK_BOX(hbox), btn, FALSE, FALSE, 0);
   gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 10);
   gtk_container_add(GTK_CONTAINER(win), vbox);
   gtk_window_resize(GTK_WINDOW(win), 400, 150);
   gtk_widget_show_all(win);
   gtk_main();
end.
Save that as pascalgtk.pas and compile it like this:
Code:
fpc pascalgtk.pas
Screenshot:
Attached Thumbnails
Click image for larger version

Name:	pascalgtk.png
Views:	97
Size:	8.7 KB
ID:	26411  
__________________
OS: Fedora 25 x86_64 | Machine: HP Pavilion a6130n | CPU: AMD 64 X2 Dual-Core 5000+ 2.6GHz | RAM: 7GB PC5300 DDR2 | Disk: 400GB SATA | Video: ATI Radeon HD 4350 512MB | Sound: Realtek ALC888S | Ethernet: Realtek RTL8201N
Reply With Quote
  #122  
Old 27th November 2014, 07:39 PM
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 6,584
linuxfedorafirefox
Re: Programming challenge: Create a GUI window

Here's an example in Pascal with XForms. For this you'll need to install the xforms-devel and fpc-src packages from the Fedora repos (yum install xforms-devel fpc-src). The reason is that the XForms bindings in Free Pascal use some XForms functions that have been renamed in the latest XForms libraries. The fix is fairly easy:
  1. First run these commands as root:
    Code:
    sed -i 's/fl_setpup_fontsize/fl_setpup_default_fontsize/g' /usr/share/fpcsrc/packages/xforms/src/xforms.pp
    sed -i 's/fl_setpup_fontstyle/fl_setpup_default_fontstyle/g' /usr/share/fpcsrc/packages/xforms/src/xforms.pp
    sed -i 's/fl_setpup_color/fl_setpup_default_color/g' /usr/share/fpcsrc/packages/xforms/src/xforms.pp
  2. Then comment out lines 2477-2479 in /usr/share/fpcsrc/packages/xforms/src/xforms.pp like this:
    Code:
    (* Function fl_setpup_default_fontsize(p1 : LongInt) : Longint;  cdecl;external;
    Function fl_setpup_default_fontstyle(p1 : LongInt) : Longint;   cdecl;external;
    Procedure fl_setpup_default_color(p1 : TFL_COLOR; p2 :  TFL_COLOR); cdecl;external; *)
  3. Next run these commands as root:
    Code:
    cd /usr/share/fpcsrc/packages/xforms
    make
    cp units/x86_64-linux/xforms* /usr/lib64/fpc/2.6.2/units/x86_64-linux/xforms
You should then be able to use the XForms bindings.

Once you've done all that, save this as pascalxforms.pas:
Code:
program pascalxforms;
{$mode objfpc}{$H+}
uses xforms;

var form : PFL_FORM; box, lbl, btn : PFL_OBJECT;

procedure exit_cb(obj : PFL_OBJECT; n : longint);cdecl;
begin
   halt(0);
end;

begin
   fl_initialize(@argc, argv, 'XFormsWindow', nil, 0);
   form := fl_bgn_form(FL_UP_BOX, 400, 150);
   box := fl_add_box(FL_FLAT_BOX, 0, 0, 400, 150, '');
   fl_set_object_color(box, 61, 61);
   lbl := fl_add_text(FL_NORMAL_TEXT, 140, 20, 120, 60, 'Welcome!');
   fl_set_object_color(lbl, 61, 61);
   fl_set_object_lsize(lbl, FL_HUGE_SIZE);
   fl_set_object_lcol(lbl, FL_WHITE);
   fl_set_object_lalign(lbl, FL_ALIGN_CENTER);
   btn := fl_add_button(FL_NORMAL_BUTTON, 175, 110, 50, 30, 'OK');
   fl_set_object_callback(btn, PFL_CALLBACKPTR(@exit_cb), 0);
   fl_end_form;
   fl_show_form(form, FL_PLACE_MOUSE, FL_TRANSIENT, 'Pascal/XForms Window Example');
   fl_do_forms();
end.
Compile it like this:
Code:
fpc pascalxforms.pas
Screenshot:
Attached Thumbnails
Click image for larger version

Name:	pascalxforms.png
Views:	79
Size:	2.4 KB
ID:	26414  
__________________
OS: Fedora 25 x86_64 | Machine: HP Pavilion a6130n | CPU: AMD 64 X2 Dual-Core 5000+ 2.6GHz | RAM: 7GB PC5300 DDR2 | Disk: 400GB SATA | Video: ATI Radeon HD 4350 512MB | Sound: Realtek ALC888S | Ethernet: Realtek RTL8201N
Reply With Quote
  #123  
Old 27th November 2014, 09:05 PM
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 6,584
linuxfedorafirefox
Re: Programming challenge: Create a GUI window

Here's another example in Pascal, this time with Tk. For this you'll need the tk-devel, tcl-devel and fp-src packages installed from the Fedora repos (yum install tk-devel tcl-devel fp-src). The reason is that the Tcl bindings in Free Pascal use an object file (argv.o) that no longer exists, and they use a library (libtcl80.so) that no longer exists. The fix is fairly easy:
  1. As root, run this:
    Code:
    ln -s /usr/lib64/libtcl.so /usr/lib64/libtcl80.so; ldconfig
  2. Then comment out line 47 in /usr/share/fpcsrc/packages/tcl/src/tcl80.pp like this:
    Code:
    (*   {$LINK argv.o} *)
  3. Then run these commands as root:
    Code:
    cd /usr/share/fpcsrc/packages/tcl
    make
    cp units/x86_64-linux/tcl* /usr/lib64/fpc/2.6.2/units/x86_64-linux/tcl/
You should then be able to use the Tcl bindings.

Once you've done all that, save this as pascaltk.pas:
Code:
program pascaltk;
uses tcl80;

var interp: PTcl_Interp;

begin
   interp := Tcl_CreateInterp();
   Tcl_Init(interp);
   Tcl_Eval(interp, 'package require Tk');
   Tcl_Eval(interp, 'wm title . "Pascal/Tk Window Example"');
   Tcl_Eval(interp, 'wm geometry . 400x150');
   Tcl_Eval(interp, '. configure -bg "darkslateblue"');
   Tcl_Eval(interp, 'label .lbl -text "Welcome!" -font {-size 32} -bg "darkslateblue" -fg "white"');
   Tcl_Eval(interp, 'pack .lbl -pady 25 -expand 1');
   Tcl_Eval(interp, 'button .btn -text "OK" -command exit');
   Tcl_Eval(interp, 'pack .btn -pady {0 10} -anchor s -expand 1');
   Tcl_Eval(interp, 'tkwait window .');
   Tcl_DeleteInterp(interp);
end.
Compile it like this:
Code:
fpc pascaltk.pas
Screenshot:
Attached Thumbnails
Click image for larger version

Name:	pascaltk.png
Views:	70
Size:	7.2 KB
ID:	26415  
__________________
OS: Fedora 25 x86_64 | Machine: HP Pavilion a6130n | CPU: AMD 64 X2 Dual-Core 5000+ 2.6GHz | RAM: 7GB PC5300 DDR2 | Disk: 400GB SATA | Video: ATI Radeon HD 4350 512MB | Sound: Realtek ALC888S | Ethernet: Realtek RTL8201N
Reply With Quote
  #124  
Old 27th November 2014, 09:43 PM
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 6,584
linuxfedorafirefox
Re: Programming challenge: Create a GUI window

Latest update: we now have 100 examples in 43 languages.

Here's a summary of what we have right now, first organized by programming language with the corresponding toolkit:
  1. C: XForms, Motif, MGUI, EZWGL, GTK+, Tk, XView, X Athena Widgets, OpenGL, WINGs
  2. Python: Tk, Qt, GTK+, Swing, Kivy, wxWidgets, FLTK
  3. C++: Qt, FOX, FLTK, GTK+ (gtkmm, c++-gtk-utils), wxWidgets, SDL
  4. Java: Swing, Qt, SWT, AWT, JavaFX, GTK+
  5. Perl: Tk, wxWidgets, Prima, GTK+, Qt
  6. Ruby: Tk, Swing, Qt, FOX, GTK+
  7. Tcl: Tk, GTK+, Qt, FLTK
  8. Pascal: GTK+ (Lazarus, cli), XForms, Tk
  9. R: Tk, Qt, GTK+
  10. Haskell: GTK+, Tk, HGL
  11. Ada: Qt, Tk, GTK+
  12. Scheme: GTK+ (Guile, Gauche), Tk
  13. JavaScript: Swing, jQuery
  14. Lua: Tk, Qt
  15. Matlab: Swing, Matlab GUI
  16. Pure: Tk, GTK+
  17. OCaml: Tk, GTK+
  18. Fantom: FWT, Swing
  19. Lisp: Swing, Tk
  20. Smalltalk: Tk, GTK+
  21. D: GTK+, Tk
  22. BASIC: Qt, GTK+
  23. Objective-C: GNUstep
  24. Icon: Icon
  25. Vala: GTK+
  26. Genie: GTK+
  27. SNOBOL: Tk
  28. Scala: Swing
  29. BeanShell: Swing
  30. Groovy: Swing
  31. Clojure: Swing
  32. Scilab: Tk
  33. ksh: Motif
  34. Julia: Tk
  35. X10: Swing
  36. Nimrod: Tk
  37. Mirah: Swing
  38. ROOT: Xclass
  39. Qore: Qt
  40. Erlang: wxWidgets
  41. Aikido: GTK+
  42. Sather: Tk
  43. Rexx: GTK+

Here's the list organized by toolkit with the corresponding language bindings:
  1. GTK+: Ada, Aikido, BASIC, C, C++ (gtkmm, c++-gtk-utils), D, Genie, Haskell, Java, OCaml, Pascal (Lazarus, cli), Perl, Pure, Python, R, Rexx, Ruby, Scheme (Guile, Gauche), Smalltalk, Tcl, Vala
  2. Tk: Ada, C, D, Guile, Haskell, Julia, Lisp, Lua, Nimrod, OCaml, Pascal, Perl, Pure, Python, R, Ruby, Sather, Scilab, Smalltalk, SNOBOL, Tcl
  3. Swing: BeanShell, Clojure, Fantom, Groovy, Java, JavaScript, Lisp, Matlab, Mirah, Python, Ruby, Scala, X10
  4. Qt: Ada, BASIC, C++, Java, Lua, Perl, Python, Qore, R, Ruby, Tcl
  5. wxWidgets: , C++, Erlang, Perl, Python
  6. FLTK: C++, Python, Tcl
  7. XForms: C, Pascal
  8. FOX: C++, Ruby
  9. Motif: C, ksh
  10. GNUstep: Objective-C
  11. Icon: Icon
  12. Prima: Perl
  13. MGUI: C
  14. EZWGL: C
  15. SWT: Java
  16. AWT: Java
  17. XView: C
  18. JavaFX: Java
  19. jQuery: JavaScript
  20. Kivy: Python
  21. Matlab GUI: Matlab
  22. X Athena Widgets: C
  23. FWT: Fantom
  24. SDL: C++
  25. HGL: Haskell
  26. Xclass: ROOT
  27. OpenGL: C
  28. WINGs: C
In the list organized by toolkit you'll notice that I changed the way the languages are listed so that they are now in alphabetical order, which makes it easier to keep track of the languages each toolkit uses. GTK+ still holds the top spot with 24 examples, followed by Tk with 21 examples. I'm surprised there aren't more bindings for Qt, but I think I might have found a few more so that Qt can start catching up. For languages, C still holds the top spot with 10 examples, which I guess is not surprising given Linux's roots in C.
__________________
OS: Fedora 25 x86_64 | Machine: HP Pavilion a6130n | CPU: AMD 64 X2 Dual-Core 5000+ 2.6GHz | RAM: 7GB PC5300 DDR2 | Disk: 400GB SATA | Video: ATI Radeon HD 4350 512MB | Sound: Realtek ALC888S | Ethernet: Realtek RTL8201N
Reply With Quote
  #125  
Old 29th November 2014, 07:21 AM
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 6,584
linuxfedorafirefox
Re: Programming challenge: Create a GUI window

Here's another example in Pascal, this time with Qt. For this you'll need the Free Pascal Qt4 Binding, which you can get from the Fedora repos (yum install qt4pas qt4pas-devel). Unfortunately there are a couple missing pieces from those packages, but it's easy to get them by running these 6 commands this as root:
Code:
wget http://users.telenet.be/Jan.Van.hijfte/qtforfpc/V2.5/demos-V2.5_Qt4.5.3.tar.gz
tar xzvf demos-V2.5_Qt4.5.3.tar.gz
cd demos-V2.5_Qt4.5.3/mainwindow
fpc mainwindow.pas
mkdir /usr/lib64/fpc/2.6.2/units/x86_64-linux/qt4
cp qt4.o qt4.ppu /usr/lib64/fpc/2.6.2/units/x86_64-linux/qt4
You should then be able to use the Qt bindings.

Save this as pascalqtwindow.pas:
Code:
program pascalqtwindow;
uses qt4;

var
   app : QApplicationH; win : QMainWindowH; lbl : QLabelH; btn : QPushButtonH;
   style, title, lbltext, btntext : WideString;
   
begin
   app := QApplication_Create(@argc,argv);
   style := 'QMainWindow, QLabel {background-color: #483D8B; color: #FFFFFF; font-size: 32pt}';
   QApplication_setStyleSheet(app, @style);
   win := QMainWindow_create();
   title := 'Pascal/Qt Window Example';
   QWidget_setWindowTitle(win, @title);
   QWidget_resize(win, 400, 150);
   lbltext := 'Welcome!';
   lbl := QLabel_create(@lbltext, win);
   QWidget_setGeometry(lbl, 90, 25, 220, 50);
   QLabel_setAlignment(lbl, QtAlignCenter);
   btntext := 'OK';
   btn := QPushButton_create(@btntext, win);
   QWidget_setGeometry(btn, 175, 100, 50, 30);
   QObject_connect(btn, '2clicked()', QCoreApplication_instance(), '1quit()');
   QWidget_Show(win);
   QApplication_Exec();
end.
Compile it like this:
Code:
fpc pascalqtwindow.pas
Screenshot:
Attached Thumbnails
Click image for larger version

Name:	pascalqtwindow.png
Views:	86
Size:	8.4 KB
ID:	26418  
__________________
OS: Fedora 25 x86_64 | Machine: HP Pavilion a6130n | CPU: AMD 64 X2 Dual-Core 5000+ 2.6GHz | RAM: 7GB PC5300 DDR2 | Disk: 400GB SATA | Video: ATI Radeon HD 4350 512MB | Sound: Realtek ALC888S | Ethernet: Realtek RTL8201N
Reply With Quote
  #126  
Old 29th November 2014, 07:44 AM
sonoran Offline
Registered User
 
Join Date: May 2005
Location: Sonoran Desert
Posts: 2,421
linuxfirefox
Re: Programming challenge: Create a GUI window

Niklaus Wirth is undoubtedly spinning in his grave.
Reply With Quote
  #127  
Old 29th November 2014, 08:10 AM
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 6,584
linuxfedorafirefox
Re: Programming challenge: Create a GUI window

Quote:
Originally Posted by sonoran View Post
Niklaus Wirth is undoubtedly spinning in his grave.
Yeah, it's a shame he died in that tragic boating accident off Lake Erie. I really liked him in Raising Arizona and those National Treasure movies.
Reply With Quote
  #128  
Old 29th November 2014, 09:35 AM
sea Offline
"Shells" (of a sub world)
 
Join Date: May 2011
Location: Confoederatio Helvetica (Swissh)
Age: 37
Posts: 4,280
linuxfedorafirefox
Re: Programming challenge: Create a GUI window

You wouldnt count a bash script - TUI - for a GUI, right?

Anyway, here it is
Code:
#!/bin/bash
#
#	As good as it gets :p
#
	. tui # Here, this is only required to print: $TUI_VERSION
	tui-header \
		"TUI $TUI_VERSION" \
		"$($SHELL -version|grep -i ${SHELL##*/})"
	tui-echo
	tui-echo
	tui-echo
	tui-echo
	tui-echo
	tui-title
	tui-title "Welcome!"
	tui-title
	tui-echo
	tui-echo
	tui-echo
	tui-echo
	tui-echo
	tui-press
Attached Thumbnails
Click image for larger version

Name:	GUI-challenge.jpg
Views:	99
Size:	22.9 KB
ID:	26419  
__________________
EFI Cheatsheet :: http://forums.fedoraforum.org/showthread.php?t=298546
Video Handler Script (VHS) (mass re-encode videos, screenrecorder, console music/webradio player, ...) :: http://forums.fedoraforum.org/showthread.php?t=299182
Windows 8+ & Fedora 20+ Dualboot :: http://forums.fedoraforum.org/showthread.php?t=298161
Reply With Quote
  #129  
Old 29th November 2014, 11:24 AM
sonoran Offline
Registered User
 
Join Date: May 2005
Location: Sonoran Desert
Posts: 2,421
linuxfirefox
Re: Programming challenge: Create a GUI window

Quote:
Originally Posted by RupertPupkin View Post
Yeah, it's a shame he died in that tragic boating accident off Lake Erie. I really liked him in Raising Arizona and those National Treasure movies.
Knew I'd regret that, but not how much...
Reply With Quote
  #130  
Old 25th April 2015, 05:42 AM
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 6,584
linuxfedorafirefox
Re: Programming challenge: Create a GUI window

Here's an example in Euphoria with GTK+. You can get Euphoria for Linux here (I used the euphoria-4.1.0-Linux-x64-57179171dbed.tar.gz file): http://sourceforge.net/projects/rapi...a/4.1.0-beta2/
You'll also need the EuGTK toolkit, which you can get here: https://sites.google.com/site/euphoriagtk/Home
Unpack the EuGTK4.9.4.tar.gz file and put the GtkEngine.e and GtkEnums.e files in the same directory as where you would write your Euphoria code. You'll need the gtk3-devel package installed from the Fedora repos for all this to work.

Once you've done all that, save this as eugtkwindow.ex:
Code:
include GtkEngine.e

constant msg = `<span foreground='white' size='32000'>Welcome!</span>`
constant win = create(GtkWindow, {{"title", "EuGTK Window Example"},
               {"default size", 400, 150}, {"background", "darkslateblue"},
               {"position", GTK_WIN_POS_CENTER}})
connect(win, "destroy", "Quit") 
constant vbox = add(win, create(GtkBox, VERTICAL, FALSE, 0)),
          lbl = pack_start(vbox, create(GtkLabel, {{"markup", msg}}), TRUE, TRUE, 0),
         hbox = pack_start(vbox, create(GtkBox, HORIZONTAL, TRUE, 0), FALSE, FALSE, 10),
          btn = pack_start(hbox, create(GtkButton, "gtk-ok", "Quit"), TRUE, FALSE, 0)
show_all(win)
main()
Assuming that the eui executable for Euphoria is in your PATH (and GtkEngine.e and GtkEnums.e are in the same directory as eugtkwindow.ex), run the code like this:
Code:
eui eugtkwindow
Screenshot:

__________________
OS: Fedora 25 x86_64 | Machine: HP Pavilion a6130n | CPU: AMD 64 X2 Dual-Core 5000+ 2.6GHz | RAM: 7GB PC5300 DDR2 | Disk: 400GB SATA | Video: ATI Radeon HD 4350 512MB | Sound: Realtek ALC888S | Ethernet: Realtek RTL8201N
Reply With Quote
  #131  
Old 22nd December 2015, 12:30 AM
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 6,584
linuxfedorafirefox
Re: Programming challenge: Create a GUI window

Here's an example in Falcon with GTK+. Unfortunately the GTK module is not included by default with the Fedora packages for Falcon (even though the Falcon-doc package for F23 does include the GTK+ API!), so you'll have to re-compile Falcon from the SRPM to include GTK support.

Save this script as gtkwindow.fal:
Code:
#!/usr/bin/falcon
load gtk
app = GtkMain(args)
class MyWindow from GtkWindow
   function on_delete_event()
      app.quit()
      return false
   end

   function on_clicked()
      app.quit()
   end

   init
      self.set_title("Falcon/GTK Window Example")
      self.modify_bg(GTK_STATE_NORMAL, GdkColor(1, 18481, 15663, 35717))
      self.set_default_size(400, 150)
      self.signal_delete_event().connect(self)
      vbox = GtkVBox(false, 0)
      lbl = GtkLabel('<span foreground="white" size="32000">Welcome!</span>')
      lbl.set_use_markup(true);
      vbox.pack_start(lbl, true, true, 0)
      okBox = GtkHBox(true, 0)
      btn = GtkButton.new_from_stock(GTK_STOCK_OK)
      btn.signal_clicked().connect(self)
      okBox.pack_start(btn, false, false, 0)
      vbox.pack_start(okBox, false, false, 10)
      self.add(vbox)
   end
end
app.run(MyWindow())
Screenshot:

__________________
OS: Fedora 25 x86_64 | Machine: HP Pavilion a6130n | CPU: AMD 64 X2 Dual-Core 5000+ 2.6GHz | RAM: 7GB PC5300 DDR2 | Disk: 400GB SATA | Video: ATI Radeon HD 4350 512MB | Sound: Realtek ALC888S | Ethernet: Realtek RTL8201N
Reply With Quote
  #132  
Old 18th February 2017, 05:04 AM
Flounder Offline
Registered User
 
Join Date: Dec 2005
Location: Arkansas
Age: 28
Posts: 1,157
linuxchrome
Re: Programming challenge: Create a GUI window

This example is a combination of Rust and QML.

src/main.rs
Code:
extern crate qml;

use qml::*;

fn main() {
    let mut engine = QmlEngine::new();

    let message = QVariant::from("Welcome!");
    engine.set_property("message", &message);

    engine.load_data("
        import QtQuick 2.0
        import QtQuick.Controls 1.0

        ApplicationWindow {
            title: qsTr(\"Rust/QML Window Example\")
            color: \"#483D8B\"
            width: 400
            height: 150

            visible: true
            Text {
                id: welcome
                color: \"white\"
                font.pointSize: 32
                anchors.top: parent.top
                anchors.horizontalCenter: parent.horizontalCenter
                text: message
            }

            Button {
                text: \"OK\"
                anchors.bottom: parent.bottom
                anchors.horizontalCenter: parent.horizontalCenter
                action: Action {
                    onTriggered: Qt.quit()
                }
            }
        }
    ");
    engine.exec();
}
Cargo.toml
Code:
[package]
name = "sousa"
version = "0.1.0"
authors = ["Steven Williams <steven.m.williams@yandex.com>"]

[dependencies]
qml = "0.0.9"
You can build and run the code using cargo.

Code:
$ cargo new rust-qml-example # to initialize the project
$ cargo build # run this after you have modified main.rs and Cargo.toml to reflect the above snippets.
$ cargo run
Sadly due to my running XMonad, I've been having a good deal of trouble finding a way to get it to float to the right size for pictures, so if someone wouldn't mind doing the honors that would be appreciated.
__________________
OS: Arch Linux x86_64
Laptop: Lenovo ThinkPad L440, CPU: Intel Core i7 4702MQ Quad Core 2.20 GHz, Ram: 16GB DDR3, Hard Drive: 500GB, Graphics: Intel 4600 HD, Wireless: Intel 7260AC
Reply With Quote
  #133  
Old 18th February 2017, 06:23 AM
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 6,584
linuxfedorafirefox
Re: Programming challenge: Create a GUI window

Nice, a Rust example! That's the first one here. For Fedora users, here is what I did to compile and run Flounder's example in F25:
  1. As root:
    Code:
    dnf install qt5-qtquickcontrols rust rust-std-static cargo
  2. As an ordinary user, change to some directory for your Rust code, then do this:
    Code:
    cargo new rust-qml-example
    cd rust-qml-example
  3. Edit the file src/main.rs as in Flounder's post.
  4. Edit the file Cargo.toml as in Flounder's post. This file should be directly in the rust-qml-example directory, not in the src subdirectory.
  5. Run these commands in the rust-qml-example directory:
    Code:
    cargo build
    cargo run
The 'cargo build' command might take a while, since it has to download and compile the necessary Rust modules (qml, lazy_static, libc). The 'cargo run' command will then produce this window:

__________________
OS: Fedora 25 x86_64 | Machine: HP Pavilion a6130n | CPU: AMD 64 X2 Dual-Core 5000+ 2.6GHz | RAM: 7GB PC5300 DDR2 | Disk: 400GB SATA | Video: ATI Radeon HD 4350 512MB | Sound: Realtek ALC888S | Ethernet: Realtek RTL8201N
Reply With Quote
  #134  
Old 20th February 2017, 08:20 AM
osce0 Offline
Registered User
 
Join Date: May 2011
Posts: 168
linuxfedorafirefox
Re: Programming challenge: Create a GUI window

Not sure a command like yad counts. Yad uses GTK. Here is a one-liner that can run in a shell (doesn't quite meet the background color of window requirement):
Code:
yad --width=400 --height=150 --text-align=center \
  --text='<span background=#483D8B font="32">Welcome!</span>' \
  --buttons-layout=center --button=OK:1 \
  --title="Yad GTK+ Window Example"

Last edited by osce0; 20th February 2017 at 08:37 AM. Reason: meet other requirements
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: 02:46 (Monday, 24-07-2017)

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