manipulating the gui with perl/python/tcl

Suggest features you'd like to see in the future. You're not likely to get it without writing the code, but it can't hurt to try :)

manipulating the gui

Postby dominikh » 16 Jun 2006 13:39

Hi. i know that there are serveral threads about this, but i didnt see anyone in this forum.
so my request: the possibility to create own windows with perl and co
dominikh
 
Posts: 13
Joined: 13 May 2006 11:32

Postby Khisanth » 17 Jun 2006 03:59

You can already do this, at least with Perl using the Gtk2 module. So what exactly are you asking?
Khisanth
 
Posts: 1724
Joined: 10 Jun 2004 05:23

Postby dominikh » 17 Jun 2006 10:21

ehm, if i try to use the gtk2 module / try to make forms
they arent working as excepted. they are crashing xchat, or some action handlers aren't working or xchat is waiting for the window, means it freezes.

i'm new at perl, yeah, but many of this problems are well known in the scripting forum. if there is a easy way, could u pls tell me?
dominikh
 
Posts: 13
Joined: 13 May 2006 11:32

Postby Khisanth » 19 Jun 2006 04:16

You can play with the commands show_window, hide_window and set_entry
Clicking button1 will print what ever is in the text entry in xchat. set_entry will put text into the text entry

This isn't the only way to do it but I am not a fan of manually creating GUIs.

If you need any explainations, just ask. :)

The code
Code: Select all
use strict;
use warnings;
use Xchat qw(:all);
use Gtk2;
use Gtk2::GladeXML;
use Glib qw(TRUE FALSE);

register( "Gtk2 GUI demo", "1.0" );

my $glade_file = get_info( "xchatdirfs" ) . "/treeview.glade";
my $glade = Gtk2::GladeXML->new( $glade_file );
$glade->signal_autoconnect_from_package(  __PACKAGE__ );

my $treeview = $glade->get_widget( 'treeview1' );
my $renderer = Gtk2::CellRendererToggle->new();
$renderer->signal_connect( toggled =>
   sub {
      my $self = shift;
      my $text_path = shift;
      my $model = $treeview->get_model;
      my $path = Gtk2::TreePath->new_from_string( $text_path );
      $model->set( $model->get_iter( $path ), 3, !$self->get_active );
   }
);

$treeview->insert_column_with_attributes(
   -1, "Stuff",
   Gtk2::CellRendererText->new(),
   "text", 0
);

$treeview->insert_column_with_attributes(
   -1, "Toggle",
   $renderer,
   "active", 3
);

my $treestore = Gtk2::TreeStore->new(
   "Glib::String",
   "Glib::String",
   "Glib::Int",
   "Glib::Boolean",
);

my $root = $treestore->append( undef );
$treestore->set( $root, 0, "Letters", 1, "@", 2, 1, 3, FALSE );
for my $word ("A".."Z") {
   my $iter = $treestore->append( $root );
   $treestore->set( $iter, 0, $word, 1, "@", 2, 1, 3, FALSE );
}

$root = $treestore->append( undef );
$treestore->set( $root, 0, "Numbers", 1, "+", 2, 1, 3, FALSE );
for my $number (1..26) {
   my $iter = $treestore->append( $root );
   $treestore->set( $iter, 0, $number, 1, "+", 2, 1, 3, FALSE );
}

$treeview->set_model( $treestore );

sub on_row_expanded {
   warn "expanded";
   my ($view, $iter, $path) = @_;
   my $model = $view->get_model();
   $glade->get_widget( "entry1" )->set_text( $model->get( $iter, 1 ) );
   return FALSE;
}

sub on_row_activated {
   my ($view, $path, $column) = @_;
   
   if( $view->row_expanded( $path ) ) {
       $view->collapse_row( $path );
   } else {
      $view->expand_row( $path, FALSE );
   }
   
   $glade->get_widget( "entry1" )->set_text( "activated" );
   return FALSE;      
}

sub on_row_collapsed {
   prnt "collapsed";
   $glade->get_widget( "entry1" )->set_text( "collapsed" );
   return FALSE;
}

sub on_entry1_activate {
   my $self = shift;
   my $model = $treeview->get_model();
   my $iter = $model->iter_nth_child( undef, 0 );
   $model->set( $iter, 0, $self->get_text );
   warn "ACTIVATED";
   return TRUE;
}

sub selection_changed {
   my $self = shift;
   my $entry = $glade->get_widget( 'entry1' );
   my $model = $treeview->get_model();
   my $iter = $model->get_iter(($self->get_selected_rows)[0]);
   $entry->set_text( $model->get( $iter, 0 ) );
   return FALSE;
}

sub on_button1_clicked {
   prnt $glade->get_widget( "entry1" )->get_text;
}

sub on_delete_event {
   $glade->get_widget( "window1" )->hide();
   return TRUE;
}

hook_command( "show_window",
   sub {
      $glade->get_widget( "window1" )->show();
      return EAT_XCHAT;
   }
);

hook_command( "hide_window",
   sub {
      $glade->get_widget( "window1" )->hide();
      return EAT_XCHAT;
   }
);

hook_command( "set_entry",
   sub {
      $glade->get_widget( "entry1" )->set_text( $_[1][1] );
      return EAT_XCHAT;
   }
);


The glade file to go with the code
this must be saved as treeview.glade in your .xchat2 directory
Code: Select all
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">

<glade-interface>

<widget class="GtkWindow" id="window1">
  <property name="title" translatable="yes">window1</property>
  <property name="type">GTK_WINDOW_TOPLEVEL</property>
  <property name="window_position">GTK_WIN_POS_NONE</property>
  <property name="modal">False</property>
  <property name="resizable">True</property>
  <property name="destroy_with_parent">False</property>
  <property name="decorated">True</property>
  <property name="skip_taskbar_hint">False</property>
  <property name="skip_pager_hint">False</property>
  <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
  <property name="focus_on_map">True</property>
  <property name="urgency_hint">False</property>
  <signal name="delete_event" handler="on_delete_event" last_modification_time="Mon, 19 Jun 2006 03:58:46 GMT"/>

  <child>
    <widget class="GtkHBox" id="hbox1">
      <property name="visible">True</property>
      <property name="homogeneous">False</property>
      <property name="spacing">0</property>

      <child>
   <widget class="GtkScrolledWindow" id="scrolledwindow1">
     <property name="visible">True</property>
     <property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
     <property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
     <property name="shadow_type">GTK_SHADOW_NONE</property>
     <property name="window_placement">GTK_CORNER_TOP_LEFT</property>

     <child>
       <widget class="GtkTreeView" id="treeview1">
         <property name="visible">True</property>
         <property name="can_focus">True</property>
         <property name="headers_visible">True</property>
         <property name="rules_hint">False</property>
         <property name="reorderable">False</property>
         <property name="enable_search">False</property>
         <property name="fixed_height_mode">False</property>
         <property name="hover_selection">False</property>
         <property name="hover_expand">False</property>
         <signal name="row_expanded" handler="on_row_expanded" last_modification_time="Sat, 30 Jul 2005 19:46:44 GMT"/>
         <signal name="row_activated" handler="on_row_activated" last_modification_time="Sat, 30 Jul 2005 20:01:36 GMT"/>
         <signal name="row_collapsed" handler="on_row_collapsed" last_modification_time="Sat, 30 Jul 2005 19:58:59 GMT"/>
       </widget>
     </child>
   </widget>
   <packing>
     <property name="padding">0</property>
     <property name="expand">True</property>
     <property name="fill">True</property>
   </packing>
      </child>

      <child>
   <widget class="GtkNotebook" id="notebook1">
     <property name="visible">True</property>
     <property name="can_focus">True</property>
     <property name="show_tabs">True</property>
     <property name="show_border">True</property>
     <property name="tab_pos">GTK_POS_TOP</property>
     <property name="scrollable">False</property>
     <property name="enable_popup">False</property>

     <child>
       <widget class="GtkVBox" id="vbox1">
         <property name="visible">True</property>
         <property name="homogeneous">False</property>
         <property name="spacing">0</property>

         <child>
      <widget class="GtkEntry" id="entry1">
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="editable">True</property>
        <property name="visibility">True</property>
        <property name="max_length">0</property>
        <property name="text" translatable="yes"></property>
        <property name="has_frame">True</property>
        <property name="invisible_char">*</property>
        <property name="activates_default">False</property>
        <signal name="activate" handler="on_entry1_activate" last_modification_time="Wed, 09 Nov 2005 06:46:20 GMT"/>
      </widget>
      <packing>
        <property name="padding">0</property>
        <property name="expand">False</property>
        <property name="fill">False</property>
      </packing>
         </child>

         <child>
      <widget class="GtkButton" id="button1">
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="label" translatable="yes">button1</property>
        <property name="use_underline">True</property>
        <property name="relief">GTK_RELIEF_NORMAL</property>
        <property name="focus_on_click">False</property>
        <signal name="clicked" handler="on_button1_clicked" last_modification_time="Sat, 03 Sep 2005 01:08:44 GMT"/>
      </widget>
      <packing>
        <property name="padding">0</property>
        <property name="expand">False</property>
        <property name="fill">False</property>
      </packing>
         </child>
       </widget>
       <packing>
         <property name="tab_expand">False</property>
         <property name="tab_fill">True</property>
       </packing>
     </child>

     <child>
       <widget class="GtkLabel" id="label1">
         <property name="visible">True</property>
         <property name="label" translatable="yes">label1</property>
         <property name="use_underline">False</property>
         <property name="use_markup">False</property>
         <property name="justify">GTK_JUSTIFY_LEFT</property>
         <property name="wrap">False</property>
         <property name="selectable">False</property>
         <property name="xalign">0.5</property>
         <property name="yalign">0.5</property>
         <property name="xpad">0</property>
         <property name="ypad">0</property>
         <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
         <property name="width_chars">-1</property>
         <property name="single_line_mode">False</property>
         <property name="angle">0</property>
       </widget>
       <packing>
         <property name="type">tab</property>
       </packing>
     </child>
   </widget>
   <packing>
     <property name="padding">0</property>
     <property name="expand">True</property>
     <property name="fill">True</property>
   </packing>
      </child>
    </widget>
  </child>
</widget>

</glade-interface>
Khisanth
 
Posts: 1724
Joined: 10 Jun 2004 05:23

Postby dominikh » 19 Jun 2006 13:25

This isn't the only way to do it but I am not a fan of manually creating GUIs.


so i guess you generate your GUIs with tools/an IDE?
could you recommend me one? writing a gui in code is a little bit much work xD
dominikh
 
Posts: 13
Joined: 13 May 2006 11:32

Postby Khisanth » 19 Jun 2006 23:19

That was done using Glade http://glade.gnome.org/
Khisanth
 
Posts: 1724
Joined: 10 Jun 2004 05:23

Postby dominikh » 20 Jun 2006 07:38

thank u very much.
now i only have to install a linux for glade and i have to look how to install gtk2 into my activeperl under windows xD

i think i will do that when i am at home again, thanks.
dominikh
 
Posts: 13
Joined: 13 May 2006 11:32

Postby Khisanth » 20 Jun 2006 12:13

Khisanth
 
Posts: 1724
Joined: 10 Jun 2004 05:23


Return to Feature Requests

Who is online

Users browsing this forum: No registered users and 0 guests