[Gtk-sharp-list] Newbie questions with code

Aaron Oxford aaron at hardwarehookups.com.au
Fri Mar 16 09:50:38 EDT 2007


Hi all,

I realise I've been a bit slack with providing evidence of my 
problems. This is a two parter with code for each, covering all the 
topics I've discussed so far. First up is just something simple that 
seems broken in the Dialog class, or maybe the ScrolledWindow.

             Gtk.Dialog dlg = new Dialog(caption, GtkWindow.getWin(), 
DialogFlags.Modal);
             dlg.AddButton(Gtk.Stock.Yes, Gtk.ResponseType.Yes);
             dlg.AddButton(Gtk.Stock.No, Gtk.ResponseType.No);
             dlg.DefaultResponse = Gtk.ResponseType.None;
             ScrolledWindow sw = new ScrolledWindow();
             Label l = new Label(" a very very very very .... long string ");
             l.Wrap = true;
             sw.Add(l);
             dlg.VBox.PackStart(sw);
             dlg.SetDefaultSize(320, 160);

             dlg.ShowAll();
             int resp = dlg.Run();
             dlg.Destroy();

If you call this with a long string in message, the label simply 
clips at the border of the dialog. Without the ScrolledWindow, you 
end up with an OK looking dialog. If the message is REALLY long 
though, the window goes off the top and bottom of the screen, so you 
can't close it (except if you know about Alt-F4). I thought the 
ScrolledWindow would fix this. Am I doing something wrong? Forcing 
scrollbars with the policy shows bars I can't move.

Second, and more importantly, the TreeView again. I need to control 
where the cursor goes, so the user doesn't become confused as to what 
they are viewing in the main pane. It would be cool to be able to 
highlight a given row as well as having a selection. Is this possible?

In any case I've found a way to crash my program by trying the code 
below. Note I'm in a RowActivated handler, and this code only crashes 
*some* of the time. As I write this and test the code it's gone from 
working, to crashing, to not working (not crashing) and now seems to 
be consistently not working.

         void machineList_RowActivated(object o, RowActivatedArgs args)
         {
             TreePath argsPath = editListPath;
             if (args != null) argsPath = args.Path;

             // If the file has been edited, we need to ask the user 
if they want to discard their changes
             // by loading a different file.
             if (fileChanged)
             {
                 if (argsPath != editListPath)
                 {
                     if (!App.window.showQuestion("Are you sure you 
want to...", "File Changed"))
                     {
                         //   *** CRASH RIGHT HERE ***
                         machineListWidget.SetCursor(editListPath, 
machineListWidget.Columns[0], false);
                         return;
                     }
                 }
                 else
                 {
                     return;
                 }
             }

I'm starting to get really nervous, because this sort of thing:

System.AccessViolationException: Attempted to read or write protected 
memory. This is often an indication that other memory is corrupt.
    at Gtk.TreeView.gtk_tree_view_set_cursor(IntPtr raw, IntPtr path, 
IntPtr focus_column, Boolean start_editing)
    at Gtk.TreeView.SetCursor(TreePath path, TreeViewColumn 
focus_column, Boolean start_editing)
    at Wavelet_Tracker.MachineManager.machineList_RowActivated(Object 
o, RowActivatedArgs args)

Has popped up before as I mentioned, and is popping up at random all 
the time now. This could be really bad news for the stability of my 
app, which was just finally starting to mature in that respect. Any 
help with this in particular would be very much appreciated.

Aaron.
---------------------------------------------------------------------------------
Aaron Oxford   -   aaron+hardwarehookups .com .au
Director, Innovative Computer Solutions (Aust) Pty. Ltd.
49 Maitland Rd, Mayfield, NSW 2304 Australia
http://www.ic-solutions.com.au
Developer, SourceForge project VioLet Composer
http://sourceforge.net/projects/buzz-like



More information about the Gtk-sharp-list mailing list