Would like to copy component parameters and events when duplicating forms to create similar components.
or…maybe…
Automagically (good magic) create parameters based on @property
and events based on self.raise_event()
and then be able to edit them in the components dialog.
Cheers!
Good news – both of these are already implemented
(I’m therefore moving this from “Feature Requests” to “Q&A”.)
copy component parameters and events when duplicating forms
You’ll want the Duplicate option on the form drop-down menu. It duplicates code, components, event handlers - everything:

create parameters … and events … and then be able to edit them in the components dialog
You’ll want the Use as component option on the form drop-down menu (see above). Once you’ve set a form up as a custom component, you can define properties (which are just attributes, so @property
works), and events (which can be used with raise_event()
). The form will then appear in the Toolbox, and you can set up its properties and events like any other component.
We have a full reference for custom components, including code samples and screenshots, here.
1 Like
Thank you, Meredydd! I followed the docs for Custom Components and was successful in creating my component in very little time. Works great!
Here’s an example of what I’m experiencing. Ultimately, I’m asking for a “Duplicate as component” feature or some variation thereof.
Example:
I create a Blank Panel, add a Label and this code:
class Form1(Form1Template):
def __init__(self, **properties):
# You must call self.init_components() before doing anything else in this function
self.init_components(**properties)
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
self.label_1.text = self._text
@text.getter
def text(self):
return self._text
Then I define my parameter text
in the Use as component dialog.
Everything works great!
Now I want to duplicate the form and change the text
property to be bound to a Text Box instead of a Label.
So I duplicate the form and the code and components are all there but the Use as component option is unchecked and its properties and events have been cleared.
A Duplicate as component feature would be good or, a larger feature request might be to autopopulate the Use as component UI to auto-populate its parameters and events, based on @property
and raise_event()
, upon checking the Make this form available as a component box.