Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Can GTK3 be driven externally?

by haukex (Bishop)
on Jan 30, 2020 at 16:19 UTC ( #11112107=note: print w/replies, xml ) Need Help??


in reply to Can GTK3 be driven externally?

I am far from an expert on Gtk, but from some quick googling it sounds like one might set up a GSocketListener and work with GSocketConnections.

Replies are listed 'Best First'.
Re^2: Can GTK3 be driven externally?
by holandes777 (Scribe) on Jan 30, 2020 at 17:18 UTC
    Thank you, I am OK with socket programming. My question is: how do I blend the socket server with the GTK3 main loop?
    What I am trying to do is to use the GTK3 window as a display attached to a server that receives messages and changes the display to what the messages say needs to be displayed.
    Additionally, I'd like to have a button in GTK3 which would allow a user to select something.

      Disclaimer: This is still just from quick Googling, I actually haven't done this myself, but I hope these pointers help. It looks to me like you would set up a GSocketService which has an incoming event, get the GSocketConnection's GSocket file descriptor, and then register that with a GIOChannel via g_io_add_watch. It also appears that one can write a handler for the client in a blocking manner in a separate thread via GThreadedSocketService.

      As an example:
      I have a GTK3 display that displays 3 choices:
      Cats
      Dogs
      Rats
      However the backend system (another program) finds we are out of Rats, we do, however, have scorpions. The backend system contacts the display and sends a message "change the third button to Scorpions", without any user interaction at the display. The result:
      Cats
      Dogs
      Scorpions
        Thanks for answering
        This almost certainly is what I need
        My application seg faulted, I will research why, but if you have a clue, please tell me!
        use Gtk3; my $window = Gtk3::Window->new ('toplevel'); my $button = Gtk3::Button->new ('Quit'); $button->signal_connect (clicked => sub { Gtk3::main_quit }); $window->add ($button); $window->show_all; my $id = Gtk3->timeout_add(1000, \&handler, $data); Gtk3::main; sub handler { my ($data) = @_; print "timed out ... \n"; # return 1 if you want the handler to be called again later # return 0 to stop the handler from being called again return 1; } result: perl test0.pl Segmentation fault (core dumped)
        Thank you, I will check it out

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11112107]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2020-10-29 14:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (271 votes). Check out past polls.

    Notices?