2009-06-18 8 views
5

Je voudrais créer une interface graphique Windows simple pour mon programme Perl. Il doit essentiellement générer une fenêtre, écrire des informations de journal dans une zone de texte, et avoir une boîte de saisie et quelques boutons de démarrage/arrêt.Module (s) Perl pour créer une interface graphique Microsoft Windows simple?

Est-ce que quelqu'un a des conseils sur les modules Perl que j'utilise? Les gens avec qui je travaille comme Qt, ça peut être une préférence, mais je ne suis pas dérangé.

Répondre

0

utiliser Perl/Tk

4

Perl 5.10 de ActiveState sont pré-compilé avec TKX qui est une plate-forme graphique. Vous pouvez télécharger Perl Tk si vous souhaitez un module avec plus d'exemples Web. Quel que soit le module que vous utilisez, vous pouvez télécharger GUIbuilder à partir de sourceforge et il écrit assez bon code Tk ou Tkx pour perl, et le code Tk pour python, ruby.

Ce code a été généré en grande partie par GuiBuilder comme un exemple de code de sortie:

use Tkx; 
Tkx::package_require('BWidget'); 

sub example::ui { 
    my($root) = @_; 

    my($_entry_box) = $root->new_entry(
    -width => 0, 
    ); 
    my($_text_box) = $root->new_text(
     -height => 0, 
     -width => 0, 
    ); 
    my($_label) = $root->new_label(
      -text => "Hello World", 
    ); 
    my($_textbox_horiz_scrollbar) = $root->new_scrollbar(
      -orient => "horizontal", 
    ); 
    my($_textbox_vert_scrollbar) = $root->new_scrollbar(
    ); 
    my($_Start_Button) = $root->new_Button(
      -text => "Start", 
      -width => 10, 
    ); 
    my($_Stop_Button) = $root->new_Button(
      -text => "Stop", 
      -width => 10, 
    ); 

    $_entry_box->configure(
      -invalidcommand => \&_entry_box_invalidcommand 
    ); 
    $_entry_box->configure(
      -validatecommand => \&_entry_box_validatecommand 
    ); 
    $_entry_box->configure(
      -xscrollcommand => \&_entry_box_xscrollcommand 
    ); 
    $_text_box->configure(
      -xscrollcommand => [ $_textbox_horiz_scrollbar => set ] 
    ); 
    $_text_box->configure(
      -yscrollcommand => [ $_textbox_vert_scrollbar => set ] 
    ); 
    $_textbox_horiz_scrollbar->configure(
      -command => [ $_text_box => xview ] 
    ); 
    $_textbox_vert_scrollbar->configure(
      -command => [ $_text_box => yview ] 
    ); 
    $_Start_Button->configure(
      -armcommand => \&_Start_Button_armcommand 
    ); 
    $_Start_Button->configure(
      -command => \&_Start_Button_command 
    ); 
    $_Start_Button->configure(
      -disarmcommand => \&_Start_Button_disarmcommand 
    ); 
    $_Stop_Button->configure(
      -armcommand => \&_Stop_Button_armcommand 
    ); 
    $_Stop_Button->configure(
      -command => \&_Stop_Button_command 
    ); 
    $_Stop_Button->configure(
      -disarmcommand => \&_Stop_Button_disarmcommand 
    ); 
    sub _entry_box_xscrollcommand {} 

# Geometry Management 
    $_entry_box->g_grid(
      -in  => $root, 
      -column => 1, 
      -row => 2, 
      -columnspan => 3, 
      -ipadx => 0, 
      -ipady => 0, 
      -padx => 0, 
      -pady => 5, 
      -rowspan => 1, 
      -sticky => "ew" 
    ); 
    $_text_box->g_grid(
      -in  => $root, 
      -column => 1, 
      -row => 3, 
      -columnspan => 2, 
      -ipadx => 0, 
      -ipady => 0, 
      -padx => 0, 
      -pady => 0, 
      -rowspan => 1, 
      -sticky => "news" 
    ); 
    $_label->g_grid(
      -in  => $root, 
      -column => 1, 
      -row => 1, 
      -columnspan => 3, 
      -ipadx => 0, 
      -ipady => 0, 
      -padx => 0, 
      -pady => 0, 
      -rowspan => 1, 
      -sticky => "ew" 
    ); 
    $_textbox_horiz_scrollbar->g_grid(
      -in  => $root, 
      -column => 1, 
      -row => 4, 
      -columnspan => 2, 
      -ipadx => 0, 
      -ipady => 0, 
      -padx => 0, 
      -pady => 0, 
      -rowspan => 1, 
      -sticky => "ew" 
    ); 
    $_textbox_vert_scrollbar->g_grid(
      -in  => $root, 
      -column => 3, 
      -row => 3, 
      -columnspan => 1, 
      -ipadx => 0, 
      -ipady => 0, 
      -padx => 0, 
      -pady => 0, 
      -rowspan => 1, 
      -sticky => "ns" 
    ); 
    $_Start_Button->g_grid(
      -in  => $root, 
      -column => 1, 
      -row => 5, 
      -columnspan => 1, 
      -ipadx => 0, 
      -ipady => 0, 
      -padx => 0, 
      -pady => 0, 
      -rowspan => 1, 
      -sticky => "" 
    ); 
    $_Stop_Button->g_grid(
      -in  => $root, 
      -column => 2, 
      -row => 5, 
      -columnspan => 2, 
      -ipadx => 0, 
      -ipady => 0, 
      -padx => 0, 
      -pady => 0, 
      -rowspan => 1, 
      -sticky => "" 
    ); 


# Resize Behavior 
    $root->g_grid_rowconfigure(1, -weight => 0, -minsize => 2, -pad => 0); 
    $root->g_grid_rowconfigure(2, -weight => 0, -minsize => 12, -pad => 0); 
    $root->g_grid_rowconfigure(3, -weight => 1, -minsize => 85, -pad => 0); 
    $root->g_grid_rowconfigure(4, -weight => 0, -minsize => 4, -pad => 0); 
    $root->g_grid_rowconfigure(5, -weight => 0, -minsize => 40, -pad => 0); 
    $root->g_grid_columnconfigure(1, -weight => 1, -minsize => 67, -pad => 0); 
    $root->g_grid_columnconfigure(2, -weight => 1, -minsize => 186, -pad => 0); 
    $root->g_grid_columnconfigure(3, -weight => 0, -minsize => 2, -pad => 0); 
} 

my($root) = Tkx::widget->new('.'); 
$root->g_wm_title('stackoverflow'); 
example::ui($root); 

Tkx::MainLoop(); 

1; 
+0

"notre" est déprécié ... hmmm –

+0

désolé mais le code a été généré. trouver et remplacer "notre" pour "mon" semble être une solution assez facile. – Akers

+4

Ape-inago: "notre" n'est pas obsolète. Seulement si vous utilisez perl 5.5.4, il vous avertira qu'il s'agit d'un futur mot-clé. –

7

J'ai utilisé Win32::GUI une fois pour un projet simple. La fenêtre principale avait un menu, une boîte de texte et quelques boutons et cases à cocher. Ça a marché.

Extrait de la méthode qui met en place l'interface graphique (juste pour vous donner une idée):

my @menu_items = (
    '&File' => 'File', 
    ' > &Open' => { 
     -name => 'FileOpen', 
     -onClick => sub { $self->onFileOpen(@_) }, 
    }, 
    ' > &Close' => { 
     -name => 'FileClose', 
     -onClick => sub { $self->onFileClose(@_) }, 
    }, 
    ' > E&xit' => { 
     -name => 'FileExit', 
     -onClick => sub { $self->onFileExit(@_) }, 
    }, 
    '&Help' => 'Help', 
    ' > &About' => { 
     -name => 'About', 
     -onClick => sub { $self->onHelpAbout(@_) }, 
    }, 
); 

$self->set_main_menu(Win32::GUI::MakeMenu(@menu_items)); 

my $window = $self->set_main_window(
    Win32::GUI::Window->new(
     -menu => $self->get_main_menu, 
     -name => 'Main', 
     -sizable => 0, 
     -resizable => 0, 
     -hasmaximize => 0, 
     -maximizebox => 0, 
     -title => $self->get_program_name, 
     -onTerminate => sub { -1 }, 
     -onTimer => sub { $self->onTimer(@_) }, 
    ), 
); 

$self->set_log_field(
    $window->AddTextfield(
     -name => 'Log', 
     -font => Win32::GUI::Font->new(
      -name => 'LogFont', 
      -face => 'Courier New', 
      -size => 9, 
     ), 
     -multiline => 1, 
     -wantreturn => 1, 
     -autovscroll => 1, 
     -vscroll => 1, 
     -readonly => 1, 
    ), 
); 

$self->get_log_field->MaxLength(40000); 

$self->set_status_bar(
    $window->AddStatusBar(
     -name => 'Status', 
     -text => $self->get_program_name, 
    ), 
); 
6

Vous avez plusieurs choix:

Je suis partielle Gtk2. Il est facilement installé dans MS Windows via le programme d'installation CamelBox.

Une application de style simple "bonjour monde" ressemble

#!/usr/bin/perl 

use strict; 
use warnings; 

use Gtk2; 

Gtk2->init; 

my $window = Gtk2::Window->new; 
my $vbox = Gtk2::VBox->new; 
my $label = Gtk2::Label->new("Hello World"); 
my $button = Gtk2::Button->new("Press me"); 

$window->add($vbox); 
$vbox->add($label); 
$vbox->add($button); 

my $i; 
$button->signal_connect(clicked => sub { 
    $label->set_text("button pressed " . ++$i . " times"); 
}); 

$window->signal_connect(destroy => sub { Gtk2->main_quit }); 

$window->show_all; 

Gtk2->main; 
+0

S'il vous plaît ne pas Wx, cette boucle d'événement est assez limitée. et le QT auquel vous vous êtes connecté est les liaisons Qt2 très obsolètes (il n'y a pas d'interfaces Qt3 et Qt4 très polies). – MkV

+0

Ne pas oublier Prima. http://www.prima.eu.org/ - C'est une bibliothèque gui natif de Perl. – daotoad

+0

james2vegas J'ai mis à jour le lien Qt pour pointer vers QtGui qui prétend être un module basé sur Qt4.Je n'aime pas Wx aussi, mais c'est toujours une option. –

0

Le seul que je l'ai utilisé est Perl Tk. Il a été rapide à apprendre, il existe de nombreux exemples sur le Web, et j'ai été capable de passer rapidement de Mac OS X à Windows. L'inconvénient est que l'interface graphique semble datée. C'est génial pour les outils internes, mais pas pour la vente à des tiers.

Questions connexes