-class QuickJump(object):
-
- MINIMAL_ENTRY = 3
-
- def __init__(self, parent, app):
- self._app = app
-
- self._searchLabel = QtGui.QLabel("Search:")
- self._searchEntry = QtGui.QLineEdit("")
- self._searchEntry.textEdited.connect(self._on_search_edited)
-
- self._entryLayout = QtGui.QHBoxLayout()
- self._entryLayout.addWidget(self._searchLabel)
- self._entryLayout.addWidget(self._searchEntry)
-
- self._resultsBox = QtGui.QTreeWidget()
- self._resultsBox.setHeaderLabels(["Categories", "Units"])
- self._resultsBox.setHeaderHidden(True)
- if not IS_MAEMO:
- self._resultsBox.setAlternatingRowColors(True)
- self._resultsBox.itemClicked.connect(self._on_result_clicked)
-
- self._layout = QtGui.QVBoxLayout()
- self._layout.addLayout(self._entryLayout)
- self._layout.addWidget(self._resultsBox)
-
- centralWidget = QtGui.QWidget()
- centralWidget.setLayout(self._layout)
-
- self._window = QtGui.QMainWindow(parent)
- self._window.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
- maeqt.set_autorient(self._window, True)
- maeqt.set_stackable(self._window, True)
- self._window.setWindowTitle("%s - Quick Jump" % constants.__pretty_app_name__)
- self._window.setWindowIcon(QtGui.QIcon(self._app.appIconPath))
- self._window.setCentralWidget(centralWidget)
-
- self._closeWindowAction = QtGui.QAction(None)
- self._closeWindowAction.setText("Close")
- self._closeWindowAction.setShortcut(QtGui.QKeySequence("CTRL+w"))
- self._closeWindowAction.triggered.connect(self._on_close_window)
-
- if IS_MAEMO:
- self._window.addAction(self._closeWindowAction)
- self._window.addAction(self._app.quitAction)
- self._window.addAction(self._app.fullscreenAction)
- else:
- fileMenu = self._window.menuBar().addMenu("&Units")
- fileMenu.addAction(self._closeWindowAction)
- fileMenu.addAction(self._app.quitAction)
-
- viewMenu = self._window.menuBar().addMenu("&View")
- viewMenu.addAction(self._app.fullscreenAction)
-
- self._window.addAction(self._app.logAction)
-
- self.set_fullscreen(self._app.fullscreenAction.isChecked())
- self._window.show()
-
- @property
- def window(self):
- return self._window
-
- def show(self):
- self._window.show()
-
- def hide(self):
- self._window.hide()
-
- def close(self):
- self._window.close()
-
- def set_fullscreen(self, isFullscreen):
- if isFullscreen:
- self._window.showFullScreen()
- else:
- self._window.showNormal()
-
- @misc_utils.log_exception(_moduleLogger)
- def _on_close_window(self, checked = True):
- self.close()
-
- @misc_utils.log_exception(_moduleLogger)
- def _on_result_clicked(self, item, columnIndex):
- categoryName = unicode(item.text(0))
- unitName = unicode(item.text(1))
- catWindow = self._app.request_category()
- unitsWindow = catWindow.select_category(categoryName)
- unitsWindow.select_unit(unitName)
- self.close()
-
- @misc_utils.log_exception(_moduleLogger)
- def _on_search_edited(self, *args):
- userInput = self._searchEntry.text()
- if len(userInput) < self.MINIMAL_ENTRY:
- return
-
- self._resultsBox.clear()
- lowerInput = str(userInput).lower()
- for catIndex, category in enumerate(unit_data.UNIT_CATEGORIES):
- units = unit_data.get_units(category)
- for unitIndex, unit in enumerate(units):
- loweredUnit = unit.lower()
- if lowerInput in loweredUnit:
- twi = QtGui.QTreeWidgetItem(self._resultsBox)
- twi.setText(0, category)
- twi.setText(1, unit)
-
-
-class Recent(object):
-
- def __init__(self, parent, app):
- self._app = app
-
- self._resultsBox = QtGui.QTreeWidget()
- self._resultsBox.setHeaderLabels(["Categories", "Units"])
- self._resultsBox.setHeaderHidden(True)
- if not IS_MAEMO:
- self._resultsBox.setAlternatingRowColors(True)
- self._resultsBox.itemClicked.connect(self._on_result_clicked)
-
- self._layout = QtGui.QVBoxLayout()
- self._layout.addWidget(self._resultsBox)
-
- centralWidget = QtGui.QWidget()
- centralWidget.setLayout(self._layout)
-
- self._window = QtGui.QMainWindow(parent)
- self._window.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
- maeqt.set_autorient(self._window, True)
- maeqt.set_stackable(self._window, True)
- self._window.setWindowTitle("%s - Recent" % constants.__pretty_app_name__)
- self._window.setWindowIcon(QtGui.QIcon(self._app.appIconPath))
- self._window.setCentralWidget(centralWidget)
-
- for cat, unit in self._app.get_recent():
- twi = QtGui.QTreeWidgetItem(self._resultsBox)
- twi.setText(0, cat)
- twi.setText(1, unit)
-
- self._closeWindowAction = QtGui.QAction(None)
- self._closeWindowAction.setText("Close")
- self._closeWindowAction.setShortcut(QtGui.QKeySequence("CTRL+w"))
- self._closeWindowAction.triggered.connect(self._on_close_window)
-
- if IS_MAEMO:
- self._window.addAction(self._closeWindowAction)
- self._window.addAction(self._app.quitAction)
- self._window.addAction(self._app.fullscreenAction)
- else:
- fileMenu = self._window.menuBar().addMenu("&Units")
- fileMenu.addAction(self._closeWindowAction)
- fileMenu.addAction(self._app.quitAction)
-
- viewMenu = self._window.menuBar().addMenu("&View")
- viewMenu.addAction(self._app.fullscreenAction)
-
- self._window.addAction(self._app.logAction)
-
- self.set_fullscreen(self._app.fullscreenAction.isChecked())
- self._window.show()
-
- @property
- def window(self):
- return self._window
-
- def show(self):
- self._window.show()
-
- def hide(self):
- self._window.hide()
-
- def close(self):
- self._window.close()
-
- def set_fullscreen(self, isFullscreen):
- if isFullscreen:
- self._window.showFullScreen()
- else:
- self._window.showNormal()
-
- @misc_utils.log_exception(_moduleLogger)
- def _on_close_window(self, checked = True):
- self.close()
-
- @misc_utils.log_exception(_moduleLogger)
- def _on_result_clicked(self, item, columnIndex):
- categoryName = unicode(item.text(0))
- unitName = unicode(item.text(1))
- catWindow = self._app.request_category()
- unitsWindow = catWindow.select_category(categoryName)
- unitsWindow.select_unit(unitName)
- self.close()
-
-