It's possible to get the evt globally

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

It's possible to get the evt globally

sebastian lópez
It's possible to make something like this


from wx import evt

def funccallbac(param1):
   
if evt.GetKeyCode() == 13:
       
return do_something()
   
return

The objective is to be able to call a function but without the need of passing the event as a function argument.

Thanks to your comments and suggestions.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

Tim Roberts
sebastian lópez wrote:
It's possible to make something like this

from wx import evt

def funccallbac(param1):
   
if evt.GetKeyCode() == 13:
       
return do_something()
   
return

The objective is to be able to call a function but without the need of passing the event as a function argument.

No.  That's simply not how it works.  Events callbacks are passed one parameter -- the event.

What do you think you'd be accomplishing by this?
-- 
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

sebastian lópez

Hi Tim

I'm trying to rewrite some wx behaviour so my attemp is to use WX just with functions i.e. usign wx.lib.pub, in fact I took one step advanced.

Here is a piece of code:


from wxs import request # request contains the last event

...

@route('btn_pressed')# route: is a pub method to register the topic
def keyboard_pressed(main):
    # this code line is equivalent to event.GetUnicodeKey()
    keycode
= request.GetUnicodeKey()
   
if keycode == 13:
       
# se evalua
       
return redirect('update', main=main, pressed='=')
   
elif keycode == 27:
       
return redirect('clearscreen', main=main)
    request
.Skip() # again event.Skip()

...


And I'm searching for a different point o view and if possible a discussion.



El jueves, 5 de abril de 2018, 14:10:43 (UTC-5), Tim Roberts escribió:
sebastian lópez wrote:
It's possible to make something like this

from wx import evt

def funccallbac(param1):
   
if evt.GetKeyCode() == 13:
       
return do_something()
   
return

The objective is to be able to call a function but without the need of passing the event as a function argument.

No.  That's simply not how it works.  Events callbacks are passed one parameter -- the event.

What do you think you'd be accomplishing by this?
-- 
Tim Roberts, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="8aByQX1jAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ti...@...
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

calculator_simple01.py (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

Dietmar Schwertberger-2
On 4/5/2018 9:29 PM, sebastian lópez wrote:
And I'm searching for a different point o view and if possible a discussion.

Sometimes it makes sense to bind an event to a lambda function and then the lambda function calls some other function.

E.g. in your example application you may do something like this:

self.Bind(wx.EVT_BUTTON, lambda evt: self.button_pressed(1), self.button_1)
self.Bind(wx.EVT_BUTTON, lambda evt: self.button_pressed(2), self.button_2)
...
self.Bind(wx.EVT_BUTTON, lambda evt: self.button_pressed("A"), self.button_A)
self.Bind(wx.EVT_BUTTON, lambda evt: self.clear(), self.button_CE)

If required, evt.Skip() can be added to the lambda function, but then thing start to get ugly...

Regards,

Dietmar


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

Tim Roberts
In reply to this post by sebastian lópez
sebastian lópez wrote:
>
> I'm trying to rewrite some wx behaviour so my attemp is to use WX just
> with functions i.e. usign wx.lib.pub, in fact I took one step advanced.

Actually, not so.  In software engineering terms, that's a huge step
backwards.  Classes and objects make for provably better software.  It
forces you to organize your thoughts, it provides better data
encapsulation, and it more naturally reflects the nested nature of
controls and windows.

However, it depends on your goal.  It looks to me like you may be trying
to write something that can switch between GUI output or web output, but
designed to appeal to the web programmer.  Your terminology ("routes")
reflects a web orientation.  That's a noble goal, but it means you will
make some compromises.

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

sebastian lópez
In reply to this post by Dietmar Schwertberger-2
In therms of wxs an equivalent code could be

self.button_1.Bind(wx.EVT_BUTTON, lambda evt: self.button_pressed(1))
self.button_2.Bind(wx.EVT_BUTTON, lambda evt:lambda evt: self.button_pressed(2))

Also if main_sizer contains the button_1 and button_2, and both are named you could use

main_sizer['button_1_name'].Bind(wx.EVT_BUTTON, lambda evt: self.button_pressed(1))
main_sizer['button_2_name'].Bind(wx.EVT_BUTTON, lambda evt: self.button_pressed(2))

Another option could be the use of the url_for, and route

from wxs import url_for, route
...
@route('topic_one')
def call_btn_1(self):
    self.button_pressed(1)
    redirect('refresh, self=self)

@route('topic_two')
def call_btn_2(self):
    self.button_pressed(1)
    redirect('refresh, self=self)

@route('refresh')
def refresh_gui(self):
 ...doing something

class Some_name:
    def __init__(...):
         ...
         main_sizer['button_1_name'].Bind(wx.EVT_BUTTON,url_for('topic_one', self=self))
         main_sizer['button_2_name'].Bind(wx.EVT_BUTTON,url_for('topic_two', self=self))

You can have multiples Bind events linked to the same control, and they'll be excecuted, if there isn´t an error.

And finally the event.Skip() is optional because you can express what you need in therms of redirect, offcourse I have to clean the code, refactory and test a lot.

El jueves, 5 de abril de 2018, 17:05:23 (UTC-5), Dietmar Schwertberger escribió:
On 4/5/2018 9:29 PM, sebastian lópez wrote:
And I'm searching for a different point o view and if possible a discussion.

Sometimes it makes sense to bind an event to a lambda function and then the lambda function calls some other function.

E.g. in your example application you may do something like this:

self.Bind(wx.EVT_BUTTON, lambda evt: self.button_pressed(1), self.button_1)
self.Bind(wx.EVT_BUTTON, lambda evt: self.button_pressed(2), self.button_2)
...
self.Bind(wx.EVT_BUTTON, lambda evt: self.button_pressed("A"), self.button_A)
self.Bind(wx.EVT_BUTTON, lambda evt: self.clear(), self.button_CE)

If required, evt.Skip() can be added to the lambda function, but then thing start to get ugly...

Regards,

Dietmar


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

sebastian lópez
In reply to this post by Tim Roberts
Hi Tim

Actually, not so.  In software engineering terms, that's a huge step
backwards.

It's a good advice. -> that's because I saw a python video called 'STOP WRITING CLASSES'


It looks to me like you may be trying
to write something that can switch between GUI output or web output

It's not one of my goals but it would be nice to do it, instead I'was inspired by Flask framework but just related to the used names, in the other hand I think It could be better to use wx.lib.pub by default.

I also think it's better to:
1. To refer a control by its name
2. To have a sizer that knowns all its children names if they are defined.
3. To set the value of a control using the equal operator
4. To let the user to use functional programing or object oriented programing, similar to python itself

I also believe we need to make it easy to learn and to use wx to the newcomers, In therms of beign more atractive and simpler. Thats why I'm trying to make this battery.


El jueves, 5 de abril de 2018, 17:50:30 (UTC-5), Tim Roberts escribió:
sebastian lópez wrote:
>
> I'm trying to rewrite some wx behaviour so my attemp is to use WX just
> with functions i.e. usign wx.lib.pub, in fact I took one step advanced.

Actually, not so.  In software engineering terms, that's a huge step
backwards.  Classes and objects make for provably better software.  It
forces you to organize your thoughts, it provides better data
encapsulation, and it more naturally reflects the nested nature of
controls and windows.

However, it depends on your goal.  It looks to me like you may be trying
to write something that can switch between GUI output or web output, but
designed to appeal to the web programmer.  Your terminology ("routes")
reflects a web orientation.  That's a noble goal, but it means you will
make some compromises.

--
Tim Roberts, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="spmcwUp0BgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ti...@...
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

sebastian lópez
Here is a link to the project

https://gitlab.com/Selobu/wxs

El jueves, 5 de abril de 2018, 19:02:38 (UTC-5), sebastian lópez escribió:
Hi Tim

Actually, not so.  In software engineering terms, that's a huge step
backwards.

It's a good advice. -> that's because I saw a python video called 'STOP WRITING CLASSES'


It looks to me like you may be trying
to write something that can switch between GUI output or web output

It's not one of my goals but it would be nice to do it, instead I'was inspired by Flask framework but just related to the used names, in the other hand I think It could be better to use wx.lib.pub by default.

I also think it's better to:
1. To refer a control by its name
2. To have a sizer that knowns all its children names if they are defined.
3. To set the value of a control using the equal operator
4. To let the user to use functional programing or object oriented programing, similar to python itself

I also believe we need to make it easy to learn and to use wx to the newcomers, In therms of beign more atractive and simpler. Thats why I'm trying to make this battery.


El jueves, 5 de abril de 2018, 17:50:30 (UTC-5), Tim Roberts escribió:
sebastian lópez wrote:
>
> I'm trying to rewrite some wx behaviour so my attemp is to use WX just
> with functions i.e. usign wx.lib.pub, in fact I took one step advanced.

Actually, not so.  In software engineering terms, that's a huge step
backwards.  Classes and objects make for provably better software.  It
forces you to organize your thoughts, it provides better data
encapsulation, and it more naturally reflects the nested nature of
controls and windows.

However, it depends on your goal.  It looks to me like you may be trying
to write something that can switch between GUI output or web output, but
designed to appeal to the web programmer.  Your terminology ("routes")
reflects a web orientation.  That's a noble goal, but it means you will
make some compromises.

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

Dietmar Schwertberger-2
In reply to this post by sebastian lópez
On 4/6/2018 2:02 AM, sebastian lópez wrote:
> It's a good advice. -> that's because I saw a python video called
> 'STOP WRITING CLASSES'

Such an advice has one point: when people start using classes they often
overuse them and create highly complex inheritance structures.


> It's not one of my goals but it would be nice to do it, instead I'was
> inspired by Flask framework but just related to the used names, in the
> other hand I think It could be better to use wx.lib.pub by default.
>
> I also think it's better to:
> 1. To refer a control by its name
> 2. To have a sizer that knowns all its children names if they are defined.
> 3. To set the value of a control using the equal operator
> 4. To let the user to use functional programing or object oriented
> programing, similar to python itself

Classes and GUI programming match each other quite well. Placing a
functional library on top does not make things clearer. Alternatively
you can do all the low-level mainloop handling yourself and invent just
another GUI toolkit. There are plenty of GUI toolkits and libraries and
most got abandoned soon. (I also have a library on top of wxPython which
I would not use for a new project any more.)

Also, the major toolkits are have similar APIs and structures. A toolkit
or tool that's completely different is not very attractive.

In addition, any new library or toolkit starts without supporting tools
and documentation. Documentation and tools are often more effort than
the technical part.


> I also believe we need to make it easy to learn and to use wx to the
> newcomers, In therms of beign more atractive and simpler. Thats why
> I'm trying to make this battery.

It has never been easier to learn wxPython than today. Just work through
the wxGlade tutorial and in half a day you'll know enough to implement a
basic GUI application. For things like drag & drop or clipboard or
graphics you can consult the book or the online documentation and - most
important - the demo. Graphics is unfortunately not the easiest part of
wxPython.

Once your application grows more complex, you will soon find that the
low-level stuff - that you want to improve - is not the difficult part.
The difficulty is how to link each and everything to your data
structures in a maintainable way. That's where dispatchers like
wx.lib.pubsub come in. Unfortunately, I'm not aware of a good book on
this. Most books etc. seem to focus on the technical aspect of GUI
programs, not on good structures. The result is that most non-trivial
GUI programs are difficult to maintain.


Regards,

Dietmar


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

sebastian lópez
Good afternoon Dietmar

It's valuable for me your opinion, about that

Classes and GUI programming match each other quite well

I made some changes and now you can create your own wxs,Frames -->Here is an example https://gitlab.com/Selobu/wxs/blob/master/examples/calculator_with_classes.py

Placing a functional library on top does not make things clearer

You are right. The library is in its earlier estages so there is a lot of things to do.


Alternatively you can do all the low-level mainloop handling yourself and invent just
another GUI toolkit

It's not my idea to reinvent the weel.


There are plenty of GUI toolkits and libraries and most got abandoned soon.

I hope this is not my case, but if it is then I hope my ideas can be used to improve wx


Also, the major toolkits are have similar APIs and structures. A toolkit or tool that's completely different is not very attractive.

I'll try to make the api as clean as possible and Also I'll try not to be far from wx itself.

 In addition, any new library or toolkit starts without supporting tools  and documentation. Documentation and tools are often more effort than
the technical part.

You are right, the library will try to reuse the wx documentation where it aplies


It has never been easier to learn wxPython than today. Just work through
the wxGlade tutorial and in half a day you'll know enough to implement a
basic GUI application. For things like drag & drop or clipboard or
graphics you can consult the book or the online documentation and - most
important - the demo. Graphics is unfortunately not the easiest part of
wxPython.
 
I agree,  wxGlade is great and also for starters. And wxpython have great documentation and forum

Once your application grows more complex, you will soon find that the
low-level stuff - that you want to improve - is not the difficult part.
The difficulty is how to link each and everything to your data
structures in a maintainable way

thats why I'am trying to use wx.lib.pub  and also I'm trying to refer the controls by its name, for example

 sizer['name_control'] ... and then you'll have the control.
 str(sizer['name_control']) ... and you will get the control value as string.
 int(sizer['name_control'])  ... and you will get the control value as an integer if possible.
 size['name_numeric_control'] = sum(range(10)) ... and then you are setting the control value to 45 and also refresh the control itself if needs it.

Unfortunately, I'm not aware of a good book on
this. Most books etc. seem to focus on the technical aspect of GUI
programs, not on good structures. The result is that most non-trivial
GUI programs are difficult to maintain.

I think there are good samples at mouse vs python blog, and exists many other resources.

Again thanks to your comments and suggestions

El viernes, 6 de abril de 2018, 13:21:15 (UTC-5), Dietmar Schwertberger escribió:
On 4/6/2018 2:02 AM, sebastian lópez wrote:
> It's a good advice. -> that's because I saw a python video called
> 'STOP WRITING CLASSES'

Such an advice has one point: when people start using classes they often
overuse them and create highly complex inheritance structures.


> It's not one of my goals but it would be nice to do it, instead I'was
> inspired by Flask framework but just related to the used names, in the
> other hand I think It could be better to use wx.lib.pub by default.
>
> I also think it's better to:
> 1. To refer a control by its name
> 2. To have a sizer that knowns all its children names if they are defined.
> 3. To set the value of a control using the equal operator
> 4. To let the user to use functional programing or object oriented
> programing, similar to python itself

Classes and GUI programming match each other quite well. Placing a
functional library on top does not make things clearer. Alternatively
you can do all the low-level mainloop handling yourself and invent just
another GUI toolkit. There are plenty of GUI toolkits and libraries and
most got abandoned soon. (I also have a library on top of wxPython which
I would not use for a new project any more.)

Also, the major toolkits are have similar APIs and structures. A toolkit
or tool that's completely different is not very attractive.

In addition, any new library or toolkit starts without supporting tools
and documentation. Documentation and tools are often more effort than
the technical part.


> I also believe we need to make it easy to learn and to use wx to the
> newcomers, In therms of beign more atractive and simpler. Thats why
> I'm trying to make this battery.

It has never been easier to learn wxPython than today. Just work through
the wxGlade tutorial and in half a day you'll know enough to implement a
basic GUI application. For things like drag & drop or clipboard or
graphics you can consult the book or the online documentation and - most
important - the demo. Graphics is unfortunately not the easiest part of
wxPython.

Once your application grows more complex, you will soon find that the
low-level stuff - that you want to improve - is not the difficult part.
The difficulty is how to link each and everything to your data
structures in a maintainable way. That's where dispatchers like
wx.lib.pubsub come in. Unfortunately, I'm not aware of a good book on
this. Most books etc. seem to focus on the technical aspect of GUI
programs, not on good structures. The result is that most non-trivial
GUI programs are difficult to maintain.


Regards,

Dietmar


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

sebastian lópez
I like to add that you can use all the methods described in the wx under the implemented control i.e.

Ctrl.Button will have the same behaviour and methods than wx.Button once it's created.

El viernes, 6 de abril de 2018, 16:00:41 (UTC-5), sebastian lópez escribió:
Good afternoon Dietmar

It's valuable for me your opinion, about that

Classes and GUI programming match each other quite well

I made some changes and now you can create your own wxs,Frames -->Here is an example <a href="https://gitlab.com/Selobu/wxs/blob/master/examples/calculator_with_classes.py" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgitlab.com%2FSelobu%2Fwxs%2Fblob%2Fmaster%2Fexamples%2Fcalculator_with_classes.py\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFo_SBiw0f5RERtUX3OIRe9j_6obQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgitlab.com%2FSelobu%2Fwxs%2Fblob%2Fmaster%2Fexamples%2Fcalculator_with_classes.py\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFo_SBiw0f5RERtUX3OIRe9j_6obQ&#39;;return true;">https://gitlab.com/Selobu/wxs/blob/master/examples/calculator_with_classes.py

Placing a functional library on top does not make things clearer

You are right. The library is in its earlier estages so there is a lot of things to do.


Alternatively you can do all the low-level mainloop handling yourself and invent just
another GUI toolkit

It's not my idea to reinvent the weel.


There are plenty of GUI toolkits and libraries and most got abandoned soon.

I hope this is not my case, but if it is then I hope my ideas can be used to improve wx


Also, the major toolkits are have similar APIs and structures. A toolkit or tool that's completely different is not very attractive.

I'll try to make the api as clean as possible and Also I'll try not to be far from wx itself.

 In addition, any new library or toolkit starts without supporting tools  and documentation. Documentation and tools are often more effort than
the technical part.

You are right, the library will try to reuse the wx documentation where it aplies


It has never been easier to learn wxPython than today. Just work through
the wxGlade tutorial and in half a day you'll know enough to implement a
basic GUI application. For things like drag & drop or clipboard or
graphics you can consult the book or the online documentation and - most
important - the demo. Graphics is unfortunately not the easiest part of
wxPython.
 
I agree,  wxGlade is great and also for starters. And wxpython have great documentation and forum

Once your application grows more complex, you will soon find that the
low-level stuff - that you want to improve - is not the difficult part.
The difficulty is how to link each and everything to your data
structures in a maintainable way

thats why I'am trying to use wx.lib.pub  and also I'm trying to refer the controls by its name, for example

 sizer['name_control'] ... and then you'll have the control.
 str(sizer['name_control']) ... and you will get the control value as string.
 int(sizer['name_control'])  ... and you will get the control value as an integer if possible.
 size['name_numeric_control'] = sum(range(10)) ... and then you are setting the control value to 45 and also refresh the control itself if needs it.

Unfortunately, I'm not aware of a good book on
this. Most books etc. seem to focus on the technical aspect of GUI
programs, not on good structures. The result is that most non-trivial
GUI programs are difficult to maintain.

I think there are good samples at mouse vs python blog, and exists many other resources.

Again thanks to your comments and suggestions

El viernes, 6 de abril de 2018, 13:21:15 (UTC-5), Dietmar Schwertberger escribió:
On 4/6/2018 2:02 AM, sebastian lópez wrote:
> It's a good advice. -> that's because I saw a python video called
> 'STOP WRITING CLASSES'

Such an advice has one point: when people start using classes they often
overuse them and create highly complex inheritance structures.


> It's not one of my goals but it would be nice to do it, instead I'was
> inspired by Flask framework but just related to the used names, in the
> other hand I think It could be better to use wx.lib.pub by default.
>
> I also think it's better to:
> 1. To refer a control by its name
> 2. To have a sizer that knowns all its children names if they are defined.
> 3. To set the value of a control using the equal operator
> 4. To let the user to use functional programing or object oriented
> programing, similar to python itself

Classes and GUI programming match each other quite well. Placing a
functional library on top does not make things clearer. Alternatively
you can do all the low-level mainloop handling yourself and invent just
another GUI toolkit. There are plenty of GUI toolkits and libraries and
most got abandoned soon. (I also have a library on top of wxPython which
I would not use for a new project any more.)

Also, the major toolkits are have similar APIs and structures. A toolkit
or tool that's completely different is not very attractive.

In addition, any new library or toolkit starts without supporting tools
and documentation. Documentation and tools are often more effort than
the technical part.


> I also believe we need to make it easy to learn and to use wx to the
> newcomers, In therms of beign more atractive and simpler. Thats why
> I'm trying to make this battery.

It has never been easier to learn wxPython than today. Just work through
the wxGlade tutorial and in half a day you'll know enough to implement a
basic GUI application. For things like drag & drop or clipboard or
graphics you can consult the book or the online documentation and - most
important - the demo. Graphics is unfortunately not the easiest part of
wxPython.

Once your application grows more complex, you will soon find that the
low-level stuff - that you want to improve - is not the difficult part.
The difficulty is how to link each and everything to your data
structures in a maintainable way. That's where dispatchers like
wx.lib.pubsub come in. Unfortunately, I'm not aware of a good book on
this. Most books etc. seem to focus on the technical aspect of GUI
programs, not on good structures. The result is that most non-trivial
GUI programs are difficult to maintain.


Regards,

Dietmar


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

Karsten Hilbert
In reply to this post by sebastian lópez
On Fri, Apr 06, 2018 at 02:00:40PM -0700, sebastian lópez wrote:

> I hope this is not my case, but if it is then I hope my
> ideas can be used to improve wx

For that you'd have to work on wxWidgets, not wxPython,
because wxPython's main goal is providing a Python "binding"
for wxWidgets.

Best,
Karsten
--

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

Tim Roberts
In reply to this post by sebastian lópez
sebastian lópez wrote:

>
> thats why I'am trying to use wx.lib.pub  and also I'm trying to refer
> the controls by its name, for example
>
>  sizer['name_control'] ... and then you'll have the control.
>  str(sizer['name_control']) ... and you will get the control value as
> string.
>  int(sizer['name_control'])  ... and you will get the control value as
> an integer if possible.
>  size['name_numeric_control'] = sum(range(10)) ... and then you are
> setting the control value to 45 and also refresh the control itself if
> needs it.

I wrote a very long reply to the last message in our thread, but I
realized I was just lecturing and it wasn't really very helpful, and I
deleted it.  I DO want to comment on this part, however, because I think
this design is dangerous.

The relationship between windows and sizers in wx is a complicated
concept to grasp, but understanding it is key to understanding how wx
works.  You are mixing the two concepts there, and I think that's a
mistake.  You should not be using sizers as your containers.

In almost every wx application, a control is present in two separate,
unrelated, but overlapping hierarchies.  A control or window is always
owned by another window.  This is a parent/child relationship, and those
are the exact terms that are used in the windowing systems where wx
works (Windows, X, GTK, Cocoa, etc.).  That tree of windows, with
parent/child linkages, are known to the windowing systems.  Given a wx
control, you could grab the handle go ask the Windows API for the parent
and child windows, and it would report them to you.

But sizers are strictly internal to wx.  Windows, X, and GTK know
absolutely nothing about the sizer tree.  A sizer keeps a list of the
windows and sub-sizers that it is managing, but there's no ownership
involved.  A control or sizer doesn't know what sizer is managing it.

I think you're going to cause confusion with your design.  At your top
level should be "main", but that should be a frame, a dialog, or a
panel.  That "main" owns the child windows, and you should be asking
"main" for a reference to the control.  The fact that "main" also has a
sizer that manages some or all of the controls it owns is just a wx
implementation detail.  If you decided tomorrow that the sizers didn't
work out and you wanted to use absolute positioning, you shouldn't have
to rewrite the whole app.  The controls would still be owned by the
parent frame, but now there's no sizer.

I ask that you give that some thought.

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

Chris Barker - NOAA Federal
In reply to this post by sebastian lópez


On Thu, Apr 5, 2018 at 5:02 PM, sebastian lópez <[hidden email]> wrote:
Hi Tim

Actually, not so.  In software engineering terms, that's a huge step
backwards.

It's a good advice. -> that's because I saw a python video called 'STOP WRITING CLASSES'

That is a great talk -- but he doesn't mean that classes don't have good use cases. What he meant is that you shouldn't use a class when all you really need is a function. the catch phrase:

if you class has only two methods, and one of them is __init__, then you don't need a class.

which is still good advice.

and when you make a to-simple-to-be-a-class into a function, he was not suggesting global state, but rather a more functional approach -- passing the data the the function needs to the function...i.e. .passing the event to the event handler.

It's not one of my goals but it would be nice to do it, instead I'was inspired by Flask framework but just related to the used names, in the other hand I think It could be better to use wx.lib.pub by default.

well, I haven't looked closely at flask, but the web frameworks I've seen pass a "request" object to the view functions -- much like passing an event to an event handler.
 
I also think it's better to:
1. To refer a control by its name

no problem there.
 
2. To have a sizer that knowns all its children names if they are defined.

not really how sizers work....
 
3. To set the value of a control using the equal operator

you can do that with most object's properties.
 
4. To let the user to use functional programing or object oriented programing, similar to python itself

also that -- an event handler needs to be a function that takes the event as the first argument -- it does not hve to be a method of any particular class. or any class at all. 

-CHB

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[hidden email]

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

sebastian lópez
Good afternoon Chris

About your comments:


and when you make a to-simple-to-be-a-class into a function, he was not suggesting global state, but rather a more functional approach -- passing the data the the function needs to the function...i.e. .passing the event to the event handler .
Well, I haven't looked closely at flask, but the web frameworks I've seen pass a "request" object to the view functions -- much like passing an event to an event handler. 

I'm trying to the same with the wxs.request object, request is an object ready to get the last event, in that way you can just left to repeat
def func(self, event)  because the current event will be put on request object.-- if there isn´t a bug somewhere, but not yet.

def func(self, *args, **kwargs):
     request.GetKeyCode() # just if needed
     # doing some stuff

you can do that with most object's properties.

I wasn't clear at all, I was trying to said it's possible to change the visible state of a widget by using
 
  control.Value = some_value, and the same if the widget has a datatime or if it is a slider or a check widget ....
  checkCtrl.Value = True.

The other parameters and properties < color, font> should be use its corresponding methods from wx.Widget as you normally do it.


also that -- an event handler needs to be a function that takes the event as the first argument -- it does not hve to be a method of any particular class. or any class at all.

I answered this above.

My comments only express my point of view and also remember that I am not a native speaker, so I hope my comments are not misinterpreted.



El viernes, 6 de abril de 2018, 16:40:42 (UTC-5), Chris Barker escribió:


On Thu, Apr 5, 2018 at 5:02 PM, sebastian lópez <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="0SwFRRC_BgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">sel...@...> wrote:
Hi Tim

Actually, not so.  In software engineering terms, that's a huge step
backwards.

It's a good advice. -> that's because I saw a python video called 'STOP WRITING CLASSES'

That is a great talk -- but he doesn't mean that classes don't have good use cases. What he meant is that you shouldn't use a class when all you really need is a function. the catch phrase:

if you class has only two methods, and one of them is __init__, then you don't need a class.

which is still good advice.

and when you make a to-simple-to-be-a-class into a function, he was not suggesting global state, but rather a more functional approach -- passing the data the the function needs to the function...i.e. .passing the event to the event handler.

It's not one of my goals but it would be nice to do it, instead I'was inspired by Flask framework but just related to the used names, in the other hand I think It could be better to use wx.lib.pub by default.

well, I haven't looked closely at flask, but the web frameworks I've seen pass a "request" object to the view functions -- much like passing an event to an event handler.
 
I also think it's better to:
1. To refer a control by its name

no problem there.
 
2. To have a sizer that knowns all its children names if they are defined.

not really how sizers work....
 
3. To set the value of a control using the equal operator

you can do that with most object's properties.
 
4. To let the user to use functional programing or object oriented programing, similar to python itself

also that -- an event handler needs to be a function that takes the event as the first argument -- it does not hve to be a method of any particular class. or any class at all. 

-CHB

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

<a href="javascript:" target="_blank" gdf-obfuscated-mailto="0SwFRRC_BgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">Chris....@...


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

sebastian lópez
In reply to this post by Karsten Hilbert
Good Afternoon Karsten

As you said wxPython is a bidding of wxWidgets so it's possible to have multiple implementations around itm, but sincerly I saw the wxpython team has done a great job during all these years an I think it's a good start to my library to use wxpython as much as I can by trying a different aproach.

For that you'd have to work on wxWidgets, not wxPython,
because wxPython's main goal is providing a Python "binding"
for wxWidgets.

You've got a big point.


El viernes, 6 de abril de 2018, 16:19:23 (UTC-5), Karsten Hilbert escribió:
On Fri, Apr 06, 2018 at 02:00:40PM -0700, sebastian lópez wrote:

> I hope this is not my case, but if it is then I hope my
> ideas can be used to improve wx

For that you'd have to work on wxWidgets, not wxPython,
because wxPython's main goal is providing a Python "binding"
for wxWidgets.

Best,
Karsten
--

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

Dietmar Schwertberger-2
In reply to this post by Tim Roberts
On 4/6/2018 11:39 PM, Tim Roberts wrote:
> But sizers are strictly internal to wx.  Windows, X, and GTK know
> absolutely nothing about the sizer tree.  A sizer keeps a list of the
> windows and sub-sizers that it is managing, but there's no ownership
> involved.  A control or sizer doesn't know what sizer is managing it.
Tying the program logic to sizers has one more disadvantage:
Sizers are only for the layout. A layout change should not require a
change in the business logic code. Especially with visual tools nobody
should need to take much care about internals like sizers.

Regards,

Dietmar

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

sebastian lópez
That's fine Dietmar

I updated the frame class to known its childrens --> here is an example https://gitlab.com/Selobu/wxs/blob/master/examples/calculator_with_classes.py

I also think it's possible to adapt wx.Glade to generate a custon wxs.Frame code so the final user hust have to deal with the bussiness logic.


Again thanks for all your participation into this discussion. All of you have been enrich me too much

El viernes, 6 de abril de 2018, 17:29:03 (UTC-5), Dietmar Schwertberger escribió:
On 4/6/2018 11:39 PM, Tim Roberts wrote:
> But sizers are strictly internal to wx.  Windows, X, and GTK know
> absolutely nothing about the sizer tree.  A sizer keeps a list of the
> windows and sub-sizers that it is managing, but there's no ownership
> involved.  A control or sizer doesn't know what sizer is managing it.
Tying the program logic to sizers has one more disadvantage:
Sizers are only for the layout. A layout change should not require a
change in the business logic code. Especially with visual tools nobody
should need to take much care about internals like sizers.

Regards,

Dietmar

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

sebastian lópez
Good Night

I analysed my library and I made the following:

1. The library is now a single file with just 106 lines of code.
2. You can search a control by its name if it is contained into a parent control.
3. request is an object where you can get the last event object
4. The migration is too easy, You just need to set the following line in you head code

   import wxs as wx

5. You can continue using your visual tools to design your GUI and the documentation is the wx's documentation

# tested under python 3.6

import wxs as wx # just import the library as wx and all works the same

class My_frame(wx.Frame):
   
def __init__(self, parent = None, id=-1, title='Ensayo'):
       
super(My_frame, self).__init__(parent, id, title)
       
self.pnl = wx.Panel(self)
       
self.sizer2 = wx.BoxSizer(wx.HORIZONTAL)
        st
= wx.Button(self.pnl,-1,'Test', name='ensayo')
       
self.sizer2.Add(st, 1, wx.EXPAND)
       
self.pnl.SetSizer(self.sizer2)
        st
.Bind(wx.EVT_BUTTON, lambda evt: self.callback(evt))
   
def callback(self, vt):
       
print('--Checking--')
       
print(wx.request.GetClassName()) # getting the evt globally
       
print(self['ensayo'].Name) # accessing an object by its name
app
= wx.App()
frame
= My_frame()
ensayo
= frame['ensayo'] # accessing the object called ensayo
frame
.Show(True)
app
.MainLoop()

It would be nice if this can be implemented by default into wxpython.  :-)


El viernes, 6 de abril de 2018, 18:47:56 (UTC-5), sebastian lópez escribió:
That's fine Dietmar

I updated the frame class to known its childrens --> here is an example <a href="https://gitlab.com/Selobu/wxs/blob/master/examples/calculator_with_classes.py" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgitlab.com%2FSelobu%2Fwxs%2Fblob%2Fmaster%2Fexamples%2Fcalculator_with_classes.py\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFo_SBiw0f5RERtUX3OIRe9j_6obQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgitlab.com%2FSelobu%2Fwxs%2Fblob%2Fmaster%2Fexamples%2Fcalculator_with_classes.py\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFo_SBiw0f5RERtUX3OIRe9j_6obQ&#39;;return true;">https://gitlab.com/Selobu/wxs/blob/master/examples/calculator_with_classes.py

I also think it's possible to adapt wx.Glade to generate a custon wxs.Frame code so the final user hust have to deal with the bussiness logic.


Again thanks for all your participation into this discussion. All of you have been enrich me too much

El viernes, 6 de abril de 2018, 17:29:03 (UTC-5), Dietmar Schwertberger escribió:
On 4/6/2018 11:39 PM, Tim Roberts wrote:
> But sizers are strictly internal to wx.  Windows, X, and GTK know
> absolutely nothing about the sizer tree.  A sizer keeps a list of the
> windows and sub-sizers that it is managing, but there's no ownership
> involved.  A control or sizer doesn't know what sizer is managing it.
Tying the program logic to sizers has one more disadvantage:
Sizers are only for the layout. A layout change should not require a
change in the business logic code. Especially with visual tools nobody
should need to take much care about internals like sizers.

Regards,

Dietmar

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

wxs.py (3K) Download Attachment
test_wxs.py (846 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: It's possible to get the evt globally

Karsten Hilbert
On Sun, Apr 08, 2018 at 05:16:06PM -0700, sebastian lópez wrote:

> class My_frame(wx.Frame):
>     def __init__(self, parent = None, id=-1, title='Ensayo'):
>         super(My_frame, self).__init__(parent, id, title)
>         self.pnl = wx.Panel(self)
>         self.sizer2 = wx.BoxSizer(wx.HORIZONTAL)
>         st = wx.Button(self.pnl,-1,'Test', name='ensayo')
>         self.sizer2.Add(st, 1, wx.EXPAND)
>         self.pnl.SetSizer(self.sizer2)
>         st.Bind(wx.EVT_BUTTON, lambda evt: self.callback(evt))
>     def callback(self, vt):
>         print('--Checking--')
>         print(wx.request.GetClassName()) # getting the evt globally
>         print(self['ensayo'].Name) # accessing an object by its name
> app = wx.App()
> frame = My_frame()
> ensayo = frame['ensayo'] # accessing the object called ensayo
> frame.Show(True)
> app.MainLoop()
>
> It would be nice if this can be implemented by default into wxpython.  :-)

Could you not make a mixin class which maps a __getitem__()
call to a call to FindWindowByName() ?

That would take care of the

        print(self['ensayo'].Name)

business.

Karsten
--

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
12