-
Notifications
You must be signed in to change notification settings - Fork 10
Create New Control Type
Eric Werner edited this page Sep 4, 2016
·
4 revisions
Creating new control elements should be much easier as it currently is. To also have it layed out and find ways to make it shorter here are the steps to do it at the moment: Maybe we can automate that from the UI actually ...
The new way: wip...
- create a module in a2element
- Have
Draw
andEdit
classes in there and a get_settings function
- Draw
- derive it from
a2element.DrawCtrl
- get user values via
self.get_user_value(value_type, 'value_name')
- set user values via
self.set_user_value('value_name', value)
- get config values from dict like
self.cfg.get('value_name', default_value)
- derive it from
- Edit
- derive it from
a2element.EditCtrl
- give it a
self.ctrlType
for display in the EditCtrl-side menu andcheck_new_name()
(see below) - set
self.helpUrl
with a documentation url registered ina2core
URLs class - do
self.ui = CONTROLTYPE_edit_ui.Ui_edit()
if you load your ui from a generated ui-module - perform
self.ui.setupUi(self.mainWidget)
on self.mainWidget! - do
self.mainWidget.setLayout(self.ui.editLayout)
at the end whereeditLayout
is the main layout in your design. Please name iteditLayout
for consistency. - use
self.check_new_name()
to make it create a new unique internal name based upon the module name and ctrlType value - use
self.connect_cfg_controls(self.ui)
- derive it from
- get_settings
- will be called with 4 arguments:
- module_key: the module_source|module_name identifyer for the database
- cfg: the layout dictionary with the settings from edit mode
- db_dict: the dictionary to put your data into
- user_cfg: the config values with user changes amended
- will be called with 4 arguments:
The old way:
- create a new module in
a2\ui\a2ctrl
- give it a short descriptive name
- currently there are:
- check
- combo
- group
- hotkey
- string
- ...
- Have
Draw
andEdit
classes in there
- Draw
- derive it from
a2ctrl.DrawCtrl
- get user values via
self.get_user_value(value_type, 'value_name')
- set user values via
self.set_user_value('value_name', value)
- get config values from dict like
self.cfg.get('value_name', default_value)
- derive it from
- Edit
- derive it from
a2ctrl.EditCtrl
- give it a
self.ctrlType
for display in the EditCtrl-side menu andcheck_new_name()
(see below) - set
self.helpUrl
with a documentation url registered ina2core
URLs class - do
self.ui = CONTROLTYPE_edit_ui.Ui_edit()
if you load your ui from a generated ui-module - perform
self.ui.setupUi(self.mainWidget)
on self.mainWidget! - do
self.mainWidget.setLayout(self.ui.editLayout)
at the end whereeditLayout
is the main layout in your design. Please name iteditLayout
for consistency. - use
self.check_new_name()
to make it create a new unique internal name based upon the module name and ctrlType value - use
self.connect_cfg_controls(self.ui)
- derive it from
- in
a2ctrl.__init__.py
- enlist your control module in the imports at the bottom of the file
- enlist your classes in
draw_classes
andedit_classes
at the bottom of the file so they can be drawn in the according mode. - enlist you ui-module in the
ui_modules
-list so it's automatically re-compiled if you made any changes in QDesigner. - enlist your icons in
Icons
class
- in
a2mod.py
- make sure your control type is listed in the
VALUE_MAP
so that it's value is automatically written to the database or removed from there if it was reset to default.