[Gtk-sharp-list] Stuck in gtk-demo port from c to c#

Yves Kurz yves@magnific.ch
Tue, 30 Sep 2003 14:08:58 +0200


On Mon, 2003-09-29 at 11:20, Daniel Kornhauser wrote:
> Hi guys:
> 

Hi Daniel and all... 

> 
> I'm stuck in my  gtk-demo port from c to c#, I'm sending as attachment what I 
> have done. I did not wanted to bother you with my small problems, but now  they have 
> accumulated to become a big problem.

I started too to port gtk-demo to c#. My intention was to learn
something about gtk#. But like you I'm somewhere in the middle of the
porting effort.

> I have waisted lots of time trying to figure some of these things, sorry if they are
> obvious but I'm newbie and I'm stuck. I haven't done any advances in a week thus 
> it's time to confess my sins :-). Keep in mind I'm a newbie while you read my code ...
> 
> I'll first present my coding conventions, and then go program by program talking
> about where I got stuck.
> 
> One of the first remarks is that every program is independent, because I decided
> to code the main of the gtk-demo program until the end, since it looks the hardest
> and I didn't want to be stuck from the beginning. Thus they all make their
> window from scratch. For naming them I used the save convention that Duncan used
> with test: that is each program is called, the name of the c program, prefixed 
> with demo.

Started like you, every program is independent (same reason).
> 
> e.g. buttonbox.c --> DemoButtonBoxcs
> 
> I used long names for everything, usually I make an instance of a widget the 
> same name except I start it by a small caps.
> 
> I took some liberties to write scrolledWindow instead of sw, I just think that 
> in examples you should be as explicit as possible ...
> 
> Keep in mind, I still have to clean up, port the comments in ALL the sources.
> I just copied and pasted the c comments.
> 
> If I'm infringing in any way and I wasn't explicit that I wasn't just porting 
> please let me know. I hope that just stating it in the comments is enough to 
> recognize the real authors.
> 
> I avoided porting the error handling, because I'm lazy ...
> 
> When I'm stuck in a program I just put a stuck comment //STUCK
> 
Ok, i will write what I did till now.

> Appwindow.c: Stuck at the beginning 5%
> =====================================
> Didn't find any ItemFactory examples :-(
> 
0% not started.

> DemoButtonBox.cs: Finished 100%
> ===============================
> Allmost exactly the same example.
> Couldn't find a equivalent for gtk_main() thus I used Application.Init()
> I used the prefix Gtk, in window because of ambiguous reference (Gtk.Window or Gdk.Window) 
> I used the prefix Gtk, with the casting of buttons because of bug in mcs compiler
> 		Gtk.ButtonBox bbox = null;
> 		if (horizontal == true){
> 			bbox =  new Gtk.HButtonBox();
> 		}
> 		else {
> 			bbox =  new Gtk.VButtonBox(); 
> 		}
100%

> 
> DemoChangeDisplay.c: Skipped i*(100%)
> =====================================
> My card only supports one display :-(
0% had no interest in it.

> DemoColorSelection.cs: Almost finished 95%
> ==========================================
> I could not write ExposeEventCallback.
> How the hell can I translate gdk_draw_rectangle !!!
> I initialized color to Gtk.Color.Zero couldn't find NULL equivalent in c-sharp.
99% haven't used ExposeEventHandler, but it works anyway. (see comments
in code)

> DemoDialog.cs: Allmost finished 99%
> ===================================
> I Couldn't find a good equivalent to gtk_dialog_new_with_butttons, thus I
> used MessageDialog. 
> Check how to handle response type. Can we make the button to have the binding to
> the cancel signal automagicly like in  gtk_dialog_new_with_butttons or should we
> just use the if ?
> Remark -> This is me just thinking aloud :  
> Wonder what is the best programming style when making several widgets like a label ?
> Declare a static label, for the class and use it for all the labels, or declare an 
> automatic label in each scope where it's needed and use it.
> I decided to declare a label in each scope since I consider it cleaner programming
> and I don't think it imposes a great penalty in memory ...
> Then again I don't have the slightest idea of how I compiler runs, but I
> have a Master in Computer Science... figure that out :-p
99% don't know if I did it like I should but it works.

> 
> DemoDrawingArea.cs: just interface done, no callbacks implemented 50%
> =======================================================================
> I'm lost handling colors, events, drawingareas, you name it, I don't know it
> :-(
> 
> One day, when I grow up, I'll understand pointers ... 
>                                           (Shit!!! I allready have gray hairs)
> 
0% 

> 
> Images.cs just interface done, no callbacks implemented 70%
> ============================================================
> I got timed out in the use of the timeout >:-G
> 
60% progressive image loading is not finished and demo crashes as when
you click twice on the button.

> 
> ItemFactory.cs: Nothing done, stuck at the beginning. -3.14%
> ============================================================
> OUCH, it really hurts when you can't get past the third line of code
> 
0% 

> DemoMenus.cs: Finished 100%
> ==========================
> Copied Menus from Duncan and just did some modifications in order
> to match exactly to the example.
99% wrote it without copying so I'm not sure if it's done right

> DemoPanes.cs:  just interface done, no callbacks implemented 80%
> =================================================================
> Guess what ?
> I Got stuck in the callbacks, :-)
> My question is plain and simple :
> If I have two widgets that call the same callback, how can I find out 
> the name of the widget that invoked the callback ???
5% started and stopped (went to holidays:)

> PixBufs.cs: Skipped  (Planck's constant)
> =======================================
> Didn't even have to try to know I would get stuck right at the begining.
> Pixbuf isn't a trivial widget.
98% works like it should but there is some code in the original demo
which doesn't work by me in gtk# (see comment in code line 116)
> 
> SizeGroups.cs : Finished 100%
> =============================
> I Love to use cp. 
> Allready implemented by Duncan :-)

0% 

> DemoStockrowser.cs:  just starting doing the interface 1%
> ===================
> I'm sure somewhere somebody know how to say :  
>   store = gtk_list_store_new (2, STOCK_ITEM_INFO_TYPE, G_TYPE_STRING);
> in c#
> I simply didn't find in monodoc that the StockItem Structure had an
> Info member :-(
> Stuck doing ListStore how de hell do they work ?!?!?!
0%

> TextWidget.cs : just starting doing the interface 5%
> ====================================================
> stuck implementing create_tags :
> 
>   gtk_text_buffer_create_tag (buffer, "heading",
> 			      "weight", PANGO_WEIGHT_BOLD,
> 			      "size", 15 * PANGO_SCALE,
> 			      NULL);
> TextBuffer.CreateTag should exist but it doesn't :-(
0%

> DemoEditableCells Stuck in the callbacks 70%
> ============================================
> I definitely don't understand how ListStore's work, I should look
> at an example. Wait a minute I'm actually TRYING to code the example !
> Bummer
> :-(
0%

> DemoListStore Skipped
> =====================
> According to the previous corollary I just skipped this example.
0%

> 
> DemoTreeStore, stuck in the begining 20%
> ========================================
> Lesson learned, I'm not capable of doing a linked list with struct in c#
> 
> If somebody ever knows how to implement a linked list that looks like this
> 
> struct ListNode
> {
>         string        component;
>         int             indentation;
>         ListNode     Link;
> };
> 
> and can avoid a cycle error, please tell me !
> Anyway I did it with a class and it worked fine ...
> But as always I got stuck, couldn't figure how to use TreeStore in a 
> Callback.
0%


> DemoMain.cs 5%
> ==============
> Should I use reflection to get the properties out of the examples, or should
> I do it by hand like in this examples ?

0%

That's it.. here is my code: http://www.magnific.ch/gtkdemo.tar.gz (at
least as long my internet connections is alive).. 

Hope it will help you bit


yves