From: <umg...@us...> - 2007-02-28 18:29:54
|
Revision: 356 http://svn.sourceforge.net/pybridge/?rev=356&view=rev Author: umgangee Date: 2007-02-28 10:29:54 -0800 (Wed, 28 Feb 2007) Log Message: ----------- Fold the pybridge.environment.Environment class into pybridge.environment module. Make appropriate changes to UI code. Modified Paths: -------------- trunk/pybridge/pybridge/environment.py trunk/pybridge/pybridge/ui/__init__.py trunk/pybridge/pybridge/ui/canvas.py trunk/pybridge/pybridge/ui/cardarea.py trunk/pybridge/pybridge/ui/dialog_preferences.py trunk/pybridge/pybridge/ui/utils.py trunk/pybridge/pybridge/ui/window_main.py trunk/pybridge/pybridge/ui/wrapper.py Modified: trunk/pybridge/pybridge/environment.py =================================================================== --- trunk/pybridge/pybridge/environment.py 2007-02-28 18:21:26 UTC (rev 355) +++ trunk/pybridge/pybridge/environment.py 2007-02-28 18:29:54 UTC (rev 356) @@ -1,5 +1,5 @@ # PyBridge -- online contract bridge made easy. -# Copyright (C) 2004-2006 PyBridge Project. +# Copyright (C) 2004-2007 PyBridge Project. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -20,76 +20,95 @@ import sys -class Environment: - """This module provides path location services for PyBridge.""" +""" +This module provides path location services for PyBridge. +Note to PyBridge packagers: - def __init__(self): - # Locate base directory. - if hasattr(sys, 'frozen'): # If py2exe distribution. - currentdir = os.path.dirname(sys.executable) - self.basedir = os.path.abspath(currentdir) - else: # Typically /usr/ or root of source distribution. - currentdir = os.path.dirname(os.path.abspath(sys.argv[0])) - self.basedir = os.path.normpath(os.path.join(currentdir, '..')) - - # Locate shared resources directory, typically /usr/share/. - if os.path.exists(os.path.join(self.basedir, 'share')): - self.sharedir = os.path.join(self.basedir, 'share') - else: # Root of source distribution. - self.sharedir = self.basedir - - # Locate config directory. - self.configdir = os.path.join(os.path.expanduser('~'), '.pybridge') - if not os.path.exists(self.configdir): - os.mkdir(self.configdir) # Create directory. +The packaging policy of your distribution may specify a filesystem organisation +standard, which conflicts with the directory structure defined in this module. +This is the only module that you should need to modify to make PyBridge +compliant with distribution policy. +""" - def find_configfile(self, name): - """A config file is located in <configdir>/""" - return os.path.join(self.configdir, name) +# Locate base directory. +if hasattr(sys, 'frozen'): # If py2exe distribution. + currentdir = os.path.dirname(sys.executable) + basedir = os.path.abspath(currentdir) +else: # Typically /usr/ (if installed) or root of source distribution. + currentdir = os.path.dirname(os.path.abspath(sys.argv[0])) + basedir = os.path.normpath(os.path.join(currentdir, '..')) - def find_doc(self, name): - """A documentation file may be located in: - - <sharedir>/doc/pybridge/ (installed) - <basedir>/ (source) - """ - if self.sharedir == self.basedir: - return os.path.join(self.basedir, name) - else: - return os.path.join(self.sharedir, 'doc', 'pybridge', name) +# Locate shared resources directory, typically /usr/share/. +if os.path.exists(os.path.join(basedir, 'share')): + sharedir = os.path.join(basedir, 'share') +else: # Root of source distribution. + sharedir = basedir +# Locate client configuration directory, typically ~/.pybridge/. +clientconfigdir = os.path.join(os.path.expanduser('~'), '.pybridge') +if not os.path.exists(clientconfigdir): + os.mkdir(clientconfigdir) # Create directory. - def find_glade(self, name): - """A Glade interface file may be located in: - - <sharedir>/pybridge/glade/ (installed) - <basedir>/glade/ (source) - """ - if self.sharedir == self.basedir: - return os.path.join(self.basedir, 'glade', name) - else: - return os.path.join(self.sharedir, 'pybridge', 'glade', name) +# Locate server configuration directory. +serverconfigdir = clientconfigdir - def find_pixmap(self, name): - """A pixmap file may be located in: - - <sharedir>/pybridge/pixmaps/ (installed) - <basedir>/pixmaps/ (source) - """ - if self.sharedir == self.basedir: - return os.path.join(self.basedir, 'pixmaps', name) - else: - return os.path.join(self.sharedir, 'pybridge', 'pixmaps', name) +def find_config_client(name): + """A client configuration file is located in: + + <clientconfigdir>/ + """ + return os.path.join(clientconfigdir, name) - def get_localedir(self): - """Returns the path of the locale directory.""" - return os.path.join(self.sharedir, 'locale') +def find_config_server(name): + """A server configuration file is located in: + <serverconfigdir>/ + """ + return os.path.join(serverconfigdir, name) -environment = Environment() +def find_doc(name): + """A documentation file may be located in: + + <sharedir>/doc/pybridge/ (installed) + <basedir>/ (source) + """ + if sharedir == basedir: + return os.path.join(basedir, name) + else: + return os.path.join(sharedir, 'doc', 'pybridge', name) + + +def find_glade(name): + """A Glade interface file may be located in: + + <sharedir>/pybridge/glade/ (installed) + <basedir>/glade/ (source) + """ + if sharedir == basedir: + return os.path.join(basedir, 'glade', name) + else: + return os.path.join(sharedir, 'pybridge', 'glade', name) + + +def find_pixmap(name): + """A pixmap file may be located in: + + <sharedir>/pybridge/pixmaps/ (installed) + <basedir>/pixmaps/ (source) + """ + if sharedir == basedir: + return os.path.join(basedir, 'pixmaps', name) + else: + return os.path.join(sharedir, 'pybridge', 'pixmaps', name) + + +def get_localedir(): + """Returns the path of the locale directory.""" + return os.path.join(sharedir, 'locale') + Modified: trunk/pybridge/pybridge/ui/__init__.py =================================================================== --- trunk/pybridge/pybridge/ui/__init__.py 2007-02-28 18:21:26 UTC (rev 355) +++ trunk/pybridge/pybridge/ui/__init__.py 2007-02-28 18:29:54 UTC (rev 356) @@ -1,5 +1,5 @@ # PyBridge -- online contract bridge made easy. -# Copyright (C) 2004-2006 PyBridge Project. +# Copyright (C) 2004-2007 PyBridge Project. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -10,14 +10,12 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -from pybridge.environment import environment - def run(): """""" from twisted.internet import gtk2reactor @@ -28,8 +26,9 @@ import locale import gettext + import pybridge.environment as env locale.setlocale(locale.LC_ALL, '') - gettext.bindtextdomain('pybridge', environment.get_localedir()) + gettext.bindtextdomain('pybridge', env.get_localedir()) gettext.textdomain('pybridge') gettext.install('pybridge') Modified: trunk/pybridge/pybridge/ui/canvas.py =================================================================== --- trunk/pybridge/pybridge/ui/canvas.py 2007-02-28 18:21:26 UTC (rev 355) +++ trunk/pybridge/pybridge/ui/canvas.py 2007-02-28 18:29:54 UTC (rev 356) @@ -1,5 +1,5 @@ # PyBridge -- online contract bridge made easy. -# Copyright (C) 2004-2006 PyBridge Project. +# Copyright (C) 2004-2007 PyBridge Project. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -10,7 +10,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -19,7 +19,7 @@ import gtk import cairo -from pybridge.environment import environment +import pybridge.environment as env class CairoCanvas(gtk.DrawingArea): @@ -28,7 +28,7 @@ Overlapping items. """ - background_path = environment.find_pixmap('baize.png') + background_path = env.find_pixmap('baize.png') background = cairo.ImageSurface.create_from_png(background_path) pattern = cairo.SurfacePattern(background) pattern.set_extend(cairo.EXTEND_REPEAT) Modified: trunk/pybridge/pybridge/ui/cardarea.py =================================================================== --- trunk/pybridge/pybridge/ui/cardarea.py 2007-02-28 18:21:26 UTC (rev 355) +++ trunk/pybridge/pybridge/ui/cardarea.py 2007-02-28 18:29:54 UTC (rev 356) @@ -1,5 +1,5 @@ # PyBridge -- online contract bridge made easy. -# Copyright (C) 2004-2006 PyBridge Project. +# Copyright (C) 2004-2007 PyBridge Project. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -10,7 +10,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -21,7 +21,7 @@ import pango import pangocairo -from pybridge.environment import environment +import pybridge.environment as env from canvas import CairoCanvas from pybridge.bridge.card import Card, Rank, Suit @@ -44,7 +44,7 @@ """ # Load card mask. - card_mask_path = environment.find_pixmap('bonded.png') + card_mask_path = env.find_pixmap('bonded.png') card_mask = cairo.ImageSurface.create_from_png(card_mask_path) font_description = pango.FontDescription('Sans Bold 10') Modified: trunk/pybridge/pybridge/ui/dialog_preferences.py =================================================================== --- trunk/pybridge/pybridge/ui/dialog_preferences.py 2007-02-28 18:21:26 UTC (rev 355) +++ trunk/pybridge/pybridge/ui/dialog_preferences.py 2007-02-28 18:29:54 UTC (rev 356) @@ -1,5 +1,5 @@ # PyBridge -- online contract bridge made easy. -# Copyright (C) 2004-2006 PyBridge Project. +# Copyright (C) 2004-2007 PyBridge Project. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -10,7 +10,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -20,7 +20,7 @@ import os from wrapper import GladeWrapper -from pybridge.environment import environment +import pybridge.environment as env import utils @@ -36,7 +36,7 @@ self.carddeck.pack_start(cell, True) self.carddeck.add_attribute(cell, 'text', 0) # Populate list of card decks. - path = environment.find_pixmap('') + path = env.find_pixmap('') for filename in os.listdir(path): if filename.endswith('.png'): iter = model.append((filename,)) Modified: trunk/pybridge/pybridge/ui/utils.py =================================================================== --- trunk/pybridge/pybridge/ui/utils.py 2007-02-28 18:21:26 UTC (rev 355) +++ trunk/pybridge/pybridge/ui/utils.py 2007-02-28 18:29:54 UTC (rev 356) @@ -1,5 +1,5 @@ # PyBridge -- online contract bridge made easy. -# Copyright (C) 2004-2006 PyBridge Project. +# Copyright (C) 2004-2007 PyBridge Project. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -10,13 +10,13 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -from pybridge.environment import environment +import pybridge.environment as env # Set up client with UI event handler. from pybridge.network.client import client @@ -49,21 +49,27 @@ self.config.read(self.filename) # Create sections if they do not exist. - if not self.config.has_section('Connection'): - self.config.add_section('Connection') - self.write() + for section in ('Connection', 'General'): + if not self.config.has_section(section): + self.config.add_section(section) + self.write() + for key, value in self.config.items('Connection'): self.connection[key] = value + for key, value in self.config.items('General'): + self.general[key] = value def write(self): """""" for key, value in self.connection.items(): self.config.set('Connection', key, value) + for key, value in self.general.items(): + self.config.set('General', key, value) self.config.write(file(self.filename, 'w')) -settings = Settings(environment.find_configfile('client.cfg')) +settings = Settings(env.find_config_client('client.cfg')) Modified: trunk/pybridge/pybridge/ui/window_main.py =================================================================== --- trunk/pybridge/pybridge/ui/window_main.py 2007-02-28 18:21:26 UTC (rev 355) +++ trunk/pybridge/pybridge/ui/window_main.py 2007-02-28 18:29:54 UTC (rev 356) @@ -1,5 +1,5 @@ # PyBridge -- online contract bridge made easy. -# Copyright (C) 2004-2006 PyBridge Project. +# Copyright (C) 2004-2007 PyBridge Project. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -10,7 +10,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -21,15 +21,15 @@ import webbrowser -from pybridge import __version__ -from pybridge.environment import environment +from pybridge import __version__ as version +import pybridge.environment as env from pybridge.network.client import client from eventhandler import eventhandler import utils -TABLE_ICON = environment.find_pixmap("table.png") -USER_ICON = environment.find_pixmap("user.png") +TABLE_ICON = env.find_pixmap("table.png") +USER_ICON = env.find_pixmap("user.png") class WindowMain(GladeWrapper): @@ -209,16 +209,16 @@ def on_about_activate(self, widget, *args): about = gtk.AboutDialog() about.set_name('PyBridge') - about.set_version(__version__) - about.set_copyright('Copyright (C) 2004-2006 Michael Banks') + about.set_version(version) + about.set_copyright('Copyright (C) 2004-2007 Michael Banks') about.set_comments(_('A free online bridge game.')) about.set_website('http://pybridge.sourceforge.net/') - license = file(environment.find_doc('COPYING')).read() + license = file(env.find_doc('COPYING')).read() about.set_license(license) - authorsfile = file(environment.find_doc('AUTHORS')) + authorsfile = file(env.find_doc('AUTHORS')) authors = [author.strip() for author in authorsfile] about.set_authors(authors) - logo_path = environment.find_pixmap('pybridge.png') + logo_path = env.find_pixmap('pybridge.png') logo = gtk.gdk.pixbuf_new_from_file(logo_path) about.set_logo(logo) Modified: trunk/pybridge/pybridge/ui/wrapper.py =================================================================== --- trunk/pybridge/pybridge/ui/wrapper.py 2007-02-28 18:21:26 UTC (rev 355) +++ trunk/pybridge/pybridge/ui/wrapper.py 2007-02-28 18:29:54 UTC (rev 356) @@ -1,5 +1,5 @@ # PyBridge -- online contract bridge made easy. -# Copyright (C) 2004-2006 PyBridge Project. +# Copyright (C) 2004-2007 PyBridge Project. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -10,7 +10,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -21,13 +21,13 @@ import gtk.glade import sys -from pybridge.environment import environment +import pybridge.environment as env -GLADE_PATH = environment.find_glade("pybridge.glade") +GLADE_PATH = env.find_glade("pybridge.glade") if sys.platform == 'win32': # Win32 should use the ICO icon. - ICON_PATH = environment.find_pixmap("pybridge.ico") + ICON_PATH = env.find_pixmap("pybridge.ico") else: # All other platforms should use the PNG icon. - ICON_PATH = environment.find_pixmap("pybridge.png") + ICON_PATH = env.find_pixmap("pybridge.png") class GladeWrapper: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |