Skip to content

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

  1. create a module in a2element
  2. Have Draw and Edit 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)
  • Edit
    • derive it from a2element.EditCtrl
    • give it a self.ctrlType for display in the EditCtrl-side menu and check_new_name() (see below)
    • set self.helpUrl with a documentation url registered in a2core 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 where editLayout is the main layout in your design. Please name it editLayout 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)
  • 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

The old way:

  1. create a new module in a2\ui\a2ctrl
  • give it a short descriptive name
  • currently there are:
    • check
    • combo
    • group
    • hotkey
    • string
    • ...
  1. Have Draw and Edit 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)
  • Edit
    • derive it from a2ctrl.EditCtrl
    • give it a self.ctrlType for display in the EditCtrl-side menu and check_new_name() (see below)
    • set self.helpUrl with a documentation url registered in a2core 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 where editLayout is the main layout in your design. Please name it editLayout 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)
  1. in a2ctrl.__init__.py
  • enlist your control module in the imports at the bottom of the file
  • enlist your classes in draw_classes and edit_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
  1. 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.