# HG changeset patch # User Dirk Olmes # Date 1273818706 -7200 # Node ID 12ed8b5fa08c251b16587805a71089886cba3602 # Parent 0c0d1760b73700e5df7487581a480fdcc6d9da80 first system preference: configure app to stat maximized. diff -r 0c0d1760b737 -r 12ed8b5fa08c Mapping.py --- a/Mapping.py Fri May 14 08:08:17 2010 +0200 +++ b/Mapping.py Fri May 14 08:31:46 2010 +0200 @@ -1,6 +1,7 @@ from Feed import Feed from FeedEntry import FeedEntry +from Preference import Preference from sqlalchemy import Column from sqlalchemy import DateTime from sqlalchemy import ForeignKey @@ -45,6 +46,12 @@ Column("updated", DateTime), Column("feed_id", Integer, ForeignKey("feed.pk")) ) + + preferencesTable = Table("preference", metadata, + Column("pk", Integer, primary_key=True), + Column("key", String(255), nullable=False), + Column("value", String(255), nullable=False) + ) metadata.create_all() @@ -54,3 +61,4 @@ "entries" : relation(FeedEntry, backref="feed") } ) + mapper(Preference, preferencesTable) diff -r 0c0d1760b737 -r 12ed8b5fa08c Preference.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Preference.py Fri May 14 08:31:46 2010 +0200 @@ -0,0 +1,16 @@ + +class Preference(object): + @staticmethod + def valueForKey(key, session): + pref = session.query(Preference).filter(Preference.key == key).first() + if pref is not None: + return pref.value + else: + return None + + def __init__(self, key, value): + self.key = key + self.value = value + + def __repr__(self): + return "" % (self.key, self.value) diff -r 0c0d1760b737 -r 12ed8b5fa08c Preferences.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Preferences.py Fri May 14 08:31:46 2010 +0200 @@ -0,0 +1,16 @@ + +from Preference import Preference +import util + +START_MAXIMIZED = "START_MAXIMIZED" + +class Preferences(object): + def __init__(self, session): + self.session = session + + def startMaximized(self): + value = Preference.valueForKey(START_MAXIMIZED, self.session) + if value is not None: + return util.str2bool(value) + else: + return False diff -r 0c0d1760b737 -r 12ed8b5fa08c PreferencesDialog.py --- a/PreferencesDialog.py Fri May 14 08:08:17 2010 +0200 +++ b/PreferencesDialog.py Fri May 14 08:31:46 2010 +0200 @@ -1,4 +1,5 @@ +from Preferences import Preferences from PyQt4 import QtGui from Ui_Preferences import Ui_Preferences @@ -6,13 +7,14 @@ def __init__(self, session=None): QtGui.QWidget.__init__(self, None) self.session = session + self.preferences = Preferences(session) self.ui = Ui_Preferences() self.ui.setupUi(self) self.fillUi() def fillUi(self): - #self.ui.startMaximized.setChecked() - pass + maximized = self.preferences.startMaximized() + self.ui.startMaximized.setChecked(maximized) def startMaximizedChanged(self, change): print("start maximized: " + str(change)) diff -r 0c0d1760b737 -r 12ed8b5fa08c feedworm-gui.py --- a/feedworm-gui.py Fri May 14 08:08:17 2010 +0200 +++ b/feedworm-gui.py Fri May 14 08:31:46 2010 +0200 @@ -1,6 +1,7 @@ import Database from MainWindow import MainWindow +from Preferences import Preferences from PyQt4 import QtGui import sys import util @@ -11,5 +12,11 @@ app = QtGui.QApplication(sys.argv) mainWindow = MainWindow(session) - mainWindow.showMaximized() + + maximized = Preferences(session).startMaximized() + if maximized: + mainWindow.showMaximized() + else: + mainWindow.show() + sys.exit(app.exec_()) diff -r 0c0d1760b737 -r 12ed8b5fa08c util.py --- a/util.py Fri May 14 08:08:17 2010 +0200 +++ b/util.py Fri May 14 08:31:46 2010 +0200 @@ -25,3 +25,6 @@ for feed in Feed.all(session): feed.next_update = datetime.now() - timedelta(minutes=1) session.commit() + +def str2bool(string): + return string.lower() in ["yes", "true", "t", "1"]