sliderbox bug: Still respond to mouse wheel when its disabled

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

sliderbox bug: Still respond to mouse wheel when its disabled

Jorge Carrión
A sliderbox with Enabled property to False still respond to mouse wheel.
I've write a little class as a  to workaround with this code:


Export
Inherits SliderBox
Public Const _Similar As String = "SpinBox,SliderBox"
Public Const _drawWith As String = "SliderBox"

Private obs As Observer

Public Sub _new()

   obs = New Observer(Me.Children[1]) As "Spin"

End

Public Sub spin_mousewheel()

 If Me.enabled = False Then Stop Event

End

But I think that it will be better fix the bug.

Best regards.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: sliderbox bug: Still respond to mouse wheel when its disabled

Fernando Cabral
Hi, gambas is new to me, but regex is not so new. But I am baffled with the
following result:

str = "A#BB##CCC###"
print RegExp.Replace(str, "[#]+", ";")
    A;BB;;CCC;;;
str = "A#BB##CCC###"
print RegExp.Replace(str, "[#][#]*", ";")
    A;BB;;CCC;;;
str = "A#BB##CCC###"
print RegExp.Replace(str, "##**", ";")
    A;BB;;CCC;;;

In my opinion, in every example above the result should be:
A;BB;CC
Nevertheless, gambas always displays A;BB;CCC;;;.

Am I missing something,, or does gambas has a bug in this point?



--
Fernando Cabral
Blogue: http://fernandocabral.org
Twitter: http://twitter.com/fjcabral
e-mail: [hidden email]
Facebook: [hidden email]
Telegram: +55 (37) 99988-8868 <%2837%29%2099988-8868>
Wickr ID: fernandocabral
WhatsApp: +55 (37) 99988-8868 <%2837%29%2099988-8868>
Skype:  fernandojosecabral
Telefone fixo: +55 (37) 3521-2183 <%2837%29%203521-2183>
Telefone celular: +55 (37) 99988-8868 <%2837%29%2099988-8868>

Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
nenhum político ou cientista poderá se gabar de nada.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: RegExp.Replace() question (was: sliderbox bug: Still respond to mouse wheel when its disabled)

Tobias Boege-2
On Fri, 28 Apr 2017, Fernando Cabral wrote:

> Hi, gambas is new to me, but regex is not so new. But I am baffled with the
> following result:
>
> str = "A#BB##CCC###"
> print RegExp.Replace(str, "[#]+", ";")
>     A;BB;;CCC;;;
> str = "A#BB##CCC###"
> print RegExp.Replace(str, "[#][#]*", ";")
>     A;BB;;CCC;;;
> str = "A#BB##CCC###"
> print RegExp.Replace(str, "##**", ";")
>     A;BB;;CCC;;;
>
> In my opinion, in every example above the result should be:
> A;BB;CC
> Nevertheless, gambas always displays A;BB;CCC;;;.
>
> Am I missing something,, or does gambas has a bug in this point?
>

We had this topic a few days ago [1]. When you use RegExp.Replace(),
the greediness of all quantifiers is inverted. So when you use

  "[#]+"

under RegExp.Replace(), this has the same meaning as the expression
(in PCRE syntax)

  "[#]+?"

matching lazily (or ungreedily) against the string, which explains
the result you get. If you want greedy behaviour (what you expected),
then you have to use ungreedy quantifiers:

  Print RegExp.Replace("A#BB##CCC###", "[#]+?", ";")
  Print RegExp.Replace("A#BB##CCC###", "[#][#]*?", ";")
  Print RegExp.Replace("A#BB##CCC###", "##*?", ";")
  ---
  A;BB;CCC;
  A;BB;CCC;
  A;BB;CCC;

Yes, admittedly it is strange behaviour of RegExp.Replace() to invert
the greediness of all quantifiers and it was discovered just a few days
ago. I don't know if it is going to be fixed though. I bet there was a
rationale behind this setting, but we'll have to wait for a comment of
Benoit who wrote the code.

Regards,
Tobi

[1] https://sourceforge.net/p/gambas/mailman/message/35802891/

PS: When you want to talk about a new topic, make a new thread and don't
    compose your email by replying to an existing message from the mailing
    list. Currently our conversation about RegExp.Replace() takes place
    in a thread about a specific SliderBox bug, which makes it harder for
    people in the future who are searching for this discussion.

--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: RegExp.Replace() question

Benoît Minisini
Le 29/04/2017 à 13:48, Tobias Boege a écrit :
>
> Yes, admittedly it is strange behaviour of RegExp.Replace() to invert
> the greediness of all quantifiers and it was discovered just a few days
> ago. I don't know if it is going to be fixed though. I bet there was a
> rationale behind this setting, but we'll have to wait for a comment of
> Benoit who wrote the code.
>

I have no idea about why I forced the PCRE_UNGREEDY flag. :-/

Maybe to match the behaviour of the Gambas Replace() function.

The only thing I can do is the following: when specifying explicitly the
RegExp.Ungreedy constant in the RegExp.Replace() options, then do the
contrary (remove the ungreedy flag).

What do you think about that?

--
Benoît Minisini

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: RegExp.Replace() question

Tobias Boege-2
On Sat, 29 Apr 2017, Benoît Minisini wrote:

> Le 29/04/2017 à 13:48, Tobias Boege a écrit :
> >
> > Yes, admittedly it is strange behaviour of RegExp.Replace() to invert
> > the greediness of all quantifiers and it was discovered just a few days
> > ago. I don't know if it is going to be fixed though. I bet there was a
> > rationale behind this setting, but we'll have to wait for a comment of
> > Benoit who wrote the code.
> >
>
> I have no idea about why I forced the PCRE_UNGREEDY flag. :-/
>
> Maybe to match the behaviour of the Gambas Replace() function.
>

Hmm, I know I was involved in adding the Match operator and Replace() method,
at least mentally, so I must have read and liked the code, too. I guess it
looked like the saner default for substitutions to be ungreedy. The greedy
and ungreedy modifiers in PCRE were something I probably didn't have in mind
at that time.

> The only thing I can do is the following: when specifying explicitly the
> RegExp.Ungreedy constant in the RegExp.Replace() options, then do the
> contrary (remove the ungreedy flag).
>
> What do you think about that?
>

That's a straightforward fix but makes the code even more confusing:

  RegExp.Replace(str, "#*", "", RegExp.Ungreedy)

would greedily replace strings of "#". Maybe it is more explicit to add
another constant entirely, like RegExp.ReplaceGreedy which does the same
as you proposed but has a matching name. The documentation should continue
to mention that the default behaviour of Replace() is to invert greediness
and IMHO it should advise not to use the ungreedy modifier "?" if possible
to avoid confusion.

Any other opinions?

Regards,
Tobi

--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: RegExp.Replace() question

Benoît Minisini
Le 29/04/2017 à 16:30, Tobias Boege a écrit :

> On Sat, 29 Apr 2017, Benoît Minisini wrote:
>> Le 29/04/2017 à 13:48, Tobias Boege a écrit :
>>>
>>> Yes, admittedly it is strange behaviour of RegExp.Replace() to invert
>>> the greediness of all quantifiers and it was discovered just a few days
>>> ago. I don't know if it is going to be fixed though. I bet there was a
>>> rationale behind this setting, but we'll have to wait for a comment of
>>> Benoit who wrote the code.
>>>
>>
>> I have no idea about why I forced the PCRE_UNGREEDY flag. :-/
>>
>> Maybe to match the behaviour of the Gambas Replace() function.
>>
>
> Hmm, I know I was involved in adding the Match operator and Replace() method,
> at least mentally, so I must have read and liked the code, too. I guess it
> looked like the saner default for substitutions to be ungreedy. The greedy
> and ungreedy modifiers in PCRE were something I probably didn't have in mind
> at that time.
>
>> The only thing I can do is the following: when specifying explicitly the
>> RegExp.Ungreedy constant in the RegExp.Replace() options, then do the
>> contrary (remove the ungreedy flag).
>>
>> What do you think about that?
>>
>
> That's a straightforward fix but makes the code even more confusing:
>
>   RegExp.Replace(str, "#*", "", RegExp.Ungreedy)
>
> would greedily replace strings of "#". Maybe it is more explicit to add
> another constant entirely, like RegExp.ReplaceGreedy which does the same
> as you proposed but has a matching name. The documentation should continue
> to mention that the default behaviour of Replace() is to invert greediness
> and IMHO it should advise not to use the ungreedy modifier "?" if possible
> to avoid confusion.
>
> Any other opinions?
>
> Regards,
> Tobi
>

Done in revision #8131. The RegExp.Greedy constant allows to disable the
default ungreedy option of RegExp.Replace().

Regards,

--
Benoît Minisini

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: RegExp.Replace() question

Fernando Cabral
In reply to this post by Benoît Minisini
Benoît

I am prety new to Gambas, but quite an old hand with regular expression
(almost from the time when sed, awk and vi were created. All of them allow
heavy use of regular expression). It took me many hours to understand that,
contrary to customs,
Gambas regex are ungreedy. It took me some more hours to find out that "?"
could be used to make the operators
+ and * to work as usual (I mean, for old hands like me). And half an hour
more to find out that "&1" replace the older "\1" and not so old "$1".
Those things are annoying when you are getting used to a new lingo.

Even so, I am very impressed with the power you have built into Gambas.
Amazing.

-fernando

2017-04-29 11:04 GMT-03:00 Benoît Minisini <[hidden email]>:

> Le 29/04/2017 à 13:48, Tobias Boege a écrit :
> >
> > Yes, admittedly it is strange behaviour of RegExp.Replace() to invert
> > the greediness of all quantifiers and it was discovered just a few days
> > ago. I don't know if it is going to be fixed though. I bet there was a
> > rationale behind this setting, but we'll have to wait for a comment of
> > Benoit who wrote the code.
> >
>
> I have no idea about why I forced the PCRE_UNGREEDY flag. :-/
>
> Maybe to match the behaviour of the Gambas Replace() function.
>
> The only thing I can do is the following: when specifying explicitly the
> RegExp.Ungreedy constant in the RegExp.Replace() options, then do the
> contrary (remove the ungreedy flag).
>
> What do you think about that?
>
> --
> Benoît Minisini
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



--
Fernando Cabral
Blogue: http://fernandocabral.org
Twitter: http://twitter.com/fjcabral
e-mail: [hidden email]
Facebook: [hidden email]
Telegram: +55 (37) 99988-8868
Wickr ID: fernandocabral
WhatsApp: +55 (37) 99988-8868
Skype:  fernandojosecabral
Telefone fixo: +55 (37) 3521-2183
Telefone celular: +55 (37) 99988-8868

Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
nenhum político ou cientista poderá se gabar de nada.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: RegExp.Replace() question (was: sliderbox bug: Still respond to mouse wheel when its disabled)

Fernando Cabral
In reply to this post by Tobias Boege-2
Tobi, I was not aware and have been careless with the subject issue. Sorry.

As to the Regexp.Replace quirk, I found it out the hardest way: trying,
trying and trying.
Now I hope I have that knack of it. At least with the more basic
expressions.

Thank you.

- fernando

2017-04-29 8:48 GMT-03:00 Tobias Boege <[hidden email]>:

> On Fri, 28 Apr 2017, Fernando Cabral wrote:
> > Hi, gambas is new to me, but regex is not so new. But I am baffled with
> the
> > following result:
> >
> > str = "A#BB##CCC###"
> > print RegExp.Replace(str, "[#]+", ";")
> >     A;BB;;CCC;;;
> > str = "A#BB##CCC###"
> > print RegExp.Replace(str, "[#][#]*", ";")
> >     A;BB;;CCC;;;
> > str = "A#BB##CCC###"
> > print RegExp.Replace(str, "##**", ";")
> >     A;BB;;CCC;;;
> >
> > In my opinion, in every example above the result should be:
> > A;BB;CC
> > Nevertheless, gambas always displays A;BB;CCC;;;.
> >
> > Am I missing something,, or does gambas has a bug in this point?
> >
>
> We had this topic a few days ago [1]. When you use RegExp.Replace(),
> the greediness of all quantifiers is inverted. So when you use
>
>   "[#]+"
>
> under RegExp.Replace(), this has the same meaning as the expression
> (in PCRE syntax)
>
>   "[#]+?"
>
> matching lazily (or ungreedily) against the string, which explains
> the result you get. If you want greedy behaviour (what you expected),
> then you have to use ungreedy quantifiers:
>
>   Print RegExp.Replace("A#BB##CCC###", "[#]+?", ";")
>   Print RegExp.Replace("A#BB##CCC###", "[#][#]*?", ";")
>   Print RegExp.Replace("A#BB##CCC###", "##*?", ";")
>   ---
>   A;BB;CCC;
>   A;BB;CCC;
>   A;BB;CCC;
>
> Yes, admittedly it is strange behaviour of RegExp.Replace() to invert
> the greediness of all quantifiers and it was discovered just a few days
> ago. I don't know if it is going to be fixed though. I bet there was a
> rationale behind this setting, but we'll have to wait for a comment of
> Benoit who wrote the code.
>
> Regards,
> Tobi
>
> [1] https://sourceforge.net/p/gambas/mailman/message/35802891/
>
> PS: When you want to talk about a new topic, make a new thread and don't
>     compose your email by replying to an existing message from the mailing
>     list. Currently our conversation about RegExp.Replace() takes place
>     in a thread about a specific SliderBox bug, which makes it harder for
>     people in the future who are searching for this discussion.
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



--
Fernando Cabral
Blogue: http://fernandocabral.org
Twitter: http://twitter.com/fjcabral
e-mail: [hidden email]
Facebook: [hidden email]
Telegram: +55 (37) 99988-8868
Wickr ID: fernandocabral
WhatsApp: +55 (37) 99988-8868
Skype:  fernandojosecabral
Telefone fixo: +55 (37) 3521-2183
Telefone celular: +55 (37) 99988-8868

Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
nenhum político ou cientista poderá se gabar de nada.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: RegExp.Replace() question

Tobias Boege-2
In reply to this post by Fernando Cabral
On Sat, 29 Apr 2017, Fernando Cabral wrote:

> Benoît
>
> I am prety new to Gambas, but quite an old hand with regular expression
> (almost from the time when sed, awk and vi were created. All of them allow
> heavy use of regular expression). It took me many hours to understand that,
> contrary to customs,
> Gambas regex are ungreedy. It took me some more hours to find out that "?"
> could be used to make the operators
> + and * to work as usual (I mean, for old hands like me). And half an hour
> more to find out that "&1" replace the older "\1" and not so old "$1".
> Those things are annoying when you are getting used to a new lingo.
>

But these two things could have been cleared up by looking at the right
portion(!) of the documentation, which is often hard to find in the
beginning, I know.

RegExp.Replace() is a method of the RegExp class which resides in the
gb.pcre component. Its main page in the wiki [1] tells you that PCRE are
Perl-Compatible Regular Expressions and links to the libpcre [2] page
for its syntax. The Replace() method page [3] itself tells you to use
"&1" for backreferences. This is for consistency with the Subst$()
intrinsic function and other substitution functions in Gambas which
came before RegExp.Replace() -- all of them use "&1".

And for the future: you will encounter another type of regular expressions
much more often in Gambas than the PCREs, namely the LIKE expressions [4].
You will notice that they are very primitive, maybe too primitive if you're
used to sed-style expressions, and have an incompatible syntax.

Regards,
Tobi

[1] http://gambaswiki.org/wiki/comp/gb.pcre
[2] http://gambaswiki.org/wiki/doc/pcre
[3] http://gambaswiki.org/wiki/comp/gb.pcre/regexp/replace
[4] http://gambaswiki.org/wiki/lang/like

--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user