From 6e3931983adbe5fbc5b4aaa71f9feb815071680b Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sat, 5 Jan 2008 22:19:03 +0000 Subject: [PATCH] fixes #7, fixes #12 * save state between invocations * update ChangeLog --- ChangeLog | 3 ++- btn4ws.py | 27 ++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 510a75f..52348c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,8 @@ 2008-01-05 Jan Dittberner * btn4ws.py: switch to non gimpfu gimpplugin, GtkAssistant GUI, - get interactive functionallity completed + get interactive functionallity completed, store settings in + btn4wsrc 2007-12-04 Jan Dittberner diff --git a/btn4ws.py b/btn4ws.py index 113a372..79f5fe6 100644 --- a/btn4ws.py +++ b/btn4ws.py @@ -29,7 +29,7 @@ port of the older gimp-perl version to python. (c) 2007, 2008 Jan Dittberner """ -import os, urllib, logging, sys +import os, urllib, logging, sys, pickle import gimp, gimpplugin, gimpui, gimpcolor import pygtk pygtk.require('2.0') @@ -780,6 +780,7 @@ class btn4wsplugin(gimpplugin.plugin): def __init__(self): self.data = {} self.inputdata = {} + self.datafile = os.path.join(gimp.directory, "btn4wsrc") def checkdata(self, data): logging.debug("checkdata " + str(data)) @@ -1033,11 +1034,27 @@ class btn4wsplugin(gimpplugin.plugin): logging.debug("destroy") gtk.main_quit() + def _loaddata(self, data): + try: + if os.path.exists(self.datafile): + return pickle.load(open(self.datafile)) + except OSError, e: + pass + return data + + def _storedata(self, data): + try: + pickle.dump(data, open(self.datafile, 'w')) + except OSError, e: + pass + def _cb_apply(self, widget): self.data = widget.data logging.debug(str(self.data)) - if self.checkdata(self.data): + if self.checkdata(self.data): self.makebuttons(**self.data) + shelf["btn4ws"] = self.data + self._storedata(self.data) else: logging.error("checking data failed") @@ -1066,11 +1083,11 @@ class btn4wsplugin(gimpplugin.plugin): "makeinactive" : makeinactive, "makeactive" : makeactive, "makepressed" : makepressed, "makejscript" : makejscript } - if runmode == RUN_WITH_LAST_VALS: - logging.debug("runmode with last vals") + if runmode in (RUN_INTERACTIVE, RUN_WITH_LAST_VALS): if shelf.has_key("btn4ws"): self.inputdata = shelf["btn4ws"] - if runmode in (RUN_INTERACTIVE, RUN_WITH_LAST_VALS): + else: + self.inputdata = self._loaddata(self.inputdata) dialog = Btn4wsDialog(self.inputdata) dialog.connect("close", self._cb_destroy) dialog.connect("cancel", self._cb_destroy)