Improve PEP 8 compliance

This commit is contained in:
Chris Jones 2009-05-07 02:35:23 +01:00
parent 1a88613904
commit 7529d1c32f
5 changed files with 79 additions and 67 deletions

View File

@ -2,18 +2,18 @@
# TerminatorConfig - layered config classes # TerminatorConfig - layered config classes
# Copyright (C) 2006-2008 cmsj@tenshu.net # Copyright (C) 2006-2008 cmsj@tenshu.net
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2 only. # the Free Software Foundation, version 2 only.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""TerminatorConfig by Chris Jones <cmsj@tenshu.net> """TerminatorConfig by Chris Jones <cmsj@tenshu.net>
@ -31,9 +31,13 @@ Trying to read a value that doesn't exist will raise an
AttributeError. This is by design. If you want to look something AttributeError. This is by design. If you want to look something
up, set a default for it first.""" up, set a default for it first."""
import os, platform, sys, re import os
import platform
import sys
import re
import pwd import pwd
import gtk, pango import gtk
import pango
try: try:
import gconf import gconf
@ -55,9 +59,9 @@ def err (log = ""):
"""Print an error message""" """Print an error message"""
print >> sys.stderr, log print >> sys.stderr, log
from configfile import ConfigFile, ParsedWithErrors from terminatorlib.configfile import ConfigFile, ParsedWithErrors
Defaults = { DEFAULTS = {
'gt_dir' : '/apps/gnome-terminal', 'gt_dir' : '/apps/gnome-terminal',
'profile_dir' : '/apps/gnome-terminal/profiles', 'profile_dir' : '/apps/gnome-terminal/profiles',
'titlebars' : True, 'titlebars' : True,
@ -165,7 +169,7 @@ Defaults = {
} }
class TerminatorConfig: class TerminatorConfig(object):
"""This class is used as the base point of the config system""" """This class is used as the base point of the config system"""
callback = None callback = None
sources = None sources = None
@ -178,7 +182,8 @@ class TerminatorConfig:
if isinstance(source, TerminatorConfValuestore): if isinstance(source, TerminatorConfValuestore):
self.sources.append (source) self.sources.append (source)
# We always add a default valuestore last so no valid config item ever goes unset # We always add a default valuestore last so no valid config item ever
# goes unset
source = TerminatorConfValuestoreDefault () source = TerminatorConfValuestoreDefault ()
self.sources.append (source) self.sources.append (source)
@ -210,7 +215,7 @@ class TerminatorConfig:
dbg (" TConfig: Out of sources") dbg (" TConfig: Out of sources")
raise (AttributeError) raise (AttributeError)
class TerminatorConfValuestore: class TerminatorConfValuestore(object):
type = "Base" type = "Base"
values = None values = None
reconfigure_callback = None reconfigure_callback = None
@ -232,7 +237,7 @@ class TerminatorConfValuestoreDefault (TerminatorConfValuestore):
def __init__ (self): def __init__ (self):
TerminatorConfValuestore.__init__ (self) TerminatorConfValuestore.__init__ (self)
self.type = "Default" self.type = "Default"
self.values = Defaults self.values = DEFAULTS
class TerminatorConfValuestoreRC (TerminatorConfValuestore): class TerminatorConfValuestoreRC (TerminatorConfValuestore):
rcfilename = "" rcfilename = ""
@ -241,8 +246,8 @@ class TerminatorConfValuestoreRC (TerminatorConfValuestore):
TerminatorConfValuestore.__init__ (self) TerminatorConfValuestore.__init__ (self)
try: try:
directory = os.environ['XDG_CONFIG_HOME'] directory = os.environ['XDG_CONFIG_HOME']
except KeyError, e: except KeyError:
dbg(" VS_RCFile: Environment variable XDG_CONFIG_HOME not found. defaulting to ~/.config") dbg(" VS_RCFile: XDG_CONFIG_HOME not found. defaulting to ~/.config")
directory = os.path.join (os.path.expanduser("~"), ".config") directory = os.path.join (os.path.expanduser("~"), ".config")
self.rcfilename = os.path.join(directory, "terminator/config") self.rcfilename = os.path.join(directory, "terminator/config")
dbg(" VS_RCFile: config file located at %s" % self.rcfilename) dbg(" VS_RCFile: config file located at %s" % self.rcfilename)
@ -258,9 +263,9 @@ class TerminatorConfValuestoreRC (TerminatorConfValuestore):
try: try:
ini = ConfigFile(self.rcfilename, self._rc_set_callback()) ini = ConfigFile(self.rcfilename, self._rc_set_callback())
ini.parse() ini.parse()
except IOError, e: except IOError, ex:
dbg (" VS_RCFile: unable to open %s (%r)" % (self.rcfilename, e)) dbg (" VS_RCFile: unable to open %s (%r)" % (self.rcfilename, ex))
except ParsedWithErrors, e: except ParsedWithErrors, ex:
# We don't really want to produce an error dialog every run # We don't really want to produce an error dialog every run
if not is_init: if not is_init:
pass pass
@ -270,25 +275,26 @@ Errors were encountered while parsing terminator_config(5) file:
<b>%s</b> <b>%s</b>
%d line(s) have been ignored.""") % (self.rcfilename, len(e.errors)) %d line(s) have been ignored.""") % (self.rcfilename, len(ex.errors))
dialog = gtk.Dialog(_("Configuration error"), None, gtk.DIALOG_MODAL, dialog = gtk.Dialog(_("Configuration error"), None, gtk.DIALOG_MODAL,
(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
dialog.set_has_separator(False) dialog.set_has_separator(False)
dialog.set_resizable(False) dialog.set_resizable(False)
image = gtk.image_new_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG) image = gtk.image_new_from_stock(gtk.STOCK_DIALOG_WARNING,
gtk.ICON_SIZE_DIALOG)
image.set_alignment (0.5, 0) image.set_alignment (0.5, 0)
dmsg = gtk.Label(msg) dmsg = gtk.Label(msg)
dmsg.set_use_markup(True) dmsg.set_use_markup(True)
dmsg.set_alignment(0, 0.5) dmsg.set_alignment(0, 0.5)
textbuff = gtk.TextBuffer() textbuff = gtk.TextBuffer()
textbuff.set_text("\n".join(map(lambda e: str(e), e.errors))) textbuff.set_text("\n".join(map(lambda ex: str(ex), ex.errors)))
textview = gtk.TextView(textbuff) textview = gtk.TextView(textbuff)
textview.set_editable(False) textview.set_editable(False)
textview.modify_font(pango.FontDescription(Defaults['font'])) textview.modify_font(pango.FontDescription(DEFAULTS['font']))
textscroll = gtk.ScrolledWindow() textscroll = gtk.ScrolledWindow()
textscroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) textscroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
textscroll.add(textview) textscroll.add(textview)
@ -302,7 +308,9 @@ Errors were encountered while parsing terminator_config(5) file:
box = gtk.HBox() box = gtk.HBox()
box.pack_start (image, False, False, 6) box.pack_start (image, False, False, 6)
box.pack_start (root, False, False, 6) box.pack_start (root, False, False, 6)
dialog.vbox.pack_start (box, False, False, 12)
vbox = dialog.get_content_area()
vbox.pack_start (box, False, False, 12)
dialog.show_all() dialog.show_all()
dialog.run() dialog.run()
@ -326,9 +334,9 @@ Errors were encountered while parsing terminator_config(5) file:
self.values['audible_bell'] = True self.values['audible_bell'] = True
key = 'visible_bell' key = 'visible_bell'
if not Defaults.has_key (key): if not DEFAULTS.has_key (key):
raise ValueError("Unknown configuration option %r" % key) raise ValueError("Unknown configuration option %r" % key)
deftype = Defaults[key].__class__.__name__ deftype = DEFAULTS[key].__class__.__name__
if key.endswith('_color'): if key.endswith('_color'):
try: try:
gtk.gdk.color_parse(value) gtk.gdk.color_parse(value)
@ -363,7 +371,7 @@ Errors were encountered while parsing terminator_config(5) file:
dbg (" VS_RCFile: Set value %r to %r" % (key, self.values[key])) dbg (" VS_RCFile: Set value %r to %r" % (key, self.values[key]))
elif section == 'keybindings': elif section == 'keybindings':
self.values.setdefault(section, {}) self.values.setdefault(section, {})
if not Defaults[section].has_key(key): if not DEFAULTS[section].has_key(key):
raise ValueError("Keybinding name %r is unknown" % key) raise ValueError("Keybinding name %r is unknown" % key)
else: else:
self.values[section][key] = value self.values[section][key] = value
@ -389,8 +397,8 @@ class TerminatorConfValuestoreGConf (TerminatorConfValuestore):
self.client = gconf.client_get_default () self.client = gconf.client_get_default ()
# Grab a couple of values from base class to avoid recursing with our __getattr__ # Grab a couple of values from base class to avoid recursing with our __getattr__
self._gt_dir = Defaults['gt_dir'] self._gt_dir = DEFAULTS['gt_dir']
self._profile_dir = Defaults['profile_dir'] self._profile_dir = DEFAULTS['profile_dir']
dbg ('VSGConf: Profile bet on is: "%s"'%profileName) dbg ('VSGConf: Profile bet on is: "%s"'%profileName)
profiles = self.client.get_list (self._gt_dir + '/global/profile_list','string') profiles = self.client.get_list (self._gt_dir + '/global/profile_list','string')
@ -412,9 +420,9 @@ class TerminatorConfValuestoreGConf (TerminatorConfValuestore):
#need to handle the list of Gconf.value #need to handle the list of Gconf.value
if profile in profiles: if profile in profiles:
dbg (" VSGConf: Found profile '%s' in profile_list"%profile) dbg (" VSGConf: Found profile '%s' in profile_list"%profile)
self.profile = '%s/%s'%(self._profile_dir, profile) self.profile = '%s/%s' % (self._profile_dir, profile)
elif "Default" in profiles: elif "Default" in profiles:
dbg (" VSGConf: profile '%s' not found, but 'Default' exists"%profile) dbg (" VSGConf: profile '%s' not found, but 'Default' exists" % profile)
self.profile = '%s/%s'%(self._profile_dir, "Default") self.profile = '%s/%s'%(self._profile_dir, "Default")
else: else:
# We're a bit stuck, there is no profile in the list # We're a bit stuck, there is no profile in the list
@ -476,14 +484,14 @@ class TerminatorConfValuestoreGConf (TerminatorConfValuestore):
if self.client.get_bool ('/system/http_proxy/use_authentication'): if self.client.get_bool ('/system/http_proxy/use_authentication'):
dbg ('HACK: Using proxy authentication') dbg ('HACK: Using proxy authentication')
value = 'http://%s:%s@%s:%s/'%( value = 'http://%s:%s@%s:%s/' % (
self.client.get_string ('/system/http_proxy/authentication_user'), self.client.get_string ('/system/http_proxy/authentication_user'),
self.client.get_string ('/system/http_proxy/authentication_password'), self.client.get_string ('/system/http_proxy/authentication_password'),
self.client.get_string ('/system/http_proxy/host'), self.client.get_string ('/system/http_proxy/host'),
self.client.get_int ('/system/http_proxy/port')) self.client.get_int ('/system/http_proxy/port'))
else: else:
dbg ('HACK: Not using proxy authentication') dbg ('HACK: Not using proxy authentication')
value = 'http://%s:%s/'%( value = 'http://%s:%s/' % (
self.client.get_string ('/system/http_proxy/host'), self.client.get_string ('/system/http_proxy/host'),
self.client.get_int ('/system/http_proxy/port')) self.client.get_int ('/system/http_proxy/port'))
elif key == 'cursor_blink': elif key == 'cursor_blink':
@ -504,11 +512,11 @@ class TerminatorConfValuestoreGConf (TerminatorConfValuestore):
value = self.client.get ('%s/%s'%(self.profile, key)) value = self.client.get ('%s/%s'%(self.profile, key))
if value != None: if value != None:
from types import StringType,BooleanType from types import StringType, BooleanType
if type(value) in [StringType, BooleanType]: if type(value) in [StringType, BooleanType]:
ret = value ret = value
else: else:
funcname = "get_" + Defaults[key].__class__.__name__ funcname = "get_" + DEFAULTS[key].__class__.__name__
dbg (' GConf: picked function: %s'%funcname) dbg (' GConf: picked function: %s'%funcname)
# Special case for str # Special case for str
if funcname == "get_str": if funcname == "get_str":

View File

@ -2,18 +2,18 @@
# TerminatorEncoding - charset encoding classes # TerminatorEncoding - charset encoding classes
# Copyright (C) 2006-2008 chantra@debuntu.org # Copyright (C) 2006-2008 chantra@debuntu.org
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2 only. # the Free Software Foundation, version 2 only.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""TerminatorEncoding by Emmanuel Bretelle <chantra@debuntu.org> """TerminatorEncoding by Emmanuel Bretelle <chantra@debuntu.org>
@ -27,6 +27,7 @@ from terminatorlib import translation
class TerminatorEncoding: class TerminatorEncoding:
"""Class to store encoding details""" """Class to store encoding details"""
encodings = [ encodings = [
[True, None, _("Current Locale")], [True, None, _("Current Locale")],
[False, "ISO-8859-1", _("Western")], [False, "ISO-8859-1", _("Western")],
@ -104,6 +105,9 @@ class TerminatorEncoding:
[False, "WINDOWS-1258", _("Vietnamese") ] [False, "WINDOWS-1258", _("Vietnamese") ]
] ]
def __init__(self):
pass
def get_list(): def get_list():
"""Return a list of supported encodings""" """Return a list of supported encodings"""
return TerminatorEncoding.encodings return TerminatorEncoding.encodings

View File

@ -1,6 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
from terminatorlib.config import dbg,err,Defaults,TerminatorConfValuestoreRC from terminatorlib.config import dbg,err,DEFAULTS,TerminatorConfValuestoreRC
from terminatorlib.keybindings import TerminatorKeybindings from terminatorlib.keybindings import TerminatorKeybindings
from terminatorlib.version import APP_NAME, APP_VERSION from terminatorlib.version import APP_NAME, APP_VERSION
from terminatorlib import translation from terminatorlib import translation
@ -85,10 +85,10 @@ class ProfileEditor:
self.window.show_all () self.window.show_all ()
def source_get_type (self, key): def source_get_type (self, key):
if Defaults.has_key (key): if DEFAULTS.has_key (key):
return Defaults[key].__class__.__name__ return DEFAULTS[key].__class__.__name__
elif Defaults['keybindings'].has_key (key): elif DEFAULTS['keybindings'].has_key (key):
return Defaults['keybindings'][key].__class__.__name__ return DEFAULTS['keybindings'][key].__class__.__name__
else: else:
raise KeyError raise KeyError
@ -364,7 +364,7 @@ class ProfileEditor:
keyval = None keyval = None
mask = None mask = None
for binding in Defaults['keybindings']: for binding in DEFAULTS['keybindings']:
value = self.term.conf.keybindings[binding] value = self.term.conf.keybindings[binding]
keyval = 0 keyval = 0
mask = 0 mask = 0

View File

@ -295,7 +295,7 @@ class Terminator:
self.keybindings = TerminatorKeybindings() self.keybindings = TerminatorKeybindings()
if self.conf.f11_modifier: if self.conf.f11_modifier:
config.Defaults['keybindings']['full_screen'] = '<Ctrl><Shift>F11' config.DEFAULTS['keybindings']['full_screen'] = '<Ctrl><Shift>F11'
print "Warning: Config setting f11_modifier is deprecated and will be removed in version 1.0" print "Warning: Config setting f11_modifier is deprecated and will be removed in version 1.0"
print "Please add the following to the end of your terminator config:" print "Please add the following to the end of your terminator config:"
print "[keybindings]" print "[keybindings]"

View File

@ -2,18 +2,18 @@
# TerminatorVersion - version number # TerminatorVersion - version number
# Copyright (C) 2008 cmsj@tenshu.net # Copyright (C) 2008 cmsj@tenshu.net
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2 only. # the Free Software Foundation, version 2 only.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""TerminatorVersion by Chris Jones <cmsj@tenshu.net> """TerminatorVersion by Chris Jones <cmsj@tenshu.net>