Dear all, how do we create an mouse click event binding for a grid? I look over the docs and cannot find any clue about it. google did not help either. Thank you Regards Hendra _______________________________________________ wxruby-users mailing list wxruby-users@rubyforge.org http://rubyforge.org/mailman/listinfo/wxruby-users
hendra kusuma wrote:> how do we create an mouse click event binding for a grid? > I look over the docs and cannot find any clue about it. > google did not help either.evt_grid_cell_left_click Documented here: http://docs.wxwidgets.org/stable/wx_wxgrid.html#wxgrid Sorry, this appears to be missing from wxRuby docs. If in doubt, it can be worth searching the wxWidgets docs as a backup. Just prepend ''wx'' to the class name for searching (eg wxGrid). With any widget, you can also use the lower-level mouse event handlers, eg grid.evt_left_up alex
Hello Hendra, You should be able to monitor evt_left_down, and evt_left_up for a click event. The actual detecting of a Click, would require that in evt_left_down, you store the mouse position, and the time at which the event was generated, then on evt_left_up, take the current time, and subtract the time at which your program received evt_left_down, to see if it''s within a normal time frame to qualify it as a click, and you would want to make sure that the mouse position matched the first one, then fire off your method you want to execute when a click occurs on the grid. Take a look at the Event sample folder, for a way to do this, through a custom event handling system. hth, Mario 2009/3/30 hendra kusuma <penguinroad at gmail.com>> Dear all, > > how do we create an mouse click event binding for a grid? > I look over the docs and cannot find any clue about it. > google did not help either. > > Thank you > Regards > Hendra > > > > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >-- Mario Steele http://www.trilake.net http://www.ruby-im.net http://rubyforge.org/projects/wxruby/ http://rubyforge.org/projects/wxride/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20090331/3aede8d4/attachment.html>
On Tue, Mar 31, 2009 at 1:25 PM, Alex Fenton <alex at pressure.to> wrote:> hendra kusuma wrote: > >> how do we create an mouse click event binding for a grid? >> I look over the docs and cannot find any clue about it. >> google did not help either. >> > > evt_grid_cell_left_click > > Documented here: http://docs.wxwidgets.org/stable/wx_wxgrid.html#wxgrid > > Sorry, this appears to be missing from wxRuby docs. If in doubt, it can be > worth searching the wxWidgets docs as a backup. Just prepend ''wx'' to the > class name for searching (eg wxGrid). > > With any widget, you can also use the lower-level mouse event handlers, eg > grid.evt_left_up > > alexThanks It works, with an unexpected behavior thought While I can catch the click event now, mouse click won''t move the selection to clicked cell anyway to fix this?> > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20090401/e5500154/attachment.html>
hendra kusuma wrote:> On Tue, Mar 31, 2009 at 1:25 PM, Alex Fenton <alex at pressure.to > <mailto:alex at pressure.to>> wrote: > > > With any widget, you can also use the lower-level mouse event > handlers, eg grid.evt_left_up >> > It works, with an unexpected behavior thought > While I can catch the click event now, > mouse click won''t move the selection to clicked cell > anyway to fix this?If you trap an event like this, you must call "event.skip" in the event handler if you want normal processing of the event (eg moving the selection on a click) to proceed. a
On Wed, Apr 1, 2009 at 5:36 PM, Alex Fenton <alex at pressure.to> wrote:> hendra kusuma wrote: > >> On Tue, Mar 31, 2009 at 1:25 PM, Alex Fenton <alex at pressure.to <mailto: >> alex at pressure.to>> wrote: >> >> >> With any widget, you can also use the lower-level mouse event >> handlers, eg grid.evt_left_up >> >> > >> It works, with an unexpected behavior thought >> While I can catch the click event now, >> mouse click won''t move the selection to clicked cell >> anyway to fix this? >> > > If you trap an event like this, you must call "event.skip" in the event > handler if you want normal processing of the event (eg moving the selection > on a click) to proceed. >you mean something looks like this? evt_grid_cell_left_click() { do_click() } def do_click() puts ''ok'' event.skip end> > > a > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20090402/22ead047/attachment.html>
On Thu, Apr 2, 2009 at 10:15 AM, hendra kusuma <penguinroad at gmail.com>wrote:> > > On Wed, Apr 1, 2009 at 5:36 PM, Alex Fenton <alex at pressure.to> wrote: > >> hendra kusuma wrote: >> >>> On Tue, Mar 31, 2009 at 1:25 PM, Alex Fenton <alex at pressure.to <mailto: >>> alex at pressure.to>> wrote: >>> >>> >>> With any widget, you can also use the lower-level mouse event >>> handlers, eg grid.evt_left_up >>> >>> >> >>> It works, with an unexpected behavior thought >>> While I can catch the click event now, >>> mouse click won''t move the selection to clicked cell >>> anyway to fix this? >>> >> >> If you trap an event like this, you must call "event.skip" in the event >> handler if you want normal processing of the event (eg moving the selection >> on a click) to proceed. >> > > you mean something looks like this? > evt_grid_cell_left_click() { do_click() } > > def do_click() > puts ''ok'' > event.skip > end >Ups, Not working Can you give me suggestion on my problem? This is what I want to do I fill datagrid with all data from a table first column is boolean, an is set with set_col_format_bool (appear as checkbox) I set all other columns to readonly so when I click the first column, it will change the value (true or false) and update the table (the primary key is at 2nd column) current state I click cell on first column, move focus to clicked-cell click the cell again, cell change to textbox, I can change the value there expected behavior click cell on first column, and it toggle the value between checked and unchecked Thanks Hendra> > > >> >> >> a >> _______________________________________________ >> wxruby-users mailing list >> wxruby-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/wxruby-users >> > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20090402/d8bbe3bc/attachment-0001.html>
I believe there are a couple of problems. First, you haven''t actually passed the GridEvent to your handler. Second, it seems you only want to call event.skip if event.get_col is 0 (I''ve never used a Grid, I''m assuming the cols and rows are 0-indexed); It sounds like you want normal event processing to stop if they simply check the checkbox in the first column, ie the cell doesn''t get highlighted afterwards, and then normal event processing to continue on any other column. I think the code you want should probably look more like this: evt_grid_cell_left_click() { |e| do_click(e) } # pass GridEvent as e def do_click(event) # get the event passed earlier puts ''ok'' event.skip unless event.get_col == 0 # do normal processing except on 1st col end Also, since evt_grid_cell_left_click doesn''t take an id parameter, it seems you''ll probably have to put that entire chunk of code inside of a class declaration for the Grid itself (either extending Grid or the variable referencing it). Otherwise wxRuby won''t know what control you''re trying to catch an event on. If there''s some other way around that, someone please correct me. Hope this helps, --Steve 2009/4/1 hendra kusuma <penguinroad at gmail.com>> > > On Thu, Apr 2, 2009 at 10:15 AM, hendra kusuma <penguinroad at gmail.com>wrote: > >> >> >> On Wed, Apr 1, 2009 at 5:36 PM, Alex Fenton <alex at pressure.to> wrote: >> >>> hendra kusuma wrote: >>> >>>> On Tue, Mar 31, 2009 at 1:25 PM, Alex Fenton <alex at pressure.to <mailto: >>>> alex at pressure.to>> wrote: >>>> >>>> >>>> With any widget, you can also use the lower-level mouse event >>>> handlers, eg grid.evt_left_up >>>> >>>> >>> >>>> It works, with an unexpected behavior thought >>>> While I can catch the click event now, >>>> mouse click won''t move the selection to clicked cell >>>> anyway to fix this? >>>> >>> >>> If you trap an event like this, you must call "event.skip" in the event >>> handler if you want normal processing of the event (eg moving the selection >>> on a click) to proceed. >>> >> >> you mean something looks like this? >> evt_grid_cell_left_click() { do_click() } >> >> def do_click() >> puts ''ok'' >> event.skip >> end >> > > Ups, Not working > > Can you give me suggestion on my problem? > This is what I want to do > > I fill datagrid with all data from a table > first column is boolean, an is set with set_col_format_bool (appear as > checkbox) > I set all other columns to readonly > so when I click the first column, it will change the value (true or false) > and update the table (the primary key is at 2nd column) > > current state > I click cell on first column, move focus to clicked-cell > click the cell again, cell change to textbox, I can change the value there > > expected behavior > click cell on first column, and it toggle the value between checked and > unchecked > > Thanks > Hendra > > > >> >> >> >>> >>> >>> a >>> _______________________________________________ >>> wxruby-users mailing list >>> wxruby-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/wxruby-users >>> >> >> > > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20090402/1e22da0d/attachment.html>
2009/4/2 Stephen Belcher <sycobuny at malkier.net>> I believe there are a couple of problems. First, you haven''t actually > passed the GridEvent to your handler. Second, it seems you only want to > call event.skip if event.get_col is 0 (I''ve never used a Grid, I''m assuming > the cols and rows are 0-indexed); It sounds like you want normal event > processing to stop if they simply check the checkbox in the first column, ie > the cell doesn''t get highlighted afterwards, and then normal event > processing to continue on any other column. I think the code you want > should probably look more like this: > > evt_grid_cell_left_click() { |e| do_click(e) } # pass GridEvent as e > > def do_click(event) # get the event passed earlier > puts ''ok'' > event.skip unless event.get_col == 0 # do normal processing except on 1st > col > end > > Also, since evt_grid_cell_left_click doesn''t take an id parameter, it seems > you''ll probably have to put that entire chunk of code inside of a class > declaration for the Grid itself (either extending Grid or the variable > referencing it). Otherwise wxRuby won''t know what control you''re trying to > catch an event on. If there''s some other way around that, someone please > correct me. > > Hope this helps, > --SteveThank you This almost help me Yes, I can catch the click on 1st column now, but the another problem arise the pointer does not move to the clicked cell This is what in my mind, when the 1st column is clicked def clicked(event) if event.get_col == 0 pk = @grid.get_cell_value(@grid.get_grid_cursor_row,1) val = @grid.get_cell_value(@grid.get_grid_cursor_row,0) if val == ''1'' sql = "update table set val =0 where pk = #{pk}" @grid.set_cell_value(@grid.get_grid_cursor_row,0, ''0'') else sql = "update table set val =1 where pk = #{pk}" @grid.set_cell_value(@grid.get_grid_cursor_row,0, ''1'') end @conn.execute(sql) else event.skip end end but @grid.get_grid_cursor_row will return previous row, not clicked row What to do now? also, I cannot find the syntax event.get_col in documentation can you point me to the doc page? It would be very helpful Many Thanks Hendra> > 2009/4/1 hendra kusuma <penguinroad at gmail.com> > > >> >> On Thu, Apr 2, 2009 at 10:15 AM, hendra kusuma <penguinroad at gmail.com>wrote: >> >>> >>> >>> On Wed, Apr 1, 2009 at 5:36 PM, Alex Fenton <alex at pressure.to> wrote: >>> >>>> hendra kusuma wrote: >>>> >>>>> On Tue, Mar 31, 2009 at 1:25 PM, Alex Fenton <alex at pressure.to<mailto: >>>>> alex at pressure.to>> wrote: >>>>> >>>>> >>>>> With any widget, you can also use the lower-level mouse event >>>>> handlers, eg grid.evt_left_up >>>>> >>>>> >>>> >>>>> It works, with an unexpected behavior thought >>>>> While I can catch the click event now, >>>>> mouse click won''t move the selection to clicked cell >>>>> anyway to fix this? >>>>> >>>> >>>> If you trap an event like this, you must call "event.skip" in the event >>>> handler if you want normal processing of the event (eg moving the selection >>>> on a click) to proceed. >>>> >>> >>> you mean something looks like this? >>> evt_grid_cell_left_click() { do_click() } >>> >>> def do_click() >>> puts ''ok'' >>> event.skip >>> end >>> >> >> Ups, Not working >> >> Can you give me suggestion on my problem? >> This is what I want to do >> >> I fill datagrid with all data from a table >> first column is boolean, an is set with set_col_format_bool (appear as >> checkbox) >> I set all other columns to readonly >> so when I click the first column, it will change the value (true or false) >> and update the table (the primary key is at 2nd column) >> >> current state >> I click cell on first column, move focus to clicked-cell >> click the cell again, cell change to textbox, I can change the value there >> >> expected behavior >> click cell on first column, and it toggle the value between checked and >> unchecked >> >> Thanks >> Hendra >> >> >> >>> >>> >>> >>>> >>>> >>>> a >>>> _______________________________________________ >>>> wxruby-users mailing list >>>> wxruby-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/wxruby-users >>>> >>> >>> >> >> _______________________________________________ >> wxruby-users mailing list >> wxruby-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/wxruby-users >> > > > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20090403/eb3d03af/attachment.html>
On Fri, Apr 3, 2009 at 9:05 AM, hendra kusuma <penguinroad at gmail.com> wrote:> > > 2009/4/2 Stephen Belcher <sycobuny at malkier.net> > >> I believe there are a couple of problems. First, you haven''t actually >> passed the GridEvent to your handler. Second, it seems you only want to >> call event.skip if event.get_col is 0 (I''ve never used a Grid, I''m assuming >> the cols and rows are 0-indexed); It sounds like you want normal event >> processing to stop if they simply check the checkbox in the first column, ie >> the cell doesn''t get highlighted afterwards, and then normal event >> processing to continue on any other column. I think the code you want >> should probably look more like this: >> >> evt_grid_cell_left_click() { |e| do_click(e) } # pass GridEvent as e >> >> def do_click(event) # get the event passed earlier >> puts ''ok'' >> event.skip unless event.get_col == 0 # do normal processing except on >> 1st col >> end >> >> Also, since evt_grid_cell_left_click doesn''t take an id parameter, it >> seems you''ll probably have to put that entire chunk of code inside of a >> class declaration for the Grid itself (either extending Grid or the variable >> referencing it). Otherwise wxRuby won''t know what control you''re trying to >> catch an event on. If there''s some other way around that, someone please >> correct me. >> >> Hope this helps, >> --Steve > > > Thank you > This almost help me > Yes, I can catch the click on 1st column now, but the another problem arise > the pointer does not move to the clicked cell > This is what in my mind, when the 1st column is clicked > > def clicked(event) > if event.get_col == 0 > pk = @grid.get_cell_value(@grid.get_grid_cursor_row,1) > val = @grid.get_cell_value(@grid.get_grid_cursor_row,0) > if val == ''1'' > sql = "update table set val =0 where pk = #{pk}" > @grid.set_cell_value(@grid.get_grid_cursor_row,0, ''0'') > else > sql = "update table set val =1 where pk = #{pk}" > @grid.set_cell_value(@grid.get_grid_cursor_row,0, ''1'') > end > @conn.execute(sql) > else > event.skip > end > end > > but @grid.get_grid_cursor_row > will return previous row, not clicked row > > What to do now? > also, > I cannot find the syntax event.get_col in documentation > can you point me to the doc page? It would be very helpful > > Many Thanks > Hendra >I did it I found the doc page (Wx::GridEvent), figure out how to use event object and finally did it Now my grid work just the way I want it the final source code looks like this def clicked(event) if event.get_col == 0 row = event.get_row @grid.set_grid_cursor(row, 0) pk = @grid.get_cell_value(row,1) val = @grid.get_cell_value(row,0) if val == ''0'' @dataset.filter(:no => pk).update(:print => 1) @grid.set_cell_value(row,0,''1'') else @dataset.filter(:no => pk).update(:print => 0) @grid.set_cell_value(row,0,''0'') end else event.skip end end Many thanks for all your help Regards Hendra -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20090403/edd7d5e0/attachment-0001.html>