def get_type_handler(mime_type, handler_type = 'MIME-types'): """Lookup the ROX-defined run action for a given mime type. mime_type is an object returned by lookup(). handler_type is a config directory leaf (e.g.'MIME-types').""" handler = basedir.load_first_config('rox.sourceforge.net', handler_type, mime_type.media + '_' + mime_type.subtype) if not handler: # Fall back to the base handler if no subtype handler exists handler = basedir.load_first_config('rox.sourceforge.net', handler_type, mime_type.media) return handler
def image_for_type(type, size=48, flags=0): '''Search XDG_CONFIG or icon theme 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') icon=None if not path: icon_name = '%s-%s' % (media, subtype) try: path=users_theme.lookup_icon(icon_name, size, flags) except: print "Error loading MIME icon" 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: icon_name = '%s-x-generic' % media try: path=users_theme.lookup_icon(icon_name, size, flags) except: print "Error loading MIME icon" if path: if hasattr(rox.g.gdk, 'pixbuf_new_from_file_at_size'): return rox.g.gdk.pixbuf_new_from_file_at_size(path, size, size) else: return rox.g.gdk.pixbuf_new_from_file(path) else: return None
def may_run_login_script(): """Called once the WM is running.""" global _logged_in global login_child if _logged_in: return _logged_in = True # Run ROX-Filer run_rox_process() # Run Login script login = basedir.load_first_config(constants.site, 'ROX-Session', 'Login') or \ os.path.join(rox.app_dir, 'Login') login_child = os.spawnlp(os.P_NOWAIT, login, login) def login_died(status): global login_child login_child = None if status != 0: rox.alert(_("Your login script ('%s') failed. " "I'll give you an xterm to try and fix it. ROX-Session " "itself is running fine though - run me a second time " "to logout.")) os.spawnlp(os.P_NOWAIT, 'xterm', 'xterm') children.register_child(login_child, login_died)
def __init__(self): MemoList.__init__(self) self.visible = MemoList() path = basedir.load_first_config('rox.sourceforge.net', 'Memo', 'Entries') if path: try: from xml.dom import minidom, Node doc = minidom.parse(path) except: rox.report_exception() errors = 0 root = doc.documentElement for node in root.getElementsByTagName('memo'): try: memo = memo_from_node(node) self.add(memo, update=0) except: if not errors: rox.report_exception() errors = 1 self.update_visible() app_options.add_notify(self.update_visible)
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
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
def save_path(site, dir, leaf, create=1): filer=basedir.load_first_config(SITE, 'ROX-Filer') if filer and os.path.isdir(filer): path=basedir.save_config_path(site, dir) path=os.path.join(path, leaf) else: path=choices.save(dir, leaf, create) return path
def save_path(site, dir, leaf, create=1): filer = basedir.load_first_config(SITE, 'ROX-Filer') if filer and os.path.isdir(filer): path = basedir.save_config_path(site, dir) path = os.path.join(path, leaf) else: path = choices.save(dir, leaf, create) return path
def run_rox_process(): global rox_pid run_rox = basedir.load_first_config(constants.site, 'ROX-Session', 'RunROX') or \ os.path.join(rox.app_dir, 'RunROX') try: rox_pid = os.spawnlp(os.P_NOWAIT, run_rox, run_rox, rox.app_dir) children.register_child(rox_pid, rox_process_died) except: rox.report_exception() rox_process_died(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
def __init__(self, screen): self.screen = screen self.selection_atom = g.gdk.atom_intern(_property_name(screen), False) self.xsettings_atom = g.gdk.atom_intern('_XSETTINGS_SETTINGS', False) self.manager_atom = g.gdk.atom_intern('MANAGER', False) self.serial = 0 self.window = g.Invisible() self.window.add_events(g.gdk.PROPERTY_CHANGE_MASK) self.window.connect('property-notify-event', self.property_notify) # List of commands to execute at an opportune moment self.to_run = [] if manager_check_running(0): print >> sys.stderr, _("An XSETTINGS manager is already running. " "Not taking control of XSETTINGS...") return else: g.gdk.selection_owner_set(self.window.window, self.selection_atom, self.get_server_time(), False) if _get_manager(screen) != self.window.window: info('Failed to acquire XSettings manager selection') self.terminate() return # Can't see how to do this with PyGTK. But, since nothing else is # running at this point, we're probably OK. # XSendEvent (display, RootWindow (display, screen), # False, StructureNotifyMask, (XEvent *)&xev); info('Acquired XSettings selection successfully - window %s', self.window.window) # Load settings try: path = basedir.load_first_config(constants.site, 'ROX-Session', 'Settings.xml') if path: self.load_settings(path) except: rox.report_exception() self.notify()
def get(scheme): """Return the handler for URI's of the named scheme (e.g. http, file, ftp, etc.) The handler for file is always rox, otherwise it obtained from the configuration directory rox.sourceforge.net/URI. None is returned if no handler is defined. The returned string may contain %s in which case it should be replaced with the URI, otherwise append the URI (after a space). """ if scheme == 'file': return 'rox -U "%s"' path = basedir.load_first_config('rox.sourceforge.net', 'URI', scheme) if not path: return if rox.isappdir(path): path = os.path.join(path, 'AppRun') return path
def get(scheme): """Return the handler for URI's of the named scheme (e.g. http, file, ftp, etc.) The handler for file is always rox, otherwise it obtained from the configuration directory rox.sourceforge.net/URI. None is returned if no handler is defined. The returned string may contain %s in which case it should be replaced with the URI, otherwise append the URI (after a space). """ if scheme=='file': return 'rox -U "%s"' path=basedir.load_first_config('rox.sourceforge.net', 'URI', scheme) if not path: return if rox.isappdir(path): path=os.path.join(path, 'AppRun') return path
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()
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()