-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Friday 08 November 2002 15:38, you wrote:
>
> I agree that it shouldn't be the only way to go.  I would definitely
> prefer to have a function that I can call that would write to disk.  The
> source code reveals, however, that a sync() call is only done in the
> destructor.  

I've never had a problem with lost settings, so I guess the writeEntry
method does what it needs to. I've attached the complete guiconfig.py
class.

> In fact, I have almost exactly what you mentioned.  I have
> a class that wraps it and provides some convenience functions for me.  I
> added in some print statements so I *know* that settings.write[Num]Entry
> is getting called with all the correct values.
>
> I guess my main question is, therefore, if I have a reference to a PyQt
> object, in this case QSettings, and at the close of my program the
> destructor never gets called for the PyQt object, then there _must_ be a
> memory leak if any memory whatsoever is allocated by that PyQt object.
>

No, it doesn't have to be a memory leak. If the process ends, the OS
will reclaim all the memory. It can do that without calling destructors,
after all, the process doesn't run anymore.

> Under *nix, has anyone ever seen QSettings actually write to the
> settings file upon a write[Num]Entry?  I have monitored the file for
> existence upon a new write[Num]Entry and for changes upon a
> write[Num]Entry and None have ever been made until the object goes out
> of scope.

Maybe I was just lucky, and have the QSettings object call the destructor.
Anyway, it's one part of my application where I've never had problems.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE9y82BdaCcgCmN5d8RAlO6AJ4mPmNnx0sT6p+6y3w6BdrqPFUL5ACgn0s8
Cg9cuwglgc+i09DfBu6KPzs=
=mH/R
-----END PGP SIGNATURE-----
""" guiconfig.py

Configuration settings for the Kura GUI. Uses the Qt.QSettings class.

"""
import sys, os

from qt import QSettings, QFont

TEXT = 0
NUM = 1

ILVIEW = 0
TREEVIEW = 1
XMLVIEW = 2

FILE="TextQuery"
SQL="dbSql"

tables = [
    "lng_project",
    "lng_user",
    "lng_document",
    "lng_doc_doc",
    "lng_doc_refs",
    "lng_linkcode",
    "lng_language",
    "lng_reference",
    "lng_proj_user",
    "lng_proj_lngg",
    "lng_recording",
    "lng_scan",
    "lng_text",
    "lng_proj_text",
    "lng_stream",
    "lng_element",
    "lng_lex",
    "lng_lex_lex",
    "lng_lxlxrelcode",
    "lng_text_tag",
    "lng_stream_tag",
    "lng_element_tag",
    "lng_lex_tag",
    "lng_tag",
    "lng_tagtypecode",
    "lng_tagdomain",
    "lng_affiliationcode",
    "lng_elementtypecode",
    "lng_categorycode"]

defaults = {
    "textselectorwidth": (NUM, "/kura/lng_text/selector/width", 120),
    "interlinearstyle": (NUM, "/kura/export/interlinear", 1),
    "backend": (TEXT, "/kura/backend", FILE),
    "datastore": (TEXT, "/kura/backend/store", "new.dbobj"),
    "filepath": (TEXT, "/kura/backend/filepath", os.environ["HOME"]),
    "database" : (TEXT, "/kura/database/database", "andal"),
    "hostname" : (TEXT, "/kura/database/hostname", "localhost"),
    "password" : (TEXT, "/kura/database/password", ""),
    "username" : (TEXT, "/kura/database/username", ""),
    "usernr" : (NUM, "/kura/defaults/usernr", 0),
    "languagenr" : (NUM, "/kura/defaults/languagenr", 0),
    "projectnr" : (NUM, "/kura/defaults/projectnr", 0),
    "textfontfamily" : (TEXT, "/kura/defaults/textfont/family", "unifont"),
    "textfontsize" : (NUM, "/kura/defaults/textfont/size", 16),
    "app_w" : (NUM, "/kura/geometry/app_w", 640),
    "app_h" : (NUM, "/kura/defaults/app_h", 640),
    "app_x" : (NUM, "/kura/geometry/app_x", 0),
    "app_y" : (NUM, "/kura/geometry/app_y", 0),
    "widgetfontfamily" : (TEXT, "/kura/defaults/widgetfont/family",
                          "helvetica"),
    "widgetfontsize" : (NUM, "/kura/defaults/widgetfont/size", 16),
    "currentTableName" : (TEXT, "/kura/defaults/currentview/tablename",
                          "lng_lex"),
    "useDefaultForSearch" : (NUM, "/kura/defaults/usedefaultforsearch", 0),
    "ShowValueHint" : (NUM, "/kura/defaults/showvaluehint", 0),
    "streamRegExp" : (TEXT, "/kura/defaults/stream/streamRegExp",
                      "\. |\.\n|[!?\12]"),
    "elementRegExp" : (TEXT, "/kura/defaults/element/elementRegExp",
                       '=--|[ ,:;"]'),
    "morphemeRegExp" : (TEXT, "/kura/defaults/element/morphemeRegExp", "[.]")
    }


def __readAndSetEntry(key, pos, default):
    d, ok = guiConf.readNumEntry("/kura/dialog/%s/%s" % (key, pos), default)
    setattr(guiConf, unicode("%s_%s" % (key, pos)), d)
    
def initialize():

    if sys.platform[:3] == 'win':
        guiConf.insertSearchPath(QSettings.Windows, "Kura")

    for k, v in defaults.items():
        if v[0] == TEXT:
            d, ok = guiConf.readEntry(v[1], v[2])
            setattr(guiConf, unicode(k), unicode(d))
        elif v[0] == NUM:
            d, ok = guiConf.readNumEntry(v[1], v[2])
            setattr(guiConf, unicode(k), int(d))
        if not ok:
            guiConf.writeEntry(v[1], v[2])

    for t in tables:
        __readAndSetEntry(t, 'x', 30)
        __readAndSetEntry(t, 'y', 30)
        __readAndSetEntry(t, 'w', 300)
        __readAndSetEntry(t, 'h', 200)
        d, ok = guiConf.readEntry("/kura/listview/%s_width" % t, "")
        setattr(guiConf, "%s_width" % t, unicode(d))

        d, ok = guiConf.readEntry("/kura/table/%s_table_width" % t, "")
        setattr(guiConf, "%s_table_width" % t, unicode(d))

        d, ok = guiConf.readEntry("/kura/table/%s_formlist_width" % t, "")
        setattr(guiConf, "%s_formlist_width" % t, unicode(d))
        
    guiConf.font = QFont(guiConf.textfontfamily, guiConf.textfontsize)

def writeConfig():
    for k, v in defaults.items():
        guiConf.writeEntry(v[1], getattr(guiConf, k, v[2]))
        
    for t in tables:
        guiConf.writeEntry("/kura/dialog/%s/x" % t, getattr(guiConf, "%s_x" % t, 30))
        guiConf.writeEntry("/kura/dialog/%s/y" % t, getattr(guiConf, "%s_y" % t, 30))
        guiConf.writeEntry("/kura/dialog/%s/w" % t, getattr(guiConf, "%s_w" % t, 300))
        guiConf.writeEntry("/kura/dialog/%s/h" % t, getattr(guiConf, "%s_h" % t, 200))
        guiConf.writeEntry("/kura/listview/%s_width" % t, getattr(guiConf, "%s_width" % t, ""))
        guiConf.writeEntry("/kura/table/%s_width" % t, getattr(guiConf, "%s_table_width" % t, ""))
        guiConf.writeEntry("/kura/formlist/%s_width" % t,
                           getattr(guiConf, "%s_formlist_width" % t, ""))
        
guiConf = QSettings()
initialize()




__copyright__="""
    copyright            : (C) 2002 by Boudewijn Rempt
                           see copyright notice for license
    email                : [EMAIL PROTECTED]
"""

__revision__="""$Revision: 1.25 $"""[11:-2]

Reply via email to