I think you kind of misunderstand the problem. It is quite simple to
open another thread and call set_text of your label from there. The
problem is that this will probably crash your program, as gtkmm is not
thread-safe. That's why you need to make sure that your set_text doesn't
overlap with the gtk main loop that updates the GUI.
And _that_ is the thing complicated to implement. At least I think so. I
never did this before, but you made me think about this once again and
it raised my interest, so eventually I will come up with a solution
later. Or somebody else will.
Am 01.08.2013 16:11, schrieb L. D. James:
Actually, Jonas, there is something like that in Gtkmm. Alan
understand what I have explained, and this is what we are working on.
I appreciate your description to me about how complicated it is, and
your advise to me that it might be too complicated for me to handle...
and of course, that is the problem.
First. I don't think it's that complicated. I just can't do it
because currently I don't know how to. Once I know how, it'll be a
very simple matter. I believe it's a simple matter for Alan, and I'm
sure, later today he and I will fix up the missing links in my crude code.
I believe, as I described below, the problem is lack of description in
the documentation and example url that I linked below. I'm sure it's
covered in the documentation, but not as an example. Hopefully the
developers will fix this oversight in the example link. Then the next
person who wants to simply log updated text to an already opened gui
window (without the user clicking on anything) would be able to easily
do it.
I know you can update to a gui window just as you do to the console
because there are many examples in the url. However, in the examples
they are doing it by having the user click on a button. I can easily
do it that way (outputting to both the gui and the console) but I
don't want the user to have to click. I don't want my application to
have to pause. I want the user to be able to just glance at the
window at anytime and be able to see the last thing what was sent to
the console, and in my three line Java code below.
And again, I'm certain that after today I'll be able to have a three
lines (absolutely less than 5) to output text to both the console and
the gui window such as:
// sample code begin
// -------------------------------------
String updatetext = "About to run a process that might take an hour...
sit back and wait...\n";
System.out.printl(updatetext);
textArea.append(updatetext);
int count = 0;
TimeUnit.SECONDS.sleep(3600); // Scanning all the local and network
hard drives for files larger than 1 gig
// Scanning all the local and network hard drives for files larger
than 1 gig
updatetext = "The scan has completed with " << count << " files found";
System.out.println(updatetext);
textArea.append(updatetext);
// -------------------------------------
// sample code end
I believe the above Java working example (from one of my Java
applications) should clearly show exactly what I'm trying to do. The
sleep function isn't sleep in my code. It's a function to go out and
work and it take about an hour to complete.
-- L. James
--
L. D. James
lja...@apollo3.com <mailto:lja...@apollo3.com>
www.apollo3.com/~ljames
On Thu, 2013-08-01 at 15:43 +0200, Jonas Platte wrote:
I understand what kind of application you try to write. But as I
already said, this is no good approach to start learning the basics
because it's a complicated thing that involves creating a thread that
runs concurrently to the one in which the window runs. The problem
you have here which you don't have on the console, is that if you
stop updating the window (the main loop is stuck because of long
comutations or such a thing), the window manager thinks it's not
responding and will show an error message. If you don't output
anything on the console, you don't output anything. That's no problem.
And about your experiences on forums: That is exactly what I want to
say. Even if other languages or libraries have a simple possibility
to do this, there is nothing like that in gtkmm, at least I can't
remember seeing something like this. And on the mailing list it
doesn't seem like anyone does, either.
Am 01.08.2013 15:28, schrieb L. D. James:
I wont the window to be updated when there is new text to update to it.
Thank of a program that updates to console out. If a process runs
and only take one second you might want to output a "." to indicate
that it has itterated and and some point update a status saying
"scan completed.. moving on to analysis of the scann".
The next process might take an hour or two. There is no reason to
have any updates to the console out, or the gui window for the hour
while the next process is running. Personally I would find it a
waste of cycles to have to program your code to have to keep polling
or checking the gui window when it has no reason to output anything
to it.
In Java it's simple. The GUI window is there and the console is
there. From my routine I can do anything I won't to do without any
timer. I just run code. At some point I want to show the user an
update. I just add these simple lines to my code:
// computer code
//------------------------------------------------
String updatetext = "About to run a process that might take an
hour... sit back and wait...\n";
cout << updatetext << endline;
textArea.append(updatetext);
// ------------------------------------------------
// code end
I appreciate your taking the time to try to understand my
objective. Just like you might not be understanding it, many people
might be missing the objective. The developers who wrote all the
sample at
https://developer.gnome.org/gtkmm-tutorial/3.2/gtkmm-tutorial.html
probably missed the point, that is why there isn't an example
included with the documents.
After we get this figured out and working, there is a chance that a
new section to include this might be added.
Of course it's something that a good programmer could probably
figure out. But again, a good programmer could probably figure out
most of the samples in the list without being given specific
examples. There is a lot of duplication in the list. But again, I
believe this important task is an oversight that deserves attention.
I have described this chore in a number of forums. Many people
start out by saying it's a complicated matter to implement. Since
so many people appears to think it's complicated, I believe this
should warrant a mention in the docs.
Again, the task is to simply append, to text that is already
displayed to a user in the gui window at the same time writing to
the console.
-- L. James
--
L. D. James
lja...@apollo3.com <mailto:lja...@apollo3.com>
www.apollo3.com/~ljames <http://www.apollo3.com/%7Eljames>
On Thu, 2013-08-01 at 14:55 +0200, Jonas Platte wrote:
You wrote:
/I'm just trying to have a gui window set that I can continually
update from a function, ie (myfunction())./
But _when_ should the window be updated?
If you want to update the UI every X seconds, you can use a timeout
signal. You shouldn't let the code execute independently from
gtkmm. This is only usable when you execute code that takes long,
and as you seemingly try to learn the basics of gtkmm, the best
would be to just start with a different approach.
And about my example not working: I'm not sure what's the problem,
perhaps you have to call show_all on the window before calling run.
I only use glade for my UI's, so I'm not very familiar with the
initialization part.
Am 01.08.2013 14:19, schrieb L. D. James:
You said:
-----------------------------------------------------------------------------
*You're problem is that your "myLabel" class isn't a label but a
window. You're deriving it from Gtk::Window.*
*Normally, you wouldn't derive your own label, I wonder what you
wanted to accomplish with that...*
-----------------------------------------------------------------------------
I'm sure your question is rhetoric. However I'll clarify it
anyway. I'm very novice when it comes to classes and gtkmm. I'm
so new to gtkmm that I haven't up to this point written anything
that actually works except to copy a few examples and look at
them. I still don't fully understand them.
None of the examples I have found has a functionality to be able
to append to data that is presented without the user clicking a
button.
I'm trying to get a window that has text data in it and have a way
to continue with various c++ functions that will log the output to
the gui window while at the same time logging the output to std::cout.
I wrote something very crude in an effort to clarify what I'm
trying to do.
I cleaned my progress up as much as I could to something that
would actually compile and give an idea of how far I have getting
in attempting to achieve what I have described.
If I were a little more confused about C++ and showed a line: (cin
<< "Hello" << endl;) and said I was trying to print hello to the
console, it should be clear to a C++ programer and novice such as
me as well to understand what is wrong with the line and to advise
that "cin" is for console in and "cout" is for console out. I
hope it would be known by my description of what I'm trying to
accomplish. At present, the code isn't doing it, because I don't
know exactly what code to type to accomplish what I'm describing
in my summary.
I appreciate your input... and again, I'm sure your comment was
rhetoric.
I studied and compiled your example without errors. The output is
identical to my crude attempt. There is no text in the window. I
appreciate your line by line description. When I find a way to
get it to actually work I'll keep it as reference and continue to
study the line by line examples to more fully digest the details.
As far as using signals, if it turns out that is the only way to
accomplish my objective, I'll eventually get around to it, because
I will stay with it until it's working. I'm not intentionally
eliminating anything. I'm just trying to have a gui window set
that I can continually update from a function, ie (myfunction()).
By the way, the closest that I could find on the gtkmm example
site is the progress bar example. I spent a lot of time studying
it, but at present it was too complicated for me to figure out how
to remove all the buttons, show a text screen and where to place
my function.
-- L. James
--
L. D. James
lja...@apollo3.com <mailto:lja...@apollo3.com>
www.apollo3.com/~ljames <http://www.apollo3.com/%7Eljames>
On Thu, 2013-08-01 at 02:27 +0200, Jonas Platte wrote:
You're problem is that your "myLabel" class isn't a label but a
window. You're deriving it from Gtk::Window.
Normally, you wouldn't derive your own label, I wonder what you
wanted to accomplish with that...
To make clear how you would structure your code with an own
Window class normally, here is a new example:
#include <gtkmm.h>
class myWindow : public Gtk::Window
{
protected:
Gtk::Label myLabel;
public:
myWindow();
void set_main_label(Glib::ustring); // Glib::ustring is just
another string class. It's used by gtkmm and is fully compatible
with std::string
}
myWindow::myWindow()
// instead of set_text, you could also pass the string to be
shown by the label in its constructor:
: myLabel("Hello...") // constructing myLabel with "Hello..." as
argument
{
myLabel.set_text("Hello..."); // setting myLabel's text via
method
add(myLabel); // I read you used Java somewhen, there the
syntax would be "this->add(myLabel);". You just don't need the
"this->" in C++
}
// you could also just make myLabel public, but I consider that
bad style
void myWindow::set_main_label(Glib::ustring str)
{
myLabel.set_text(str);
}
int main()
{
Gtk::Main kit(argc, argv);
myWindow win;
win.set_main_label("Changed the text");
kit.run(win); // if you declare that kit thing, you should
also use it instead of the static function ^^
return 0;
}
The thing is, you have only got one thread here. And the window
is when calling run, not before. This was just to make clear how
to structure it. Adding a seperate thread would be much too
complicated I think. You should understand how to let the program
react the certain events first, I think. And for your purpose it
would be enough to change the label after a certain amount of
time, thus a timeout signal, right?
One last thing: When you call set_text of a Gtk::Label, and then
change the string passed to set_text, that won't affect the
label. You normally would just call set_text every time instead
of changing some string (but you could even simply derive your
own Label class to get that behaviour).
_______________________________________________
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list