a99.gui package¶
Submodules¶
a99.gui.a_WBase module¶
-
class
a99.gui.a_WBase.WBase(parent)¶ Bases:
PyQt5.QtWidgets.QWidgetWidget with ‘changed’ signal, keep_ref(), logging tools
-
add_log(x, flag_also_show=False)¶ Delegates to parent form
-
add_log_error(x, flag_also_show=False, E=None)¶ Delegates to parent form
-
changed¶
-
clear_log()¶
-
keep_ref(obj)¶ Adds obj to internal list to keep a reference to it.
WHen using PyQt, it happens that the Python object gets garbage-collected even when a C++ Qt object still exists, causing a mess
-
status(msg)¶ Probably shows message in status bar
-
update_gui_label_fn()¶
-
a99.gui.a_WCollapsiblePanel module¶
a99.gui.a_WConfigEditor module¶
-
class
a99.gui.a_WConfigEditor.WConfigEditor(*args, **kwargs)¶ Bases:
a99.gui.a_WEditor.WEditorBase class for FileConfig editors
-
class
a99.gui.a_WConfigEditor.CEMapItem(fieldname, guiobj, propertyname=None, getter=None, setter=None)¶ Bases:
objectConfig Editor map item
There to way to get-set values. The order of precedence is as follows:
(getter, setter) > (guiobj, propertyname)- Notes on building an editor:
- properties must block signals (implement self._after_update_gui() if necessary)
-
get_value()¶
-
set_value(value)¶
a99.gui.a_WDBRegistry module¶
-
class
a99.gui.a_WDBRegistry.WDBRegistry(*args)¶ Bases:
a99.gui.a_WBase.WBaseBase class for registry widgets
- Comes with
- table widget
- tool bar
- set of actions
- signals: id_changed, changed
- ‘id’ and ‘row’ properties
-
eventFilter(source, event)¶
-
f¶ Object representing the file being edited (possibly a DataFile object)
-
id¶ Molecule id or None
-
id_changed¶
-
on_delete()¶
-
on_edit()¶
-
on_insert()¶
-
on_tableWidget_currentCellChanged(currentRow, currentColumn, previousRow, previousColumn)¶
-
on_tableWidget_customContextMenuRequested(position)¶
-
on_tableWidget_doubleClicked()¶
-
row¶ Returns current data row – MyDBRow object, or None
a99.gui.a_WEditor module¶
a99.gui.a_WParametersEditor module¶
Parameters Editor Widget. Mostly used embedded in XParametersEditor
-
class
a99.gui.a_WParametersEditor.WParametersEditor(parent=None, specs=None, parameters=None)¶ Bases:
PyQt5.QtWidgets.QWidgetParameters editor widget.
Parameters: - parent=None –
- -- list as [ (specs=None) – to Parameters constructor. Parameter.FromSpec() for full documentation.
- -- Parameters instance. If passed, ignores specs and sets (parameters=None) –
- parameters attribute directly (internal) –
-
ParametersChanged¶
-
get_kwargs()¶
-
setFocus(reason=None)¶ Sets focus to first field. Note: reason is ignored.
-
set_error_text(x)¶
-
validate()¶
a99.gui.a_WSelectFileOrDir module¶
-
class
a99.gui.a_WSelectFileOrDir.WSelectDir(*args, **kwargs)¶ Bases:
a99.gui.a_WSelectFileOrDir._WSelectFileOrDir
-
class
a99.gui.a_WSelectFileOrDir.WSelectFile(*args, **kwargs)¶ Bases:
a99.gui.a_WSelectFileOrDir._WSelectFileOrDir
a99.gui.a_XLogDialog module¶
-
class
a99.gui.a_XLogDialog.XLogDialog(parent=None)¶ Bases:
PyQt5.QtWidgets.QDialog,a99.gui._logpart._LogPartQDialog subclass that carries a logging facility
a99.gui.a_XLogMainWindow module¶
-
class
a99.gui.a_XLogMainWindow.XLogMainWindow(parent=None)¶ Bases:
PyQt5.QtWidgets.QMainWindow,a99.gui._logpart._LogPartQMainWindow subclass that carries a logging facility
a99.gui.a_XParametersEditor module¶
Parameters Editor dialog.
-
class
a99.gui.a_XParametersEditor.XParametersEditor(parent=None, specs=None, title=None)¶ Bases:
PyQt5.QtWidgets.QDialog,a99.gui.ui_XParametersEditor.Ui_XParametersEditorParameters: - -- nevermind (parent=None) –
- -- Required! list as [ (specs=None) – to Parameters constructor. Parameter.FromSpec() for full documentation.
-
accept()¶
-
get_kwargs()¶
-
show()¶
a99.gui.errorcollector module¶
-
class
a99.gui.errorcollector.ErrorCollector(flag_warnings=True)¶ Bases:
objectWalks through directory in search for files ‘python.log’ and ‘fortran.log’.
Parameters: flag_warnings – collect warnings (besides errors)? Opens these files and extracts error information from them (if found).
-
collect_errors(path_)¶
-
get_html()¶
-
get_plain_text()¶ Returns a list of strings
-
-
class
a99.gui.errorcollector.Occurrence(filename, type_, line, message)¶ Bases:
objectClass that carries information about an error/warning, with HTML rendering ability
-
colors= {'undefined': '#000000', 'warning': '#C98A00', 'error': '#AA0000', 'cannot open': '#AA0000'}¶
-
get_html()¶
-
get_plain_text()¶ Returns a list
-
a99.gui.parameter module¶
-
class
a99.gui.parameter.Parameter(spec=None)¶ Bases:
objectDefinition of a single parameter, with QWidget rendering facility
-
FromSpec(spec)¶ Parameters: spec – (name, {…}), or Parameter object - Dict keys:
- “caption” – (optional) text for label in editor. Defaults to the
- keyword argument name
“toolTip” (optional) “type” – (optional, defaults to type(“value”) or int if “value” is
- not specified. Accepts:
- int
- float
- str
- bool
- list
- “value” – (optional) defaults to 1 if numeric, False if bool,
- “” if str
-
RenderWidget()¶ Returns a QWidget subclass instance. Exact class depends on self.type
-
UpdateValueFromWidget()¶
-
a99.gui.syntax module¶
https://wiki.python.org/moin/PyQt/Python%20syntax%20highlighting
-
class
a99.gui.syntax.PythonHighlighter(document)¶ Bases:
PyQt5.QtGui.QSyntaxHighlighterSyntax highlighter for the Python language.
-
braces= ['\\{', '\\}', '\\(', '\\)', '\\[', '\\]']¶
-
highlightBlock(text)¶ Apply syntax highlighting to the given block of text.
-
keywords= ['and', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'yield', 'None', 'True', 'False']¶
-
match_multiline(text, delimiter, in_state, style)¶ Do highlighting of multi-line strings.
delimitershould be aQRegExpfor triple-single-quotes or triple-double-quotes, andin_stateshould be a unique integer to represent the corresponding state changes when inside those strings. Returns True if we’re still inside a multi-line string when this function is finished.
-
operators= ['=', '==', '!=', '<', '<=', '>', '>=', '\\+', '-', '\\*', '/', '//', '\\%', '\\*\\*', '\\+=', '-=', '\\*=', '/=', '\\%=', '\\^', '\\|', '\\&', '\\~', '>>', '<<']¶
-
a99.gui.ui_XParametersEditor module¶
a99.gui.xmisc module¶
-
a99.gui.xmisc.keep_ref(obj)¶ Keeps a reference to Python object representing a C++ Qt object
- Rationale: Qt windows may simply disappear when the Python object (e.g., QMainWindow())
- representing a Qt object runs out of scope (i.e., the program leaves the method that created the Python object). Python deletes the object and the C++ object may be deleted as well. Keeping these objects in a list prevents this from happening.
Drawback will keep reference until the Python program finishes.
Returns: obj
-
a99.gui.xmisc.check_return_space(event, callable_)¶ Checks if event corresponds to Return/Space being pressed and calls callable_ if so.
-
a99.gui.xmisc.show_error(s)¶
-
a99.gui.xmisc.enc_name_descr(name, descr, color='#222222')¶ Encodes html given name and description.
-
class
a99.gui.xmisc.SignalProxy(signals, delay=0.3, rateLimit=0, slot=None, flag_connect=True)¶ Bases:
PyQt5.QtCore.QObjectObject which collects rapid-fire signals and condenses them into a single signal or a rate-limited stream of signals. Used, for example, to prevent a SpinBox from generating multiple signals when the mouse wheel is rolled over it.
Emits sigDelayed after input signals have stopped for a certain period of time.
Note: queued connection is made to slot.
Original author: Luke Campagnola – pyqtgraph package
Parameters: - -- a list of bound signals or pyqtSignal instance (signals) –
- -- Time (delay=0.3) –
- -- Optional function to connect sigDelayed to. (slot) –
- -- (rateLimit=0) – stream out at a steady rate while they are being received.
- -- whether or not to start with the connections already (flag_connect=True) – made. If False, the signals and slots can be connected by calling connect_all()
-
add_signal(signal)¶ Adds “input” signal to connected signals. Internally connects the signal to a control slot.
-
connect_all()¶ [Re-]connects all signals and slots.
If already in “connected” state, ignores the call.
-
disconnect_all()¶ Disconnects all signals and slots.
If already in “disconnected” state, ignores the call.
-
a99.gui.xmisc.are_you_sure(flag_changed, evt, parent=None, title='File has been changed', msg='Are you sure you want to exit?')¶ “Are you sure you want to exit” question dialog.
If flag_changed, shows question dialog. If answer is not yes, calls evt.ignore()
Parameters: - flag_changed –
- -- QCloseEvent instance (evt) –
- -- parent form, used to centralize the question dialog at (parent=None) –
- -- title for question dialog (title) –
- -- text of question dialog (msg) –
Returns True or False. True means: “yes, I want to exit”
-
a99.gui.xmisc.show_warning(s)¶
-
a99.gui.xmisc.style_checkboxes(widget)¶ Iterates over widget children to change checkboxes stylesheet.
The default rendering of checkboxes does not allow to tell a focused one from an unfocused one.
-
class
a99.gui.xmisc.VerticalLabel¶ Bases:
PyQt5.QtWidgets.QLabelLabel that draws itself vertically.
- This was created to be used at lateral title:
- It paints in bold
- No HTML support
-
minimumSizeHint()¶
-
paintEvent(evt)¶
-
sizeHint()¶
-
a99.gui.xmisc.show_message(s)¶
-
a99.gui.xmisc.get_matplotlib_layout(widget, flag_toolbar=True)¶ Creates figure, toolbar, layout, sets widget layout
Returns figure, canvas, layout
Reference: http://stackoverflow.com/questions/12459811
-
a99.gui.xmisc.nerdify(window)¶
-
a99.gui.xmisc.place_center(window, width=None, height=None)¶ Places window in the center of the screen.
-
a99.gui.xmisc.get_window_title(prefix)¶
-
a99.gui.xmisc.style_widget_changed(spinbox, flag_changed)¶ (Paints background yellow)/(removes stylesheet)
-
a99.gui.xmisc.get_QApplication(args=[])¶ Returns the QApplication instance, creating it is does not yet exist.
-
a99.gui.xmisc.get_icon(keyword)¶ Transforms a PNG file in a QIcon
Looks for a file named <keyword>.png in the “icons” directory
If file does not exist, returns None
-
a99.gui.xmisc.show_edit_form(obj, attrs=None, title='')¶ Shows parameters editor modal form.
Parameters: -- object to extract attribute values from, or a dict-like (obj) – attrs – list of attribute names
-
a99.gui.xmisc.snap_left(window, width=None)¶ Snaps window to left of desktop. :param window – a QWidget: :param width=None – window width, in case you want to change it: :type width=None – window width, in case you want to change it: if not passed, not changed
-
a99.gui.xmisc.snap_right(window, width=None)¶ Snaps window to right of desktop. :param window – a QWidget: :param width=None – window width, in case you want to change it: :type width=None – window width, in case you want to change it: if not passed, not changed
-
a99.gui.xmisc.enc_name(name, color='#222222')¶ Encodes html given name.
-
a99.gui.xmisc.place_left_top(window, width=None, height=None)¶ Places window in top left corner of screen.
Parameters: - -- a QWidget (window) –
- -- window width, in case you want to change it (width=None) –
- -- window height, in case you want to change it (height=None) –
-
a99.gui.xmisc.reset_table_widget(t, rowCount, colCount)¶ Clears and resizes a table widget.
-
a99.gui.xmisc.table_info_to_parameters(table_info)¶ Converts a list of MyDBRow into a parameters.Parameters object
This facilitates transfering data from SQLite table row to a XParameterEditor window
See also: get_table_info()
-
a99.gui.xmisc.format_title0(s)¶ Formats string as first-level title (to use as QLabel text)
-
a99.gui.xmisc.format_title1(s)¶ Formats string as second-level title (to use as QLabel text)
-
a99.gui.xmisc.format_title2(s)¶ Formats string as third-level title (to use as QLabel text)
-
a99.gui.xmisc.style_widget_valid(spinbox, flag_valid)¶ (Paints background pastel red)/(removes stylesheet)
Reference: http://www.colorhexa.com/ff6961
-
a99.gui.xmisc.set_margin(obj, margin)¶ …because Qt5 no longer has xxxx.setMargin() method
-
a99.gui.xmisc.get_frame()¶ Returns a QFrame formatted in a particular way
-
a99.gui.xmisc.set_checkbox_value(w, value)¶ Sets a checkbox’s “checked” property + signal blocking + value tolerance
Parameters: - w – QCheckBox instance
- value – something that can be converted to a bool
Module contents¶
API to facilitate building a GUI
- Reusable and subclassable widgets and windows
- miscellanea of GUI-related features in xmisc.py
- Python syntax highlighter
- File naming conventions:
- a_X*.py : classes descending from QMainWindow or QMainDialog a_W*.py : widgets