/usr/share/pyshared/driconf_complexui.py is in driconf 0.9.1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 | # DRI configuration GUI: complex UI components
# Copyright (C) 2003-2006 Felix Kuehling
# 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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Contact: http://fxk.de.vu/
import dri
import pygtk
pygtk.require ("2.0")
import gtk
import gobject
import driconf_commonui
commonui = driconf_commonui # short cut
from driconf_commonui import _, lang, findInShared, escapeMarkup, WrappingCheckButton, SectionPage, UnknownSectionPage
class DriverPanel (gtk.Frame):
""" Panel for driver settings for a specific application. """
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 execChanged (self, widget):
self.app.modified(self.app)
def execToggled (self, widget):
self.execEntry.set_sensitive (self.execCheck.get_active())
self.app.modified(self.app)
def validate (self):
""" Validate the configuration.
Labels of invalid section pages are highlighted. Returns whether
there were invalid option values. """
index = 0
allValid = True
for sectPage in self.sectPages:
valid = sectPage.validate()
if not valid:
# strange, active and normal appear to be swapped :-/
self.sectLabels[index].modify_fg (
gtk.STATE_NORMAL, gtk.gdk.Color (65535, 0, 0))
self.sectLabels[index].modify_fg (
gtk.STATE_ACTIVE, gtk.gdk.Color (65535, 0, 0))
else:
self.sectLabels[index].modify_fg (
gtk.STATE_NORMAL, self.default_normal_fg)
self.sectLabels[index].modify_fg (
gtk.STATE_ACTIVE, self.default_active_fg)
allValid = allValid and valid
index = index+1
return allValid
def commit (self):
""" Commit changes to the configuration. """
executable = self.execEntry.get_text()
if not self.execCheck.get_active():
if self.app.executable != None:
self.app.executable = None
self.app.modified(self.app)
elif executable != self.app.executable:
self.app.executable = executable
self.app.modified(self.app)
for sectPage in self.sectPages:
sectPage.commit()
def renameApp (self):
""" Change the application name. """
self.set_label ("Application: " + self.app.name)
class NameDialog (gtk.Dialog):
""" Dialog for setting the name of an application. """
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 activateSignal (self, widget):
self.response (gtk.RESPONSE_OK)
def responseSignal (self, dialog, response):
if response == gtk.RESPONSE_OK:
self.callback (self.entry.get_text(), self.data)
self.destroy()
class DeviceDialog (gtk.Dialog):
""" Dialog for choosing driver and screen of a device. """
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 screenSignal (self, widget, data=None):
screenName = self.screenCombo.entry.get_text()
try:
screenNum = int(screenName)
except ValueError:
pass
else:
screen = commonui.dpy.getScreen(screenNum)
if screen != None:
driver = screen.driver
self.driverCombo.entry.set_text (str(driver.name))
def responseSignal (self, dialog, response):
if response == gtk.RESPONSE_OK:
self.callback (self.screenCombo.entry.get_text(),
self.driverCombo.entry.get_text(), self.data)
self.destroy()
class ConfigTreeModel (gtk.GenericTreeModel):
# constructur
def __init__ (self, configList):
gtk.GenericTreeModel.__init__ (self)
self.configList = []
for config in configList:
self.addNode (config)
def iconFromShared (self, name, size, missing):
path = findInShared (name)
if path:
icon = gtk.gdk.pixbuf_new_from_file (path)
return icon.scale_simple (size, size, gtk.gdk.INTERP_BILINEAR)
else:
return missing
def renderIcons (self, widget):
self.configIcon = widget.render_icon ("gtk-properties",
gtk.ICON_SIZE_MENU, None)
self.appIcon = widget.render_icon ("gtk-execute",
gtk.ICON_SIZE_MENU, None)
self.unspecIcon = widget.render_icon ("gtk-dialog-question",
gtk.ICON_SIZE_MENU, None)
missing = widget.render_icon ("gtk-missing-image",
gtk.ICON_SIZE_MENU, None)
size = max (missing.get_width(), missing.get_height())
self.screenIcon = self.iconFromShared ("screen.png", size, missing)
self.driverIcon = self.iconFromShared ("card.png", size, missing)
self.screenDriverIcon = self.iconFromShared ("screencard.png",
size, missing)
# implementation of the GenericTreeModel interface
def on_get_flags (self):
return gtk.TREE_MODEL_ITERS_PERSIST
def on_get_n_columns (self):
return 2
def on_get_column_type (self, col):
if col == 0:
return gobject.TYPE_OBJECT
else:
return gobject.TYPE_STRING
def on_get_path (self, node):
if node.__class__ == dri.DRIConfig:
return (self.configList.index(node),)
elif node.__class__ == dri.DeviceConfig:
config = node.config
return (self.configList.index(config),
config.devices.index(node))
elif node.__class__ == dri.AppConfig:
device = node.device
config = device.config
return (self.configList.index(config),
config.devices.index(device),
device.apps.index(node))
else:
assert 0
def on_get_iter (self, path):
if len(path) > 3:
return None
configIndex = path[0] # config
if configIndex < len(self.configList):
config = self.configList[configIndex]
else:
return None
if len(path) == 1:
return config
deviceIndex = path[1] # device
if deviceIndex < len(config.devices):
device = config.devices[deviceIndex]
else:
return None
if len(path) == 2:
return device
appIndex = path[2] # application
if appIndex < len(device.apps):
app = device.apps[appIndex]
else:
return None
return app
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 on_iter_next (self, node):
if node.__class__ == dri.DRIConfig:
list = self.configList
elif node.__class__ == dri.DeviceConfig:
list = node.config.devices
elif node.__class__ == dri.AppConfig:
list = node.device.apps
else:
return None
index = list.index(node)
if index+1 < len(list):
return list[index+1]
else:
return None
def on_iter_children (self, node):
return self.on_iter_nth_child (node, 0)
def on_iter_has_child (self, node):
return (self.on_iter_n_children (node) > 0)
def on_iter_n_children (self, node):
if not node:
return len(self.configList)
elif node.__class__ == dri.DRIConfig:
return len(node.devices)
elif node.__class__ == dri.DeviceConfig:
return len(node.apps)
else:
return 0
def on_iter_nth_child (self, node, index):
if not node:
list = self.configList
elif node.__class__ == dri.DRIConfig:
list = node.devices
elif node.__class__ == dri.DeviceConfig:
list = node.apps
else:
return None
if len(list) > index:
return list[index]
else:
return None
def on_iter_parent (self, node):
if node.__class__ == dri.DeviceConfig:
return node.config
elif node.__class__ == dri.AppConfig:
return node.device
else:
return None
# helpers for converting between nodes, paths and TreeIterators
def getPathFromNode (self, node):
return self.on_get_path (node)
def getNodeFromPath (self, path):
return self.on_get_iter (path)
def getIterFromNode (self, node):
return self.get_iter (self.getPathFromNode(node))
# config list
def getConfigList (self):
return self.configList
# callback for registring modifications
def nodeModified (self, node, b=True):
if node.__class__ == dri.DRIConfig:
config = node
elif node.__class__ == dri.DeviceConfig:
config = node.config
elif node.__class__ == dri.AppConfig:
config = node.device.config
if config.isModified != b:
config.isModified = b
curNode = commonui.mainWindow.configTree.getSelection (allowNone=True)
if not curNode:
commonui.mainWindow.deactivateButtons()
elif curNode.__class__ == dri.DRIConfig:
commonui.mainWindow.activateConfigButtons(curNode)
elif curNode.__class__ == dri.DeviceConfig:
commonui.mainWindow.activateDeviceButtons(curNode)
elif curNode.__class__ == dri.AppConfig:
commonui.mainWindow.activateAppButtons(curNode)
# higher level model manipulations
def addNode (self, node, sibling = None):
""" Add a new node and inform the TreeView. """
self.initNode (node)
if node.__class__ == dri.DRIConfig:
list = self.configList
elif node.__class__ == dri.DeviceConfig:
list = node.config.devices
elif node.__class__ == dri.AppConfig:
list = node.device.apps
if sibling != None:
index = list.index (sibling)
list.insert (index, node)
else:
list.append (node)
self.registerNode (node)
def initNode (self, node):
node.modified = self.nodeModified
if node.__class__ == dri.DRIConfig:
if not hasattr(node,"isModified"):
node.isModified = False
for device in node.devices:
self.initNode (device)
elif node.__class__ == dri.DeviceConfig:
for app in node.apps:
self.initNode (app)
elif node.__class__ == dri.AppConfig:
self.validateAppNode (node)
def registerNode (self, node):
path = self.on_get_path (node)
iter = self.get_iter (path)
self.row_inserted (path, iter)
if node.__class__ == dri.DRIConfig:
for device in node.devices:
self.registerNode (device)
elif node.__class__ == dri.DeviceConfig:
for app in node.apps:
self.registerNode (app)
def removeNode (self, node):
if node.__class__ == dri.DRIConfig:
list = self.configList
while len(node.devices) > 0:
self.removeNode (node.devices[0])
elif node.__class__ == dri.DeviceConfig:
list = node.config.devices
while len(node.apps) > 0:
self.removeNode (node.apps[0])
elif node.__class__ == dri.AppConfig:
list = node.device.apps
path = self.on_get_path (node)
list.remove (node)
self.row_deleted (path)
# find the first writable application
def findFirstWritableApp (self):
foundApp = None
for config in self.configList:
if not config.writable:
continue
for device in config.devices:
if len(device.apps) > 0:
foundApp = device.apps[0]
break
return foundApp
# validate an application node
def validateAppNode (self, app):
try:
driver = app.device.getDriver(commonui.dpy)
except dri.XMLError:
driver = None
if driver and not driver.validate (app.options):
app.isValid = False
else:
app.isValid = True
class ConfigTreeView (gtk.TreeView):
def __init__ (self, configList):
self.model = ConfigTreeModel (configList)
gtk.TreeView.__init__ (self, self.model)
self.model.renderIcons (self)
self.connect ("style-set", lambda widget, prevStyle:
self.model.renderIcons (widget))
self.set_size_request (200, -1)
self.set_headers_visible (False)
self.expand_all()
self.get_selection().set_mode (gtk.SELECTION_BROWSE)
self.get_selection().connect ("changed", self.selectionChangedSignal)
column = gtk.TreeViewColumn()
column.set_spacing (2)
renderPixbuf = gtk.CellRendererPixbuf()
column.pack_start (renderPixbuf, expand=False)
column.add_attribute (renderPixbuf, "pixbuf", 0)
renderText = gtk.CellRendererText()
column.pack_start (renderText, expand=True)
column.add_attribute (renderText, "markup", 1)
self.append_column (column)
def getConfigList (self):
return self.model.getConfigList()
# selection handling
def getSelection (self, allowNone=False):
model, iter = self.get_selection().get_selected()
assert iter or allowNone
if iter:
path = self.model.get_path (iter)
return self.model.getNodeFromPath (path)
else:
return None
def selectFirstWritableApp (self):
app = self.model.findFirstWritableApp()
if app:
path = self.model.getPathFromNode (app)
self.get_selection().select_path (path)
self.scroll_to_cell (path=path, use_align=False)
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()
else:
driver = None
app = None
commonui.mainWindow.commitDriverPanel()
commonui.mainWindow.switchDriverPanel (driver, app)
if not node:
commonui.mainWindow.deactivateButtons()
elif node.__class__ == dri.DRIConfig:
commonui.mainWindow.activateConfigButtons(node)
elif node.__class__ == dri.DeviceConfig:
commonui.mainWindow.activateDeviceButtons(node)
elif node.__class__ == dri.AppConfig:
commonui.mainWindow.activateAppButtons(node)
# highlight invalid nodes
def validateAppNode (self, app):
self.model.validateAppNode (app)
# Emit a row_changed event so that the view gets updated properly.
path = self.model.getPathFromNode (app)
iter = self.model.get_iter (path)
self.model.row_changed (path, iter)
# UI actions on the config tree
def moveUp (self, widget):
self.moveItem (-1)
def moveDown (self, widget):
self.moveItem (1)
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 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 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 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 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
cfile.close()
# Check if the file is writable in the end.
newConfig.writable = commonui.fileIsWritable (config.fileName)
# find the position of config
configList = self.getConfigList()
index = configList.index (config)
if index == len(configList)-1:
sibling = None
else:
sibling = configList[index+1]
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 (config)
self.model.addNode (newConfig, sibling)
path = self.model.getPathFromNode (newConfig)
self.expand_row (path, True)
self.get_selection().select_path (path)
self.scroll_to_cell (path=path, use_align=False)
# helper function for moving tree nodes around
def moveItem (self, inc):
node = self.getSelection()
if node.__class__ == dri.AppConfig:
parent = node.device
siblings = parent.apps
elif node.__class__ == dri.DeviceConfig:
parent = node.config
siblings = parent.devices
else:
assert False
index = siblings.index (node)
newIndex = index+inc
if newIndex < 0 or newIndex >= len(siblings):
return
siblings.remove (node)
siblings.insert (newIndex, node)
newOrder = range(len(siblings))
newOrder[index] = newIndex
newOrder[newIndex] = index
path = self.model.getPathFromNode (parent)
iter = self.model.get_iter (path)
self.model.rows_reordered (path, iter, newOrder)
parent.modified(parent)
path = self.model.getPathFromNode (node)
self.scroll_to_cell (path=path, use_align=False)
# callbacks from dialogs
def renameCallback (self, name, app):
app.name = name
path = self.model.getPathFromNode (app)
iter = self.model.get_iter (path)
self.model.row_changed (path, iter)
commonui.mainWindow.renameApp (app)
app.modified(app)
def propertiesCallback (self, screen, driver, device):
device.screen = screen
device.driver = driver
path = self.model.getPathFromNode (device)
iter = self.model.get_iter (path)
self.model.row_changed (path, iter)
device.modified(device)
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)
def newDeviceCallback (self, screen, driver, config):
device = dri.DeviceConfig (config, screen, driver)
self.model.addNode (device)
config.modified(config)
path = self.model.getPathFromNode (device)
self.get_selection().select_path (path)
self.scroll_to_cell (path=path, use_align=False)
class MainWindow (gtk.Window):
""" The main window consiting of ConfigTree, DriverPanel and toolbar. """
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 initSelection (self):
self.configTree.selectFirstWritableApp()
def commitDriverPanel (self):
if self.curDriverPanel != None:
self.curDriverPanel.commit()
self.configTree.validateAppNode (self.curDriverPanel.app)
def validateDriverPanel (self):
if self.curDriverPanel != None:
self.curDriverPanel.validate()
self.curDriverPanel.commit()
self.configTree.validateAppNode (self.curDriverPanel.app)
def switchDriverPanel (self, driver=None, app=None):
if self.curDriverPanel != None:
if self.curDriverPanel.driver == driver and \
self.curDriverPanel.app == app:
return
self.paned.remove (self.curDriverPanel)
elif app != None:
self.paned.remove (self.logo)
if app != None:
self.curDriverPanel = DriverPanel (driver, app)
self.curDriverPanel.show ()
self.paned.add2 (self.curDriverPanel)
elif self.curDriverPanel != None:
self.curDriverPanel = None
self.logo.show()
self.paned.add2 (self.logo)
def removeApp (self, app):
if self.curDriverPanel != None and self.curDriverPanel.app == app:
self.paned.remove (self.curDriverPanel)
self.curDriverPanel = None
self.logo.show()
self.paned.add2 (self.logo)
def renameApp (self, app):
if self.curDriverPanel != None and self.curDriverPanel.app == app:
self.curDriverPanel.renameApp()
def deactivateButtons (self):
self.saveButton .set_sensitive (False)
self.reloadButton .set_sensitive (False)
self.newButton .set_sensitive (False)
self.removeButton .set_sensitive (False)
self.upButton .set_sensitive (False)
self.downButton .set_sensitive (False)
self.propertiesButton.set_sensitive (False)
def activateConfigButtons (self, config):
writable = config.writable
modified = config.isModified
self.saveButton .set_sensitive (writable and modified)
self.reloadButton .set_sensitive (True)
self.newButton .set_sensitive (writable)
self.removeButton .set_sensitive (False)
self.upButton .set_sensitive (False)
self.downButton .set_sensitive (False)
self.propertiesButton.set_sensitive (False)
def activateDeviceButtons (self, device):
writable = device.config.writable
modified = device.config.isModified
self.saveButton .set_sensitive (writable and modified)
self.reloadButton .set_sensitive (True)
self.newButton .set_sensitive (writable)
self.removeButton .set_sensitive (writable)
self.upButton .set_sensitive (writable)
self.downButton .set_sensitive (writable)
self.propertiesButton.set_sensitive (writable)
def activateAppButtons (self, app):
# Button sensitivity is identical for apps and devices.
self.activateDeviceButtons (app.device)
def aboutHandler (self, widget):
dialog = commonui.AboutDialog()
dialog.connect("response",
lambda dialog, response: dialog.destroy())
dialog.show()
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 doExit (self, dialog, response):
dialog.destroy()
if response == gtk.RESPONSE_YES:
gtk.main_quit()
def start (configList):
# initSelection must be called before and after mainWindow.show().
# Before makes sure that the initial window size is correct.
# After is needed since the selection seems to get lost in
# mainWindow.show().
mainWindow = MainWindow(configList)
commonui.mainWindow = mainWindow
mainWindow.set_default_size (750, 375)
mainWindow.initSelection()
mainWindow.show ()
mainWindow.initSelection()
|