Skip to content

Commit

Permalink
REF: Add property MainWindow.current_tab
Browse files Browse the repository at this point in the history
  • Loading branch information
kernc committed Dec 28, 2022
1 parent 8d48aca commit 096a7b6
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions efck/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def __init__(self, parent):
from .tabs._options import OptionsTab

def _on_text_edited():
tab = self.tabs[self.currentIndex()]
tab = self.current_tab
text = tab.line_edit.text()
logger.debug('Text edited: %s', text)
if hasattr(tab.model, 'set_text'):
Expand Down Expand Up @@ -212,7 +212,7 @@ def _on_tab_changed(idx):

# End in the following state and wait for user input

self.tabs[self.currentIndex()].line_edit.setFocus()
self.current_tab.line_edit.setFocus()
options_tab.findChild(QSlider).setFocus() # On Options tab, set focus to first child
self.setCurrentIndex(config_state['selected_tab'])
self.raise_()
Expand Down Expand Up @@ -246,13 +246,10 @@ def keyPressEvent(self, event: QKeyEvent):
if key == Qt.Key.Key_Escape or event.matches(QKeySequence.StandardKey.Cancel):
QApplication.instance().quit()

tab = self.current_tab
# Don't handle other keypresses on Options tab here
tab_index = self.currentIndex()
OPTIONS_TAB_IDX = len(self.tabs)
if tab_index == OPTIONS_TAB_IDX:
if not tab:
return

tab = self.tabs[self.currentIndex()]
view = tab.view

# Alt+[1-9] selects and activates the corresponding view item
Expand Down Expand Up @@ -289,9 +286,16 @@ def keyPressEvent(self, event: QKeyEvent):
BUGGY_ALT_NUMERIC_KEYPRESS_SLEEP_MS = 1
WM_SWITCH_ACTIVE_WINDOW_SLEEP_MS = 1

@property
def current_tab(self):
try:
return self.tabs[self.currentIndex()]
except IndexError:
return None # I.e. on Options tab

def on_activated(self):
"""On listView activation, type out the characters and exit the app"""
tab = self.tabs[self.currentIndex()]
tab = self.current_tab

# Ensure some view item is selected
mi = tab.view.currentIndex()
Expand Down

0 comments on commit 096a7b6

Please sign in to comment.