Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Can GTK3 be driven externally?

by holandes777 (Scribe)
on Jan 30, 2020 at 16:05 UTC ( [id://11112104]=perlquestion: print w/replies, xml ) Need Help??

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

I am a GTK neophyte: I would like to create a program that: 1) has a display (Gtk3) containing text fields and a button 2) can receive messages from other programs (socket) which modify the text fields (externally driven change) 3) and can send a message to another program when the button is pressed (via a socket) All the examples I have seen end in "Gtk3->main();", how do I get that to check on incoming messages?

Replies are listed 'Best First'.
Re: Can GTK3 be driven externally?
by haukex (Archbishop) on Jan 30, 2020 at 16:19 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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11112104]
Approved by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-26 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found