Пример #1
0
 def newAppCallback(self, name, device):
     app = dri.AppConfig(device, name)
     self.model.addNode(app)
     if len(device.apps) == 1:
         self.expand_row(self.model.getPathFromNode(device), True)
     device.modified(device)
     path = self.model.getPathFromNode(app)
     self.get_selection().select_path(path)
     self.scroll_to_cell(path=path, use_align=False)
Пример #2
0
 def addApp(self, button):
     dialog = AppDialog(_("Add Application"), self)
     done = False
     while not done:
         response = dialog.run()
         if response == gtk.RESPONSE_OK:
             name = dialog.getName().strip()
             executable = dialog.getExecutable().strip()
             if self.checkAppProperties(dialog, name, executable):
                 app = dri.AppConfig(self.deviceConfig, name, executable)
                 self.deviceConfig.apps.append(app)
                 self.appCombo.append_text(name)
                 self.appCombo.set_active(len(self.deviceConfig.apps) - 2)
                 self.configModified(self.deviceConfig)
                 done = True
         else:
             done = True
     dialog.destroy()
Пример #3
0
    # read or create configuration files
    fileNameList = ["/etc/drirc", os.path.join(os.environ["HOME"], ".drirc")]
    configList = []
    newFiles = []
    for fileName in fileNameList:
        try:
            cfile = open(fileName, "r")
        except IOError:
            # Make a default configuration file.
            config = dri.DRIConfig(None, fileName)
            config.writable = True
            for screen in configScreens:
                device = dri.DeviceConfig(config, str(screen.num),
                                          screen.driver.name)
                app = dri.AppConfig(device, "all")
                device.apps.append(app)
                config.devices.append(device)
            # Try to write the new file. If it fails, don't add this config.
            try:
                file = open(config.fileName, "w")
            except IOError:
                config = None
            else:
                file.write(str(config))
                file.close()
                newFiles.append(fileName)
        else:
            # Try to parse the configuration file.
            try:
                config = dri.DRIConfig(cfile)
Пример #4
0
def genNormalDeviceConfigs(configList, dpy):
    """ Generate a list of normalized device configurations.

    One device configuration for each installed device. Each contains
    a default application configuration that explicitly sets all
    options to their default values in order to override values in
    previous less specific device sections. Then it appends
    application configurations for all application configurations in
    all configuration files that affect the respective device. The
    result is one device configuration per existing device that
    summarizes the entire configuration of existing devices and
    overrides any previous settings.

    If there is no user configuration file, an empty list is returned. """
    userConfig = getUserConfig(configList)
    if not userConfig:
        return []
    screens = [screen for screen in dpy.screens if screen]
    deviceConfigs = []
    # Create one device configuration for each installed device on this display
    for screen in screens:
        if screen == None:
            continue
        driver = screen.driver
        deviceConfig = dri.DeviceConfig(userConfig, str(screen.num),
                                        driver.name)
        defaultApp = dri.AppConfig(deviceConfig, "Default")
        deviceConfig.apps.append(defaultApp)
        for sect in driver.optSections:
            for opt in sect.options.values():
                defaultApp.options[opt.name] = dri.ValueToStr(
                    opt.default, opt.type)
        deviceConfig.isNormalized = True
        deviceConfigs.append(deviceConfig)
    for config in configList:
        configIsUser = isUserConfig(config)
        for device in config.devices:
            # Determine all installed devices affected by this device-section
            # in the original configuration file
            curDeviceConfigs = [
                deviceConfig for deviceConfig in deviceConfigs
                if (device.screen == None
                    or device.screen == deviceConfig.screen) and
                (device.driver == None or device.driver == deviceConfig.driver)
            ]
            for curDevice in curDeviceConfigs:
                driver = dpy.getScreen(int(curDevice.screen)).driver
                for app in device.apps:
                    # Determine all applications on this device affected by
                    # this application section in the original config file.
                    # It should be one at most. Create a new application
                    # configuration if needed.
                    curApps = [
                        curApp for curApp in curDevice.apps
                        if app.executable == curApp.executable
                    ]
                    assert len(curApps) <= 1
                    if curApps:
                        curApp = curApps[0]
                    else:
                        curApp = dri.AppConfig(curDevice, app.name,
                                               app.executable)
                        curDevice.apps.append(curApp)
                    # Update all option settings. Non-existing options
                    # or invalid values are only considered in
                    # redundant device sections.
                    for opt, value in app.options.items():
                        isValid = False
                        if configIsUser and \
                               device.screen != None and device.driver != None:
                            isValid = True
                        else:
                            optInfo = driver.getOptInfo(opt)
                            if optInfo and optInfo.validate(value):
                                isValid = True
                        if isValid:
                            curApp.options[opt] = value
    return deviceConfigs