Re: Extra code / Extra properties

"Brendan Simon (eTRIX)" <[email protected]>
Newsgroups gmane.comp.python.wxglade
Organization eTRIX pty ltd
Message-ID <[email protected]>
On 7/11/17 6:07 am, Dietmar Schwertberger wrote:
> Hi!
>
> Is anyone actually using "Extra properties for this widget"?
>
> I was just about to prepare a code example for how to use the
> CustomWidget for adding classes that are not supported natively by
> wxGlade.
>
> My example would be a matplotlib canvas. This requires some imports
> and a bit of code before and after creation, as it requires an object
> to be created and supplied as argument. The workaround would be to
> derive a class and use this instead of the original matplotlib canvas.
> That's possible, but not too nice.
>
> I'm completely missing a way to specify the code to be executed before
> creation of an object.
>
> Also, for the code after creation, there's only the method to specify
> extra properties.
> E.g. property "maxLength" and value "10".
> This is then magically converted to
> self.my_custom_widget.SetMaxLength(10).
>
> Personally, I would prefer to have three fields:
>  * Extra import code (added on module level, just as now).
>  * Extra setup code (to be called right before the widget is
> instantiated)
>  * Extra code (to be called right after the widget is instantiated)
>
> With this setup, I'm wondering whether the Extra properties make sense
> any more.
>
> What do you think? Do you have real-world examples? Do you have any
> preferences in favour or against such a change?
>
> In theory the Extra properties have the advantage that they are
> language-neutral, but I have some doubts whether this has practical
> relevance.

I've used `CustomWidget` to implement a plot canvas from `wx.lib`

I put the following in the Extra Code section for the widget instance.

    import my_custom_plot


and specify the following as the Class (in Common tab).

    my_custom_plot.MyCustomPlot


The custom widget class definition and constructor are:

    import wx
    from wx.lib import plot as wxplot

    class MyCustomPlot(wxplot.PlotCanvas):

        def __init__(self, *args, **kwds):

            #! these attributes are used in other methods when updating
    the graph,
            #! and can be specified by Extra Properties in wxglade,
            #! however I now use a `set_props()` method from the main app
            #! to set these properties (and others that may not be
    settable in the constructor)
            self.line_colour = kwds.pop('line_colour', "red")
            self.line_width  = kwds.pop('line_width',  1) 
            self.axes_colour = kwds.pop('axes_colour', "blue")

            wxplot.PlotCanvas.__init__(self, *args, **kwds)

            self.clear()

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

_______________________________________________
wxGlade-general mailing list
wxGlade-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/wxglade-general
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.