From: Ed Page Date: Thu, 27 May 2010 12:05:59 +0000 (-0500) Subject: Switching over to separate windows X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=5a5adff742cbe81e18fe4f37f8be93690e2ef248;p=gonvert Switching over to separate windows --- diff --git a/src/gonvert_qt.py b/src/gonvert_qt.py index 11ffc45..3ed1bf7 100755 --- a/src/gonvert_qt.py +++ b/src/gonvert_qt.py @@ -63,9 +63,6 @@ def split_number(number): class Gonvert(object): - ORIENTATION_HORIZONTAL = "ORIENTATION_HORIZONTAL" - ORIENTATION_VERTICAL = "ORIENTATION_VERTICAL" - _DATA_PATHS = [ os.path.dirname(__file__), os.path.join(os.path.dirname(__file__), "../data"), @@ -75,7 +72,6 @@ class Gonvert(object): ] def __init__(self): - self.__isPortrait = False self._dataPath = "" for dataPath in self._DATA_PATHS: appIconPath = os.path.join(dataPath, "pixmaps", "gonvert.png") @@ -85,8 +81,31 @@ class Gonvert(object): else: raise RuntimeError("UI Descriptor not found!") - self._unitCategory = QtGui.QPushButton() + self._catWindow = CategoryWindow(None, appIconPath) + + +class CategoryWindow(object): + + def __init__(self, parent, appIconPath): + self._categories = QtGui.QTreeWidget() + + self._layout = QtGui.QVBoxLayout() + self._layout.addWidget(self._categories) + + centralWidget = QtGui.QWidget() + centralWidget.setLayout(self._layout) + + self._window = QtGui.QMainWindow() + self._window.setWindowTitle("%s - Categories" % constants.__pretty_app_name__) + self._window.setWindowIcon(QtGui.QIcon(appIconPath)) + self._window.setCentralWidget(centralWidget) + self._window.show() + + +class UnitWindow(object): + + def __init__(self, parent, category, appIconPath): self._selectedUnitName = QtGui.QLabel() self._selectedUnitValue = QtGui.QLineEdit() self._selectedUnitSymbol = QtGui.QLabel() @@ -108,7 +127,6 @@ class Gonvert(object): self._searchLayout.addWidget(self._searchCloseButton) self._layout = QtGui.QVBoxLayout() - self._layout.addWidget(self._unitCategory) self._layout.addLayout(self._selectedUnitLayout) self._layout.addWidget(self._units) self._layout.addLayout(self._searchLayout) @@ -117,106 +135,13 @@ class Gonvert(object): centralWidget.setLayout(self._layout) self._window = QtGui.QMainWindow() - self._window.setWindowTitle("%s - Unit Conversion Utility" % constants.__pretty_app_name__) + self._window.setWindowTitle("%s - %s" % (constants.__pretty_app_name__, category)) self._window.setWindowIcon(QtGui.QIcon(appIconPath)) self._window.setCentralWidget(centralWidget) - self._load_settings() self._window.show() self._hide_search() - def _load_settings(self): - #Restore window size from previously saved settings if it exists and is valid. - windowDatPath = "/".join((constants._data_path_, "window.dat")) - if os.path.exists(windowDatPath): - saved_window = pickle.load(open(windowDatPath, "r")) - try: - a, b = saved_window['size'] - except KeyError: - pass - else: - self._window.resize(a, b) - try: - isFullscreen = saved_window["isFullscreen"] - except KeyError: - pass - else: - if isFullscreen: - self._window.fullscreen() - try: - isPortrait = saved_window["isPortrait"] - except KeyError: - pass - else: - if isPortrait ^ self.__isPortrait: - if isPortrait: - orientation = self.ORIENTATION_VERTICAL - else: - orientation = self.ORIENTATION_HORIZONTAL - self.set_orientation(orientation) - - #Restore selections from previously saved settings if it exists and is valid. - categoryIndex = 0 - selectedCategoryName = unit_data.UNIT_CATEGORIES[0] - selectionsDatPath = "/".join((constants._data_path_, "selections.dat")) - if os.path.exists(selectionsDatPath): - selections = pickle.load(open(selectionsDatPath, 'r')) - try: - self._defaultUnitForCategory = selections['selected_units'] - except KeyError: - pass - - try: - selectedCategoryName = selections['selected_category'] - except KeyError: - pass - else: - try: - categoryIndex = unit_data.UNIT_CATEGORIES.index(selectedCategoryName) - except ValueError: - _moduleLogger.warn("Unknown category: %s" % selectedCategoryName) - - if False: - self._categorySelectionButton.get_child().set_markup("%s" % selectedCategoryName) - self._categoryView.set_cursor(categoryIndex, self._categoryColumn, False) - self._categoryView.grab_focus() - - self._select_default_unit() - - def _save_settings(self): - """ - This routine saves the selections to a file, and - should therefore only be called when exiting the program. - - Update selections dictionary which consists of the following keys: - 'self._selectedCategoryName': full name of selected category - 'self._defaultUnitForCategory': self._defaultUnitForCategory dictionary which contains: - [categoryname: #1 displayed unit, #2 displayed unit] - """ - if False: - #Determine the contents of the selected category row - selected, iter = self._categoryView.get_selection().get_selected() - self._selectedCategoryName = self._categoryModel.get_value(iter, 0) - - selections = { - 'selected_category': self._selectedCategoryName, - 'selected_units': self._defaultUnitForCategory - } - selectionsDatPath = "/".join((constants._data_path_, "selections.dat")) - pickle.dump(selections, open(selectionsDatPath, 'w')) - - #Get last size of app and save it - window_settings = { - 'size': self._window.get_size(), - "isFullscreen": self._isFullScreen, - "isPortrait": self.__isPortrait, - } - windowDatPath = "/".join((constants._data_path_, "window.dat")) - pickle.dump(window_settings, open(windowDatPath, 'w')) - - def set_orientation(self, orientation): - pass - def _hide_search(self): self._searchButton.hide() self._searchEntry.hide()