It is currently Fri Dec 06, 2019 9:40 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 32 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Make a ListIcon column editable
PostPosted: Thu Oct 02, 2014 1:46 am 
Offline
User
User

Joined: Sat Apr 12, 2014 11:31 am
Posts: 25
This example demonstrates how to make a given column in a ListIconGadget editable

Code:
EnableExplicit


ImportC "-gtk"
  g_object_set(object, property.p-UTF8, value, v=0)
  gtk_cell_layout_get_cells(col)
  g_signal_connect(instance, signal.p-ascii, callback, vdata, destroy=0, flags=0) As "g_signal_connect_data"
EndImport
 


ProcedureC _MakeColumnEditable_Callback(Cell, Path.s, newTxt.s, Gadget)
  Protected  Row  = Val(Path)
  SetGadgetItemText(Gadget, row, PeekS(@newTxt, -1, #PB_UTF8), GetGadgetData(Gadget))
EndProcedure

Procedure MakeColumnEditable(ListIcon, Column)
  Protected col = gtk_tree_view_get_column_(GadgetID(ListIcon), Column)
  Protected aList = gtk_cell_layout_get_cells(col)
  Protected renderer = g_list_nth_data_(alist, 0)
  g_list_free_(aList)
  SetGadgetData(ListIcon, Column)
  g_signal_connect(renderer, "edited", @_MakeColumnEditable_Callback(), ListIcon)
  g_object_set(Renderer, "editable", 1)
 
EndProcedure


OpenWindow(1, 100, 100,400, 200, "ListIcon Editing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(1, 5, 5, 390, 190, "Column1", 90)
gtk_tree_view_set_enable_search_(GadgetID(1), 0)
AddGadgetColumn(1, 1, "Column2", 200)
MakeColumnEditable(1, 1)

AddGadgetItem(1,0, "001" + #LF$ + "Test 1")
AddGadgetItem(1,1, "002" + #LF$ + "Test 2")
AddGadgetItem(1,2, "003" + #LF$ + "Test 3")
;
Repeat
  Define Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow

End


Last edited by empty on Wed Oct 08, 2014 4:57 pm, edited 4 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Make a ListIcon column editable
PostPosted: Thu Oct 02, 2014 10:33 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1656
Location: Germany
Sorry, but your code example doesn't work for me (tested with PB 5.30 on Ubuntu 14.04 x86 Unity, Linux Mint 17 x86 Cinnamon and Kubuntu 9.04 x86 KDE in both ASCII and Unicode mode). It always displays an invalid memory access in
Code:
  g_object_set_(Renderer, UTF8("editable"), 1)

After changing that line to
Code:
  g_object_set_data_(Renderer, UTF8("editable"), 1)
your code starts without error but unfortunately writing the new text into a cell doesn't work. When placing a Debug statement into your _MakeColumnEditable_Callback(), this callback is never executed. By the way, Linux callbacks have always to be ProcedureC, but even this modification doesn't change the fact that the callback won't be called...

Another small hint: instead of your procedure UTF8() you may redefine the API functions using pseudotype P-UTF8 letting PureBasic do the conversion work for you... :wink:
Code:
ImportC ""
  g_signal_connect(*Instance, SignalName.P-UTF8, *Callback, *Data)
  g_object_set_data(*Object.GObject, KeyName.P-UTF8, *Data)
EndImport

So instead of
Code:
  g_object_set_data_(Renderer, UTF8("editable"), 1)
you may simply use
Code:
  g_object_set_data(Renderer, "editable", 1)


Top
 Profile  
Reply with quote  
 Post subject: Re: Make a ListIcon column editable
PostPosted: Thu Oct 02, 2014 11:32 am 
Offline
User
User

Joined: Sat Apr 12, 2014 11:31 am
Posts: 25
True it should be ProcedureC

I know about the pseudotypes, but I tried to avoid imports for this example.

Have only tried it with 64bit distributions (among them Ubuntu 14.04) and it worked perfectly there in ASCII and Unicode.
Something to investigate.

Have you tried to import g_object_set?
g_object_set(object, property.p-utf8, value, v=0)

Just to make sure that there's a terminating NULL.


Top
 Profile  
Reply with quote  
 Post subject: Re: Make a ListIcon column editable
PostPosted: Thu Oct 02, 2014 11:53 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1656
Location: Germany
empty wrote:
Have you tried to import g_object_set?
g_object_set(object, property.p-utf8, value, v=0)

Just to make sure that there's a terminating NULL.

I have tried both
Code:
ImportC ""
  g_object_set_data(*Object.GObject, KeyName.P-UTF8, Value.I)
  g_object_set(*Object.GObject, KeyName.P-UTF8, Value.I, Terminator.I = 0)
EndImport
but in the tested x86 Distros the callback is never activated...


Top
 Profile  
Reply with quote  
 Post subject: Re: Make a ListIcon column editable
PostPosted: Thu Oct 02, 2014 12:10 pm 
Offline
User
User

Joined: Sat Apr 12, 2014 11:31 am
Posts: 25
Hm. Interesting. I need to install a 32 bit distro at some point.


Top
 Profile  
Reply with quote  
 Post subject: Re: Make a ListIcon column editable
PostPosted: Thu Oct 02, 2014 5:33 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1656
Location: Germany
empty wrote:
Have only tried it with 64bit distributions (among them Ubuntu 14.04) and it worked perfectly there in ASCII and Unicode.

Are you really sure to have posted the correct code? I have tested the code from your first posting also on Ubuntu 14.04 x64 with KDE and again
Code:
g_object_set_(Renderer, UTF8("editable"), 1)
throws an error in Unicode mode (and a similar one in ASCII mode):
Quote:
[WARNING] GLib-GObject (WARNING): g_object_set_valist: object class 'GtkCellRendererText' has no property named 'w.GtkVBo1'

After changing that line as mentioned above to
Code:
g_object_set_data_(Renderer, UTF8("editable"), 1)
your example code is executed but again the new text is not written into the modified cell and your callback isn't called...


Top
 Profile  
Reply with quote  
 Post subject: Re: Make a ListIcon column editable
PostPosted: Thu Oct 02, 2014 8:47 pm 
Offline
User
User

Joined: Sat Apr 12, 2014 11:31 am
Posts: 25
Are you using the gtk3 sublibrary by any chance? That's when I got the warnings on g_object_set_() too (the reason is the missing termination, and so it's trying to set whatever string fragment it finds on the stack). Despite the warnings it still works here, but it surely won't under many other circumstances. However, this can be fixed by importing the function manually as discussed above (although of course it will keep spitting out warnings on a couple of native functions...).

Edit
Alright, I just tried it on Ubuntu 32bit, and in fact, g_object_set_() seems to be broken. Yet, manually importing that function fixes all problems (even with gtk3).
Will need to try it on a KDE distro soon. As our current project is aimed at a specific distro, it's not high on my list, but surely curiosity will get the better part of me ;)).

Edit2
I was just informed that the code has been successfully tested on KUbuntu 32bit and CentOS 64bit (with the import fix)... So I'm not sure why I wouldn't work for you, Shardik. :/

I'll re-post the code with the imports later.


Top
 Profile  
Reply with quote  
 Post subject: Re: Make a ListIcon column editable
PostPosted: Fri Oct 03, 2014 1:11 am 
Offline
User
User

Joined: Sat Apr 12, 2014 11:31 am
Posts: 25
Updated the above code to work on 32 bit and KDE distros as well.


Video (Ubuntu 32bit)


Top
 Profile  
Reply with quote  
 Post subject: Re: Make a ListIcon column editable
PostPosted: Fri Oct 03, 2014 10:41 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1656
Location: Germany
Thank you for your patience and for even making a video. This video possibly gives a hint what may be different on our systems. In your video you edit the cell value directly in your table. On all my tested systems it looks like my screenshot below: after selecting a line and pressing a key a separate input field is opened below the ListIconGadget...

Image

I have tested your updated code example on Ubuntu 14.04 x64 with KDE and on pressing <Enter> or <Tab> the new text is not written into the cell of the selected row...

Nevertheless I want to pinpoint to some errors or shortcomings in your example code although changing them do not enable your example to work successfully on my tested distros:

- In procedure MakeColumnEditable() you have forgotten to free the obtained g_list:
GTK+ 2 Reference Manual wrote:
gtk_tree_view_column_get_cell_renderers ()
...
The list must be freed with g_list_free().

- gtk_tree_view_column_get_cell_renderers is deprecated since Gtk 2.18 (although still working):
GTK+ 2 Reference Manual wrote:
gtk_tree_view_column_get_cell_renderers ()
...
Warning

gtk_tree_view_column_get_cell_renderers has been deprecated since version 2.18 and should not be used in newly-written code. use gtk_cell_layout_get_cells() instead.

- The cell renderers in the list returned from gtk_tree_view_column_get_cell_renderers() are in no particular order. So you can't simply use the 1st list entry because that may change and indeed I have already experienced this on different distributions in that I had to switch between list element 0 and 1...
GTK+ 2 Reference Manual wrote:
gtk_tree_view_column_get_cell_renderers ()
...
Returns a newly-allocated GList of all the cell renderers in the column, in no particular order.


Again thank you for your example and your help!


Top
 Profile  
Reply with quote  
 Post subject: Re: Make a ListIcon column editable
PostPosted: Fri Oct 03, 2014 11:01 am 
Offline
User
User

Joined: Sat Apr 12, 2014 11:31 am
Posts: 25
Quote:
I have tested your updated code example on Ubuntu 14.04 x64 with KDE and on pressing <Enter> or <Tab> the new text is not written into the cell of the selected row...

When you start typing even on an unmodifed listicongadget, you're invoking the infamous search feature of gtk treeviews. ;)
You must of course select a cell and press enter or double click on a cell before you can edit a cell. That's the way gtk handles it.
By the way, you can switch off column search by calling gtk_tree_view_set_column_search_(Gadget, 0), which is a good idea in many cases anyway.


Quote:
- In procedure MakeColumnEditable() you have forgotten to free the obtained g_list


That is true, thanks for the reminder! :)


Quote:
- The cell renderers in the list returned from gtk_tree_view_column_get_cell_renderers() are in no particular order. So you can't simply use the 1st list entry because that may change and indeed I have already experienced this on different distributions in that I had to switch between list element 0 and 1...
[/quote]
That doesn't matter in our case, because purebasic only uses on renderer to fill the ListIconGadget, so you can safely use the first one.
It should indeed be replaced by gtk_cell_layout_get_cells in the code at some point even though it works on gkt3, but alas, currently it's not a good idea to compile pb code against gtk3 amyway


Last edited by empty on Fri Oct 03, 2014 3:17 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Make a ListIcon column editable
PostPosted: Fri Oct 03, 2014 3:13 pm 
Offline
User
User

Joined: Sat Apr 12, 2014 11:31 am
Posts: 25
And another update.
- Replaced gtk_tree_view_column_get_cell_renderers()
- now frees the allocated list
- since Imports seem to be unavoidable, all string related functions are imported manually, thus we can get rid of the UTF8 conversion function
- while I was at it, fixed a bug in the wstring() function so now it correctly converts Ascii and Unicode strings form UTF8 strings, depending on the compiler settings

tested on various different distros


Top
 Profile  
Reply with quote  
 Post subject: Re: Make a ListIcon column editable
PostPosted: Sat Oct 04, 2014 4:52 am 
Offline
Addict
Addict
User avatar

Joined: Tue Apr 29, 2003 9:18 pm
Posts: 1459
Location: North by Northwest
Works with ManjaroBox 64 (Arch) but only with gtk2.
As soon as I switch to the gtk3 subsystem I get the error message:
The compiler wrote:
[20:48:56] [WARNING] Gtk (ERROR): GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported
[20:48:58] The debugged executable quit unexpectedly.

This is not the first time I see valid gtk3 API beeing rejected by PureBasic.(and the gtk2 library used instead)

_________________

I am to provide the public with beneficial shocks.
Alfred Hitshock


Top
 Profile  
Reply with quote  
 Post subject: Re: Make a ListIcon column editable
PostPosted: Sun Oct 05, 2014 1:23 am 
Offline
User
User

Joined: Sat Apr 12, 2014 11:31 am
Posts: 25
Thanks for testing! :)

Yeah PB has its fair share of issues with GTK3...


Top
 Profile  
Reply with quote  
 Post subject: Re: Make a ListIcon column editable
PostPosted: Tue Oct 07, 2014 10:36 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1656
Location: Germany
empty wrote:
When you start typing even on an unmodifed listicongadget, you're invoking the infamous search feature of gtk treeviews. ;)
You must of course select a cell and press enter or double click on a cell before you can edit a cell. That's the way gtk handles it.

Sorry for all the fuss caused by me. It simply seems to have been caused by my wrong handling:
- When selecting a line by a left click and pressing a letter or number key in one of your previous code examples, a new line below the ListIconGadget will be opened (like in my snapshot above). The input into this external box won't be written on <Enter> into the respective cell of the selected line!
- When selecting a line by a left click and pressing a letter or number key in your current code example, the line will be selected but nothing else will happen.
- When left double clicking a line, the double clicked line will be selected but nothing else will happen.
- When left clicking a line and doing a 2nd left click after a short wait (in effect doing two single clicks in succession), the line will be selected, the text in the 2nd column will be selected and you are able to change the text. After pressing <Enter>, <Tab>, <Up arrow> or <Down arrow>, the modified text will be finally displayed in the modified cell.

With the last input method your previous examples and your current example are finally working on my Ubuntu 14.04 x64 distribution with KDE... :wink:

Thank you for your help and your repeated improvements of your code example!


Top
 Profile  
Reply with quote  
 Post subject: Re: Make a ListIcon column editable
PostPosted: Tue Oct 07, 2014 2:39 pm 
Offline
User
User

Joined: Sat Apr 12, 2014 11:31 am
Posts: 25
Thanks for your response :)

No worries, that way we have tested it on an even wider range of systems :)
Glad it works for you now


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 32 posts ]  Go to page 1, 2, 3  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye