Skip to content

Commit 88ba5c8

Browse files
Merge pull request #395 from AndreWohnsland/dev
v1: fix numpad disappearing on main window click
2 parents 55039d5 + 9165986 commit 88ba5c8

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

src/display_controller.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
QApplication,
1212
QCheckBox,
1313
QComboBox,
14+
QDialog,
1415
QLabel,
1516
QLayout,
1617
QLineEdit,
@@ -40,7 +41,7 @@
4041

4142
class ItemDelegate(QStyledItemDelegate):
4243
def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex) -> None:
43-
option.decorationPosition = QStyleOptionViewItem.Right # type: ignore
44+
option.decorationPosition = QStyleOptionViewItem.Right
4445
super().paint(painter, option, index)
4546

4647

@@ -93,7 +94,7 @@ def get_list_widget_selection(self, list_widget: QListWidget) -> str:
9394
# use selected items because currentItem is sometimes still last and not the current one ...
9495
# The widget got only single select, so there is always (if there is a selection) one item
9596
first_selected = selected[0]
96-
user_data: Cocktail | None = first_selected.data(Qt.UserRole) # type: ignore
97+
user_data: Cocktail | None = first_selected.data(Qt.UserRole)
9798
if user_data:
9899
# If the user data is a cocktail object, return the name, else the user data
99100
# Usually the data should be a cocktail object, but fallback if it may set differently
@@ -248,17 +249,28 @@ def change_input_value(
248249
def set_display_settings(self, window_object: QWidget, resize: bool = True) -> None:
249250
"""Check dev environment, adjust cursor and resize accordingly, if resize is wished."""
250251
if not cfg.UI_DEVENVIRONMENT:
251-
window_object.setCursor(Qt.BlankCursor) # type: ignore
252+
window_object.setCursor(Qt.BlankCursor)
252253
if resize:
253254
window_object.setFixedSize(cfg.UI_WIDTH, cfg.UI_HEIGHT)
254255
window_object.resize(cfg.UI_WIDTH, cfg.UI_HEIGHT)
255256

256-
def initialize_window_object(self, window_object: QWidget, x_pos: int = 0, y_pos: int = 0) -> None:
257+
def initialize_window_object(
258+
self,
259+
window_object: QWidget,
260+
x_pos: int = 0,
261+
y_pos: int = 0,
262+
stay_on_top: bool = True,
263+
) -> None:
257264
"""Initialize the window, set according flags, sets icon and stylesheet."""
258-
window_object.setWindowFlags(
259-
Qt.Window | Qt.FramelessWindowHint | Qt.CustomizeWindowHint | Qt.WindowStaysOnTopHint # type: ignore
260-
)
261-
window_object.setAttribute(Qt.WA_DeleteOnClose) # type: ignore
265+
# Respect the widget type so dialogs keep their expected modality behavior.
266+
if isinstance(window_object, QDialog):
267+
flags = Qt.Dialog | Qt.FramelessWindowHint | Qt.CustomizeWindowHint
268+
else:
269+
flags = Qt.Window | Qt.FramelessWindowHint | Qt.CustomizeWindowHint
270+
if stay_on_top:
271+
flags |= Qt.WindowStaysOnTopHint
272+
window_object.setWindowFlags(flags)
273+
window_object.setAttribute(Qt.WA_DeleteOnClose)
262274
self.inject_stylesheet(window_object)
263275
icon_path = str(APP_ICON_FILE)
264276
window_object.setWindowIcon(QIcon(icon_path))
@@ -277,7 +289,7 @@ def set_tab_width(self, mainscreen: MainScreen) -> None:
277289
# especially on the rpi, we need a little bit more space than mathematically calculated
278290
width_buffer = 15
279291
width = round((total_width - first_tab_width) / 4, 0) - width_buffer
280-
mainscreen.tabWidget.setStyleSheet( # type: ignore
292+
mainscreen.tabWidget.setStyleSheet(
281293
"QTabBar::tab {"
282294
+ f"width: {width}px;"
283295
+ "}"
@@ -356,7 +368,7 @@ def fill_multiple_combobox_individually(
356368

357369
def delete_single_combobox_item(self, combobox: QComboBox, item: str) -> None:
358370
"""Delete the given item from a combobox."""
359-
index = combobox.findText(item, Qt.MatchFixedString) # type: ignore
371+
index = combobox.findText(item, Qt.MatchFixedString)
360372
if index >= 0:
361373
combobox.removeItem(index)
362374

@@ -383,21 +395,21 @@ def set_multiple_combobox_items(self, combobox_list: list[QComboBox], items_to_s
383395

384396
def set_combobox_item(self, combobox: QComboBox, item: str) -> None:
385397
"""Set the combobox to the given item."""
386-
index = combobox.findText(item, Qt.MatchFixedString) # type: ignore
398+
index = combobox.findText(item, Qt.MatchFixedString)
387399
combobox.setCurrentIndex(index)
388400

389401
def adjust_bottle_comboboxes(self, combobox_list: list[QComboBox], old_item: str, new_item: str) -> None:
390402
"""Remove the old item name and add new one in given comboboxes, sorting afterwards."""
391403
for combobox in combobox_list:
392-
if (old_item != "") and (combobox.findText(old_item, Qt.MatchFixedString) < 0): # type: ignore
404+
if (old_item != "") and (combobox.findText(old_item, Qt.MatchFixedString) < 0):
393405
combobox.addItem(old_item)
394406
if (new_item != "") and (new_item != combobox.currentText()):
395407
self.delete_single_combobox_item(combobox, new_item)
396408
combobox.model().sort(0)
397409

398410
def rename_single_combobox(self, combobox: QComboBox, old_item: str, new_item: str) -> None:
399411
"""Rename the old item to new one in given box."""
400-
index = combobox.findText(old_item, Qt.MatchFixedString) # type: ignore
412+
index = combobox.findText(old_item, Qt.MatchFixedString)
401413
if index >= 0:
402414
combobox.setItemText(index, new_item)
403415
combobox.model().sort(0)
@@ -442,7 +454,7 @@ def select_list_widget_item(self, list_widget: QListWidget, to_select: str | Coc
442454

443455
def delete_list_widget_item(self, list_widget: QListWidget, item: str) -> None:
444456
"""Delete an item in the list widget."""
445-
index_to_delete = list_widget.findItems(item, Qt.MatchExactly) # type: ignore
457+
index_to_delete = list_widget.findItems(item, Qt.MatchExactly)
446458
if len(index_to_delete) > 0:
447459
for index in index_to_delete:
448460
list_widget.takeItem(list_widget.row(index))
@@ -467,7 +479,7 @@ def _generate_list_widget_item(self, item_data: str | Cocktail) -> QListWidgetIt
467479

468480
else:
469481
lw_item = QListWidgetItem(item_data)
470-
lw_item.setData(Qt.UserRole, item_data) # type: ignore
482+
lw_item.setData(Qt.UserRole, item_data)
471483
return lw_item
472484

473485
def clear_list_widget(self, list_widget: QListWidget) -> None:

src/ui/setup_numpad_widget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(
2525
header_is_entered_number: bool = False,
2626
) -> None:
2727
"""Init. Connect all the buttons and set window policy."""
28-
super().__init__()
28+
super().__init__(parent)
2929
self.setupUi(self)
3030
DP_CONTROLLER.initialize_window_object(self, x_pos, y_pos)
3131
# Connect all the buttons, generates a list of the numbers an object names to do that

0 commit comments

Comments
 (0)