Bump to 1.1.6 to fix a user issue
[gonvert] / gonvert / gonvert_qt.py
index 370ea5e..074c4de 100755 (executable)
@@ -8,7 +8,11 @@ from __future__ import with_statement
 
 import os
 import math
 
 import os
 import math
-import simplejson
+try:
+       import json as simplejson
+except ImportError:
+       print "json not available, falling back to simplejson"
+       import simplejson
 import logging
 import logging.handlers
 
 import logging
 import logging.handlers
 
@@ -579,11 +583,12 @@ class QuickConvert(object):
        def select_category(self, categoryName):
                self._select_category(categoryName)
 
        def select_category(self, categoryName):
                self._select_category(categoryName)
 
+               self._categoryView.clearSelection()
                i = unit_data.UNIT_CATEGORIES.index(categoryName)
                rootIndex = self._categoryView.rootIndex()
                currentIndex = self._categoryView.model().index(i, 0, rootIndex)
                self._categoryView.scrollTo(currentIndex)
                i = unit_data.UNIT_CATEGORIES.index(categoryName)
                rootIndex = self._categoryView.rootIndex()
                currentIndex = self._categoryView.model().index(i, 0, rootIndex)
                self._categoryView.scrollTo(currentIndex)
-               self._categoryView.setItemSelected(self._categoryView.topLevelItem(i), True)
+               self._categoryView.topLevelItem(i).setSelected(True)
 
                return self
 
 
                return self
 
@@ -594,20 +599,22 @@ class QuickConvert(object):
        def select_input(self, name):
                self._select_input(name)
 
        def select_input(self, name):
                self._select_input(name)
 
+               self._inputView.clearSelection()
                i = self._unitNames.index(name)
                rootIndex = self._inputView.rootIndex()
                currentIndex = self._inputView.model().index(i, 0, rootIndex)
                self._inputView.scrollTo(currentIndex)
                i = self._unitNames.index(name)
                rootIndex = self._inputView.rootIndex()
                currentIndex = self._inputView.model().index(i, 0, rootIndex)
                self._inputView.scrollTo(currentIndex)
-               self._inputView.setItemSelected(self._inputView.topLevelItem(i), True)
+               self._inputView.topLevelItem(i).setSelected(True)
 
        def select_output(self, name):
                self._select_output(name)
 
 
        def select_output(self, name):
                self._select_output(name)
 
+               self._outputView.clearSelection()
                i = self._unitNames.index(name)
                rootIndex = self._outputView.rootIndex()
                currentIndex = self._outputView.model().index(i, 0, rootIndex)
                self._outputView.scrollTo(currentIndex)
                i = self._unitNames.index(name)
                rootIndex = self._outputView.rootIndex()
                currentIndex = self._outputView.model().index(i, 0, rootIndex)
                self._outputView.scrollTo(currentIndex)
-               self._outputView.setItemSelected(self._outputView.topLevelItem(i), True)
+               self._outputView.topLevelItem(i).setSelected(True)
 
        def _select_category(self, categoryName):
                self._inputUnitName = ""
 
        def _select_category(self, categoryName):
                self._inputUnitName = ""
@@ -640,7 +647,13 @@ class QuickConvert(object):
                if defaultInputUnitName:
                        self.select_input(defaultInputUnitName)
                        defaultOutputUnitName = self._app.get_recent_unit(categoryName, 1)
                if defaultInputUnitName:
                        self.select_input(defaultInputUnitName)
                        defaultOutputUnitName = self._app.get_recent_unit(categoryName, 1)
-                       assert defaultOutputUnitName
+                       if not defaultOutputUnitName:
+                               _moduleLogger.error(
+                                       "Somehow we have an odd numer of items in the history for category %r with only %r present",
+                                       categoryName,
+                                       defaultInputUnitName,
+                               )
+                               defaultOutputUnitName = defaultInputUnitName
                        self.select_output(defaultOutputUnitName)
 
        def _select_input(self, name):
                        self.select_output(defaultOutputUnitName)
 
        def _select_input(self, name):
@@ -813,8 +826,8 @@ class QuickConvert(object):
                        str(item.text(0))
                        for item in self._categoryView.selectedItems()
                ]
                        str(item.text(0))
                        for item in self._categoryView.selectedItems()
                ]
-               assert len(selectedNames) == 1
-               self._select_category(selectedNames[0])
+               if selectedNames:
+                       self._select_category(selectedNames[0])
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_input_selection_changed(self, selected, deselected):
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_input_selection_changed(self, selected, deselected):
@@ -952,11 +965,12 @@ class CategoryWindow(object):
        def select_category(self, categoryName):
                self._select_category(categoryName)
 
        def select_category(self, categoryName):
                self._select_category(categoryName)
 
+               self._categories.clearSelection()
                i = unit_data.UNIT_CATEGORIES.index(categoryName)
                rootIndex = self._categories.rootIndex()
                currentIndex = self._categories.model().index(i, 0, rootIndex)
                self._categories.scrollTo(currentIndex)
                i = unit_data.UNIT_CATEGORIES.index(categoryName)
                rootIndex = self._categories.rootIndex()
                currentIndex = self._categories.model().index(i, 0, rootIndex)
                self._categories.scrollTo(currentIndex)
-               self._categories.setItemSelected(self._categories.topLevelItem(i), True)
+               self._categories.topLevelItem(i).setSelected(True)
                return self._unitWindow
 
        def set_fullscreen(self, isFullscreen):
                return self._unitWindow
 
        def set_fullscreen(self, isFullscreen):