in reply to Re: Gtk2: TextView to file
in thread Gtk2: TextView to file

I tried the suggestions that were offered but nothing is printed out in the terminal. EDIT: Nevermind I got it to work. It needed the code "my $buffer = $textview_nav->get_buffer". Also, I noticed that this seems to work with a 'popup' window. I'm still writing the code so I hope it will have no problems. Yeah I know, I'm very fancy!!
#!/usr/bin/perl -w use strict; use warnings; use Glib qw/TRUE FALSE/; use Gtk2 '-init'; #global variables my $interface; my $mapped = 0; my $progressbar_uasposition; my $progressbar_waytemp2; my $progressbar_waytemp1; my $progressbar_wayfinal; my $progressbar_waytemp3; my $progressbar_uas; #shared Variables my $die: shared = 0; my $count_waytemp3 = 0; my $count_uas = 0; my $count_uasposition = 0; my $current_controls = 0; $interface = Gtk2::Window->new('popup'); $interface->set_position('mouse'); $interface->set_border_width( 5); #$interface->set_decorated(0); #Gtk2::Window::set_decorated($interface, 0); #Eventbox for capturing the mouse click my $eventbox_interface = Gtk2::EventBox->new; #table to contain the widgets my $table_interface = Gtk2::Table->new( 14, 2, FALSE); #spacers for the widgets my $spacer1 = Gtk2::Label->new(); my $spacer2 = Gtk2::Label->new(); my $spacer3 = Gtk2::Label->new(); my $spacer4 = Gtk2::Label->new(); #Labels my $label_downloading = Gtk2::Label->new( 'Downloading'); my $label_uploading = Gtk2::Label->new( 'Uploading'); #Bold text for the Main Labels my $fontdescription = Gtk2::Pango::FontDescription->new; $fontdescription->set_weight( 'bold'); $label_uploading->modify_font( $fontdescription); $label_downloading->modify_font( $fontdescription); #The interface for Nav #text features my $buffer = Gtk2::TextBuffer->new(); #Label my $label_nav_waypoint = Gtk2::Label->new( ); my $label_nav_waytemp = Gtk2::Label->new( 'waytemp'); my $label_nav_uas = Gtk2::Label->new( 'uaspf.txt'); #Markup for the text labels $label_nav_waypoint->set_markup( '<b>Waypoint Generation</b>'); #Create the scrolled window that the lat and long entries will be disp +layed in my $swindow_nav = Gtk2::ScrolledWindow->new( undef, undef); $swindow_nav->set_policy( 'automatic', 'automatic'); $swindow_nav->set_shadow_type( 'etched-out'); my $textview_nav = Gtk2::TextView->new; $swindow_nav->add( $textview_nav); #Buttons to compile the waypoint files my $button_nav_waypoint = Gtk2::Button->new( 'Compile/Send'); my $button_nav_connect = Gtk2::Button->new( 'Connect'); #Horizontal separator my $hseparator_nav = Gtk2::HSeparator->new; #Progressbar for the waytemp upload and the uaspf.txt download $progressbar_waytemp3 = Gtk2::ProgressBar->new; $progressbar_uas = Gtk2::ProgressBar->new; #pack the widgets into the table $table_interface->attach_defaults( $label_nav_waypoint, 0, 2, 0, 1); $table_interface->attach_defaults( $spacer1, 0, 2, 1, 2); $table_interface->attach_defaults( $swindow_nav, 0, 2, 2, 3); $table_interface->attach_defaults( $spacer2, 0, 2, 3, 4); $table_interface->attach_defaults( $button_nav_waypoint, 0, 2, 4, 5); $table_interface->attach_defaults( $spacer3, 0, 2, 5, 6); $table_interface->attach_defaults( $hseparator_nav, 0, 2, 6, 7); $table_interface->attach_defaults( $label_uploading, 0, 2, 7, 8); $table_interface->attach_defaults( $label_nav_waytemp, 0, 1, 8, 9); $table_interface->attach_defaults( $progressbar_waytemp3, 0, 2, 9, 10) +; $table_interface->attach_defaults( $spacer4, 0, 2, 10, 11); $table_interface->attach_defaults( $label_downloading, 0, 2, 11, 12); $table_interface->attach_defaults( $label_nav_uas, 0, 1, 12, 13); $table_interface->attach_defaults( $progressbar_uas, 0, 2, 13, 14); $table_interface->attach_defaults( $button_nav_connect, 1, 2, 14, 15); #Button function; starts the connection $button_nav_waypoint->signal_connect( 'button-press-event' => sub {my +$buffer = $textview_nav->get_buffer; my $string = $buffer->get_text($ +buffer->get_start_iter, $buffer->get_end_iter, 1); print "$string\n"; +}); $button_nav_connect->signal_connect( 'button-press-event' => sub { my +$button_nav_label = $button_nav_connect->get_label; if ( $button_nav_l +abel eq 'Connect') { $button_nav_co +nnect->set_label( 'Disconnect'); } else { $button_nav_co +nnect->set_label( 'Connect'); } }); #add the widgets to the window: widgets->table->eventbox->window $eventbox_interface->add( $table_interface); $interface->add( $eventbox_interface); $interface->show_all; $interface->signal_connect( 'button-release-event' => sub { Gtk2->main +_quit}); #allows the popup window entries to work correctly my $rc = Gtk2::Gdk->keyboard_grab($interface->window, 0 ,Gtk2->get_cur +rent_event_time); Gtk2->main;

Replies are listed 'Best First'.
Re^3: Gtk2: TextView to file
by zentara (Cardinal) on Aug 11, 2007 at 15:20 UTC
    It needed the code "my $buffer = $textview_nav->get_buffer".

    Doh!!! I shouldn't have missed that. I see the problem now.... in your code you create the textview (with a an automatic buffer ), and you thought it was using $buffer.

    #my $textview_nav = Gtk2::TextView->new; # should have been my $textview_nav = Gtk2::TextView->new_with_buffer($buffer);
    If you had used new_with_buffer($buffer) , then reading from the global $buffer would have worked. As it now is written, your global $buffer is unused.

    P.S. You might also want to add a line to make the textview have the cursor when it opens.

    my $rc = Gtk2::Gdk->keyboard_grab($textview_nav->window, 0 , Gtk2->get_current_event_time);

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum