COMP2100
Assignment 3 Hints and FAQFrequently Asked Questions
See also the questions and answers from the the second FAQ lecture.
The code you gave us won't compile. Is it broken, or am I doing something wrong?
Go back to the first GUI lab and read the instructions on setting the EXG environment variable.
What does a tree widget look like?
Check out the screenshot in the third project lecture.
In Q1, can I just change the values of top_margin and bottom_margin to zero and get rid of the black border?
No. That's not enough. If you do that, you will often end up with half a page blank at the bottom. I want you to figure out how to make the drawing area exactly the right size for the document.
I'm doing Q1 using one-line pages, but now the first word on each line is missing. What am I doing wrong?
Assume that you're adding a word to the last line of a page, and it won't fit on that line. If you trace through the calls to add_word, flush_line, flush_page and start_new_page, you'll realise that when the first word of the new page is written to the page pixmap in add_word, the foreground colour in the graphics context is white.
You said to do the tree widget using a new visitor, but I can't figure out how to make that work. What do you suggest?
Strange, isn't it? It looks at first as though it should be easy, but when you try to fit this operation into the VISITOR framework, it just doesn't seem to go. I think it might be easier to do this using an "Expression Version 3"-style implementation. Try adding a feature to XML_ELEMENT and its subclasses that returns a GTK_TREE_ITEM representing that element and anything below it. (A bit like the pretty_print feature.)
Old Frequently Asked Questions
These are some questions and answers from 2003 that might be relevant and/or helpful.
How do I find the class files for classes in EXG or eiffel-gtk? The finder tool can't find them, nor can short. (How does the compiler find them?)
The information about where to find them is in the ACE file. Instead of typing
finder gtk_widgettype
finder oops.ace gtk_widgetIt works the same way with short.
(I'm leaving this next question and answer here, even though you probably don't need to know about draw_pixmap this year. The same method for finding things out will still work for other features of EXG/GTK that you need to find out about this year.)
I have been trying to find out about the draw_pixmap feature in class GDK_PIXMAP. I can't find it in the GDK referrence. Any suggestions?Firstly, to find the Eiffel documentation, cd to your Assignment 3 directory, then do
short oops.ace gdk_pixmap | lessNow remember that in less, the slash character gives you a search. So type
/draw_pixmapto search for the feature you want, and you should see:
draw_pixmap (gc: GDK_GC; source: GDK_PIXMAP; xsrc, ysrc, xdest, ydest, width, height: INTEGER)There's no header comment to help us, so we'll either have to guess and experiment to figure out what the arguments are and how they work, or else look it up in the GDK reference. Let this be a lesson to you on the importance of good header comments.
To look it up, go to http://www.gtk.org (following the link at the bottom of Lecture 13: GUI I). Now follow the link to API Reference (in the Documentation box on the left-hand side) and then the link to GDK in the lower section headed "GTK+ 1.2 API Reference (obsolete)". OK we're there.
Looking at the table of contents, the first place to try is in the "Bitmaps and Pixmaps" section, but there's nothing there about drawing them. The next step is to look for drawing functions, since we're trying to find out about draw_pixmap. Sure enough, searching for the word "pixmap" in the "Drawing Primitives" section gives me some quite good documentation, and it looks like it matches up fine with the Eiffel argument list. (As is often the case, the first argument of the C function is the target of the Eiffel call. The rest of the arguments line up precisely.)
I keep getting this error message:
"Gtk-CRITICAL **: file gtkbin.c: line 217 (gtk_bin_add): assertion `bin->child == NULL' failed."What does it mean, and what can I do about it?
This looks to me like the C equivalent of a require clause violation. You're trying to add something to a container, and the precondition is that it shouldn't already have a child. The expression bin->child == NULL is something like child = Void in Eiffel. Look for places where you try to add more than one child to a widget, and check whether it can really take more than one. Most widgets can't. If you want to put several other widgets inside them, you need to make a VBOX or an HBOX the child, and then pack things inside the box.
The program is now Oops but the given program has the name as "Socks". Do I have to change to "Oops" or leave it like that?
Oops! Yes, change the name in the title bar at the top of the window to "Oops".
My "open" menu works, but I don't know whether to open the new document in a different window or the same window. What I should do?
Open the new file in the same window, replacing the old document.
Even older Frequently Asked Questions
These are some questions and answers from 2002 that might be helpful.
Where can you find the short forms to the EXG/GTK libraries? What do you have to type on the command line?
There are links to the web versions on the Reading page or the first GUI lecture.
If you want to do it from the command line, you have to tell it what ACE file to use to know where to look: you do it like this
comp2100@partch short socks.ace gtk_menu_itemIn the file selection dialogue boxes, is there a way to filter so that only certian file types get shown in the file list box?
Not that I know of. Looking at the code for class EXG_FILE_SELECTION_MODAL, I can't see anything helpful. That class creates and uses an object of class GTK_FILE_SELECTION, so perhaps you can find something useful in there. If so, then maybe you could create your own subclass of EXG_FILE_SELECTION_MODAL with an extra feature to set the filtering. That would be cute.
Looking at GTK_FILE_SELECTION, the only feature I can see that might be relevant is complete (pattern: STRING). You might want to play around with that.
Note that having the file selection apply a filter so that it only displays .sxw files (2004 note: and/or .xml files) is not part of the requirements of the assignment, so don't worry if you can't do this.
How do GTK_MENU, GTK_MENU_ENTRY, GTK_MENU_ITEM, GTK_MENU_BAR work? There's nothing in the short forms to help at all.
Confusing, isn't it? They certainly don't work the way I would have guessed.
But I'm not going to tell you the answer. Part of what this assignment is about is learning to read documentation. The information you need is in the GTK documentation for C programmers, at www.gtk.org. Big hint: Look at the GTK Tutorial.
Copyright © 2004, Ian Barnes, The Australian National University
Feedback & Queries to
comp2100@iwaki.anu.edu.au
Version 2004.4, 27 May 2004, 17:50:16