from __future__ import with_statement
-import sys
import os
import math
import simplejson
_moduleLogger = logging.getLogger(__name__)
-IS_MAEMO = True
-
-
def split_number(number):
if number == 0.0:
# Optimize the startup case
return self._mainWindow
def search_units(self):
- jumpWindow = QuickJump(None, self)
+ import windows
+ jumpWindow = windows.QuickJump(None, self)
jumpWindow.window.destroyed.connect(self._on_jump_close)
self._jumpWindow = jumpWindow
return self._jumpWindow
def show_recent(self):
- recentWindow = Recent(None, self)
+ import windows
+ recentWindow = windows.Recent(None, self)
recentWindow.window.destroyed.connect(self._on_recent_close)
self._recentWindow = recentWindow
return self._recentWindow
self._close_windows()
-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()
-
-
class QuickConvert(object):
def __init__(self, parent, app):
self._categoryView = QtGui.QTreeWidget()
self._categoryView.setHeaderLabels(["Categories"])
self._categoryView.setHeaderHidden(False)
- if not IS_MAEMO:
+ if not constants.IS_MAEMO:
self._categoryView.setAlternatingRowColors(True)
self._categoryView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self._categoryView.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
self._inputView.setHeaderLabels(["From", "Name"])
self._inputView.setHeaderHidden(False)
self._inputView.header().hideSection(1)
- if not IS_MAEMO:
+ if not constants.IS_MAEMO:
self._inputView.setAlternatingRowColors(True)
self._inputView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self._inputView.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
self._outputView.setHeaderLabels(["To", "Name"])
self._outputView.setHeaderHidden(False)
self._outputView.header().hideSection(1)
- if not IS_MAEMO:
+ if not constants.IS_MAEMO:
self._outputView.setAlternatingRowColors(True)
self._outputView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self._outputView.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
self._closeWindowAction.setShortcut(QtGui.QKeySequence("CTRL+w"))
self._closeWindowAction.triggered.connect(self._on_close_window)
- if IS_MAEMO:
+ if constants.IS_MAEMO:
self._window.addAction(self._closeWindowAction)
self._window.addAction(self._app.quitAction)
self._window.addAction(self._app.fullscreenAction)
@misc_utils.log_exception(_moduleLogger)
def _on_choose_category_favorites(self, obj = None):
assert self._favoritesWindow is None
- self._favoritesWindow = FavoritesWindow(
+ import windows
+ self._favoritesWindow = windows.FavoritesWindow(
self._window,
self._app,
unit_data.UNIT_CATEGORIES,
@misc_utils.log_exception(_moduleLogger)
def _on_choose_unit_favorites(self, obj = None):
assert self._favoritesWindow is None
- self._favoritesWindow = FavoritesWindow(
+ import windows
+ self._favoritesWindow = windows.FavoritesWindow(
self._window,
self._app,
unit_data.get_units(self._categoryName),
pass
-class FavoritesWindow(object):
-
- def __init__(self, parent, app, source, hidden):
- self._app = app
- self._source = list(source)
- self._hidden = hidden
-
- self._categories = QtGui.QTreeWidget()
- self._categories.setHeaderLabels(["Categories"])
- self._categories.setHeaderHidden(True)
- self._categories.setSelectionMode(QtGui.QAbstractItemView.NoSelection)
- if not IS_MAEMO:
- self._categories.setAlternatingRowColors(True)
- self._childWidgets = []
- for catName in self._source:
- twi = QtGui.QTreeWidgetItem(self._categories)
- twi.setText(0, catName)
- self._childWidgets.append(twi)
- if catName in self._hidden:
- twi.setCheckState(0, QtCore.Qt.Unchecked)
- else:
- twi.setCheckState(0, QtCore.Qt.Checked)
- self._categories.itemChanged.connect(self._on_item_changed)
-
- self._allButton = QtGui.QPushButton("All")
- self._allButton.clicked.connect(self._on_select_all)
- self._invertButton = QtGui.QPushButton("Invert")
- self._invertButton.clicked.connect(self._on_invert_selection)
- self._noneButton = QtGui.QPushButton("None")
- self._noneButton.clicked.connect(self._on_select_none)
-
- self._buttonLayout = QtGui.QHBoxLayout()
- self._buttonLayout.addWidget(self._allButton)
- self._buttonLayout.addWidget(self._invertButton)
- self._buttonLayout.addWidget(self._noneButton)
-
- self._layout = QtGui.QVBoxLayout()
- self._layout.addWidget(self._categories)
- self._layout.addLayout(self._buttonLayout)
-
- 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 - Favorites" % 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_select_all(self, checked = False):
- for child in self._childWidgets:
- child.setCheckState(0, QtCore.Qt.Checked)
-
- @misc_utils.log_exception(_moduleLogger)
- def _on_invert_selection(self, checked = False):
- for child in self._childWidgets:
- state = child.checkState(0)
- if state == QtCore.Qt.Unchecked:
- newState = QtCore.Qt.Checked
- elif state == QtCore.Qt.Checked:
- newState = QtCore.Qt.Unchecked
- else:
- raise RuntimeError("Bad check state %r" % state)
- child.setCheckState(0, newState)
-
- @misc_utils.log_exception(_moduleLogger)
- def _on_select_none(self, checked = False):
- for child in self._childWidgets:
- child.setCheckState(0, QtCore.Qt.Unchecked)
-
- @misc_utils.log_exception(_moduleLogger)
- def _on_item_changed(self, item, column):
- state = item.checkState(column)
- if state == QtCore.Qt.Unchecked:
- name = str(item.text(column))
- self._hidden.add(name)
- elif state == QtCore.Qt.Checked:
- name = str(item.text(column))
- self._hidden.remove(name)
- else:
- raise RuntimeError("Bad check state %r" % state)
-
- @misc_utils.log_exception(_moduleLogger)
- def _on_close_window(self, checked = True):
- self.close()
-
-
class CategoryWindow(object):
def __init__(self, parent, app):
self._categories.setHeaderHidden(True)
self._categories.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self._categories.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
- if not IS_MAEMO:
+ if not constants.IS_MAEMO:
self._categories.setAlternatingRowColors(True)
for catName in unit_data.UNIT_CATEGORIES:
twi = QtGui.QTreeWidgetItem(self._categories)
self._closeWindowAction.setShortcut(QtGui.QKeySequence("CTRL+w"))
self._closeWindowAction.triggered.connect(self._on_close_window)
- if IS_MAEMO:
+ if constants.IS_MAEMO:
fileMenu = self._window.menuBar().addMenu("&Units")
fileMenu.addAction(self._chooseFavoritesAction)
@misc_utils.log_exception(_moduleLogger)
def _on_choose_favorites(self, obj = None):
assert self._favoritesWindow is None
- self._favoritesWindow = FavoritesWindow(
+ import windows
+ self._favoritesWindow = windows.FavoritesWindow(
self._window,
self._app,
unit_data.UNIT_CATEGORIES,
self._unitsView.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
self._unitsView.setHeaderHidden(True)
self._unitsView.clicked.connect(self._on_unit_clicked)
- if not IS_MAEMO:
+ if not constants.IS_MAEMO:
self._unitsView.setAlternatingRowColors(True)
viewHeader = self._unitsView.header()
self._closeWindowAction.setShortcut(QtGui.QKeySequence("CTRL+w"))
self._closeWindowAction.triggered.connect(self._on_close_window)
- if IS_MAEMO:
+ if constants.IS_MAEMO:
self._window.addAction(self._closeWindowAction)
self._window.addAction(self._app.quitAction)
self._window.addAction(self._app.fullscreenAction)
@misc_utils.log_exception(_moduleLogger)
def _on_choose_favorites(self, obj = None):
assert self._favoritesWindow is None
- self._favoritesWindow = FavoritesWindow(
+ import windows
+ self._favoritesWindow = windows.FavoritesWindow(
self._window,
self._app,
unit_data.get_units(self._categoryName),
if __name__ == "__main__":
+ import sys
logging.basicConfig(level = logging.DEBUG)
try:
os.makedirs(constants._data_path_)
--- /dev/null
+#!/usr/bin/env python
+
+from __future__ import with_statement
+from __future__ import division
+
+import logging
+
+from PyQt4 import QtGui
+from PyQt4 import QtCore
+
+import constants
+import maeqt
+from util import misc as misc_utils
+import unit_data
+
+
+_moduleLogger = logging.getLogger(__name__)
+
+
+class FavoritesWindow(object):
+
+ def __init__(self, parent, app, source, hidden):
+ self._app = app
+ self._source = list(source)
+ self._hidden = hidden
+
+ self._categories = QtGui.QTreeWidget()
+ self._categories.setHeaderLabels(["Categories"])
+ self._categories.setHeaderHidden(True)
+ self._categories.setSelectionMode(QtGui.QAbstractItemView.NoSelection)
+ if not constants.IS_MAEMO:
+ self._categories.setAlternatingRowColors(True)
+ self._childWidgets = []
+ for catName in self._source:
+ twi = QtGui.QTreeWidgetItem(self._categories)
+ twi.setText(0, catName)
+ self._childWidgets.append(twi)
+ if catName in self._hidden:
+ twi.setCheckState(0, QtCore.Qt.Unchecked)
+ else:
+ twi.setCheckState(0, QtCore.Qt.Checked)
+ self._categories.itemChanged.connect(self._on_item_changed)
+
+ self._allButton = QtGui.QPushButton("All")
+ self._allButton.clicked.connect(self._on_select_all)
+ self._invertButton = QtGui.QPushButton("Invert")
+ self._invertButton.clicked.connect(self._on_invert_selection)
+ self._noneButton = QtGui.QPushButton("None")
+ self._noneButton.clicked.connect(self._on_select_none)
+
+ self._buttonLayout = QtGui.QHBoxLayout()
+ self._buttonLayout.addWidget(self._allButton)
+ self._buttonLayout.addWidget(self._invertButton)
+ self._buttonLayout.addWidget(self._noneButton)
+
+ self._layout = QtGui.QVBoxLayout()
+ self._layout.addWidget(self._categories)
+ self._layout.addLayout(self._buttonLayout)
+
+ 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 - Favorites" % 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 constants.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_select_all(self, checked = False):
+ for child in self._childWidgets:
+ child.setCheckState(0, QtCore.Qt.Checked)
+
+ @misc_utils.log_exception(_moduleLogger)
+ def _on_invert_selection(self, checked = False):
+ for child in self._childWidgets:
+ state = child.checkState(0)
+ if state == QtCore.Qt.Unchecked:
+ newState = QtCore.Qt.Checked
+ elif state == QtCore.Qt.Checked:
+ newState = QtCore.Qt.Unchecked
+ else:
+ raise RuntimeError("Bad check state %r" % state)
+ child.setCheckState(0, newState)
+
+ @misc_utils.log_exception(_moduleLogger)
+ def _on_select_none(self, checked = False):
+ for child in self._childWidgets:
+ child.setCheckState(0, QtCore.Qt.Unchecked)
+
+ @misc_utils.log_exception(_moduleLogger)
+ def _on_item_changed(self, item, column):
+ state = item.checkState(column)
+ if state == QtCore.Qt.Unchecked:
+ name = str(item.text(column))
+ self._hidden.add(name)
+ elif state == QtCore.Qt.Checked:
+ name = str(item.text(column))
+ self._hidden.remove(name)
+ else:
+ raise RuntimeError("Bad check state %r" % state)
+
+ @misc_utils.log_exception(_moduleLogger)
+ def _on_close_window(self, checked = True):
+ self.close()
+
+
+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 constants.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 constants.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 constants.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 constants.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()