Skip to content

Commit

Permalink
Added shortcut Ctrl-E to set focus to search box
Browse files Browse the repository at this point in the history
  • Loading branch information
wooni005 committed Aug 7, 2020
1 parent 95fb391 commit e6448c9
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import subprocess

from PySide2.QtCore import Qt, QAbstractTableModel, QRect, QSize, QPoint, QSettings
from PySide2.QtGui import QStandardItemModel, QStandardItem, QIcon
from PySide2.QtWidgets import (QApplication, QMenu, QMainWindow, QMessageBox, QHeaderView, QSplitter, QTableView, QGroupBox, QFrame, QVBoxLayout, QCheckBox, QHBoxLayout, QLabel, QLineEdit, QPushButton)
from PySide2.QtGui import QStandardItemModel, QStandardItem, QIcon, QKeySequence
from PySide2.QtWidgets import (QApplication, QMenu, QMainWindow, QMessageBox, QHeaderView, QSplitter, QTableView, QGroupBox, QFrame, QVBoxLayout, QCheckBox, QHBoxLayout, QLabel, QLineEdit, QPushButton, QShortcut)

from src import search
from src import sidebar
Expand Down Expand Up @@ -63,6 +63,13 @@ def __init__(self):
self.menuBar().addMenu(helpMenu)
self.statusBar()
self.setWindowTitle("Tracker Search")
self.setSearchBoxFocus()

shortcut = QShortcut(QKeySequence("Ctrl+E"), self)
shortcut.activated.connect(self.setSearchBoxFocus)

def setSearchBoxFocus(self):
# print("setSearchBoxFocus")
self.searchBoxLineEdit.setFocus()

def informationMessage(self):
Expand Down Expand Up @@ -174,18 +181,15 @@ def __init__(self, dataModel):

def keyPressEvent(self, event):
super(QTableView, self).keyPressEvent(event)
# Determine the current selected table row
indexes = self.selectionModel().selectedRows()
for index in sorted(indexes):
self.selectedRow = index.row()

# Open the file when hitting enter or return
if (event.key() == Qt.Key_Return) or (event.key() == Qt.Key_Enter):
url = self.dataModel.index(self.selectedRow, 5).data()
self.openFileWithDefaultApplication(url)
# elif event.key == Qt.Key_Down:
# print("KeyDown")
# elif event.key == Qt.Key_Up:
# print("KeyUp")
# else:
# print(event.key)

def onTableClicked(self, event):
self.selectedRow = event.row()
Expand Down

0 comments on commit e6448c9

Please sign in to comment.