PyrexKidd has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I would like to develop a program that spawns a window/tool bar with buttons with programmable text that when clicked prints the programmed text at the cursor. In most programs there are options to print text repeatedly, i.e. macros, but I would like to design one program that can print text in any application from Spread Sheets to Web Browsers

Ideally, the application will be able to run on both Linux and winblows, but winblows is a secondary goal. The main focus will be to make it operate on a Linux platform

I really need some assistance planning the design of the application. For instance: Wx is a very popular module for windows management, but there is also Tk, Tkx and Gtk2. I'm really not sure where to start in planning and designing the structure of the application. Can any one point me in the right direction please?

Thanks, in advance.

Replies are listed 'Best First'.
Re: Quick-Buttons Toolbar
by Corion (Patriarch) on Feb 26, 2011 at 21:58 UTC

    Personally, I would first try to get the core functionality right, that is, finding windows and sending events to them, instead of worrying about how to make things look pretty.

    For X Windows, there is X11::GUITest, which, if it is anything like its Win32 counterpart, can send keystrokes and mouseclicks to windows. I'd first write a self-contained program that sends a series of keystrokes to a given window. Making a pretty interface will still take a lot of time, but if you don't have the core functionality, all the chrome of a shiny GUI won't help you make your application.

      Usking X11::GUITest was a good place to start. Thanks.

Re: Quick-Buttons Toolbar
by PyrexKidd (Monk) on Feb 28, 2011 at 00:27 UTC

    I was able to successfully send keys to the window.

    Since I need an event based model, a GUI interface, and Wx and Events to work together, I need to have the main loop of Wx perform the polling of WindowIds

    This is how I did it using events:

    #!/usr/bin/perl use 5.010001; use strict; use warnings; use X11::GUITest qw/:ALL/; use Event; my $window_id = 0; my $last_window_id = 0; #check the id of the window with focus every 'interval' Event->timer( interval => 1, cb => \&check_focus_id ); sub check_focus_id { #check the current window ID my $curr_id = GetInputFocus; #if it has changed if ($curr_id != $window_id){ #write the change to the log; write_to_log ($curr_id); #shift variables out, I thought of using an array to do this #but for testing purposes I chose this to explicative $last_window_id = $window_id; $window_id = $curr_id; } #if focus ID is the same else { #for now do nothing } } #write to log sub write_to_log { my $id = shift; open my $LOG, '>>', '/home/jon/log.out'; say $LOG $id; close $LOG; return 1; } #start the main event loop Event::loop;

    Can someone assist me in figuring out how to get Wx to poll like that, or a better method of polling?

    Thanks

Re: Quick-Buttons Toolbar
by PyrexKidd (Monk) on Feb 28, 2011 at 07:42 UTC

    The story so far...

    • For the time being I have decided to use Wx as the GUI engine for my application.
    • Figuring out Wx with only C++ documentation is interesting. (I'm not very familiar with C++)
    • My biggest challenge was determining a method to 'watch' for input focus to change. (there weren't many examples, I did find one in python, which--well,looks like line noise to me)
    • I still need to determine a method for sending special keys, i.e.: ^N, etc
    • and as someone pointed out on IRC, I don't format like a normal person... I'll leave that up to you to decide...

    anyway, here is my first attempt on all of this. I was successful at sending text to the screen. As I am sure there is a better way to do all of this, Comments, suggestions, jokes, are welcomed, even invited.

    #!/usr/bin/perl use strict; use warnings; use 5.010001; use Wx; my $last_id = 0; my $curr_id = 0; my @id_list = (undef) x 3; package MyFrame; use base 'Wx::Frame'; use Wx::Event qw(EVT_BUTTON EVT_TIMER); sub new { #use X11::GUITest qw/:ALL/; use X11::GUITest qw/GetInputFocus SetInputFocus SendKeys/; my $ref = shift; my $self= $ref->SUPER::new( undef, #Parent Window -1, #Window ID (-1 means any) 'wxPerl', #Window Title [-1, -1], #Default Position [171, 30], #size ); #create panel my $panel = Wx::Panel->new( $self, #parent window -1, #id ); #create send key button my $button = Wx::Button->new( $panel, # Parent Panel -1, # id 'Send Hello', # label [85, 1], # position [-1, -1], # default size ); # create Quit button my $button_quit = Wx::Button->new( $panel, # Parent Panel -1, # id 'Quit', # label [1, 1], # position [-1, -1], # default size ); my $timer = Wx::Timer->new( $self, # Parent Frame -1, # Timer ID ); $timer->Start(1); EVT_TIMER $self, $timer,\&do_stuff; #send key button EVT_BUTTON $self, $button, \&on_click_button; #send key click quit EVT_BUTTON $self, $button_quit, \&on_click_quit; return $self; } sub do_stuff { my $this_id = GetInputFocus; if ($this_id != $id_list[2]){ print STDOUT $this_id . "\n"; shift @id_list; push @id_list, $this_id; } else { #do nothing for now } } sub on_click_quit { my ($self, $event) = @_; $self->quit; } sub on_click_button { my ($self, $event) = @_; say @id_list; SetInputFocus $id_list[0]; print STDOUT "sent to: $id_list[0], last: $id_list[1], $id_list[2] +\n"; # SendKeys QuoteStringForSendKeys("%N"); SendKeys ('hello'); $self->SetTitle( 'Clicked'); } package MyApp; use base 'Wx::App'; sub OnInit { my $frame = MyFrame->new; $frame->Show(1); } package main; my $app = MyApp->new; $app->MainLoop;