GUI.Utils.guiutils module

Copyright (C) Korcan Karaokçu <korcankaraokcu@gmail.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

GUI.Utils.guiutils.append_shortcut_to_tooltip(qt_object, shortcut)[source]

Appends key string of the given QShortcut to the toolTip of the given QObject

Parameters:
  • qt_object (QObject) – Self-explanatory

  • shortcut (QShortcut) – Self-explanatory

GUI.Utils.guiutils.center(window)[source]

Center the given window to desktop

Parameters:

window (QWidget) – The window that’ll be centered to desktop

GUI.Utils.guiutils.center_scroll_bar(scrollbar)[source]

Center the given scrollbar

Parameters:

scrollbar (QScrollbar) – Self-explanatory

GUI.Utils.guiutils.center_to_parent(window)[source]

Center the given window to its parent

Parameters:

window (QWidget) – The window that’ll be centered to its parent

GUI.Utils.guiutils.contains_reference_mark(string)[source]

Checks if given string contains the reference mark

Parameters:

string (str) – String that’ll be checked for the reference mark

Returns:

True if given string contains the reference mark, False otherwise

Return type:

bool

GUI.Utils.guiutils.delete_menu_entries(menu, QAction_list)[source]

Deletes given QActions from the QMenu recursively and cleans up the remaining redundant separators and menus Doesn’t support menus that includes types other than actions, separators and menus

Parameters:
  • menu (QMenu) – Self-explanatory

  • QAction_list (list) – List of QActions. Leave blank if you just want to clean the redundant separators up

GUI.Utils.guiutils.fill_endianness_combobox(combobox, current_index=0)[source]

Fills the given QComboBox with endianness strings

Parameters:
  • combobox (QComboBox) – The combobox that’ll be filled

  • current_index (int) – Can be a member of typedefs.ENDIANNESS

GUI.Utils.guiutils.fill_value_combobox(combobox, current_index=2)[source]

Fills the given QComboBox with value_index strings

Parameters:
  • combobox (QComboBox) – The combobox that’ll be filled

  • current_index (int) – Can be a member of typedefs.VALUE_INDEX

GUI.Utils.guiutils.get_current_item(widget)[source]

Returns the currently selected item for the given widget If you try to use only selectionModel().currentItem() for this purpose, you’ll get the last selected item even if it was unselected afterwards. This is why this function exists, it checks the selection state before returning the selected item. Unlike get_current_row, this function can be used with QTreeWidget

Parameters:

widget (QListWidget | QTableWidget | QTreeWidget) – Self-explanatory

Returns:

Currently selected item. Returns None if nothing is selected

Return type:

Any

Note

This function doesn’t work properly when used within signals such as currentItemChanged, currentIndexChanged, currentChanged and currentRowChanged. Use the row, item, QModelIndex or whatever the signal provides instead. This bug occurs because those signals only update the changed row, not the selectionModel. This causes selectionModel().selectedRows() to return None and this function to behave improperly

For developers: You can use the regex .current.*.connect to search signals if a cleanup is needed

GUI.Utils.guiutils.get_current_row(tablewidget)[source]

Returns the currently selected row index for the given QTableWidget If you try to use only selectionModel().currentIndex().row() for this purpose, you’ll get the last selected row even if it was unselected afterwards. This is why this function exists, it checks the selection state before returning the selected row

Parameters:

tablewidget (QTableWidget) – Self-explanatory

Returns:

Currently selected row. Returns -1 if nothing is selected

Return type:

int

Note

This function doesn’t work properly when used within signals such as currentItemChanged, currentIndexChanged, currentChanged and currentRowChanged. Use the row, item, QModelIndex or whatever the signal provides instead. This bug occurs because those signals only update the changed row, not the selectionModel. This causes selectionModel().selectedRows() to return None and this function to behave improperly

For developers: You can use the regex .current.*.connect to search signals if a cleanup is needed

GUI.Utils.guiutils.get_icons_directory()[source]

Gets the directory of the icons

Returns:

Path to the icons directory

Return type:

str

GUI.Utils.guiutils.get_layout_widgets(layout)[source]

Returns the widgets of a QLayout as a list

Parameters:

layout (QLayout) – Self-explanatory

Returns:

A list that contains the widgets of the given layout

Return type:

list

GUI.Utils.guiutils.resize_to_contents(tablewidget)[source]

Resizes the columns of the given QTableWidget to its contents This also fixes the stretch problem of the last column

Parameters:

tablewidget (QTableWidget) – Self-explanatory

GUI.Utils.guiutils.search_parents_by_function(qt_object, func_name)[source]

Search for func_name in the parents of given QObject. Once function is found, parent that possesses func_name is returned

Parameters:
  • qt_object (QObject) – The object that’ll be searched for it’s parents

  • func_name (str) – The name of the function that’ll be searched