Skip to content

Code organization and convention

Fabrice edited this page Mar 9, 2025 · 11 revisions

Code organization

A modular approach is attempted to get shorter files. The name of the module is the name of the class. These modules are located in src folder. Additional classes are built to reduce the size of objects, especially widgets. An attempt is made to get cleaner code to reduce chances to get lost in my own code.

Conventions

Formatting

PEP-8 limits of 80 characters for code or 72 characters for docstrings are not considered.

Functions

Always start with a verb followed by nouns and additional information if needed. Names of instances must not be used, instead the descriptives names of the object should be used -> application for root window.

Start of name

  • Change message of status -> set_
  • Create widget -> create_
  • Prepare something -> setup_ or define_
  • Plot one or several curves or update a plot -> plot_
  • Read or write a file -> read / write
  • Retrieve or modify a value -> get / set

End of name

  • Tabbed panels in notebook (RH panel) -> _tab
  • Modification of curve out of Curve class -> _curve
  • CSV curves or Curve objects -> curve

Variables

  • Class composition links main GUI class to lower level classes. Master class of any widget -> self.parent

Constants

Always with UPPER CASE. Defined in Constants class

End of name for widgets

  • Label -> lbl
  • Entry -> ent
  • Spinbox -> sbx
  • Combobox -> cbx
  • Listbox -> lbx
  • tkMessageBox -> mbx
  • Checkbutton -> cbn
  • Radiobutton -> rbn
  • Button -> btn
  • Menubutton -> mbn
  • text -> txt
  • Frame -> frm
  • Labelframe -> lfm
  • Input -> inp
  • Notebook -> ntb
  • Frame -> frm
  • Canva -> cva
  • Scale -> scl
  • Panedwindow -> pwn
  • Frame -> frm
  • Progressbar -> pbr
  • Scrollbar -> sbr

End of name

  • Related to a directory -> _dir
  • Related to a file -> _file

Curve class

  • Point data read from CSV file -> input_points
  • Point data ready for plotting after a possible processing (offset, shift, etc.) -> points
  • Flag for visibility of curve on plot -> is_shown
  • Line attributes -> line_color, line_width, line_style, line_marker