def on_get_value(self, node, col): if node.__class__ == dri.DRIConfig: if col == 0: return self.configIcon else: return "<b>" + escapeMarkup(str(node.fileName)) + "</b>" elif node.__class__ == dri.DeviceConfig: if node.screen and node.driver: name = _("%s on screen %s") % (node.driver.capitalize(), node.screen) icon = self.screenDriverIcon elif node.screen: name = _("Screen %s") % node.screen icon = self.screenIcon elif node.driver: name = "%s" % node.driver.capitalize() icon = self.driverIcon else: name = _("Unspecified device") icon = self.unspecIcon if col == 0: return icon else: return escapeMarkup(str(name)) elif node.__class__ == dri.AppConfig: if col == 0: return self.appIcon elif not node.isValid: return '<span foreground="red">' + \ escapeMarkup(str(node.name)) + '</span>' else: return escapeMarkup(str(node.name))
def selectApp(self, app): if self.appNotebook: self.expanderVBox.remove(self.appNotebook) self.appNotebook = None self.appPage = None elif self.appPage: self.expanderVBox.remove(self.appPage) self.appPage = None if not app: self.appPropButton.set_sensitive(False) self.appRemoveButton.set_sensitive(False) return self.appPropButton.set_sensitive(True) self.appRemoveButton.set_sensitive(True) app.modified = self.configModified unknownPage = commonui.UnknownSectionPage(self.driver, app) if len(unknownPage.opts) > 0: self.appNotebook = gtk.Notebook() self.appNotebook.popup_enable() unknownPage.show() unknownLabel = gtk.Label(_("Unknown options")) unknownLabel.show() self.appNotebook.append_page(unknownPage, unknownLabel) self.appPage = AppPage(self.driver, app) self.appPage.show() appPageLabel = gtk.Label(_("Known options")) appPageLabel.show() self.appNotebook.append_page(self.appPage, appPageLabel) self.appNotebook.show() appWidget = self.appNotebook else: self.appPage = AppPage(self.driver, app) self.appPage.show() appWidget = self.appPage self.expanderVBox.pack_start(appWidget, True, True, 0)
def removeItem(self, widget): node = self.getSelection() if node.__class__ == dri.AppConfig: parent = node.device dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _("Really delete application \"%s\"?") % node.name) elif node.__class__ == dri.DeviceConfig: parent = node.config dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _("Really delete device and all applications in it?")) else: # The remove button should be unsensitive. assert False response = dialog.run() dialog.destroy() if response != gtk.RESPONSE_YES: return if node.__class__ == dri.AppConfig: commonui.mainWindow.removeApp(node) elif node.__class__ == dri.DeviceConfig: for app in node.apps: commonui.mainWindow.removeApp(app) self.model.removeNode(node) parent.modified(parent) path = self.model.getPathFromNode(parent) self.get_selection().select_path(path) self.scroll_to_cell(path=path, use_align=False)
def __init__(self, title, callback, name, data): gtk.Dialog.__init__(self, title, commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL, (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) self.callback = callback self.data = data self.connect("response", self.responseSignal) table = gtk.Table(2, 2) commentLabel = gtk.Label( _("Enter the name of the application below. This just serves as " "a description for you. Don't forget to set the executable " "afterwards.")) commentLabel.set_line_wrap(True) commentLabel.show() table.attach(commentLabel, 0, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.EXPAND, 10, 5) label = gtk.Label(_("Application Name")) label.show() table.attach(label, 0, 1, 1, 2, 0, gtk.EXPAND, 10, 5) self.entry = gtk.Entry() self.entry.set_text(name) self.entry.select_region(0, len(name)) self.entry.connect("activate", self.activateSignal) self.entry.show() table.attach(self.entry, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.EXPAND, 10, 5) table.show() self.vbox.pack_start(table, True, True, 5) self.show() self.entry.grab_focus()
def on_get_value(self, node, col): if node.__class__ == dri.DRIConfig: if col == 0: return self.configIcon else: return "<b>" + escapeMarkup(str(node.fileName)) + "</b>" elif node.__class__ == dri.DeviceConfig: if node.screen and node.driver: name = _("%s on screen %s") % (node.driver.capitalize(), node.screen) icon = self.screenDriverIcon elif node.screen: name = _("Screen %s") % node.screen icon = self.screenIcon elif node.driver: name = "%s" % node.driver.capitalize() icon = self.driverIcon else: name = _("Unspecified device") icon = self.unspecIcon if col == 0: return icon else: return escapeMarkup(str(name)) elif node.__class__ == dri.AppConfig: if col == 0: return self.appIcon elif not node.isValid: return '<span foreground="red">' + \ escapeMarkup(str(node.name)) + '</span>' else: return escapeMarkup(str(node.name))
def selectApp(self, app): if self.appNotebook: self.expanderVBox.remove(self.appNotebook) self.appNotebook = None self.appPage = None elif self.appPage: self.expanderVBox.remove(self.appPage) self.appPage = None if not app: self.appPropButton.set_sensitive(False) self.appRemoveButton.set_sensitive(False) return self.appPropButton.set_sensitive(True) self.appRemoveButton.set_sensitive(True) app.modified = self.configModified unknownPage = commonui.UnknownSectionPage(self.driver, app) if len(unknownPage.opts) > 0: self.appNotebook = gtk.Notebook() self.appNotebook.popup_enable() unknownPage.show() unknownLabel = gtk.Label(_("Unknown options")) unknownLabel.show() self.appNotebook.append_page(unknownPage, unknownLabel) self.appPage = AppPage(self.driver, app) self.appPage.show() appPageLabel = gtk.Label(_("Known options")) appPageLabel.show() self.appNotebook.append_page(self.appPage, appPageLabel) self.appNotebook.show() appWidget = self.appNotebook else: self.appPage = AppPage(self.driver, app) self.appPage.show() appWidget = self.appPage self.expanderVBox.pack_start(appWidget, True, True, 0)
def checkAppProperties(self, dialog, name, executable, sameApp=None): errorStr = None if name == "" or executable == "": # Error message errorStr = _("You must enter both an application name and " "an executable name.") else: for app in self.deviceConfig.apps: if app != sameApp and name == app.name: errorStr = _("There exists an application " "configuration with the same name. " "Please enter a different name.") break elif app != sameApp and executable == app.executable: errorStr = _("There exists an application " "configuration for the same " "executable. You can't create multiple " "application configurations for the " "same executable.") break if errorStr: dialog = gtk.MessageDialog( dialog, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, errorStr) dialog.run() dialog.destroy() return False return True
def removeItem(self, widget): node = self.getSelection() if node.__class__ == dri.AppConfig: parent = node.device dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _("Really delete application \"%s\"?") % node.name) elif node.__class__ == dri.DeviceConfig: parent = node.config dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _("Really delete device and all applications in it?")) else: # The remove button should be unsensitive. assert False response = dialog.run() dialog.destroy() if response != gtk.RESPONSE_YES: return if node.__class__ == dri.AppConfig: commonui.mainWindow.removeApp(node) elif node.__class__ == dri.DeviceConfig: for app in node.apps: commonui.mainWindow.removeApp(app) self.model.removeNode(node) parent.modified(parent) path = self.model.getPathFromNode(parent) self.get_selection().select_path(path) self.scroll_to_cell(path=path, use_align=False)
def __init__(self, title, callback, name, data): gtk.Dialog.__init__(self, title, commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL, (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) self.callback = callback self.data = data self.connect("response", self.responseSignal) table = gtk.Table(2, 2) commentLabel = gtk.Label( _("Enter the name of the application below. This just serves as " "a description for you. Don't forget to set the executable " "afterwards.")) commentLabel.set_line_wrap(True) commentLabel.show() table.attach(commentLabel, 0, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.EXPAND, 10, 5) label = gtk.Label(_("Application Name")) label.show() table.attach(label, 0, 1, 1, 2, 0, gtk.EXPAND, 10, 5) self.entry = gtk.Entry() self.entry.set_text(name) self.entry.select_region(0, len(name)) self.entry.connect("activate", self.activateSignal) self.entry.show() table.attach(self.entry, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.EXPAND, 10, 5) table.show() self.vbox.pack_start(table, True, True, 5) self.show() self.entry.grab_focus()
def checkAppProperties(self, dialog, name, executable, sameApp=None): errorStr = None if name == "" or executable == "": # Error message errorStr = _("You must enter both an application name and " "an executable name.") else: for app in self.deviceConfig.apps: if app != sameApp and name == app.name: errorStr = _("There exists an application " "configuration with the same name. " "Please enter a different name.") break elif app != sameApp and executable == app.executable: errorStr = _("There exists an application " "configuration for the same " "executable. You can't create multiple " "application configurations for the " "same executable.") break if errorStr: dialog = gtk.MessageDialog( dialog, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, errorStr) dialog.run() dialog.destroy() return False return True
def properties(self, widget): node = self.getSelection() if node.__class__ == dri.AppConfig: dialog = NameDialog(_("Rename Application"), self.renameCallback, node.name, node) else: dialog = DeviceDialog(_("Device Properties"), self.propertiesCallback, node)
def properties(self, widget): node = self.getSelection() if node.__class__ == dri.AppConfig: dialog = NameDialog( _("Rename Application"), self.renameCallback, node.name, node) else: dialog = DeviceDialog( _("Device Properties"), self.propertiesCallback, node)
def __init__(self, title, parent, app=None): gtk.Dialog.__init__(self, title, parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, ("gtk-ok", gtk.RESPONSE_OK, "gtk-cancel", gtk.RESPONSE_CANCEL)) self.set_resizable(False) table = gtk.Table(3, 2) nameLabel = gtk.Label(_("Application Name")) nameLabel.show() table.attach(nameLabel, 0, 1, 0, 1, 0, gtk.EXPAND, 10, 5) self.nameEntry = gtk.Entry() if app: self.nameEntry.set_text(app.name) self.nameEntry.connect("activate", lambda widget: self.response(gtk.RESPONSE_OK)) self.nameEntry.show() table.attach(self.nameEntry, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.EXPAND, 10, 5) execLabel = gtk.Label(_("Executable Name")) execLabel.show() table.attach(execLabel, 0, 1, 1, 2, 0, gtk.EXPAND, 10, 5) self.execEntry = gtk.Entry() if app: self.execEntry.set_text(app.executable) self.execEntry.connect("activate", lambda widget: self.response(gtk.RESPONSE_OK)) self.execEntry.show() table.attach(self.execEntry, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.EXPAND, 10, 5) hBox = gtk.HBox(spacing=10) infoImageVBox = gtk.VBox() infoImage = commonui.StockImage(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_DIALOG) infoImage.show() infoImageVBox.pack_start(infoImage, False, False, 0) infoImageVBox.show() hBox.pack_start(infoImageVBox, False, False, 0) infoLabel = gtk.Label( _("The executable name is important for identifying the " "application. If you get it wrong, your settings will not " "apply. Beware that some applications are started by a " "shell script, that has a different name than the real " "executable.")) # TODO: Add a small database of known applications with their # executable names that can be picked from a menu. infoLabel.set_line_wrap(True) infoLabel.show() hBox.pack_start(infoLabel, False, False, 0) hBox.show() table.attach(hBox, 0, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.EXPAND, 10, 5) table.show() self.vbox.pack_start(table, True, True, 5) self.show() self.nameEntry.grab_focus()
def __init__(self, title, parent, app=None): gtk.Dialog.__init__( self, title, parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, ("gtk-ok", gtk.RESPONSE_OK, "gtk-cancel", gtk.RESPONSE_CANCEL)) self.set_resizable(False) table = gtk.Table(3, 2) nameLabel = gtk.Label(_("Application Name")) nameLabel.show() table.attach(nameLabel, 0, 1, 0, 1, 0, gtk.EXPAND, 10, 5) self.nameEntry = gtk.Entry() if app: self.nameEntry.set_text(app.name) self.nameEntry.connect("activate", lambda widget: self.response(gtk.RESPONSE_OK)) self.nameEntry.show() table.attach(self.nameEntry, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.EXPAND, 10, 5) execLabel = gtk.Label(_("Executable Name")) execLabel.show() table.attach(execLabel, 0, 1, 1, 2, 0, gtk.EXPAND, 10, 5) self.execEntry = gtk.Entry() if app: self.execEntry.set_text(app.executable) self.execEntry.connect("activate", lambda widget: self.response(gtk.RESPONSE_OK)) self.execEntry.show() table.attach(self.execEntry, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.EXPAND, 10, 5) hBox = gtk.HBox(spacing=10) infoImageVBox = gtk.VBox() infoImage = commonui.StockImage(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_DIALOG) infoImage.show() infoImageVBox.pack_start(infoImage, False, False, 0) infoImageVBox.show() hBox.pack_start(infoImageVBox, False, False, 0) infoLabel = gtk.Label( _("The executable name is important for identifying the " "application. If you get it wrong, your settings will not " "apply. Beware that some applications are started by a " "shell script, that has a different name than the real " "executable.")) # TODO: Add a small database of known applications with their # executable names that can be picked from a menu. infoLabel.set_line_wrap(True) infoLabel.show() hBox.pack_start(infoLabel, False, False, 0) hBox.show() table.attach(hBox, 0, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.EXPAND, 10, 5) table.show() self.vbox.pack_start(table, True, True, 5) self.show() self.nameEntry.grab_focus()
def newItem(self, widget): node = self.getSelection() if node.__class__ == dri.AppConfig: node = node.device if node.__class__ == dri.DeviceConfig: dialog = NameDialog( _("New Application"), self.newAppCallback, "", node) elif node.__class__ == dri.DRIConfig: dialog = DeviceDialog( _("New Device"), self.newDeviceCallback, node)
def newItem(self, widget): node = self.getSelection() if node.__class__ == dri.AppConfig: node = node.device if node.__class__ == dri.DeviceConfig: dialog = NameDialog(_("New Application"), self.newAppCallback, "", node) elif node.__class__ == dri.DRIConfig: dialog = DeviceDialog(_("New Device"), self.newDeviceCallback, node)
def __init__(self, title, callback, data): gtk.Dialog.__init__(self, title, commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL, (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) self.callback = callback self.data = data self.connect("response", self.responseSignal) table = gtk.Table(2, 3) commentLabel = gtk.Label( _("Describe the device that you would like to configure.")) commentLabel.set_line_wrap(True) commentLabel.show() table.attach(commentLabel, 0, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.EXPAND, 10, 5) screenLabel = gtk.Label(_("Screen Number")) screenLabel.show() table.attach(screenLabel, 0, 1, 1, 2, 0, gtk.EXPAND, 10, 5) self.screenCombo = gtk.Combo() self.screenCombo.set_popdown_strings( [""] + map(str, range(len(commonui.dpy.screens)))) self.screenCombo.entry.connect("activate", self.screenSignal) self.screenCombo.list.connect("select_child", self.screenSignal) self.screenCombo.show() table.attach(self.screenCombo, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.EXPAND, 10, 5) driverLabel = gtk.Label(_("Driver Name")) driverLabel.show() table.attach(driverLabel, 0, 1, 2, 3, 0, gtk.EXPAND, 10, 5) self.driverCombo = gtk.Combo() self.driverCombo.set_popdown_strings( [""] + [str(driver.name) for driver in dri.DisplayInfo.drivers.values()]) self.driverCombo.show() table.attach(self.driverCombo, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.EXPAND, 10, 5) if data and data.__class__ == dri.DeviceConfig: if data.screen: self.screenCombo.entry.set_text(data.screen) if data.driver: self.driverCombo.entry.set_text(data.driver) table.show() self.vbox.pack_start(table, True, True, 5) self.show()
def __init__(self, title, callback, data): gtk.Dialog.__init__(self, title, commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL, (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) self.callback = callback self.data = data self.connect("response", self.responseSignal) table = gtk.Table(2, 3) commentLabel = gtk.Label(_( "Describe the device that you would like to configure.")) commentLabel.set_line_wrap(True) commentLabel.show() table.attach(commentLabel, 0, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.EXPAND, 10, 5) screenLabel = gtk.Label(_("Screen Number")) screenLabel.show() table.attach(screenLabel, 0, 1, 1, 2, 0, gtk.EXPAND, 10, 5) self.screenCombo = gtk.Combo() self.screenCombo.set_popdown_strings([""] + map(str, range(len( commonui.dpy.screens)))) self.screenCombo.entry.connect("activate", self.screenSignal) self.screenCombo.list.connect("select_child", self.screenSignal) self.screenCombo.show() table.attach(self.screenCombo, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.EXPAND, 10, 5) driverLabel = gtk.Label(_("Driver Name")) driverLabel.show() table.attach(driverLabel, 0, 1, 2, 3, 0, gtk.EXPAND, 10, 5) self.driverCombo = gtk.Combo() self.driverCombo.set_popdown_strings([""] + [str( driver.name) for driver in dri.DisplayInfo.drivers.values()]) self.driverCombo.show() table.attach(self.driverCombo, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.EXPAND, 10, 5) if data and data.__class__ == dri.DeviceConfig: if data.screen: self.screenCombo.entry.set_text(data.screen) if data.driver: self.driverCombo.entry.set_text(data.driver) table.show() self.vbox.pack_start(table, True, True, 5) self.show()
def reloadConfig(self, widget): node = self.getSelection() if node.__class__ == dri.AppConfig: config = node.device.config elif node.__class__ == dri.DeviceConfig: config = node.config else: config = node dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _("Really reload \"%s\" from disk?") % config.fileName) response = dialog.run() dialog.destroy() if response != gtk.RESPONSE_YES: return try: cfile = open(config.fileName, "r") except IOError: dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Couldn't open \"%s\" for reading. " "The file was not reloaded.") % config.fileName) dialog.run() dialog.destroy() return # Try to parse the configuration file. try: newConfig = dri.DRIConfig(cfile) except dri.XMLError, problem: dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Configuration file \"%s\" contains errors:\n" "%s\n" "The file was not reloaded.") % (config.fileName, str(problem))) dialog.run() dialog.destroy() cfile.close() return
def reloadConfig(self, widget): node = self.getSelection() if node.__class__ == dri.AppConfig: config = node.device.config elif node.__class__ == dri.DeviceConfig: config = node.config else: config = node dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _("Really reload \"%s\" from disk?") % config.fileName) response = dialog.run() dialog.destroy() if response != gtk.RESPONSE_YES: return try: cfile = open(config.fileName, "r") except IOError: dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Couldn't open \"%s\" for reading. " "The file was not reloaded.") % config.fileName) dialog.run() dialog.destroy() return # Try to parse the configuration file. try: newConfig = dri.DRIConfig(cfile) except dri.XMLError, problem: dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Configuration file \"%s\" contains errors:\n" "%s\n" "The file was not reloaded.") % (config.fileName, str(problem))) dialog.run() dialog.destroy() cfile.close() return
def saveConfig(self, widget): node = self.getSelection() if node.__class__ == dri.AppConfig: config = node.device.config elif node.__class__ == dri.DeviceConfig: config = node.config elif node.__class__ == dri.DRIConfig: config = node valid = True for device in config.devices: try: driver = device.getDriver(commonui.dpy) except dri.XMLError: driver = None if driver == None: continue for app in device.apps: valid = valid and driver.validate(app.options) if not valid: dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _("The configuration contains invalid entries. Save anyway?")) response = dialog.run() dialog.destroy() if response != gtk.RESPONSE_YES: return try: file = open(config.fileName, "w") except IOError: dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Can't open \"%s\" for writing.") % config.fileName) dialog.run() dialog.destroy() return commonui.mainWindow.commitDriverPanel() file.write(str(config)) file.close() config.modified(config, False)
def saveConfig(self, widget): node = self.getSelection() if node.__class__ == dri.AppConfig: config = node.device.config elif node.__class__ == dri.DeviceConfig: config = node.config elif node.__class__ == dri.DRIConfig: config = node valid = True for device in config.devices: try: driver = device.getDriver(commonui.dpy) except dri.XMLError: driver = None if driver == None: continue for app in device.apps: valid = valid and driver.validate(app.options) if not valid: dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _("The configuration contains invalid entries. Save anyway?")) response = dialog.run() dialog.destroy() if response != gtk.RESPONSE_YES: return try: file = open(config.fileName, "w") except IOError: dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Can't open \"%s\" for writing.") % config.fileName) dialog.run() dialog.destroy() return commonui.mainWindow.commitDriverPanel() file.write(str(config)) file.close() config.modified(config, False)
def refreshOptions(self): if self.table: self.remove(self.get_child()) self.optLines = [] self.table = gtk.Table(len(self.app.options) + 1, 3) self.add_with_viewport(self.table) self.optionTree = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_INT) i = 0 sectI = 0 for sect in self.driver.optSections: sectIter = self.optionTree.append(None, [ lineWrap(sect.getDesc([lang])), sectI, -1 ]) sectHasOpts = False optI = 0 for opt in sect.optList: if self.app.options.has_key(opt.name): self.optLines.append(commonui.OptionLine(self, i, opt, True, True)) i = i + 1 else: self.optionTree.append(sectIter, [ lineWrap(opt.getDesc([lang]).text), sectI, optI ]) sectHasOpts = True optI = optI + 1 if not sectHasOpts: self.optionTree.remove(sectIter) sectI = sectI + 1 if len(self.optionTree) > 0: addLabel = commonui.WrappingDummyCheckButton( _("Add setting"), width=200) addLabel.show() self.table.attach(addLabel, 0, 1, i, i + 1, gtk.EXPAND | gtk.FILL, 0, 5, 5) addCombo = gtk.ComboBox(self.optionTree) addCombo.connect("changed", self.addOption) cell = gtk.CellRendererText() addCombo.pack_start(cell, True) addCombo.add_attribute(cell, 'text', 0) addCombo.show() self.table.attach(addCombo, 1, 2, i, i + 1, gtk.FILL, 0, 5, 5) self.table.show()
def selectionChangedSignal(self, data): node = self.getSelection(allowNone=True) if not node: driver = None app = None elif node.__class__ == dri.AppConfig: app = node try: driver = app.device.getDriver(commonui.dpy) except dri.XMLError, problem: driver = None dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Parsing the driver's configuration information: %s") % problem) dialog.connect("response", lambda d, r: d.destroy()) dialog.show()
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()
def configModified(self, node, b=True): if b != True: return # Save the configuration file try: file = open(self.userConfig.fileName, "w") except IOError: dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Can't open \"%s\" for writing.") % self.userConfig.fileName) dialog.run() dialog.destroy() self.inConfigModified = False return self.commit() file.write(str(self.userConfig)) file.close()
def selectionChangedSignal(self, data): node = self.getSelection(allowNone=True) if not node: driver = None app = None elif node.__class__ == dri.AppConfig: app = node try: driver = app.device.getDriver(commonui.dpy) except dri.XMLError, problem: driver = None dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Parsing the driver's configuration information: %s") % problem) dialog.connect("response", lambda d, r: d.destroy()) dialog.show()
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()
def configModified(self, node, b=True): if b != True: return # Save the configuration file try: file = open(self.userConfig.fileName, "w") except IOError: dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Can't open \"%s\" for writing.") % self.userConfig.fileName) dialog.run() dialog.destroy() self.inConfigModified = False return self.commit() file.write(str(self.userConfig)) file.close()
def exitHandler(self, widget, event=None): modified = False for config in self.configTree.getConfigList(): if config.isModified: modified = True break if modified: dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _("There are unsaved modifications. Exit anyway?")) dialog.connect("response", self.doExit) dialog.show() return True elif event == None: # called from toolbar button: main_quit! gtk.main_quit() else: # called from delete_event: indicate it's ok to destroy return False
def exitHandler(self, widget, event=None): modified = False for config in self.configTree.getConfigList(): if config.isModified: modified = True break if modified: dialog = gtk.MessageDialog( commonui.mainWindow, gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _("There are unsaved modifications. Exit anyway?")) dialog.connect("response", self.doExit) dialog.show() return True elif event == None: # called from toolbar button: main_quit! gtk.main_quit() else: # called from delete_event: indicate it's ok to destroy return False
def appProperties(self, button): if not self.appPage: return dialog = AppDialog(_("Application Properties"), self, self.appPage.app) 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, self.appPage.app): i = self.deviceConfig.apps.index(self.appPage.app) self.appCombo.remove_text(i - 1) self.appCombo.insert_text(i - 1, name) self.appCombo.set_active(i - 1) self.appPage.app.name = name self.appPage.app.executable = executable self.configModified(self.appPage.app) done = True else: done = True dialog.destroy()
def appProperties(self, button): if not self.appPage: return dialog = AppDialog(_("Application Properties"), self, self.appPage.app) 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, self.appPage.app): i = self.deviceConfig.apps.index(self.appPage.app) self.appCombo.remove_text(i - 1) self.appCombo.insert_text(i - 1, name) self.appCombo.set_active(i - 1) self.appPage.app.name = name self.appPage.app.executable = executable self.configModified(self.appPage.app) done = True else: done = True dialog.destroy()
def start(configList): userConfig = getUserConfig(configList) if not userConfig: dialog = gtk.MessageDialog( None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("The DRI configuration file \"%s\" is broken or could not be " "created.") % os.path.join(os.environ["HOME"], ".drirc") + " " + _("DRIconf will be started in expert mode.")) dialog.run() dialog.destroy() complexui.start(configList) return if not userConfig.writable: # Not writable: start expert mode dialog = gtk.MessageDialog( None, 0, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, _("Your DRI configuration file \"%s\" is not writable.") % userConfig.fileName + " " + _("DRIconf will be started in expert mode.")) dialog.run() dialog.destroy() complexui.start(configList) return normalizedDeviceConfigs = normalizeConfig(configList, commonui.dpy) if normalizedDeviceConfigs == None: dialog = gtk.MessageDialog( None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Normalization of your DRI configuration file \"%s\" failed. " "Please report a bug with the original configuration file " "attached. The file will be treated as read-only for now.") % userConfig.fileName + " " + _("DRIconf will be started in expert mode.")) dialog.run() dialog.destroy() userConfig.writable = False complexui.start(configList) return mainWindow = MainWindow(configList) commonui.mainWindow = mainWindow mainWindow.set_default_size(-1, 500) mainWindow.show() # Save modified normalized configuration before we start if hasattr(userConfig, "isModified") and userConfig.isModified: mainWindow.configModified(userConfig)
def start(configList): userConfig = getUserConfig(configList) if not userConfig: dialog = gtk.MessageDialog( None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("The DRI configuration file \"%s\" is broken or could not be " "created.") % os.path.join(os.environ["HOME"], ".drirc") + " " + _("DRIconf will be started in expert mode.")) dialog.run() dialog.destroy() complexui.start(configList) return if not userConfig.writable: # Not writable: start expert mode dialog = gtk.MessageDialog( None, 0, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, _("Your DRI configuration file \"%s\" is not writable.") % userConfig.fileName + " " + _("DRIconf will be started in expert mode.")) dialog.run() dialog.destroy() complexui.start(configList) return normalizedDeviceConfigs = normalizeConfig(configList, commonui.dpy) if normalizedDeviceConfigs == None: dialog = gtk.MessageDialog( None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Normalization of your DRI configuration file \"%s\" failed. " "Please report a bug with the original configuration file " "attached. The file will be treated as read-only for now.") % userConfig.fileName + " " + _("DRIconf will be started in expert mode.")) dialog.run() dialog.destroy() userConfig.writable = False complexui.start(configList) return mainWindow = MainWindow(configList) commonui.mainWindow = mainWindow mainWindow.set_default_size(-1, 500) mainWindow.show() # Save modified normalized configuration before we start if hasattr(userConfig, "isModified") and userConfig.isModified: mainWindow.configModified(userConfig)
expert = args.expertui # read configuration information from the drivers try: commonui.dpy = dri.DisplayInfo() except dri.DRIError, problem: dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, str(problem)) dialog.run() dialog.destroy() return except dri.XMLError, problem: dialog = gtk.MessageDialog( None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("There are errors in a driver's configuration information:\n" "%s\n" "This should not happen. It probably means that you have to " "update DRIconf.") % str(problem)) dialog.run() dialog.destroy() return configScreens = [screen for screen in commonui.dpy.screens if screen != None] if len(configScreens) == 0: dialog = gtk.MessageDialog( None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Could not detect any configurable direct-rendering capable " "devices.") + " " + _("DRIconf will be started in expert mode.")) dialog.run() dialog.destroy() expert = True
expert = args.expertui # read configuration information from the drivers try: commonui.dpy = dri.DisplayInfo() except dri.DRIError, problem: dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, str(problem)) dialog.run() dialog.destroy() return except dri.XMLError, problem: dialog = gtk.MessageDialog( None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("There are errors in a driver's configuration information:\n" "%s\n" "This should not happen. It probably means that you have to " "update DRIconf.") % str(problem)) dialog.run() dialog.destroy() return configScreens = [ screen for screen in commonui.dpy.screens if screen != None ] if len(configScreens) == 0: dialog = gtk.MessageDialog( None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Could not detect any configurable direct-rendering capable " "devices.") + " " + _("DRIconf will be started in expert mode.")) dialog.run() dialog.destroy()
def __init__(self, configList): gtk.Window.__init__(self) self.set_title("DRIconf") self.connect("destroy", lambda dummy: gtk.main_quit()) self.connect("delete_event", self.exitHandler) self.vbox = gtk.VBox() self.paned = gtk.HPaned() self.configTree = ConfigTreeView(configList) self.configTree.show() scrolledWindow = gtk.ScrolledWindow() scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolledWindow.add(self.configTree) scrolledWindow.show() self.paned.add1(scrolledWindow) self.paned.show() self.toolbar = gtk.Toolbar() iconSize = self.toolbar.get_icon_size() self.saveButton = self.toolbar.insert_stock( "gtk-save", _("Save selected configuration file"), "priv", self.configTree.saveConfig, None, -1) self.reloadButton = self.toolbar.insert_stock( "gtk-revert-to-saved", _("Reload selected configuration file"), "priv", self.configTree.reloadConfig, None, -1) self.toolbar.append_space() self.newButton = self.toolbar.insert_stock( "gtk-new", _("Create a new device or application"), "priv", self.configTree.newItem, None, -1) self.removeButton = self.toolbar.insert_stock( "gtk-delete", _("Remove selected device or application"), "priv", self.configTree.removeItem, None, -1) self.upButton = self.toolbar.insert_stock("gtk-go-up", _("Move selected item up"), "priv", self.configTree.moveUp, None, -1) self.downButton = self.toolbar.insert_stock( "gtk-go-down", _("Move selected item down"), "priv", self.configTree.moveDown, None, -1) self.propertiesButton = self.toolbar.insert_stock( "gtk-properties", _("Properties of selected device or application"), "priv", self.configTree.properties, None, -1) self.toolbar.append_space() # The gtk-about stock item is available with gtk >= 2.6. # It's definitely not available with gtk 2.2. Not sure about 2.4. if gtk.gtk_version[0] == 2 and gtk.gtk_version[1] < 6: aboutStock = "gtk-dialog-info" else: aboutStock = "gtk-about" self.aboutButton = self.toolbar.insert_stock(aboutStock, _("About DRIconf"), "priv", self.aboutHandler, None, -1) self.toolbar.append_space() self.exitButton = self.toolbar.insert_stock("gtk-quit", _("Exit DRIconf"), "priv", self.exitHandler, None, -1) if len(configList) != 0: self.activateConfigButtons(configList[0]) self.toolbar.show() self.vbox.pack_start(self.toolbar, False, True, 0) self.vbox.pack_start(self.paned, True, True, 0) self.vbox.show() self.add(self.vbox) self.curDriverPanel = None self.logo = gtk.EventBox() logoPath = findInShared("drilogo.jpg") if logoPath: image = gtk.Image() image.set_from_file(logoPath) self.logo.add(image) self.logo.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(65535, 65535, 65535)) self.logo.show_all() self.paned.add2(self.logo)
def __init__(self, configList): gtk.Window.__init__(self) self.set_title(_("Direct Rendering Preferences")) self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) self.set_border_width(10) self.connect("destroy", lambda dummy: gtk.main_quit()) self.connect("delete_event", self.exitHandler) self.configList = configList # Remember for switching to expert mode self.userConfig = getUserConfig(configList) self.screens = [screen for screen in commonui.dpy.screens if screen] self.vbox = gtk.VBox(spacing=10) if len(self.screens) > 1: self.deviceCombo = gtk.combo_box_new_text() for screen in self.screens: if screen.glxInfo: self.deviceCombo.append_text(_("Screen") + " %d: %s (%s)" % (screen.num, screen.glxInfo.renderer, screen.glxInfo.vendor)) else: self.deviceCombo.append_text(_("Screen") + " %d: %s" % ( screen.num, screen.driver.name.capitalize())) self.deviceCombo.set_active(0) self.deviceCombo.connect("changed", self.changeDevice) self.deviceCombo.show() self.vbox.pack_start(self.deviceCombo, False, False, 0) else: screen = self.screens[0] if screen.glxInfo: text = "%s (%s)" % (screen.glxInfo.renderer, screen.glxInfo.vendor) else: text = _("Screen") + " %d: %s" % ( screen.num, screen.driver.name.capitalize()) deviceHBox = gtk.HBox() deviceLabel = gtk.Label() deviceLabel.set_justify(gtk.JUSTIFY_LEFT) deviceLabel.set_markup("<b>" + commonui.escapeMarkup(text) + "</b>") deviceLabel.show() deviceHBox.pack_start(deviceLabel, False, False, 0) deviceHBox.show() self.vbox.pack_start(deviceHBox, False, False, 0) buttonBox = gtk.HButtonBox() buttonBox.set_layout(gtk.BUTTONBOX_END) expertButton = gtk.Button() expertHBox = gtk.HBox() expertImage = commonui.StockImage("gtk-jump-to", gtk.ICON_SIZE_BUTTON) expertImage.show() expertHBox.pack_start(expertImage) expertLabel = gtk.Label(_("Expert Mode")) expertLabel.show() expertHBox.pack_start(expertLabel) expertHBox.show() expertButton.add(expertHBox) expertButton.connect("clicked", self.expertHandler) expertButton.show() buttonBox.add(expertButton) closeButton = gtk.Button(stock="gtk-close") closeButton.connect("clicked", lambda dummy: gtk.main_quit()) closeButton.show() buttonBox.add(closeButton) aboutButton = gtk.Button(stock="gtk-about") aboutButton.connect("clicked", self.aboutHandler) aboutButton.show() buttonBox.add(aboutButton) buttonBox.set_child_secondary(aboutButton, True) buttonBox.show() self.vbox.pack_end(buttonBox, False, False, 0) self.expander = gtk.Expander("<b>" + commonui.escapeMarkup(_( "Application settings")) + "</b>") self.expander.set_use_markup(True) self.expander.connect("activate", self.expanderChanged) self.expander.show() self.vbox.pack_end(self.expander, False, True, 0) self.expanderVBox = gtk.VBox(spacing=10) self.appButtonBox = gtk.HBox() self.appRemoveButton = gtk.Button(stock="gtk-remove") self.appRemoveButton.connect("clicked", self.removeApp) self.appRemoveButton.show() self.appButtonBox.pack_end(self.appRemoveButton, False, False, 0) addButton = gtk.Button(stock="gtk-add") addButton.connect("clicked", self.addApp) addButton.show() self.appButtonBox.pack_end(addButton, False, False, 0) self.appPropButton = gtk.Button(stock="gtk-properties") self.appPropButton.connect("clicked", self.appProperties) self.appPropButton.show() self.appButtonBox.pack_end(self.appPropButton, False, False, 0) self.appButtonBox.show() self.expanderVBox.pack_start(self.appButtonBox, False, False, 0) self.expanderVBox.show() self.expander.add(self.expanderVBox) self.notebook = None self.appCombo = None self.appNotebook = None self.appPage = None self.selectScreen(0) self.vbox.show() self.add(self.vbox)
def selectScreen(self, n): self.curScreen = self.screens[n] # Find that device's configuration in the user config. Search # from the end, because that's where the normalized configs are. self.deviceConfig = None i = len(self.userConfig.devices) - 1 while i >= 0 and self.userConfig.devices[i].screen != None and \ self.userConfig.devices[i].driver != None: if self.curScreen.num == int(self.userConfig.devices[i].screen) and \ self.curScreen.driver.name == self.userConfig.devices[i].driver: self.deviceConfig = self.userConfig.devices[i] self.driver = self.curScreen.driver break i = i - 1 # Sanity checks. These should all be true after normalization. assert (self.deviceConfig) assert (self.deviceConfig.isNormalized) assert (len(self.deviceConfig.apps) > 0 and self.deviceConfig.apps[0].executable == None) # Register modified callback self.deviceConfig.apps[0].modified = self.configModified # Build UI for the screen configuration if self.notebook: self.vbox.remove(self.notebook) self.notebook = gtk.Notebook() self.notebook.popup_enable() self.sectPages = [] self.sectLabels = [] unknownPage = commonui.UnknownSectionPage(self.driver, self.deviceConfig.apps[0]) if len(unknownPage.opts) > 0: unknownPage.show() unknownLabel = gtk.Label(_("Unknown options")) unknownLabel.show() self.notebook.append_page(unknownPage, unknownLabel) self.sectPages.append(unknownPage) self.sectLabels.append(unknownLabel) for sect in self.driver.optSections: sectPage = commonui.SectionPage(sect, self.deviceConfig.apps[0], True) sectPage.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) sectPage.show() desc = sect.getDesc([lang]) if desc: sectLabel = gtk.Label(desc) sectLabel.set_line_wrap(True) else: sectLabel = gtk.Label(_("(no description)")) sectLabel.show() self.notebook.append_page(sectPage, sectLabel) self.sectPages.append(sectPage) self.sectLabels.append(sectLabel) if len(self.sectLabels) > 0: style = self.sectLabels[0].get_style() self.default_normal_fg = style.fg[gtk.STATE_NORMAL].copy() self.default_active_fg = style.fg[gtk.STATE_ACTIVE].copy() self.validate() self.notebook.show() self.vbox.pack_start(self.notebook, True, True, 0) if self.appCombo: self.appButtonBox.remove(self.appCombo) self.appCombo = gtk.combo_box_new_text() for i in range(1, len(self.deviceConfig.apps)): self.appCombo.append_text(self.deviceConfig.apps[i].name) if len(self.deviceConfig.apps) > 1: self.appCombo.set_active(0) self.expander.set_expanded(True) self.vbox.set_child_packing(self.expander, True, True, 0, gtk.PACK_END) self.appPropButton.set_sensitive(True) self.appRemoveButton.set_sensitive(True) else: self.expander.set_expanded(False) self.vbox.set_child_packing(self.expander, False, True, 0, gtk.PACK_END) self.appPropButton.set_sensitive(False) self.appRemoveButton.set_sensitive(False) self.appCombo.connect("changed", self.changeApp) self.appCombo.show() self.appButtonBox.pack_start(self.appCombo, True, True, 0) if len(self.deviceConfig.apps) > 1: self.selectApp(self.deviceConfig.apps[1]) else: self.selectApp(None)
def __init__(self, configList): gtk.Window.__init__(self) self.set_title(_("Direct Rendering Preferences")) self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) self.set_border_width(10) self.connect("destroy", lambda dummy: gtk.main_quit()) self.connect("delete_event", self.exitHandler) self.configList = configList # Remember for switching to expert mode self.userConfig = getUserConfig(configList) self.screens = [screen for screen in commonui.dpy.screens if screen] self.vbox = gtk.VBox(spacing=10) if len(self.screens) > 1: self.deviceCombo = gtk.combo_box_new_text() for screen in self.screens: if screen.glxInfo: self.deviceCombo.append_text( _("Screen") + " %d: %s (%s)" % (screen.num, screen.glxInfo.renderer, screen.glxInfo.vendor)) else: self.deviceCombo.append_text( _("Screen") + " %d: %s" % (screen.num, screen.driver.name.capitalize())) self.deviceCombo.set_active(0) self.deviceCombo.connect("changed", self.changeDevice) self.deviceCombo.show() self.vbox.pack_start(self.deviceCombo, False, False, 0) else: screen = self.screens[0] if screen.glxInfo: text = "%s (%s)" % (screen.glxInfo.renderer, screen.glxInfo.vendor) else: text = _("Screen") + " %d: %s" % ( screen.num, screen.driver.name.capitalize()) deviceHBox = gtk.HBox() deviceLabel = gtk.Label() deviceLabel.set_justify(gtk.JUSTIFY_LEFT) deviceLabel.set_markup("<b>" + commonui.escapeMarkup(text) + "</b>") deviceLabel.show() deviceHBox.pack_start(deviceLabel, False, False, 0) deviceHBox.show() self.vbox.pack_start(deviceHBox, False, False, 0) buttonBox = gtk.HButtonBox() buttonBox.set_layout(gtk.BUTTONBOX_END) expertButton = gtk.Button() expertHBox = gtk.HBox() expertImage = commonui.StockImage("gtk-jump-to", gtk.ICON_SIZE_BUTTON) expertImage.show() expertHBox.pack_start(expertImage) expertLabel = gtk.Label(_("Expert Mode")) expertLabel.show() expertHBox.pack_start(expertLabel) expertHBox.show() expertButton.add(expertHBox) expertButton.connect("clicked", self.expertHandler) expertButton.show() buttonBox.add(expertButton) closeButton = gtk.Button(stock="gtk-close") closeButton.connect("clicked", lambda dummy: gtk.main_quit()) closeButton.show() buttonBox.add(closeButton) aboutButton = gtk.Button(stock="gtk-about") aboutButton.connect("clicked", self.aboutHandler) aboutButton.show() buttonBox.add(aboutButton) buttonBox.set_child_secondary(aboutButton, True) buttonBox.show() self.vbox.pack_end(buttonBox, False, False, 0) self.expander = gtk.Expander( "<b>" + commonui.escapeMarkup(_("Application settings")) + "</b>") self.expander.set_use_markup(True) self.expander.connect("activate", self.expanderChanged) self.expander.show() self.vbox.pack_end(self.expander, False, True, 0) self.expanderVBox = gtk.VBox(spacing=10) self.appButtonBox = gtk.HBox() self.appRemoveButton = gtk.Button(stock="gtk-remove") self.appRemoveButton.connect("clicked", self.removeApp) self.appRemoveButton.show() self.appButtonBox.pack_end(self.appRemoveButton, False, False, 0) addButton = gtk.Button(stock="gtk-add") addButton.connect("clicked", self.addApp) addButton.show() self.appButtonBox.pack_end(addButton, False, False, 0) self.appPropButton = gtk.Button(stock="gtk-properties") self.appPropButton.connect("clicked", self.appProperties) self.appPropButton.show() self.appButtonBox.pack_end(self.appPropButton, False, False, 0) self.appButtonBox.show() self.expanderVBox.pack_start(self.appButtonBox, False, False, 0) self.expanderVBox.show() self.expander.add(self.expanderVBox) self.notebook = None self.appCombo = None self.appNotebook = None self.appPage = None self.selectScreen(0) self.vbox.show() self.add(self.vbox)
def selectScreen(self, n): self.curScreen = self.screens[n] # Find that device's configuration in the user config. Search # from the end, because that's where the normalized configs are. self.deviceConfig = None i = len(self.userConfig.devices) - 1 while i >= 0 and self.userConfig.devices[i].screen != None and \ self.userConfig.devices[i].driver != None: if self.curScreen.num == int(self.userConfig.devices[i].screen) and \ self.curScreen.driver.name == self.userConfig.devices[i].driver: self.deviceConfig = self.userConfig.devices[i] self.driver = self.curScreen.driver break i = i - 1 # Sanity checks. These should all be true after normalization. assert (self.deviceConfig) assert (self.deviceConfig.isNormalized) assert (len(self.deviceConfig.apps) > 0 and self.deviceConfig.apps[0].executable == None) # Register modified callback self.deviceConfig.apps[0].modified = self.configModified # Build UI for the screen configuration if self.notebook: self.vbox.remove(self.notebook) self.notebook = gtk.Notebook() self.notebook.popup_enable() self.sectPages = [] self.sectLabels = [] unknownPage = commonui.UnknownSectionPage(self.driver, self.deviceConfig.apps[0]) if len(unknownPage.opts) > 0: unknownPage.show() unknownLabel = gtk.Label(_("Unknown options")) unknownLabel.show() self.notebook.append_page(unknownPage, unknownLabel) self.sectPages.append(unknownPage) self.sectLabels.append(unknownLabel) for sect in self.driver.optSections: sectPage = commonui.SectionPage(sect, self.deviceConfig.apps[0], True) sectPage.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) sectPage.show() desc = sect.getDesc([lang]) if desc: sectLabel = gtk.Label(desc) sectLabel.set_line_wrap(True) else: sectLabel = gtk.Label(_("(no description)")) sectLabel.show() self.notebook.append_page(sectPage, sectLabel) self.sectPages.append(sectPage) self.sectLabels.append(sectLabel) if len(self.sectLabels) > 0: style = self.sectLabels[0].get_style() self.default_normal_fg = style.fg[gtk.STATE_NORMAL].copy() self.default_active_fg = style.fg[gtk.STATE_ACTIVE].copy() self.validate() self.notebook.show() self.vbox.pack_start(self.notebook, True, True, 0) if self.appCombo: self.appButtonBox.remove(self.appCombo) self.appCombo = gtk.combo_box_new_text() for i in range(1, len(self.deviceConfig.apps)): self.appCombo.append_text(self.deviceConfig.apps[i].name) if len(self.deviceConfig.apps) > 1: self.appCombo.set_active(0) self.expander.set_expanded(True) self.vbox.set_child_packing(self.expander, True, True, 0, gtk.PACK_END) self.appPropButton.set_sensitive(True) self.appRemoveButton.set_sensitive(True) else: self.expander.set_expanded(False) self.vbox.set_child_packing(self.expander, False, True, 0, gtk.PACK_END) self.appPropButton.set_sensitive(False) self.appRemoveButton.set_sensitive(False) self.appCombo.connect("changed", self.changeApp) self.appCombo.show() self.appButtonBox.pack_start(self.appCombo, True, True, 0) if len(self.deviceConfig.apps) > 1: self.selectApp(self.deviceConfig.apps[1]) else: self.selectApp(None)
def __init__(self, driver, app): """ Constructor. """ gtk.Frame.__init__(self) frameLabel = gtk.Label() frameLabel.set_markup("<b>" + escapeMarkup(_("Application") + ": " + app.name) + "</b>") frameLabel.show() self.set_label_widget(frameLabel) self.driver = driver self.app = app tooltips = gtk.Tooltips() table = gtk.Table(2, 2) self.execCheck = WrappingCheckButton( _("Apply only to this executable")) self.execCheck.set_sensitive(app.device.config.writable) tooltips.set_tip( self.execCheck, _("Leave this disabled to configure all applications.\n" "Beware that some applications or games are just a shell script " "that starts a real executable with a different name.")) self.execCheck.show() table.attach(self.execCheck, 0, 1, 0, 1, 0, 0, 5, 5) self.execEntry = gtk.Entry() if app.executable != None: self.execCheck.set_active(True) self.execEntry.set_text(app.executable) self.execEntry.set_sensitive(app.device.config.writable and app.executable != None) self.execEntry.show() self.execCheck.connect("toggled", self.execToggled) self.execEntry.connect("changed", self.execChanged) table.attach(self.execEntry, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, 0, 5, 5) notebook = gtk.Notebook() notebook.popup_enable() notebook.set_scrollable(True) self.sectPages = [] self.sectLabels = [] unknownPage = UnknownSectionPage(driver, app) if not driver or len(unknownPage.opts) > 0: unknownPage.show() unknownLabel = gtk.Label(_("Unknown")) unknownLabel.show() notebook.append_page(unknownPage, unknownLabel) self.sectPages.append(unknownPage) self.sectLabels.append(unknownLabel) if driver: for sect in driver.optSections: sectPage = SectionPage(sect, app, False) sectPage.show() desc = sect.getDesc([lang]) if desc: sectLabel = gtk.Label(desc) sectLabel.set_line_wrap(True) else: sectLabel = gtk.Label(_("(no description)")) sectLabel.show() notebook.append_page(sectPage, sectLabel) self.sectPages.append(sectPage) self.sectLabels.append(sectLabel) if len(self.sectLabels) > 0: style = self.sectLabels[0].get_style() self.default_normal_fg = style.fg[gtk.STATE_NORMAL].copy() self.default_active_fg = style.fg[gtk.STATE_ACTIVE].copy() self.validate() notebook.show() table.attach(notebook, 0, 2, 1, 2, gtk.FILL, gtk.EXPAND | gtk.FILL, 5, 5) table.show() self.add(table)
def __init__(self, driver, app): """ Constructor. """ gtk.Frame.__init__(self) frameLabel = gtk.Label() frameLabel.set_markup("<b>" + escapeMarkup(_("Application") + ": " + app.name) + "</b>") frameLabel.show() self.set_label_widget(frameLabel) self.driver = driver self.app = app tooltips = gtk.Tooltips() table = gtk.Table(2, 2) self.execCheck = WrappingCheckButton(_( "Apply only to this executable")) self.execCheck.set_sensitive(app.device.config.writable) tooltips.set_tip( self.execCheck, _("Leave this disabled to configure all applications.\n" "Beware that some applications or games are just a shell script " "that starts a real executable with a different name.")) self.execCheck.show() table.attach(self.execCheck, 0, 1, 0, 1, 0, 0, 5, 5) self.execEntry = gtk.Entry() if app.executable != None: self.execCheck.set_active(True) self.execEntry.set_text(app.executable) self.execEntry.set_sensitive(app.device.config.writable and app.executable != None) self.execEntry.show() self.execCheck.connect("toggled", self.execToggled) self.execEntry.connect("changed", self.execChanged) table.attach(self.execEntry, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, 0, 5, 5) notebook = gtk.Notebook() notebook.popup_enable() notebook.set_scrollable(True) self.sectPages = [] self.sectLabels = [] unknownPage = UnknownSectionPage(driver, app) if not driver or len(unknownPage.opts) > 0: unknownPage.show() unknownLabel = gtk.Label(_("Unknown")) unknownLabel.show() notebook.append_page(unknownPage, unknownLabel) self.sectPages.append(unknownPage) self.sectLabels.append(unknownLabel) if driver: for sect in driver.optSections: sectPage = SectionPage(sect, app, False) sectPage.show() desc = sect.getDesc([lang]) if desc: sectLabel = gtk.Label(desc) sectLabel.set_line_wrap(True) else: sectLabel = gtk.Label(_("(no description)")) sectLabel.show() notebook.append_page(sectPage, sectLabel) self.sectPages.append(sectPage) self.sectLabels.append(sectLabel) if len(self.sectLabels) > 0: style = self.sectLabels[0].get_style() self.default_normal_fg = style.fg[gtk.STATE_NORMAL].copy() self.default_active_fg = style.fg[gtk.STATE_ACTIVE].copy() self.validate() notebook.show() table.attach(notebook, 0, 2, 1, 2, gtk.FILL, gtk.EXPAND | gtk.FILL, 5, 5) table.show() self.add(table)
def __init__(self, configList): gtk.Window.__init__(self) self.set_title("DRIconf") self.connect("destroy", lambda dummy: gtk.main_quit()) self.connect("delete_event", self.exitHandler) self.vbox = gtk.VBox() self.paned = gtk.HPaned() self.configTree = ConfigTreeView(configList) self.configTree.show() scrolledWindow = gtk.ScrolledWindow() scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolledWindow.add(self.configTree) scrolledWindow.show() self.paned.add1(scrolledWindow) self.paned.show() self.toolbar = gtk.Toolbar() iconSize = self.toolbar.get_icon_size() self.saveButton = self.toolbar.insert_stock( "gtk-save", _("Save selected configuration file"), "priv", self.configTree.saveConfig, None, -1) self.reloadButton = self.toolbar.insert_stock( "gtk-revert-to-saved", _("Reload selected configuration file"), "priv", self.configTree.reloadConfig, None, -1) self.toolbar.append_space() self.newButton = self.toolbar.insert_stock( "gtk-new", _("Create a new device or application"), "priv", self.configTree.newItem, None, -1) self.removeButton = self.toolbar.insert_stock( "gtk-delete", _("Remove selected device or application"), "priv", self.configTree.removeItem, None, -1) self.upButton = self.toolbar.insert_stock( "gtk-go-up", _("Move selected item up"), "priv", self.configTree.moveUp, None, -1) self.downButton = self.toolbar.insert_stock( "gtk-go-down", _("Move selected item down"), "priv", self.configTree.moveDown, None, -1) self.propertiesButton = self.toolbar.insert_stock( "gtk-properties", _("Properties of selected device or application"), "priv", self.configTree.properties, None, -1) self.toolbar.append_space() # The gtk-about stock item is available with gtk >= 2.6. # It's definitely not available with gtk 2.2. Not sure about 2.4. if gtk.gtk_version[0] == 2 and gtk.gtk_version[1] < 6: aboutStock = "gtk-dialog-info" else: aboutStock = "gtk-about" self.aboutButton = self.toolbar.insert_stock( aboutStock, _("About DRIconf"), "priv", self.aboutHandler, None, -1) self.toolbar.append_space() self.exitButton = self.toolbar.insert_stock( "gtk-quit", _("Exit DRIconf"), "priv", self.exitHandler, None, -1) if len(configList) != 0: self.activateConfigButtons(configList[0]) self.toolbar.show() self.vbox.pack_start(self.toolbar, False, True, 0) self.vbox.pack_start(self.paned, True, True, 0) self.vbox.show() self.add(self.vbox) self.curDriverPanel = None self.logo = gtk.EventBox() logoPath = findInShared("drilogo.jpg") if logoPath: image = gtk.Image() image.set_from_file(logoPath) self.logo.add(image) self.logo.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(65535, 65535, 65535)) self.logo.show_all() self.paned.add2(self.logo)