X-Git-Url: http://git.maemo.org/git/?p=gonvert;a=blobdiff_plain;f=gonvert%2Fgonvert_qt.py;h=c37b024b914f5ca51745700d76dfddd96e08a79a;hp=aa3d7e591b8d13f50679c15925e561d78065af51;hb=ce0c4b63966441e2f5efc601637af4d08386317c;hpb=18df79328b4665753f6d41d549ab991e060bb39d diff --git a/gonvert/gonvert_qt.py b/gonvert/gonvert_qt.py index aa3d7e5..c37b024 100755 --- a/gonvert/gonvert_qt.py +++ b/gonvert/gonvert_qt.py @@ -19,6 +19,8 @@ QtGui = qt_compat.import_module("QtGui") import constants from util import qui_utils from util import misc as misc_utils +from util import linux as linux_utils + import unit_data @@ -225,8 +227,11 @@ class Gonvert(object): 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") @@ -291,7 +296,11 @@ class Gonvert(object): "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 @@ -398,7 +407,10 @@ class Gonvert(object): @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) @@ -567,11 +579,12 @@ class QuickConvert(object): 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 @@ -582,20 +595,22 @@ class QuickConvert(object): 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 = "" @@ -801,8 +816,8 @@ class QuickConvert(object): 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): @@ -940,11 +955,12 @@ class CategoryWindow(object): 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): @@ -1547,14 +1563,25 @@ class UnitWindow(object): 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)