Exemplo n.º 1
0
	def testMigrateNothing(self):
		choices.migrate('Edit', 'rox.sourceforge.net')
		choices.load('Draw', 'Options')
		try:
			choices.load('Edit', 'Options')
			raise Exception('Expected exception!')
		except AssertionError:
			pass
		assert not os.path.exists('/tmp/config')
Exemplo n.º 2
0
def load_path(site, dir, leaf):
    path=None
    try:
        path=basedir.load_first_config(site, dir, leaf)
        if not path:
            path=choices.load(dir, leaf)
    except:
        pass
    return path
Exemplo n.º 3
0
def load_path(site, dir, leaf):
    path = None
    try:
        path = basedir.load_first_config(site, dir, leaf)
        if not path:
            path = choices.load(dir, leaf)
    except:
        pass
    return path
Exemplo n.º 4
0
def image_for_type(type):
    'Search <Choices> for a suitable icon. Returns a pixbuf, or None.'
    from icon_theme import rox_theme
    media, subtype = type.split('/', 1)
    path = choices.load('MIME-icons', media + '_' + subtype + '.png')
    if not path:
        icon = 'mime-%s:%s' % (media, subtype)
        try:
            path = rox_theme.lookup_icon(icon, 48)
            if not path:
                icon = 'mime-%s' % media
                path = rox_theme.lookup_icon(icon, 48)
        except:
            print "Error loading MIME icon"
    if not path:
        path = choices.load('MIME-icons', media + '.png')
    if path:
        return gdk.pixbuf_new_from_file(path)
    else:
        return None
Exemplo n.º 5
0
	def testLoad(self):
		os.mkdir('/tmp/choices')
		os.mkdir('/tmp/choices/Edit')
		self.assertEquals(choices.load('Edit', 'Options'), None)

		file('/tmp/choices/Edit/Options', 'w').close()
		self.assertEquals(choices.load('Edit', 'Options'),
				  '/tmp/choices/Edit/Options')

		os.mkdir('/tmp/choices2')
		os.mkdir('/tmp/choices2/Edit')
		self.assertEquals(choices.load('Edit', 'Options'),
				  '/tmp/choices/Edit/Options')

		file('/tmp/choices2/Edit/Options', 'w').close()
		self.assertEquals(choices.load('Edit', 'Options'),
				  '/tmp/choices/Edit/Options')

		os.unlink('/tmp/choices/Edit/Options')
		self.assertEquals(choices.load('Edit', 'Options'),
				  '/tmp/choices2/Edit/Options')
Exemplo n.º 6
0
def image_for_type(type, size=48, flags=0):
	'Search <Choices> for a suitable icon. Returns a pixbuf, or None.'
	from icon_theme import users_theme
	
	media, subtype = type.split('/', 1)

	path=basedir.load_first_config('rox.sourceforge.net', 'MIME-icons',
				       media + '_' + subtype + '.png')
	if not path:
		path = choices.load('MIME-icons',
				    media + '_' + subtype + '.png')
	icon=None
	if not path:
		icon_name = 'mime-%s:%s' % (media, subtype)

		try:
			path=users_theme.lookup_icon(icon_name, size, flags)
			if not path:
				icon_name = 'mime-%s' % media
				path = users_theme.lookup_icon(icon_name, size)

		except:
			print "Error loading MIME icon"

	if not path:
		path = basedir.load_first_config('rox.sourceforge.net',
						 'MIME-icons', media + '.png')
	if not path:
		path = choices.load('MIME-icons', media + '.png')
	if path:
		if hasattr(gdk, 'pixbuf_new_from_file_at_size'):
			return gdk.pixbuf_new_from_file_at_size(path, size, size)
		else:
			return gdk.pixbuf_new_from_file(path)
	else:
		return None
Exemplo n.º 7
0
    def __init__(self, program, leaf, site=None):
        """program/leaf is a Choices pair for the saved options. If site
		is given, the basedir module is used for saving choices (the new system).
		Otherwise, the deprecated choices module is used."""
        self.site = site
        self.program = program
        self.leaf = leaf
        self.pending = {}  # Loaded, but not registered
        self.options = {}  # Name -> Option
        self.callbacks = []
        self.too_late_for_registrations = 0

        if site:
            path = basedir.load_first_config(site, program, leaf)
        else:
            path = choices.load(program, leaf)
        if not path:
            return

        try:
            doc = minidom.parse(path)

            root = doc.documentElement
            assert root.localName == 'Options'
            for o in root.childNodes:
                if o.nodeType != Node.ELEMENT_NODE:
                    continue
                if o.localName == 'Option':
                    name = o.getAttribute('name')
                    self.pending[name] = data(o)
                elif o.localName == 'ListOption':
                    name = o.getAttribute('name')
                    v = []
                    for s in o.getElementsByTagName('Value'):
                        v.append(data(s))
                        self.pending[name] = v
                else:
                    print "Warning: Non Option element", o
        except:
            rox.report_exception()
Exemplo n.º 8
0
	def __init__(self, program, leaf, site = None):
		"""program/leaf is a Choices pair for the saved options. If site
		is given, the basedir module is used for saving choices (the new system).
		Otherwise, the deprecated choices module is used."""
		self.site = site
		self.program = program
		self.leaf = leaf
		self.pending = {}	# Loaded, but not registered
		self.options = {}	# Name -> Option
		self.callbacks = []
		self.too_late_for_registrations = 0
		
		if site:
			path = basedir.load_first_config(site, program, leaf)
		else:
			path = choices.load(program, leaf)
		if not path:
			return

		try:
			doc = minidom.parse(path)
			
			root = doc.documentElement
			assert root.localName == 'Options'
			for o in root.childNodes:
				if o.nodeType != Node.ELEMENT_NODE:
					continue
				if o.localName == 'Option':
					name = o.getAttribute('name')
					self.pending[name] = data(o)
				elif o.localName=='ListOption':
					name = o.getAttribute('name')
					v=[]
					for s in o.getElementsByTagName('Value'):
						v.append(data(s))
						self.pending[name]=v
				else:
					print "Warning: Non Option element", o
		except:
			rox.report_exception()
Exemplo n.º 9
0
	def testLoadNothing(self):
		self.assertEquals('/tmp/choices', choices.paths[0])
		assert not os.path.exists('/tmp/choices')

		self.assertEquals(choices.load('Edit', 'Options'), None)