del net-oscar
[learning-git.git] / pgworksheet_yvesf / pgw / __init__.py
blobeba0aad03ee99f3df5ecfb178b3ada8e9f12c075
1 # -*- coding: latin-1; -*-
3 # PgWorksheet - PostgreSQL Front End
4 # http://pgworksheet.projects.postgresql.org/
6 # Copyright © 2004-2005 Henri Michelon & CML http://www.e-cml.org/
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details (read LICENSE.txt).
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 # $Id: __init__.py,v 1.8 2005/06/10 15:14:34 hmichelon Exp $
24 import sys
25 import os
26 import string
27 import gettext
29 def mswindows():
30 """Return TRUE is we run under Microsoft Windows"""
31 return sys.platform == "win32"
34 def get_user_encoding():
35 if (mswindows()):
36 return "ISO-8859-1" #"UTF-8"
37 try:
38 enc = os.environ['MM_CHARSET']
39 return enc
40 except KeyError:
41 try:
42 enc = os.environ['LANG']
43 except KeyError:
44 try:
45 enc = os.environ['LC_LANG']
46 except KeyError:
47 try:
48 enc = os.environ['LC_ALL']
49 except KeyError:
50 return "ISO8859-1"
51 parts = string.split(enc, '.')
52 if (len(parts) > 1) :
53 return parts[1]
54 return "ISO8859-1"
57 def set_proportional(buffer):
58 """Change the font of a widget to proportional"""
59 tagname = 'font-' + str(buffer)
60 try:
61 font = buffer.create_tag(tagname)
62 if (mswindows()):
63 font.set_property('font', 'Courier New 10')
64 else:
65 font.set_property('family', 'monospace')
66 buffer.apply_tag(font, buffer.get_start_iter(), buffer.get_end_iter())
67 except TypeError: # tag already exists
68 buffer.apply_tag_by_name(tagname, buffer.get_start_iter(), buffer.get_end_iter())
71 def get_user_configdir():
72 """Return the directory where the configuration file is stored"""
73 if (mswindows()):
74 try:
75 return os.environ['USERPROFILE']
76 except KeyError:
77 try:
78 return os.environ['ALLUSERSPROFILE']
79 except KeyError:
80 return os.environ['SYSTEMROOT']
81 else:
82 return os.environ['HOME']
85 def get_config_path():
86 return os.path.join(get_user_configdir(), '.pgworksheet')
91 #Utils
92 import gobject
93 class GObjectContainer(gobject.GObject):
94 def __init__(self, data):
95 gobject.GObject.__init__(self)
96 self.set_data("key", data)
98 def get(self):
99 return self.get_data("key")
101 def set(self, data):
102 self.set_data("key", data)
103 return data