Making an assert a bit more helpful
[gonvert] / src / gonvert_qt.py
index c0e68b8..561c737 100755 (executable)
@@ -10,12 +10,14 @@ import os
 import math
 import simplejson
 import logging
+import logging.handlers
 
-from PyQt4 import QtGui
-from PyQt4 import QtCore
+import util.qt_compat as qt_compat
+QtCore = qt_compat.QtCore
+QtGui = qt_compat.import_module("QtGui")
 
 import constants
-import maeqt
+from util import qui_utils
 from util import misc as misc_utils
 import unit_data
 
@@ -424,12 +426,12 @@ class QuickConvert(object):
                self._favoritesWindow = None
 
                self._inputUnitValue = QtGui.QLineEdit()
-               maeqt.mark_numbers_preferred(self._inputUnitValue)
+               qui_utils.mark_numbers_preferred(self._inputUnitValue)
                self._inputUnitValue.textEdited.connect(self._on_value_edited)
                self._inputUnitSymbol = QtGui.QLabel()
 
                self._outputUnitValue = QtGui.QLineEdit()
-               maeqt.mark_numbers_preferred(self._outputUnitValue)
+               qui_utils.mark_numbers_preferred(self._outputUnitValue)
                self._outputUnitValue.textEdited.connect(self._on_output_value_edited)
                self._outputUnitSymbol = QtGui.QLabel()
 
@@ -442,6 +444,7 @@ class QuickConvert(object):
                self._categoryView = QtGui.QTreeWidget()
                self._categoryView.setHeaderLabels(["Categories"])
                self._categoryView.setHeaderHidden(False)
+               self._categoryView.setRootIsDecorated(False)
                if not constants.IS_MAEMO:
                        self._categoryView.setAlternatingRowColors(True)
                self._categoryView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
@@ -456,6 +459,7 @@ class QuickConvert(object):
                self._inputView.setHeaderLabels(["From", "Name"])
                self._inputView.setHeaderHidden(False)
                self._inputView.header().hideSection(1)
+               self._inputView.setRootIsDecorated(False)
                if not constants.IS_MAEMO:
                        self._inputView.setAlternatingRowColors(True)
                self._inputView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
@@ -467,6 +471,7 @@ class QuickConvert(object):
                self._outputView.setHeaderLabels(["To", "Name"])
                self._outputView.setHeaderHidden(False)
                self._outputView.header().hideSection(1)
+               self._outputView.setRootIsDecorated(False)
                if not constants.IS_MAEMO:
                        self._outputView.setAlternatingRowColors(True)
                self._outputView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
@@ -489,8 +494,7 @@ class QuickConvert(object):
 
                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)
+               qui_utils.set_stackable(self._window, True)
                self._window.setWindowTitle("%s - Quick Convert" % (constants.__pretty_app_name__, ))
                self._window.setWindowIcon(QtGui.QIcon(app.appIconPath))
                self._window.setCentralWidget(centralWidget)
@@ -827,7 +831,7 @@ class QuickConvert(object):
                        for item in self._outputView.selectedItems()
                ]
                if selectedNames:
-                       assert len(selectedNames) == 1
+                       assert len(selectedNames) == 1, selectedNames
                        name = selectedNames[0]
                        self._select_output(name)
                else:
@@ -845,6 +849,7 @@ class CategoryWindow(object):
                self._categories.setHeaderLabels(["Categories"])
                self._categories.itemClicked.connect(self._on_category_clicked)
                self._categories.setHeaderHidden(True)
+               self._categories.setRootIsDecorated(False)
                self._categories.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
                self._categories.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
                if not constants.IS_MAEMO:
@@ -861,8 +866,7 @@ class CategoryWindow(object):
 
                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)
+               qui_utils.set_stackable(self._window, True)
                self._window.setWindowTitle("%s - Categories" % constants.__pretty_app_name__)
                self._window.setWindowIcon(QtGui.QIcon(self._app.appIconPath))
                self._window.setCentralWidget(centralWidget)
@@ -1247,7 +1251,7 @@ class UnitWindow(object):
                self._selectedUnitName = QtGui.QLabel()
                self._selectedUnitValue = QtGui.QLineEdit()
                self._selectedUnitValue.textEdited.connect(self._on_value_edited)
-               maeqt.mark_numbers_preferred(self._selectedUnitValue)
+               qui_utils.mark_numbers_preferred(self._selectedUnitValue)
                self._selectedUnitSymbol = QtGui.QLabel()
                self._updateDelayTimer = QtCore.QTimer()
                self._updateDelayTimer.setInterval(100)
@@ -1264,6 +1268,7 @@ class UnitWindow(object):
                self._unitsView.setModel(self._unitsModel)
                self._unitsView.setUniformRowHeights(True)
                self._unitsView.setSortingEnabled(True)
+               self._unitsView.setRootIsDecorated(False)
                self._unitsView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
                self._unitsView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
                self._unitsView.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
@@ -1299,8 +1304,7 @@ class UnitWindow(object):
 
                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)
+               qui_utils.set_stackable(self._window, True)
                self._window.setWindowTitle("%s - %s" % (constants.__pretty_app_name__, category))
                self._window.setWindowIcon(QtGui.QIcon(app.appIconPath))
                self._window.setCentralWidget(centralWidget)
@@ -1549,6 +1553,23 @@ class UnitWindow(object):
 
 
 def run_gonvert():
+       try:
+               os.makedirs(constants._data_path_)
+       except OSError, e:
+               if e.errno != 17:
+                       raise
+
+       logFormat = '(%(relativeCreated)5d) %(levelname)-5s %(threadName)s.%(name)s.%(funcName)s: %(message)s'
+       logging.basicConfig(level=logging.DEBUG, format=logFormat)
+       rotating = logging.handlers.RotatingFileHandler(constants._user_logpath_, maxBytes=512*1024, backupCount=1)
+       rotating.setFormatter(logging.Formatter(logFormat))
+       root = logging.getLogger()
+       root.addHandler(rotating)
+       _moduleLogger.info("%s %s-%s" % (constants.__app_name__, constants.__version__, constants.__build__))
+       _moduleLogger.info("OS: %s" % (os.uname()[0], ))
+       _moduleLogger.info("Kernel: %s (%s) for %s" % os.uname()[2:])
+       _moduleLogger.info("Hostname: %s" % os.uname()[1])
+
        app = QtGui.QApplication([])
        handle = Gonvert(app)
        if constants.PROFILE_STARTUP:
@@ -1559,12 +1580,5 @@ def run_gonvert():
 
 if __name__ == "__main__":
        import sys
-       logging.basicConfig(level = logging.DEBUG)
-       try:
-               os.makedirs(constants._data_path_)
-       except OSError, e:
-               if e.errno != 17:
-                       raise
-
        val = run_gonvert()
        sys.exit(val)