I'm attemping to simplify the gui creation by a library

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

I'm attemping to simplify the gui creation by a library

sebastian lópez

Hi everyone at this group

I'm trying to create a library based on wx that can simplify the gui creation, and  so I like to show you an example about how I created a gui


# including the path to the library
import sys
from os.path import split

path
= split(split(sys.argv[0])[0])[0]
if path not in sys.path:
    sys
.path.append(path)
# <

from wxs import Ctrl, route, url_for
from wxs import wx as wx

# defining a function to calculate the temperature
def volumecalc(pressure, volume):
   
if not isinstance(pressure, (int, float)):
       
return 0
   
if not isinstance(volume, (int, float)):
       
return 0
    temperature
= round(pressure*volume,2)
   
return temperature

# append the listener
@route('temperature_calc')
def listener(main):
    pressure
=  main['pressure'].Value
    volume
= main['volume'].Value
    main
['result'].Value = volumecalc(pressure, volume)

# defining them main function that generates the GUI
def GetMainFrame():
   
# simplifying some names
    sizer
= Ctrl.Sizer
    st
= Ctrl.StaticText
    num
= Ctrl.TextNum

   
# the library considers that everyting is inside a sizer
    main
= sizer([
                sizer
([st('Ideal gas law').\
                       
Bold().\
                       
Italic().\
                       
PointSize(15) # this lines define an static text with Bold, Italic and 15 point size
                     
],
                      horzCenter
=True), # this line indicates to the sizer the control has horizontal alignment
                sizer
([ # sizer can contain indefined number of children sizers
                       sizer
([
                              sizer
([st('Pressure:').\
                                       
Bold().\
                                       
Italic().\
                                        proportion
(1),
                                    num
(1).\
                                       
Italic().\
                                        name
('pressure').\
                                        tooltip
('Input the pressure')# you can add tooltips by using only an instruction
                                   
],
                                    flag
=wx.ALL),# the flags are the same used by wx
                              sizer
([st('Volume:').\
                                       
Italic().\
                                        proportion
(1),
                                    num
(12).\
                                        name
('volume').\ # you can define the control name
                                        tooltip
('Input the volume')
                                   
],
                                    flag
=wx.ALL)
                             
],
                              title
='Input params',
                              horz
=wx.VERTICAL,
                              flag
=wx.ALL|wx.EXPAND),
                       sizer
([st('system temperature:').\
                               
Bold(),
                             
Ctrl.TextNum(0).\
                               
Bold().\
                                name
('result').\
                               
Enable(False).\
                                proportion
(1),
                             
],
                             title
='Results',
                             horz
=wx.VERTICAL),
                     
]),
               
],
               title
='-',# this tile indicates to show a rectangular line containing the widgets
               flag
=wx.ALL|wx.EXPAND,
               horz
=wx.VERTICAL,
               horzCenter
=True)

   
# Here are som biding
   
# You just need to use the name of the control
    main
['pressure'].Bind(wx.EVT_TEXT, url_for('temperature_calc', main=main))
    main
['volume'].Bind(wx.EVT_TEXT, url_for('temperature_calc', main=main))

   
return main

if __name__ == '__main__':
    app
= wx.App()
    mainFrame
= GetMainFrame()
    mainFrame
.asFrame(title='wxs demo', size=wx.Size(420,260)).Show()
    app
.MainLoop()



It would be nice if you express your opinion and sugestions


--
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: I'm attemping to simplify the gui creation by a library

GadgetSteve
Hi Sebastian,

A few (hopefully constructive), comments:

1. If the Library considers everything is in a sizer then the user
shouldn't need to define the sizer the library should simply wrap each
thing in a sizer.
2. There seems to be a need to know a lot of the inner workings of the
GUI to be able to use what you are doing - have you considered simply
letting the user define elements with a type, name, user name, tooltip
and either optional range (for floats or ints) or list of options, (the
latter being a tupple of name, user name & tooltip). Your library could
then select the appropriate control type for the type, possibly with an
optional hint from the user.
3. The code would be more pythonic if dictionaries were used rather than
lists of presumably positional arguments.
4. Avoid if possible line continues \ dictionaries will help here as you
will be using {name: value, constructs rather than . and the former can
have a linefeed after each.
5. Definitely avoid \# comment as it can be an error
6. Consider using argparse arguments as your inputs then a command line
and GUI is possible without code duplication.

Hope that is helpful.

Steve

On 03/04/2018 03:09, sebastian lópez wrote:

> <https://lh3.googleusercontent.com/-GAQeJqaWqCE/WsLiRS0FeRI/AAAAAAAAKCo/syOltoc5r5Ykr9tARR97VruIAi3fhJeLwCLcBGAs/s1600/example1.png>
>
> Hi everyone at this group
>
> I'm trying to create a library based on wx that can simplify the gui
> creation, and  so I like to show you an example about how I created a gui
>
>
> |
> # including the path to the library
> importsys
> fromos.path importsplit
>
> path =split(split(sys.argv[0])[0])[0]
> ifpath notinsys.path:
>      sys.path.append(path)
> # <
>
> fromwxs importCtrl,route,url_for
> fromwxs importwx aswx
>
> # defining a function to calculate the temperature
> defvolumecalc(pressure,volume):
> ifnotisinstance(pressure,(int,float)):
> return0
> ifnotisinstance(volume,(int,float)):
> return0
>      temperature =round(pressure*volume,2)
> returntemperature
>
> # append the listener
> @route('temperature_calc')
> deflistener(main):
>      pressure = main['pressure'].Value
>      volume =main['volume'].Value
>      main['result'].Value=volumecalc(pressure,volume)
>
> # defining them main function that generates the GUI
> defGetMainFrame():
> # simplifying some names
>      sizer =Ctrl.Sizer
>      st =Ctrl.StaticText
>      num =Ctrl.TextNum
>
> # the library considers that everyting is inside a sizer
>      main =sizer([
>                  sizer([st('Ideal gas law').\
> Bold().\
> Italic().\
> PointSize(15)# this lines define an static text with Bold, Italic and 15
> point size
> ],
>                        horzCenter=True),# this line indicates to the
> sizer the control has horizontal alignment
>                  sizer([# sizer can contain indefined number of children
> sizers
>                         sizer([
>                                sizer([st('Pressure:').\
> Bold().\
> Italic().\
>                                          proportion(1),
>                                      num(1).\
> Italic().\
>                                          name('pressure').\
>                                          tooltip('Input the pressure')#
> you can add tooltips by using only an instruction
> ],
>                                      flag=wx.ALL),# the flags are the
> same used by wx
>                                sizer([st('Volume:').\
> Italic().\
>                                          proportion(1),
>                                      num(12).\
>                                          name('volume').\# you can
> define the control name
>                                          tooltip('Input the volume')
> ],
>                                      flag=wx.ALL)
> ],
>                                title='Input params',
>                                horz=wx.VERTICAL,
>                                flag=wx.ALL|wx.EXPAND),
>                         sizer([st('system temperature:').\
> Bold(),
> Ctrl.TextNum(0).\
> Bold().\
>                                  name('result').\
> Enable(False).\
>                                  proportion(1),
> ],
>                               title='Results',
>                               horz=wx.VERTICAL),
> ]),
> ],
>                 title='-',# this tile indicates to show a rectangular
> line containing the widgets
>                 flag=wx.ALL|wx.EXPAND,
>                 horz=wx.VERTICAL,
>                 horzCenter=True)
>
> # Here are som biding
> # You just need to use the name of the control
>      
> main['pressure'].Bind(wx.EVT_TEXT,url_for('temperature_calc',main=main))
>      main['volume'].Bind(wx.EVT_TEXT,url_for('temperature_calc',main=main))
>
> returnmain
>
> if__name__ =='__main__':
>      app =wx.App()
>      mainFrame =GetMainFrame()
>      mainFrame.asFrame(title='wxs demo',size=wx.Size(420,260)).Show()
>      app.MainLoop()
>
>
> |
>
> It would be nice if you express your opinion and sugestions
>
>
> --
> 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]
> <mailto:[hidden email]>.
> For more options, visit https://groups.google.com/d/optout.

--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.

---
This email has been checked for viruses by AVG.
http://www.avg.com

--
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: I'm attemping to simplify the gui creation by a library

sebastian lópez

Thanks to your comments

I changed the code related to your last three points

Here is a minimal example

from wxs import Ctrl, route, url_for
from wxs import wx as wx

def volumecalc(pressure, volume):
   
if not isinstance(pressure, (int, float)):
       
return 0
   
if not isinstance(volume, (int, float)):
       
return 0
    temperature
= round(pressure*volume,2)
   
return temperature

@route('temperature_calc')
def listener(main):
    pressure
=  main['pressure'].Value # you can use the property valuet o Get and Set the Value of the control
    volume
= main['volume'].Value
    main
['result'].Value = volumecalc(pressure, volume)

def Minimum():
    sizer
= Ctrl.Sizer
    st
= Ctrl.StaticText
    num
= Ctrl.TextNum
    main
= sizer([
         st
('Ideal gas law', bold=True, italic=True, pointsize=15),
         st
('Pressure:', bold=True, proportion=1),
         num
(1, name= 'pressure', italic=True, tooltip ='Input the pressure'),
         st
('Volume:', italic=True, proportion=1),
         num
(12, name='volume', tooltip = 'Input the volume'),
         st
('system temperature:', bold= True),
         num
(0, name='result', bold=True, enable=False, proportion=1)
         
],
        title
='-',
        flag
=wx.ALL|wx.EXPAND,
        horz
=wx.VERTICAL,
        horzCenter
=True)

    main
['pressure'].Bind(wx.EVT_TEXT, url_for('temperature_calc', main=main))
    main
['volume'].Bind(wx.EVT_TEXT, url_for('temperature_calc', main=main))

   
return main    
if __name__ == '__main__':
    app
= wx.App()
    mainFrame
= Minimum()
    mainFrame
.asFrame(title='wxs demo', size=wx.Size(200,320)).Show()
    app
.MainLoop()






So the library allows the user to use at least one sizer but if you want to have a better displaying control you should use Sizers inside sizers


El martes, 3 de abril de 2018, 0:02:04 (UTC-5), Gadget Steve escribió:
Hi Sebastian,

A few (hopefully constructive), comments:

1. If the Library considers everything is in a sizer then the user
shouldn't need to define the sizer the library should simply wrap each
thing in a sizer.
2. There seems to be a need to know a lot of the inner workings of the
GUI to be able to use what you are doing - have you considered simply
letting the user define elements with a type, name, user name, tooltip
and either optional range (for floats or ints) or list of options, (the
latter being a tupple of name, user name & tooltip). Your library could
then select the appropriate control type for the type, possibly with an
optional hint from the user.
3. The code would be more pythonic if dictionaries were used rather than
lists of presumably positional arguments.
4. Avoid if possible line continues \ dictionaries will help here as you
will be using {name: value, constructs rather than . and the former can
have a linefeed after each.
5. Definitely avoid \# comment as it can be an error
6. Consider using argparse arguments as your inputs then a command line
and GUI is possible without code duplication.

Hope that is helpful.

Steve

On 03/04/2018 03:09, sebastian lópez wrote:

> <<a href="https://lh3.googleusercontent.com/-GAQeJqaWqCE/WsLiRS0FeRI/AAAAAAAAKCo/syOltoc5r5Ykr9tARR97VruIAi3fhJeLwCLcBGAs/s1600/example1.png" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://lh3.googleusercontent.com/-GAQeJqaWqCE/WsLiRS0FeRI/AAAAAAAAKCo/syOltoc5r5Ykr9tARR97VruIAi3fhJeLwCLcBGAs/s1600/example1.png&#39;;return true;" onclick="this.href=&#39;https://lh3.googleusercontent.com/-GAQeJqaWqCE/WsLiRS0FeRI/AAAAAAAAKCo/syOltoc5r5Ykr9tARR97VruIAi3fhJeLwCLcBGAs/s1600/example1.png&#39;;return true;">https://lh3.googleusercontent.com/-GAQeJqaWqCE/WsLiRS0FeRI/AAAAAAAAKCo/syOltoc5r5Ykr9tARR97VruIAi3fhJeLwCLcBGAs/s1600/example1.png>
>
> Hi everyone at this group
>
> I'm trying to create a library based on wx that can simplify the gui
> creation, and  so I like to show you an example about how I created a gui
>
>
> |
> # including the path to the library
> importsys
> fromos.path importsplit
>
> path =split(split(sys.argv[0])[0])[0]
> ifpath notinsys.path:
>      sys.path.append(path)
> # <
>
> fromwxs importCtrl,route,url_for
> fromwxs importwx aswx
>
> # defining a function to calculate the temperature
> defvolumecalc(pressure,volume):
> ifnotisinstance(pressure,(int,float)):
> return0
> ifnotisinstance(volume,(int,float)):
> return0
>      temperature =round(pressure*volume,2)
> returntemperature
>
> # append the listener
> @route('temperature_calc')
> deflistener(main):
>      pressure = main['pressure'].Value
>      volume =main['volume'].Value
>      main['result'].Value=volumecalc(pressure,volume)
>
> # defining them main function that generates the GUI
> defGetMainFrame():
> # simplifying some names
>      sizer =Ctrl.Sizer
>      st =Ctrl.StaticText
>      num =Ctrl.TextNum
>
> # the library considers that everyting is inside a sizer
>      main =sizer([
>                  sizer([st('Ideal gas law').\
> Bold().\
> Italic().\
> PointSize(15)# this lines define an static text with Bold, Italic and 15
> point size
> ],
>                        horzCenter=True),# this line indicates to the
> sizer the control has horizontal alignment
>                  sizer([# sizer can contain indefined number of children
> sizers
>                         sizer([
>                                sizer([st('Pressure:').\
> Bold().\
> Italic().\
>                                          proportion(1),
>                                      num(1).\
> Italic().\
>                                          name('pressure').\
>                                          tooltip('Input the pressure')#
> you can add tooltips by using only an instruction
> ],
>                                      flag=wx.ALL),# the flags are the
> same used by wx
>                                sizer([st('Volume:').\
> Italic().\
>                                          proportion(1),
>                                      num(12).\
>                                          name('volume').\# you can
> define the control name
>                                          tooltip('Input the volume')
> ],
>                                      flag=wx.ALL)
> ],
>                                title='Input params',
>                                horz=wx.VERTICAL,
>                                flag=wx.ALL|wx.EXPAND),
>                         sizer([st('system temperature:').\
> Bold(),
> Ctrl.TextNum(0).\
> Bold().\
>                                  name('result').\
> Enable(False).\
>                                  proportion(1),
> ],
>                               title='Results',
>                               horz=wx.VERTICAL),
> ]),
> ],
>                 title='-',# this tile indicates to show a rectangular
> line containing the widgets
>                 flag=wx.ALL|wx.EXPAND,
>                 horz=wx.VERTICAL,
>                 horzCenter=True)
>
> # Here are som biding
> # You just need to use the name of the control
>      
> main['pressure'].Bind(wx.EVT_TEXT,url_for('temperature_calc',main=main))
>      main['volume'].Bind(wx.EVT_TEXT,url_for('temperature_calc',main=main))
>
> returnmain
>
> if__name__ =='__main__':
>      app =wx.App()
>      mainFrame =GetMainFrame()
>      mainFrame.asFrame(title='wxs demo',size=wx.Size(420,260)).Show()
>      app.MainLoop()
>
>
> |
>
> It would be nice if you express your opinion and sugestions
>
>
> --
> 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="IxTb1wSYAQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">wxpython-user...@googlegroups.com
> <mailto:<a href="javascript:" target="_blank" gdf-obfuscated-mailto="IxTb1wSYAQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">wxpython-users+unsubscribe@...>.
> For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.

---
This email has been checked for viruses by AVG.
<a href="http://www.avg.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.avg.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPVsPPPUdri1u74y4soGOX1W5g_g&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.avg.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPVsPPPUdri1u74y4soGOX1W5g_g&#39;;return true;">http://www.avg.com

--
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: I'm attemping to simplify the gui creation by a library

sebastian lópez
In reply to this post by GadgetSteve

About the second point I designed the library by using metaclasses so the Ctrl can interactively displays all the controls kind when it's imported by the shell.
I attached an eclipse ide example, It also works under Wing Ide. But the library Jedi doesn't work propertly with metaclasses.

The additional suggestions are wellcome.





El martes, 3 de abril de 2018, 0:02:04 (UTC-5), Gadget Steve escribió:
Hi Sebastian,

A few (hopefully constructive), comments:

1. If the Library considers everything is in a sizer then the user
shouldn't need to define the sizer the library should simply wrap each
thing in a sizer.
2. There seems to be a need to know a lot of the inner workings of the
GUI to be able to use what you are doing - have you considered simply
letting the user define elements with a type, name, user name, tooltip
and either optional range (for floats or ints) or list of options, (the
latter being a tupple of name, user name & tooltip). Your library could
then select the appropriate control type for the type, possibly with an
optional hint from the user.
3. The code would be more pythonic if dictionaries were used rather than
lists of presumably positional arguments.
4. Avoid if possible line continues \ dictionaries will help here as you
will be using {name: value, constructs rather than . and the former can
have a linefeed after each.
5. Definitely avoid \# comment as it can be an error
6. Consider using argparse arguments as your inputs then a command line
and GUI is possible without code duplication.

Hope that is helpful.

Steve

On 03/04/2018 03:09, sebastian lópez wrote:

> <<a href="https://lh3.googleusercontent.com/-GAQeJqaWqCE/WsLiRS0FeRI/AAAAAAAAKCo/syOltoc5r5Ykr9tARR97VruIAi3fhJeLwCLcBGAs/s1600/example1.png" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://lh3.googleusercontent.com/-GAQeJqaWqCE/WsLiRS0FeRI/AAAAAAAAKCo/syOltoc5r5Ykr9tARR97VruIAi3fhJeLwCLcBGAs/s1600/example1.png&#39;;return true;" onclick="this.href=&#39;https://lh3.googleusercontent.com/-GAQeJqaWqCE/WsLiRS0FeRI/AAAAAAAAKCo/syOltoc5r5Ykr9tARR97VruIAi3fhJeLwCLcBGAs/s1600/example1.png&#39;;return true;">https://lh3.googleusercontent.com/-GAQeJqaWqCE/WsLiRS0FeRI/AAAAAAAAKCo/syOltoc5r5Ykr9tARR97VruIAi3fhJeLwCLcBGAs/s1600/example1.png>
>
> Hi everyone at this group
>
> I'm trying to create a library based on wx that can simplify the gui
> creation, and  so I like to show you an example about how I created a gui
>
>
> |
> # including the path to the library
> importsys
> fromos.path importsplit
>
> path =split(split(sys.argv[0])[0])[0]
> ifpath notinsys.path:
>      sys.path.append(path)
> # <
>
> fromwxs importCtrl,route,url_for
> fromwxs importwx aswx
>
> # defining a function to calculate the temperature
> defvolumecalc(pressure,volume):
> ifnotisinstance(pressure,(int,float)):
> return0
> ifnotisinstance(volume,(int,float)):
> return0
>      temperature =round(pressure*volume,2)
> returntemperature
>
> # append the listener
> @route('temperature_calc')
> deflistener(main):
>      pressure = main['pressure'].Value
>      volume =main['volume'].Value
>      main['result'].Value=volumecalc(pressure,volume)
>
> # defining them main function that generates the GUI
> defGetMainFrame():
> # simplifying some names
>      sizer =Ctrl.Sizer
>      st =Ctrl.StaticText
>      num =Ctrl.TextNum
>
> # the library considers that everyting is inside a sizer
>      main =sizer([
>                  sizer([st('Ideal gas law').\
> Bold().\
> Italic().\
> PointSize(15)# this lines define an static text with Bold, Italic and 15
> point size
> ],
>                        horzCenter=True),# this line indicates to the
> sizer the control has horizontal alignment
>                  sizer([# sizer can contain indefined number of children
> sizers
>                         sizer([
>                                sizer([st('Pressure:').\
> Bold().\
> Italic().\
>                                          proportion(1),
>                                      num(1).\
> Italic().\
>                                          name('pressure').\
>                                          tooltip('Input the pressure')#
> you can add tooltips by using only an instruction
> ],
>                                      flag=wx.ALL),# the flags are the
> same used by wx
>                                sizer([st('Volume:').\
> Italic().\
>                                          proportion(1),
>                                      num(12).\
>                                          name('volume').\# you can
> define the control name
>                                          tooltip('Input the volume')
> ],
>                                      flag=wx.ALL)
> ],
>                                title='Input params',
>                                horz=wx.VERTICAL,
>                                flag=wx.ALL|wx.EXPAND),
>                         sizer([st('system temperature:').\
> Bold(),
> Ctrl.TextNum(0).\
> Bold().\
>                                  name('result').\
> Enable(False).\
>                                  proportion(1),
> ],
>                               title='Results',
>                               horz=wx.VERTICAL),
> ]),
> ],
>                 title='-',# this tile indicates to show a rectangular
> line containing the widgets
>                 flag=wx.ALL|wx.EXPAND,
>                 horz=wx.VERTICAL,
>                 horzCenter=True)
>
> # Here are som biding
> # You just need to use the name of the control
>      
> main['pressure'].Bind(wx.EVT_TEXT,url_for('temperature_calc',main=main))
>      main['volume'].Bind(wx.EVT_TEXT,url_for('temperature_calc',main=main))
>
> returnmain
>
> if__name__ =='__main__':
>      app =wx.App()
>      mainFrame =GetMainFrame()
>      mainFrame.asFrame(title='wxs demo',size=wx.Size(420,260)).Show()
>      app.MainLoop()
>
>
> |
>
> It would be nice if you express your opinion and sugestions
>
>
> --
> 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="IxTb1wSYAQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">wxpython-user...@googlegroups.com
> <mailto:<a href="javascript:" target="_blank" gdf-obfuscated-mailto="IxTb1wSYAQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">wxpython-users+unsubscribe@...>.
> For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.

---
This email has been checked for viruses by AVG.
<a href="http://www.avg.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.avg.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPVsPPPUdri1u74y4soGOX1W5g_g&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.avg.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPVsPPPUdri1u74y4soGOX1W5g_g&#39;;return true;">http://www.avg.com

--
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: I'm attemping to simplify the gui creation by a library

sebastian lópez
In reply to this post by sebastian lópez

Here is an example by using the property grid


from datetime import date
from random import randint

from wxs import Ctrl, route, url_for, CtrlPg
from wxs import wx as wx

@route('updatePg')
def leerFecha(main):
   
# changing some Pg controls
    dt
= main['pg']['Date'].Value
    main
['StaticText'].Value = 'Read the date: '+ dt.strftime('%Y/%m/%d')
    main
['pg']['BoolWithCheckbox'].Value = main['pg']['Bool'].Value
    main
['pg']['Bool'].Value = not main['pg']['Bool'].Value

def Minimum():
    controls
= [CtrlPg.ArrayString('ArrayString',['ensayo']),
               
CtrlPg.Bool('Bool', True),
               
CtrlPg.BoolWithCheckbox('BoolWithCheckbox', True),
               
CtrlPg.Category('Categoria 1'),
               
CtrlPg.Colour('Colour',wx.Colour() ),
               
CtrlPg.Date('Date', date.today()),
               
CtrlPg.Dir('Dir',''),
               
CtrlPg.EditEnum('EditEnum',['a','b','c']),
               
CtrlPg.Enum('Enum', ['a','b','c']),
               
CtrlPg.File('File', ''),
               
CtrlPg.Flags('Flags', ['1','2']),
               
CtrlPg.Float('Float', 12.5),
               
CtrlPg.Font('Font', wx.Font()),
               
CtrlPg.Int('Int', 4),
               
CtrlPg.SystemColour('SystemColour'),
               
CtrlPg.LongString('LongString', "message "*20),
               
CtrlPg.MultiChoice('MultiChoice', [str(i) for i in range(10)] ),
               
CtrlPg.String('String','string')
               
]
   
# every Pg control includes its custom editor
   
# so by default the user doesn't need to set editors
   
# actualy the pg is limited by having all controls different texts
   
    pg
= Ctrl.Pg(controls, name='pg', proportion=1)
    main
= Ctrl.Sizer([Ctrl.StaticText('Read the date', name='StaticText'),
                       
Ctrl.Button('Read the date', name='Boton'),
                       pg
],
        title
='-',
        flag
=wx.ALL|wx.EXPAND,
        horz
=wx.VERTICAL,)
   
    main
['Boton'].Bind(wx.EVT_BUTTON, url_for('updatePg', main= main))
   
return main

if __name__ == '__main__':
    app
= wx.App()
    mainFrame
= Minimum()
    mainFrame
.asFrame(title='wxs Propertygrid demo', size=wx.Size(420,450)).Show()
    app
.MainLoop()


In the above example the user doesn´t need to defineby default the editors. It's is under development yet.



El lunes, 2 de abril de 2018, 21:09:31 (UTC-5), sebastian lópez escribió:

<a href="https://lh3.googleusercontent.com/-GAQeJqaWqCE/WsLiRS0FeRI/AAAAAAAAKCo/syOltoc5r5Ykr9tARR97VruIAi3fhJeLwCLcBGAs/s1600/example1.png" style="margin-left:1em;margin-right:1em" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://lh3.googleusercontent.com/-GAQeJqaWqCE/WsLiRS0FeRI/AAAAAAAAKCo/syOltoc5r5Ykr9tARR97VruIAi3fhJeLwCLcBGAs/s1600/example1.png&#39;;return true;" onclick="this.href=&#39;https://lh3.googleusercontent.com/-GAQeJqaWqCE/WsLiRS0FeRI/AAAAAAAAKCo/syOltoc5r5Ykr9tARR97VruIAi3fhJeLwCLcBGAs/s1600/example1.png&#39;;return true;">

Hi everyone at this group

I'm trying to create a library based on wx that can simplify the gui creation, and  so I like to show you an example about how I created a gui


# including the path to the library
import sys
from os.path import split

path
= split(split(sys.argv[0])[0])[0]
if path not in sys.path:
    sys
.path.append(path)
# <

from wxs import Ctrl, route, url_for
from wxs import wx as wx

# defining a function to calculate the temperature
def volumecalc(pressure, volume):
   
if not isinstance(pressure, (int, float)):
       
return 0
   
if not isinstance(volume, (int, float)):
       
return 0
    temperature
= round(pressure*volume,2)
   
return temperature

# append the listener
@route('temperature_calc')
def listener(main):
    pressure
=  main['pressure'].Value
    volume
= main['volume'].Value
    main
['result'].Value = volumecalc(pressure, volume)

# defining them main function that generates the GUI
def GetMainFrame():
   
# simplifying some names
    sizer
= Ctrl.Sizer
    st
= Ctrl.StaticText
    num
= Ctrl.TextNum

   
# the library considers that everyting is inside a sizer
    main
= sizer([
                sizer
([st('Ideal gas law').\
                       
Bold().\
                       
Italic().\
                       
PointSize(15) # this lines define an static text with Bold, Italic and 15 point size
                     
],
                      horzCenter
=True), # this line indicates to the sizer the control has horizontal alignment
                sizer
([ # sizer can contain indefined number of children sizers
                       sizer
([
                              sizer
([st('Pressure:').\
                                       
Bold().\
                                       
Italic().\
                                        proportion
(1),
                                    num
(1).\
                                       
Italic().\
                                        name
('pressure').\
                                        tooltip
('Input the pressure')# you can add tooltips by using only an instruction
                                   
],
                                    flag
=wx.ALL),# the flags are the same used by wx
                              sizer
([st('Volume:').\
                                       
Italic().\
                                        proportion
(1),
                                    num
(12).\
                                        name
('volume').\ # you can define the control name
                                        tooltip
('Input the volume')
                                   
],
                                    flag
=wx.ALL)
                             
],
                              title
='Input params',
                              horz
=wx.VERTICAL,
                              flag
=wx.ALL|wx.EXPAND),
                       sizer
([st('system temperature:').\
                               
Bold(),
                             
Ctrl.TextNum(0).\
                               
Bold().\
                                name
('result').\
                               
Enable(False).\
                                proportion
(1),
                             
],
                             title
='Results',
                             horz
=wx.VERTICAL),
                     
]),
               
],
               title
='-',# this tile indicates to show a rectangular line containing the widgets
               flag
=wx.ALL|wx.EXPAND,
               horz
=wx.VERTICAL,
               horzCenter
=True)

   
# Here are som biding
   
# You just need to use the name of the control
    main
['pressure'].Bind(wx.EVT_TEXT, url_for('temperature_calc', main=main))
    main
['volume'].Bind(wx.EVT_TEXT, url_for('temperature_calc', main=main))

   
return main

if __name__ == '__main__':
    app
= wx.App()
    mainFrame
= GetMainFrame()
    mainFrame
.asFrame(title='wxs demo', size=wx.Size(420,260)).Show()
    app
.MainLoop()



It would be nice if you express your opinion and sugestions


--
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.