RE: Running Gtk application in new terminal
Here you go. This code implements a simple command processor, one command of which starts up a gtk app. I tried it with an app of mine called ngdcs and it works. You might want to read up on fork and exec (man fork, man execv) but this does work for me: #include stdio.h #include stdlib.h int main() { int pid; char *argv[2]; char command[80]; printf(Enter command, either gtk or sayhello: ); while (fgets(command, sizeof(command), stdin) != NULL) { if (strcmp(command, gtk\n) == 0) { pid = fork(); if (pid == 0) { argv[0] = /usr/local/bin/ngdcs; argv[1] = NULL; (void)execv(argv[0], argv); printf(execv failed!\n); exit(1); } } else if (strcmp(command, sayhello\n) == 0) printf(hello\n); else printf(bad command\n); printf(Enter command, either gtk or sayhello: ); } } From: Abhinav singh [abhinavksing...@gmail.com] Sent: Thursday, June 05, 2014 8:52 AM To: Mazer, Alan S (389M) Cc: gtkmm-list@gnome.org Subject: Re: Running Gtk application in new terminal On Thu, Jun 5, 2014 at 8:57 PM, Alan Mazer alan.s.ma...@jpl.nasa.govmailto:alan.s.ma...@jpl.nasa.gov wrote: On 6/5/2014 12:20 AM, Gavin Lambert wrote: Quoth Abhinav singh: I am running a gtk application from another program lets call it main program. This program is command driven and proceed according to command given to it. What my problem is when the command which runs my gtk application is given into main program the terminal gets hang up till the application window is closed then only my main program is able to process further command given to it. Is there any way to run my gtk application in entire new terminal or without terminal associated with it so that my main program will be able to process the next command in the list with gtk application running in parallel? It sounds like you're asking how to run a GTK app from a shell script without waiting for it to end. You do that just like you'd do it for anything else -- you run it as a background task (usually by adding at the end of your command line). Sounds like a place for fork/exec. Your main app forks then execs the gtk app. I'm assuming this is running in a *nix environment, although there are similar constructs on Windows. ___ gtkmm-list mailing list gtkmm-list@gnome.orgmailto:gtkmm-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtkmm-list Yes, this is running in a nix* environment. Can you please provide me link of tutorial related to fork/exec or some code structure which implement something similar to what you are saying. Thanks, Abhinav ___ gtkmm-list mailing list gtkmm-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtkmm-list
RE: What is the minimum number of lines to update a gui window without user clicking a button
I'm pretty sure this is NOT thread safe. You generally need a dispatcher for that in from. I would expect lockups without a dispatcher. Sent from my Android phone using TouchDown (www.nitrodesk.com) -Original Message- From: Markus Elfring [markus.elfr...@web.de] Received: Tuesday, 20 Aug 2013, 1:44am To: L. D. James [lja...@apollo3.com] CC: gtkmm-list@gnome.org [gtkmm-list@gnome.org] Subject: Re: What is the minimum number of lines to update a gui window without user clicking a button HelloWorld::HelloWorld() : m_textview() { add(m_textview); m_textview.show(); Glib::Thread::create(sigc::mem_fun(*this, HelloWorld::cpp_app), true); } [...] void HelloWorld::cpp_app() { string texttoprint = ; Glib::RefPtrGtk::TextBuffer m_refTextBuffer; m_refTextBuffer = Gtk::TextBuffer::create(); string runit(std::string c); texttoprint += About to run a number of c++ functions\nand display the results\n; m_refTextBuffer-set_text(texttoprint); m_textview.set_buffer(m_refTextBuffer); sleep(10); // This sleep function represents any c++ function performaing a task I would like to clarify implementation details a bit more from this programming attempt. Can it be that the referenced text buffer is written in a thread-unsafe way here? How do think about to apply improved techniques and software ingredients like locks for memory consistency? (Andrew Potter and Gavin Lambert suggested also an alternative program structure. - https://mail.gnome.org/archives/gtkmm-list/2013-August/msg00135.html ) Regards, Markus ___ gtkmm-list mailing list gtkmm-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtkmm-list ___ gtkmm-list mailing list gtkmm-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtkmm-list
RE: How to update both the Console and the GTKMM gui window after running other functions
Ah. You need to call the thread init routine first. Can't remember the syntax now. Perhaps someone else can remind me or I'll check later when I get back to my office. Sent from my Android phone using TouchDown (www.nitrodesk.com) -Original Message- From: L. D. James [lja...@apollo3.com] Received: Monday, 05 Aug 2013, 12:05pm To: Mazer, Alan S (389M) [alan.s.ma...@jpl.nasa.gov] CC: gtkmm-list@gnome.org [gtkmm-list@gnome.org] Subject: Re: How to update both the Console and the GTKMM gui window after running other functions Thanks, Alan. It compiles without errors. When run I get this error at the console: Threads aren't supported! // c++ code begin // --- #include gtkmm.h #include iostream using namespace std; class myLabel: public Gtk::Window { // blah blah blah public: myLabel(); virtual ~myLabel(); protected: Gtk::Label m_label; string labeltext; string newtext; void myprocess1(void); }; myLabel::myLabel() : m_label(Hello World) { // myLabel.set_text(hello); // This line gives errors (*1) void myprocess1(); set_title(Gtkmm Programming - C++); add(m_label); m_label.show(); Glib::Thread::create(sigc::mem_fun(*this, myLabel::myprocess1), true); cout Window should be displayed endl; } myLabel::~myLabel() { } void myLabel::myprocess1(void) { labeltext = About to preform a number of processes.\n; labeltext += Each process may take up to three hours.\n; labeltext += Please carry your daily chores and wait.\n; cout labeltext endl; m_label.set_text(labeltext); sleep(10); // Back from a three hour function newtext = Back from a three hour function\n; labeltext += newtext; m_label.set_text(labeltext); cout newtext endl; sleep(10); // Back from a three hour function newtext = Back from another three hour function\n; labeltext += newtext; m_label.set_text(labeltext); cout newtext endl; } int main(int argc, char* argv[]) { if (!Glib::thread_supported()) Glib::thread_init(); else { cerr Threads aren't supported! endl; exit(1); } Gtk::Main kit(argc, argv); myLabel mylabel; Gtk::Main::run(mylabel); return 0; } // --- // c++ code end -- L. James -- L. D. James lja...@apollo3.commailto:lja...@apollo3.com www.apollo3.com/~ljames On Mon, 2013-08-05 at 08:18 -0700, Alan Mazer wrote: Take a look at this. It still doesn't have dispatchers (I'm trying to keep it simple). It's possible for this program to crash if you try to interact with the window while it's updating. Dispatchers prevent that. But this should be otherwise functional, and I didn't want adding dispatchers to make understanding the thread concept more difficult. Adding dispatchers is just one more step. All I did here was put your long-running computation into a secondary thread, and have that thread update your label. The problem with your previous approach is that what run does is display the window and label you've created and then wait for you to interact with the window. If you put your computation *before* the run, the window won't be displayed until your computation ends. If you put your computation *after the run, it won't be executed until you close the window. You can also put your computation *in* the window creation, but this means that the program won't be handling any user interactions during your computation. If you cover the window with another window, for example, and then uncover it again, it will probably be blank until your computation is over. Or if you had a button in the window, button presses would be ignored until the computation was over. What you want is for your computation to be going on at the same time as run is handling user interaction, both of them working together. So we create a thread, which is a separate function that runs simultaneously with the run. I hope this helps. You probably want to switch from a label to something with scroll bars. -- Alan ___ gtkmm-list mailing list gtkmm-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtkmm-list
RE: How to update both the Console and the GTKMM gui window after running other functions
I haven't forgotten your end goal. You need threading to get there if you want the GUI to be responsive while the long computations are taking place. I sent you a little sample code already but I can show you how it fits together on Monday. There's not much left to be done. Sent from my Android phone using TouchDown (www.nitrodesk.com) -Original Message- From: L. D. James [lja...@apollo3.com] Received: Friday, 02 Aug 2013, 5:45pm To: Mazer, Alan S (389M) [alan.s.ma...@jpl.nasa.gov] CC: gtkmm-list@gnome.org [gtkmm-list@gnome.org] Subject: Re: How to update both the Console and the GTKMM gui window after running other functions Thanks. I forgot to remind you of important details. For one I forget to mention that the “sleep(10)” function represented a function that is processing such as searching all the network drives for a string and doing other chores that might take up to three hours or more. Then when it gets back it's supposed to update the gui screen and console. I thought I had tested run(mylabel) and had problems. I should have left the line there commented out. But I'm glad to see that your update prints. However, it prints all the text at once. It doesn't print anything after a function. I uncommented the sleep(10) function. There is no window until the function ends. Then everything is printed. So if the user ran the program he would have no idea what is happening until three hours later. He might try to run the application numerous times to get something on the screen and really cause problems. My objective is to immediately print something on the gui. Then run functions. The print and update to the gui, the same way you see the console output updated. And yes. I appreciate anything I can learn about those terms (threading, etc), especially if this is what is going to be needed to update what is on the gui. I'm adding what might be a clearer description of what I'm trying to do to your new code that prints. Most likely the threading is where the sleep() and myprocess1() functions should be. // code begin // --- #include gtkmm.h #include iostream using namespace std; class myLabel: public Gtk::Window { // blah blah blah public: myLabel(); virtual ~myLabel(); protected: Gtk::Label m_label; string labeltext; string newtext; }; myLabel::myLabel() : m_label(Hello World) { // myLabel.set_text(hello); // This line gives errors (*1) void myprocess1(); set_title(Gtkmm Programming - C++); add(m_label); m_label.show(); labeltext = About to preform a number of processes.\n; labeltext += Each process may take up to three hours.\n; labeltext += Please carry your daily chores and wait.\n; cout labeltext endl; m_label.set_text(labeltext); sleep(10); // Back from a three hour function newtext = Back from a three hour function\n; labeltext += newtext; m_label.set_text(labeltext); cout newtext endl; myprocess1(); cout Window should be displayed endl; } myLabel::~myLabel() { } void myprocess1() { cout Running another process that is generating output... endl; } int main(int argc, char* argv[]) { Gtk::Main kit(argc, argv); myLabel mylabel; Gtk::Main::run(mylabel); return 0; } // --- // code end -- L. James -- L. D. James lja...@apollo3.commailto:lja...@apollo3.com www.apollo3.com/~ljames On Fri, 2013-08-02 at 15:05 -0700, Alan Mazer wrote: This is tricky to explain, but, in a nutshell, myLabel, because it's derived from Gtk::Window, is itself a window you can pass to run. You don't want to create a separate Gtk::Window object as you're doing, because run can't see it. I've removed the Gtk::Window window; line, and changed window.set_title to just set_title, and window.add to just add. With these changes, there's text in your window. I'll include the code below so you can see what I did. (I also needed to change back to the kit approach in main which you had originally, because I don't have gtkmm 3 on my computer, but you can keep your main routine using the newer approach if you prefer.) Do you want me to show you threading or would you prefer to explore that on your own? -- Alan #include gtkmm.h #include iostream using namespace std; class myLabel: public Gtk::Window { // blah blah blah public: myLabel(); virtual ~myLabel(); protected: Gtk::Label m_label; string labeltext; string newtext; }; myLabel::myLabel() : m_label(Hello World) { // myLabel.set_text(hello); // This line gives errors (*1) void myprocess1(); set_title(Gtkmm Programming - C++); add(m_label); m_label.show(); labeltext = About to preform a number of processes.\n; labeltext += Each process may take up to three hours.\n; labeltext += Please carry your daily chores and wait.\n; cout labeltext endl; m_label.set_text(labeltext); // sleep(10); // Back from a three hour function newtext = Back from a three hour function\n; labeltext += newtext; cout newtext