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 constants
from util import qui_utils
from util import misc as misc_utils
+from util import linux as linux_utils
+
import unit_data
return self._hiddenUnits[categoryName]
def load_settings(self):
+ settingsPath = linux_utils.get_resource_path(
+ "config", constants.__app_name__, "settings.json"
+ )
try:
- with open(constants._user_settings_, "r") as settingsFile:
+ with open(settingsPath, "r") as settingsFile:
settings = simplejson.load(settingsFile)
except IOError, e:
_moduleLogger.info("No settings")
"useQuick": self._condensedAction.isChecked(),
"sortBy": sortBy,
}
- with open(constants._user_settings_, "w") as settingsFile:
+
+ settingsPath = linux_utils.get_resource_path(
+ "config", constants.__app_name__, "settings.json"
+ )
+ with open(settingsPath, "w") as settingsFile:
simplejson.dump(settings, settingsFile)
@property
@misc_utils.log_exception(_moduleLogger)
def _on_log(self, checked = False):
- with open(constants._user_logpath_, "r") as f:
+ logPath = linux_utils.get_resource_path(
+ "cache", self._constants.__app_name__, "%s.log" % self._constants.__app_name__
+ )
+ with open(logPath, "r") as f:
logLines = f.xreadlines()
log = "".join(logLines)
self._clipboard.setText(log)
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)
- self._categoryView.setItemSelected(self._categoryView.topLevelItem(i), True)
+ self._categoryView.topLevelItem(i).setSelected(True)
return self
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)
- self._inputView.setItemSelected(self._inputView.topLevelItem(i), True)
+ self._inputView.topLevelItem(i).setSelected(True)
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)
- self._outputView.setItemSelected(self._outputView.topLevelItem(i), True)
+ self._outputView.topLevelItem(i).setSelected(True)
def _select_category(self, categoryName):
self._inputUnitName = ""
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):
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):
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)
- self._categories.setItemSelected(self._categories.topLevelItem(i), True)
+ self._categories.topLevelItem(i).setSelected(True)
return self._unitWindow
def set_fullscreen(self, isFullscreen):
def run_gonvert():
try:
- os.makedirs(constants._data_path_)
+ os.makedirs(linux_utils.get_resource_path("config", constants.__app_name__))
+ except OSError, e:
+ if e.errno != 17:
+ raise
+ try:
+ os.makedirs(linux_utils.get_resource_path("cache", constants.__app_name__))
+ except OSError, e:
+ if e.errno != 17:
+ raise
+ try:
+ os.makedirs(linux_utils.get_resource_path("data", constants.__app_name__))
except OSError, e:
if e.errno != 17:
raise
+ logPath = linux_utils.get_resource_path("cache", constants.__app_name__, "%s.log" % constants.__app_name__)
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 = logging.handlers.RotatingFileHandler(logPath, maxBytes=512*1024, backupCount=1)
rotating.setFormatter(logging.Formatter(logFormat))
root = logging.getLogger()
root.addHandler(rotating)