How to use gtkmm-3 and standard input together?

3

I want to make a program with Gtk that reads data from standard input and interprets by doing drawings in a DrawingArea .

The concept is simple, but I came across a problem: after I call Gtk::Application::run the only code written by me to execute is the on_draw sign of DrawingArea .

I need to receive the default entry and I can not do this in the on_draw method because the program would stop responding.

What I want is to be able to send data at any time, and the drawing updates in real time.

Drawing input, interpretation, and display on the screen are easy to implement, but doing them together seems like a daunting task.

So how could I do it? A simple example would be very useful (basically what I want is to be able to enter text while the Gtk::Application::run function executes)

    
asked by anonymous 28.03.2014 / 05:31

2 answers

1

I've never used gtkmm, but in "standard" gtk I see two ways to do this (in linux) ...

  • The simplest way: Raise a thread by reading the standard input with fgets and including the data in a GAsyncQueue handled by a timer on the main thread. The queue is to prevent the thread from accessing the gui message queue at an "undue" time.

  • More complicated: "encapsulate" the standard input handle into a GIO (via g_unix_input_stream) and treat it like any other data source. This only uses a thread and avoids any synchronization problems; is what I usually use.

  • 09.04.2014 / 03:52
    0

    One solution to your problem is to use interprocess communication ( IPC ). That way, you divide your program into two parts:

    • The first one will start the other process (program) that will do the drawings and then only works to receive the input values of the user.
    • The second part will "listen" to the commands sent by the first process and make the drawings.

    To do this, you can use gtkmm-3 itself ( example ) or another library that does the serving. For example: Boost.Interprocess .

        
    02.04.2014 / 04:20