Discussion:
Drag & Drop
(too old to reply)
sbungay
2007-01-29 19:04:32 UTC
Permalink
The image of the item being dragged appears to the lower right of the
mouse cursor. What I want to do is have it work like in the ide. When
you drag a control around on a form it appears to be held by the mouse
at the spot where you pressed the mouse button on it.
I have grepped through the class files of gambas2 for 'drag' to see
if I could locate it's events and work-out how it accomplishes the task
but came up empty. If anyone can point me in the right direction I'd
appreciate it.

Steve.
Richard
2007-01-29 23:53:48 UTC
Permalink
I am not sure if this is a bug, or if I just don't know what is happening.
I have two RadioButtons which I use to select the audio recording mode; Mono
or Stereo. The recording mode can be stored as a TRUE or FALSE value in an
array of settings for a number of scheduled recording events.

The user may select one of ten stored settings for recordings by clicking on a
control and the values for a selected recording are copied to the controls on
the form so that they may be reviewed or altered.

The click event handler for the RadioButton controls does not have to do very
much as the occurrence of the event means that the control value must be
"TRUE", so I just use it to copy the value of the stereo RadioButton (or the
complement of the mono RadioButton) to the storage array.

Unfortunately, when I update the RadioButton value from the stored array then,
regardless of the stored value, the RadioButton click event is triggered. If
I am expecting a TRUE value to be changed to the FALSE value stored for the
new current recording then I will be disappointed as my click event handler
does not see the value which has just been written from the array, and
incorrectly updates the array value with the TRUE value I was trying to
overwrite.

Do you think it is me or the RadioButton being unreasonable?

Richard
Richard
2007-01-30 22:49:13 UTC
Permalink
I have prepared a test program which demonstrates the issue described in
yesterday's message in a few lines of code shown below. There is a source
archive of the test program attached.

To use the test program just use the spinner control to select each of the 5
test cases and compare the result shown in the RadioButton controls to the
illustration on the form.

On reaching case 4 try setting RadioButton1 to TRUE and step back down to zero
to see different, but still incorrect results.

There is no difference in behaviour under either 1.9.46a or 1.9.47. Any
guidance on how to get the correct results would be gratefully received.

' Gambas class file

PUBLIC SUB _new()

END

PUBLIC SUB Form_Open()

END

PUBLIC SUB SpinBox1_Change()

SELECT CASE SpinBox1.Value
CASE 0
RadioButton2.Value = TRUE
CASE 1
RadioButton2.Value = FALSE
CASE 2
RadioButton2.Value = TRUE
CASE 3
RadioButton2.Value = FALSE
CASE 4
RadioButton2.Value = FALSE
END SELECT

END

PUBLIC SUB Button1_Click()

ME.Close

END
Stefano Palmeri
2007-01-31 06:52:33 UTC
Permalink
Post by Richard
I have prepared a test program which demonstrates the issue described in
yesterday's message in a few lines of code shown below. There is a source
archive of the test program attached.
To use the test program just use the spinner control to select each of the 5
test cases and compare the result shown in the RadioButton controls to the
illustration on the form.
Hello. I modified your example to make it work. It seems you have to use
only the TRUE value. I'm on Gambas 1.9.47
Bye,

Stefano
Post by Richard
On reaching case 4 try setting RadioButton1 to TRUE and step back down to zero
to see different, but still incorrect results.
There is no difference in behaviour under either 1.9.46a or 1.9.47. Any
guidance on how to get the correct results would be gratefully received.
' Gambas class file
PUBLIC SUB _new()
END
PUBLIC SUB Form_Open()
END
PUBLIC SUB SpinBox1_Change()
SELECT CASE SpinBox1.Value
CASE 0
RadioButton2.Value = TRUE
CASE 1
RadioButton2.Value = FALSE
CASE 2
RadioButton2.Value = TRUE
CASE 3
RadioButton2.Value = FALSE
CASE 4
RadioButton2.Value = FALSE
END SELECT
END
PUBLIC SUB Button1_Click()
ME.Close
END
Benoit Minisini
2007-01-31 17:12:03 UTC
Permalink
Post by Richard
I am not sure if this is a bug, or if I just don't know what is happening.
I have two RadioButtons which I use to select the audio recording mode;
Mono or Stereo. The recording mode can be stored as a TRUE or FALSE value
in an array of settings for a number of scheduled recording events.
The user may select one of ten stored settings for recordings by clicking
on a control and the values for a selected recording are copied to the
controls on the form so that they may be reviewed or altered.
The click event handler for the RadioButton controls does not have to do
very much as the occurrence of the event means that the control value must
be "TRUE", so I just use it to copy the value of the stereo RadioButton (or
the complement of the mono RadioButton) to the storage array.
Unfortunately, when I update the RadioButton value from the stored array
then, regardless of the stored value, the RadioButton click event is
triggered. If I am expecting a TRUE value to be changed to the FALSE value
stored for the new current recording then I will be disappointed as my
click event handler does not see the value which has just been written from
the array, and incorrectly updates the array value with the TRUE value I
was trying to overwrite.
Do you think it is me or the RadioButton being unreasonable?
Richard
The RadioButton Click event is only raised when its value is set to TRUE. You
get no events when it is set to FALSE.

Regards,
--
Benoit Minisini
Richard
2007-01-31 19:25:36 UTC
Permalink
Post by Stefano Palmeri
Hello. I modified your example to make it work. It seems you have to use
only the TRUE value. I'm on Gambas 1.9.47
Bye,
Stefano
The RadioButton Click event is only raised when its value is set to TRUE.
You get no events when it is set to FALSE.
Regards
Thank you both very much for setting me straight. Stefano, I'd love to know
how you knew to change a RadioButton value by setting the value of another
RadioButton. I stared at it for hours without guessing that approach.

Benoit, are there any other controls which can only be assigned a TRUE value
while a program is running? I tried last night to use a pair of ToggleButtons
in my program instead of four RadioButtons and got some results I didn't
expect. I was going to explore that problem tonight but now I know I can use
RadioButtons (with a lot more code to sort out which ones need to be set to
TRUE) I will leave the Toggle Button until I have more time.

Regards, and again, many thanks,

Richard
Stefano Palmeri
2007-01-31 22:41:46 UTC
Permalink
Post by Richard
Thank you both very much for setting me straight. Stefano, I'd love to know
how you knew to change a RadioButton value by setting the value of another
RadioButton. I stared at it for hours without guessing that approach.
This is from the Gambas help:
---------------------------------------------------------
RadioButton

This implements a radio button control.
Radio buttons having the same parent are mutually exclusive. Only one can be
selected at the same time.
----------------------------------------------------------


They are different from CheckBoxes, which are not mutually exclusive.

Ciao,

Stefano
Richard
2007-01-31 23:00:42 UTC
Permalink
Post by Stefano Palmeri
Post by Richard
Thank you both very much for setting me straight. Stefano, I'd love to
know how you knew to change a RadioButton value by setting the value of
another RadioButton. I stared at it for hours without guessing that
approach.
---------------------------------------------------------
RadioButton
This implements a radio button control.
Radio buttons having the same parent are mutually exclusive. Only one can
be selected at the same time.
----------------------------------------------------------
They are different from CheckBoxes, which are not mutually exclusive.
Ciao,
Stefano
Thanks Stefano, I had understood the operation, I just hadn't realised that I
wouldn't be allowed to toggle the TRUE button in a pair. By choosing just one
to set to either TRUE or FALSE, I had expected that the "other" button would
become the complement of the one I was assigning a value.

My program is switching between mono and stereo for both the input and the
output. I am storing the required mode in two boolean variables; one for
input and one for output. I was updating the form controls by writing the
value of each variable into one of the input and one of the output
RadioButton controls. This depended on the mono/stereo pairs of RadioButtons
being updated in a way not supported by Gambas.

Following your advice I have added two more event handlers (for the "mono"
buttons) and a few extra lines to figure out which RadioButton must be set to
TRUE. It is a lot less "elegant" but has the distinct advantage of working
properly :~)

Richard
Benoit Minisini
2007-01-31 16:56:13 UTC
Permalink
Post by sbungay
The image of the item being dragged appears to the lower right of the
mouse cursor. What I want to do is have it work like in the ide. When
you drag a control around on a form it appears to be held by the mouse
at the spot where you pressed the mouse button on it.
I have grepped through the class files of gambas2 for 'drag' to see
if I could locate it's events and work-out how it accomplishes the task
but came up empty. If anyone can point me in the right direction I'd
appreciate it.
Steve.
I will add a Drag.IconX and a Draw.IconY properties to define the drag icon
hot spot.

Regards,
--
Benoit Minisini
sbungay
2007-02-01 04:48:36 UTC
Permalink
You're the best Benoit. If I had extra cash I'd be sponsoring this project.
Post by Benoit Minisini
Post by sbungay
The image of the item being dragged appears to the lower right of the
mouse cursor. What I want to do is have it work like in the ide. When
you drag a control around on a form it appears to be held by the mouse
at the spot where you pressed the mouse button on it.
I have grepped through the class files of gambas2 for 'drag' to see
if I could locate it's events and work-out how it accomplishes the task
but came up empty. If anyone can point me in the right direction I'd
appreciate it.
Steve.
I will add a Drag.IconX and a Draw.IconY properties to define the drag icon
hot spot.
Regards,
Continue reading on narkive:
Loading...