/usr/share/pyshared/Onboard/Config.py is in onboard 0.97.0-0ubuntu3.
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 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | # -*- coding: utf-8 -*-
"""
File containing Config singleton.
"""
from __future__ import division, print_function, unicode_literals
import os
import sys
from shutil import copytree
from optparse import OptionParser
from gi.repository import GLib, Gtk
from Onboard.utils import show_confirmation_dialog, Version, unicode_str
from Onboard.WindowUtils import Handle
from Onboard.ConfigUtils import ConfigObject
from Onboard.MouseControl import Mousetweaks, ClickMapper
from Onboard.Exceptions import SchemaError
### Logging ###
import logging
_logger = logging.getLogger("Config")
###############
# gsettings objects
SCHEMA_ONBOARD = "apps.onboard"
SCHEMA_KEYBOARD = "apps.onboard.keyboard"
SCHEMA_WINDOW = "apps.onboard.window"
SCHEMA_WINDOW_LANDSCAPE = "apps.onboard.window.landscape"
SCHEMA_WINDOW_PORTRAIT = "apps.onboard.window.portrait"
SCHEMA_ICP = "apps.onboard.icon-palette"
SCHEMA_ICP_LANDSCAPE = "apps.onboard.icon-palette.landscape"
SCHEMA_ICP_PORTRAIT = "apps.onboard.icon-palette.portrait"
SCHEMA_AUTO_SHOW = "apps.onboard.auto-show"
SCHEMA_UNIVERSAL_ACCESS = "apps.onboard.universal-access"
SCHEMA_THEME = "apps.onboard.theme-settings"
SCHEMA_LOCKDOWN = "apps.onboard.lockdown"
SCHEMA_SCANNER = "apps.onboard.scanner"
SCHEMA_GSS = "org.gnome.desktop.screensaver"
SCHEMA_GDI = "org.gnome.desktop.interface"
MODELESS_GKSU_KEY = "/apps/gksu/disable-grab" # old gconf key, unused
# hard coded defaults
DEFAULT_X = 100 # Make sure these match the schema defaults,
DEFAULT_Y = 50 # else dconf data migration won't happen.
DEFAULT_HEIGHT = 200
DEFAULT_WIDTH = 600
DEFAULT_ICP_X = 100 # Make sure these match the schema defaults,
DEFAULT_ICP_Y = 50 # else dconf data migration won't happen.
DEFAULT_ICP_HEIGHT = 64
DEFAULT_ICP_WIDTH = 64
DEFAULT_LAYOUT = "Compact"
DEFAULT_THEME = "Classic Onboard"
DEFAULT_COLOR_SCHEME = "Classic Onboard"
START_ONBOARD_XEMBED_COMMAND = "onboard --xid"
GTK_KBD_MIXIN_MOD = "Onboard.KeyboardGTK"
GTK_KBD_MIXIN_CLS = "KeyboardGTK"
INSTALL_DIR = "/usr/share/onboard"
LOCAL_INSTALL_DIR = "/usr/local/share/onboard"
USER_DIR = ".onboard"
SYSTEM_DEFAULTS_FILENAME = "onboard-defaults.conf"
DEFAULT_RESIZE_HANDLES = list(Handle.RESIZERS)
SCHEMA_VERSION_0_97 = Version(1, 0) # Onboard 0.97
SCHEMA_VERSION = SCHEMA_VERSION_0_97
# enum for simplified number of resize_handles
class NumResizeHandles:
NONE = 0
SOME = 1
ALL = 2
class Config(ConfigObject):
"""
Singleton Class to encapsulate the gsettings stuff and check values.
"""
# String representation of the module containing the Keyboard mixin
# used to draw keyboard
_kbd_render_mixin_mod = GTK_KBD_MIXIN_MOD
# String representation of the keyboard mixin used to draw keyboard.
_kbd_render_mixin_cls = GTK_KBD_MIXIN_CLS
# extension of layout files
LAYOUT_FILE_EXTENSION = ".onboard"
# A copy of snippets so that when the list changes in gsettings we can
# tell which items have changed.
_last_snippets = None
# Margin to leave around labels
LABEL_MARGIN = (1, 1)
# Horizontal label alignment
DEFAULT_LABEL_X_ALIGN = 0.5
# Vertical label alignment
DEFAULT_LABEL_Y_ALIGN = 0.5
# layout group for independently sized superkey labels
SUPERKEY_SIZE_GROUP = "super"
# width of frame around onboard when window decoration is disabled
UNDECORATED_FRAME_WIDTH = 5.0
# radius of the rounded window corners
CORNER_RADIUS = 10
# y displacement of the key face of dish keys
DISH_KEY_Y_OFFSET = 1.0
# raised border size of dish keys
DISH_KEY_BORDER = (2.5, 2.5)
# index of currently active pane, not stored in gsettings
active_layer_index = 0
# threshold protect window move/resize
drag_protection = True
# Allow to iconify onboard when neither icon-palette nor
# status-icon are enabled, else hide and show the window.
# Iconifying is shaky in unity and gnome-shell. After unhiding
# from launcher once, the WM won't allow to unminimize onboard
# itself anymore for auto-show. (Precise)
allow_iconifying = False
def __new__(cls, *args, **kwargs):
"""
Singleton magic.
"""
if not hasattr(cls, "self"):
cls.self = object.__new__(cls, args, kwargs)
cls.self.construct()
return cls.self
def __init__(self):
"""
This constructor is still called multiple times.
Do nothing here and use the singleton constructor construct() instead.
Don't call base class constructors.
"""
pass
def construct(self):
"""
Singleton constructor, runs only once.
First intialization stage to runs before the
single instance check. Only do the bare minimum here.
"""
# parse command line
parser = OptionParser()
parser.add_option("-l", "--layout", dest="layout",
help="Specify layout file ({}) or name" \
.format(self.LAYOUT_FILE_EXTENSION))
parser.add_option("-t", "--theme", dest="theme",
help="Specify theme file (.theme) or name")
parser.add_option("-x", type="int", dest="x", help="x coord of window")
parser.add_option("-y", type="int", dest="y", help="y coord of window")
parser.add_option("-s", "--size", dest="size",
help="size widthxheight")
parser.add_option("-e", "--xid", action="store_true", dest="xid_mode",
help="XEmbed mode for gnome-screensaver")
parser.add_option("-a", "--keep-aspect", action="store_true",
dest="keep_aspect_ratio",
help="Keep aspect ratio when resizing the window")
parser.add_option("-d", "--debug", type="str", dest="debug",
help="DEBUG={notset|debug|info|warning|error|critical}")
parser.add_option("-m", "--allow-multiple-instances",
action="store_true", dest="allow_multiple_instances",
help="Allow multiple Onboard instances")
options = parser.parse_args()[0]
self.options = options
self.xid_mode = options.xid_mode
# setup logging
log_params = {
"format" : '%(asctime)s:%(levelname)s:%(name)s: %(message)s'
}
if options.debug:
log_params["level"] = getattr(logging, options.debug.upper())
if False: # log to file
log_params["level"] = "DEBUG"
log_params["filename"] = "/tmp/onboard.log"
log_params["filemode"] = "w"
logging.basicConfig(**log_params)
def init(self):
"""
Second initialization stage.
Call this after single instance checking on application start.
"""
# call base class constructor once logging is available
try:
ConfigObject.__init__(self)
except SchemaError as e:
_logger.error(unicode_str(e))
sys.exit()
# init paths
self.install_dir = self._get_install_dir()
self.user_dir = self._get_user_dir()
# migrate old user dir ".sok" to ".onboard"
old_user_dir = os.path.join(os.path.expanduser("~"), ".sok")
user_dir = self.user_dir
if not os.path.exists(user_dir) and os.path.exists(old_user_dir):
_logger.info(_("Migrating user directory '{}' to '{}'.") \
.format(old_user_dir, user_dir))
try:
copytree(old_user_dir, user_dir)
except OSError as ex: # python >2.5
_logger.error(_("Failed to migrate user directory. ") + \
unicode_str(ex))
# Load system defaults (if there are any, not required).
# Used for distribution specific settings, aka branding.
paths = [os.path.join(self.install_dir, SYSTEM_DEFAULTS_FILENAME),
os.path.join("/etc/onboard", SYSTEM_DEFAULTS_FILENAME)]
self.load_system_defaults(paths)
# initialize all property values
self.init_properties(self.options)
# Make sure there is a 'Default' entry when tracking the system theme.
# 'Default' is the theme used when encountering an so far unknown
# gtk-theme. 'Default' is added on first start and therefore a
# corresponding system default is respected.
theme_assocs = self.system_theme_associations
if not "Default" in theme_assocs:
theme_assocs["Default"] = self.theme
self.system_theme_associations = theme_assocs
# remember command line theme for system theme tracking
if self.options.theme:
self.remember_theme(self.theme)
# load theme
global Theme
from Onboard.Appearance import Theme
self.apply_theme()
# give gtk theme a chance to take over
self.update_theme_from_system_theme()
# misc initializations
self._last_snippets = dict(self.snippets) # store a copy
# remember state of mousetweaks click-type window
if self.mousetweaks:
self.mousetweaks.old_click_type_window_visible = \
self.mousetweaks.click_type_window_visible
if self.mousetweaks.is_active() and \
self.universal_access.hide_click_type_window:
self.mousetweaks.click_type_window_visible = False
# remember if we are running under GDM
self.running_under_gdm = 'RUNNING_UNDER_GDM' in os.environ
# tell config objects that their properties are valid now
self.on_properties_initialized()
_logger.debug("Leaving init")
def cleanup(self):
# This used to stop dangling main windows from responding
# when restarting. Restarts don't happen anymore, keep
# this for now anyway.
self.disconnect_notifications()
self.clickmapper.cleanup()
if self.mousetweaks:
self.mousetweaks.cleanup()
def final_cleanup(self):
if self.mousetweaks:
if self.xid_mode:
self.mousetweaks.click_type_window_visible = \
self.mousetweaks.old_click_type_window_visible
else:
if self.universal_access.enable_click_type_window_on_exit:
self.mousetweaks.click_type_window_visible = True
else:
self.mousetweaks.click_type_window_visible = \
self.mousetweaks.old_click_type_window_visible
def _init_keys(self):
""" Create key descriptions """
self.schema = SCHEMA_ONBOARD
self.sysdef_section = "main"
self.add_key("schema-version", "") # is assigned SCHEMA_VERSION on first start
self.add_key("use-system-defaults", False)
self.layout_key = \
self.add_key("layout", DEFAULT_LAYOUT)
self.theme_key = \
self.add_key("theme", DEFAULT_THEME)
self.add_key("system-theme-tracking-enabled", True)
self.add_key("system-theme-associations", {})
self.add_key("snippets", {})
self.add_key("show-status-icon", True)
self.add_key("start-minimized", False)
self.add_key("xembed-onboard", False, "onboard_xembed_enabled")
self.add_key("show-tooltips", True)
self.add_key("key-label-font", "") # default font for all themes
self.add_key("key-label-overrides", {}) # default labels for all themes
self.add_key("current-settings-page", 0)
self.keyboard = ConfigKeyboard()
self.window = ConfigWindow()
self.icp = ConfigICP(self)
self.auto_show = ConfigAutoShow()
self.universal_access = ConfigUniversalAccess(self)
self.theme_settings = ConfigTheme(self)
self.lockdown = ConfigLockdown(self)
self.gss = ConfigGSS(self)
self.gdi = ConfigGDI(self)
self.scanner = ConfigScanner(self)
self.children = [self.keyboard,
self.window,
self.icp,
self.auto_show,
self.universal_access,
self.theme_settings,
self.lockdown,
self.gss,
self.gdi,
self.scanner]
try:
self.mousetweaks = Mousetweaks()
self.children.append(self.mousetweaks)
except (SchemaError, ImportError) as e:
_logger.warning(unicode_str(e))
self.mousetweaks = None
self.clickmapper = ClickMapper()
def init_from_gsettings(self):
"""
Overloaded to migrate old dconf data to a new gsettings schema
"""
ConfigObject.init_from_gsettings(self)
import osk
util = osk.Util()
def migrate_dconf_value(dconf_key, config_object, gskey):
try:
value = util.read_dconf_key(dconf_key)
except (ValueError, TypeError) as e:
value = None
_logger.warning("migrate_dconf_value: {}".format(e))
if not value is None:
setattr(config_object, gskey.prop, value)
_logger.debug("migrate_dconf_value: {key} -> {path} {gskey}, value={value}" \
.format(key=dconf_key,
path=co.schema,
gskey=gskey.key, value=value))
def migrate_dconf_key(dconf_key, config_object, key):
gskey = config_object.find_key(key)
if gskey.is_default():
migrate_dconf_value(dconf_key, config_object, gskey)
# --- onboard 0.96 -> 0.97 ---------------------------------------------
format = Version.from_string(self.schema_version)
if format < SCHEMA_VERSION_0_97:
# window rect moves from apps.onboard to
# apps.onboard.window.landscape/portrait
co = self.window.landscape
if co.gskeys["x"].is_default() and \
co.gskeys["y"].is_default() and \
co.gskeys["width"].is_default() and \
co.gskeys["height"].is_default():
co.settings.delay()
migrate_dconf_value("/apps/onboard/x", co, co.gskeys["x"])
migrate_dconf_value("/apps/onboard/y", co, co.gskeys["y"])
migrate_dconf_value("/apps/onboard/width", co, co.gskeys["width"])
migrate_dconf_value("/apps/onboard/height", co, co.gskeys["height"])
co.settings.apply()
# icon-palette rect moves from apps.onboard.icon-palette to
# apps.onboard.icon-palette.landscape/portrait
co = self.icp.landscape
if co.gskeys["x"].is_default() and \
co.gskeys["y"].is_default() and \
co.gskeys["width"].is_default() and \
co.gskeys["height"].is_default():
co.settings.delay()
migrate_dconf_value("/apps/onboard/icon-palette/x", co, co.gskeys["x"])
migrate_dconf_value("/apps/onboard/icon-palette/y", co, co.gskeys["y"])
migrate_dconf_value("/apps/onboard/icon-palette/width", co, co.gskeys["width"])
migrate_dconf_value("/apps/onboard/icon-palette/height", co, co.gskeys["height"])
co.settings.apply()
# move keys from root to window
co = self.window
migrate_dconf_key("/apps/onboard/window-decoration", co, "window-decoration")
migrate_dconf_key("/apps/onboard/force-to-top", co, "force-to-top")
migrate_dconf_key("/apps/onboard/transparent-background", co, "transparent-background")
migrate_dconf_key("/apps/onboard/transparency", co, "transparency")
migrate_dconf_key("/apps/onboard/background-transparency", co, "background-transparency")
migrate_dconf_key("/apps/onboard/enable-inactive-transparency", co, "enable-inactive-transparency")
migrate_dconf_key("/apps/onboard/inactive-transparency", co, "inactive-transparency")
migrate_dconf_key("/apps/onboard/inactive-transparency-delay", co, "inactive-transparency-delay")
# accessibility keys move from root to universal-access
co = self.universal_access
migrate_dconf_key("/apps/onboard/hide-click-type-window", co, "hide-click-type-window")
migrate_dconf_key("/apps/onboard/enable-click-type-window-on-exit", co, "enable-click-type-window-on-exit")
# move keys from root to keyboard
co = self.keyboard
migrate_dconf_key("/apps/onboard/show-click-buttons", co, "show-click-buttons")
self.schema_version = SCHEMA_VERSION.to_string()
##### handle special keys only valid in system defaults #####
def _read_sysdef_section(self, parser):
super(self.__class__, self)._read_sysdef_section(parser)
# Convert the simplified superkey_label setting into
# the more general key_label_overrides setting.
sds = self.system_defaults
if "superkey_label" in sds:
overrides = sds.get( "key_label_overrides", {})
group = self.SUPERKEY_SIZE_GROUP \
if sds.get("superkey_label_independent_size") else ""
for key_id in ["LWIN", "RWIN"]:
overrides[key_id] = (sds["superkey_label"], group)
sds["key_label_overrides"] = overrides
def _convert_sysdef_key(self, gskey, sysdef, value):
# key exclusive to system defaults?
if sysdef in ["superkey-label", \
"superkey-label-independent-size"]:
return value
else:
return super(self.__class__, self). \
_convert_sysdef_key(gskey, sysdef, value)
##### property helpers #####
def _gsettings_get_key_label_overrides(self, gskey):
return self.get_unpacked_string_list(gskey, "a{s[ss]}")
def _gsettings_set_key_label_overrides(self, gskey, value):
self.set_packed_string_list(gskey, value)
def _gsettings_get_snippets(self, gskey):
return self.get_unpacked_string_list(gskey, "a{i[ss]}")
def _gsettings_set_snippets(self, gskey, value):
self.set_packed_string_list(gskey, value)
# Property layout_filename, linked to gsettings key "layout".
# layout_filename may only get/set a valid filename,
# whereas layout also allows to get/set only the basename of a layout.
def layout_filename_notify_add(self, callback):
self.layout_notify_add(callback)
def get_layout_filename(self):
return self._get_user_sys_filename_gs(
gskey = self.layout_key,
user_filename_func = lambda x: \
os.path.join(self.user_dir, "layouts", x) + \
self.LAYOUT_FILE_EXTENSION,
system_filename_func = lambda x: \
os.path.join(self.install_dir, "layouts", x) + \
self.LAYOUT_FILE_EXTENSION,
final_fallback = os.path.join(self.install_dir,
"layouts", DEFAULT_LAYOUT +
self.LAYOUT_FILE_EXTENSION))
def set_layout_filename(self, filename):
if filename and os.path.exists(filename):
self.layout = filename
else:
_logger.warning(_("layout '{filename}' does not exist") \
.format(filename=filename))
layout_filename = property(get_layout_filename, set_layout_filename)
# Property theme_filename, linked to gsettings key "theme".
# theme_filename may only get/set a valid filename,
# whereas theme also allows to get/set only the basename of a theme.
def theme_filename_notify_add(self, callback):
self.theme_notify_add(callback)
def get_theme_filename(self):
return self._get_user_sys_filename_gs(
gskey = self.theme_key,
user_filename_func = Theme.build_user_filename,
system_filename_func = Theme.build_system_filename,
final_fallback = os.path.join(self.install_dir,
"themes", DEFAULT_THEME +
"." + Theme.extension()))
def set_theme_filename(self, filename, save = True):
if filename and os.path.exists(filename):
self.set_theme(filename, save)
# remember currently active gtk theme
if self.system_theme_tracking_enabled:
self.remember_theme(filename)
else:
_logger.warning(_("theme '{filename}' does not exist") \
.format(filename=filename))
theme_filename = property(get_theme_filename, set_theme_filename)
def remember_theme(self, theme_filename):
if self.gdi: # be defensive
gtk_theme = self.get_gtk_theme()
theme_assocs = self.system_theme_associations
theme_assocs[gtk_theme] = theme_filename
self.system_theme_associations = theme_assocs
def _gsettings_get_system_theme_associations(self, gskey):
return gskey.settings.get_value(gskey.key).unpack()
def _gsettings_set_system_theme_associations(self, gskey, value):
gskey.settings.set_value(gskey.key, GLib.Variant('a{ss}', value))
def apply_theme(self):
theme_filename = self.theme_filename
_logger.info(_("Loading theme from '{}'").format(theme_filename))
theme = Theme.load(theme_filename)
if not theme:
_logger.error(_("Unable to read theme '{}'").format(theme_filename))
else:
# Save to gsettings
# Make sure gsettings is in sync with onboard (LP: 877601)
self.theme = theme_filename
theme.apply()
# Fix theme not saved to gesettings when switching
# system contrast themes.
# Possible gsettings bug in Precise (wasn't in Oneiric).
self.settings.apply()
def update_theme_from_system_theme(self):
""" Switches themes for system theme tracking """
if self.system_theme_tracking_enabled:
gtk_theme = self.get_gtk_theme()
theme_assocs = self.system_theme_associations
new_theme = theme_assocs.get(gtk_theme, None)
if not new_theme:
new_theme = theme_assocs.get("Default", None)
if not new_theme:
new_theme = DEFAULT_THEME
self.theme = new_theme
self.apply_theme()
def get_gtk_theme(self):
gtk_settings = Gtk.Settings.get_default()
if gtk_settings: # be defensive, don't know if this can fail
gtk_theme = gtk_settings.get_property('gtk-theme-name')
return gtk_theme
return None
def get_image_filename(self, image_filename):
"""
Returns an absolute path for a label image.
This function isn't linked to any gsettings key.'
"""
return self._get_user_sys_filename(
filename = image_filename,
description = "image",
user_filename_func = lambda x: \
os.path.join(self.user_dir, "layouts", "images", x),
system_filename_func = lambda x: \
os.path.join(self.install_dir, "layouts", "images", x))
def allow_system_click_type_window(self, allow):
""" called from hover click button """
if not self.mousetweaks:
return
# This assumes that mousetweaks.click_type_window_visible never
# changes between activation and deactivation of mousetweaks.
if allow:
self.mousetweaks.click_type_window_visible = \
self.mousetweaks.old_click_type_window_visible
else:
# hide the mousetweaks window when onboard's settings say so
if self.universal_access.hide_click_type_window:
self.mousetweaks.old_click_type_window_visible = \
self.mousetweaks.click_type_window_visible
self.mousetweaks.click_type_window_visible = False
def enable_hover_click(self, enable):
if enable:
self.allow_system_click_type_window(False)
self.mousetweaks.set_active(True)
else:
self.mousetweaks.set_active(False)
self.allow_system_click_type_window(True)
def is_visible_on_start(self):
return not self.xid_mode and \
not self.start_minimized and \
not self.auto_show.enabled
def is_auto_show_enabled(self):
return not self.xid_mode and \
self.auto_show.enabled
def get_frame_width(self):
""" width of the frame around the keyboard """
if self.xid_mode:
return 1.0
elif self.has_window_decoration():
return 0.0
elif self.window.transparent_background:
return 1.0
else:
return self.UNDECORATED_FRAME_WIDTH
def check_gnome_accessibility(self, parent = None):
if not self.xid_mode and \
not self.gdi.toolkit_accessibility:
question = _("Enabling auto-show requires Gnome Accessibility.\n\n"
"Onboard can turn on accessiblity now, however it is "
"recommended that you log out and back in "
"for it to reach its full potential.\n\n"
"Enable accessibility now?")
reply = show_confirmation_dialog(question, parent)
if not reply == True:
return False
self.gdi.toolkit_accessibility = True
return True
def get_drag_threshold(self):
threshold = self.universal_access.gskeys["drag_threshold"].value
if threshold == -1:
# get the systems DND threshold
threshold = Gtk.Settings.get_default(). \
get_property("gtk-dnd-drag-threshold")
return threshold
def is_icon_palette_in_use(self):
"""
Show icon palette when there is no other means to unhide onboard.
Unhiding by unity launcher isn't available in force-to-top mode.
"""
return self.icp.in_use or self.is_icon_palette_last_unhide_option()
def is_icon_palette_last_unhide_option(self):
"""
Is the icon palette the last remaining way to unhide onboard?
Consider single instance check a way to always unhide onboard.
"""
return False
def has_unhide_option(self):
"""
No native ui visible to unhide onboard?
There might still be the launcher to unminimize it.
"""
return self.is_icon_palette_in_use() or self.show_status_icon
def has_window_decoration(self):
""" Force-to-top mode doesn't support window decoration """
return self.window.window_decoration and not self.window.force_to_top
def get_sticky_state(self):
return not self.xid_mode and \
(self.window.window_state_sticky or self.window.force_to_top)
def is_inactive_transparency_enabled(self):
return self.window.enable_inactive_transparency and \
not self.scanner.enabled
def is_keep_aspect_ratio_enabled(self):
return self.window.keep_aspect_ratio or self.options.keep_aspect_ratio
####### resize handles #######
def resize_handles_notify_add(self, callback):
self.window.resize_handles_notify_add(callback)
self.icp.resize_handles_notify_add(callback)
def get_num_resize_handles(self):
""" Translate array of handles to simplified NumResizeHandles enum """
handles = self.window.resize_handles
if len(handles) == 0:
return NumResizeHandles.NONE
if len(handles) == 8:
return NumResizeHandles.ALL
return NumResizeHandles.SOME
def set_num_resize_handles(self, num):
if num == NumResizeHandles.ALL:
window_handles = list(Handle.RESIZERS)
icp_handles = list(Handle.RESIZERS)
elif num == NumResizeHandles.NONE:
window_handles = []
icp_handles = []
else:
window_handles = list(Handle.CORNERS)
icp_handles = [Handle.SOUTH_EAST]
self.window.resize_handles = window_handles
self.icp.resize_handles = icp_handles
@staticmethod
def _string_to_handles(string):
""" String of handle ids to array of Handle enums """
ids = string.split()
handles = []
for id in ids:
handle = Handle.RIDS.get(id)
if not handle is None:
handles.append(handle)
return handles
@staticmethod
def _handles_to_string(handles):
""" Array of handle enums to string of handle ids """
ids = []
for handle in handles:
ids.append(Handle.IDS[handle])
return " ".join(ids)
####### Snippets editing #######
def set_snippet(self, index, value):
"""
Set a snippet in the snippet list. Enlarge the list if not big
enough.
@type index: int
@param index: index of the snippet to set.
@type value: str
@param value: Contents of the new snippet.
"""
if value == None:
raise TypeError("Snippet text must be str")
label, text = value
snippets = dict(self.snippets) # copy to enable callbacks
_logger.info("Setting snippet %d to '%s', '%s'" % (index, label, text))
snippets[index] = (label, text)
self.snippets = snippets
def del_snippet(self, index):
"""
Delete a snippet.
@type index: int
@param index: index of the snippet to delete.
"""
_logger.info("Deleting snippet %d" % index)
snippets = dict(self.snippets) # copy to enable callbacks
del snippets[index]
self.snippets = snippets
###### gnome-screensaver, xembedding #####
def enable_gss_embedding(self, enable):
if enable:
self.onboard_xembed_enabled = True
self.gss.embedded_keyboard_enabled = True
self.set_xembed_command_string_to_onboard()
else:
self.onboard_xembed_enabled = False
self.gss.embedded_keyboard_enabled = False
def is_onboard_in_xembed_command_string(self):
"""
Checks whether the gsettings key for the embeded application command
contains the entry defined by onboard.
Returns True if it is set to onboard and False otherwise.
"""
if self.gss.embedded_keyboard_command.startswith(START_ONBOARD_XEMBED_COMMAND):
return True
else:
return False
def set_xembed_command_string_to_onboard(self):
"""
Write command to start the embedded onboard into the corresponding
gsettings key.
"""
self.gss.embedded_keyboard_command = START_ONBOARD_XEMBED_COMMAND
def _get_kbd_render_mixin(self):
__import__(self._kbd_render_mixin_mod)
return getattr(sys.modules[self._kbd_render_mixin_mod],
self._kbd_render_mixin_cls)
kbd_render_mixin = property(_get_kbd_render_mixin)
# modeless gksu - disabled until gksu moves to gsettings
def modeless_gksu_notify_add(self, callback):
pass
modeless_gksu = property(lambda self: False)
def _get_install_dir(self):
result = None
# when run from source
src_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
src_data_path = os.path.join(src_path, "data")
if os.path.isfile(os.path.join(src_data_path, "onboard.gschema.xml")):
# Add the data directory to the icon search path
icon_theme = Gtk.IconTheme.get_default()
src_icon_path = os.path.join(src_path, "icons")
icon_theme.append_search_path(src_icon_path)
result = src_path
# when installed to /usr/local
elif os.path.isdir(LOCAL_INSTALL_DIR):
result = LOCAL_INSTALL_DIR
# when installed to /usr
elif os.path.isdir(INSTALL_DIR):
result = INSTALL_DIR
assert(result) # warn early when the installation dir wasn't found
return result
def _get_user_dir(self):
return os.path.join(os.path.expanduser("~"), USER_DIR)
class ConfigKeyboard(ConfigObject):
"""Window configuration """
def _init_keys(self):
self.schema = SCHEMA_KEYBOARD
self.sysdef_section = "keyboard"
self.add_key("show-click-buttons", False)
self.add_key("sticky-key-release-delay", 0.0)
self.add_key("sticky-key-behavior", {"all" : "cycle"})
def _gsettings_get_sticky_key_behavior(self, gskey):
return gskey.settings.get_value(gskey.key).unpack()
def _gsettings_set_sticky_key_behavior(self, gskey, value):
gskey.settings.set_value(gskey.key, GLib.Variant('a{ss}', value))
class ConfigWindow(ConfigObject):
"""Window configuration """
def _init_keys(self):
self.schema = SCHEMA_WINDOW
self.sysdef_section = "window"
self.add_key("window-state-sticky", True)
self.add_key("window-decoration", False)
self.add_key("force-to-top", False)
self.add_key("keep-aspect-ratio", False)
self.add_key("transparent-background", False)
self.add_key("transparency", 0.0)
self.add_key("background-transparency", 10.0)
self.add_key("enable-inactive-transparency", False)
self.add_key("inactive-transparency", 50.0)
self.add_key("inactive-transparency-delay", 1.0)
self.add_key("resize-handles", DEFAULT_RESIZE_HANDLES)
self.landscape = ConfigWindow.Landscape(self)
self.portrait = ConfigWindow.Portrait(self)
self.children = [self.landscape, self.portrait]
##### property helpers #####
def _convert_sysdef_key(self, gskey, sysdef, value):
if sysdef == "resize-handles":
return Config._string_to_handles(value)
else:
return ConfigObject._convert_sysdef_key(self, gskey, sysdef, value)
def _gsettings_get_resize_handles(self, gskey):
value = self.settings.get_string(gskey.key)
return Config._string_to_handles(value)
def _gsettings_set_resize_handles(self, gskey, handles):
value = Config._handles_to_string(handles)
self.settings.set_string(gskey.key, value)
def position_notify_add(self, callback):
self.landscape.x_notify_add(callback)
self.landscape.y_notify_add(callback)
self.portrait.x_notify_add(callback)
self.portrait.y_notify_add(callback)
def size_notify_add(self, callback):
self.landscape.width_notify_add(callback)
self.landscape.height_notify_add(callback)
self.portrait.width_notify_add(callback)
self.portrait.height_notify_add(callback)
class Landscape(ConfigObject):
def _init_keys(self):
self.schema = SCHEMA_WINDOW_LANDSCAPE
self.sysdef_section = "window.landscape"
self.add_key("x", DEFAULT_X)
self.add_key("y", DEFAULT_Y)
self.add_key("width", DEFAULT_WIDTH)
self.add_key("height", DEFAULT_HEIGHT)
class Portrait(ConfigObject):
def _init_keys(self):
self.schema = SCHEMA_WINDOW_PORTRAIT
self.sysdef_section = "window.portrait"
self.add_key("x", DEFAULT_X)
self.add_key("y", DEFAULT_Y)
self.add_key("width", DEFAULT_WIDTH)
self.add_key("height", DEFAULT_HEIGHT)
class ConfigICP(ConfigObject):
""" Icon palette configuration """
def _init_keys(self):
self.schema = SCHEMA_ICP
self.sysdef_section = "icon-palette"
self.add_key("in-use", False)
self.add_key("resize-handles", DEFAULT_RESIZE_HANDLES)
self.landscape = ConfigICP.Landscape(self)
self.portrait = ConfigICP.Portrait(self)
self.children = [self.landscape, self.portrait]
##### property helpers #####
def _convert_sysdef_key(self, gskey, sysdef, value):
if sysdef == "resize-handles":
return Config._string_to_handles(value)
else:
return ConfigObject._convert_sysdef_key(self, gskey, sysdef, value)
def _gsettings_get_resize_handles(self, gskey):
value = self.settings.get_string(gskey.key)
return Config._string_to_handles(value)
def _gsettings_set_resize_handles(self, gskey, handles):
value = Config._handles_to_string(handles)
self.settings.set_string(gskey.key, value)
def position_notify_add(self, callback):
self.landscape.x_notify_add(callback)
self.landscape.y_notify_add(callback)
self.portrait.x_notify_add(callback)
self.portrait.y_notify_add(callback)
def size_notify_add(self, callback):
self.landscape.width_notify_add(callback)
self.landscape.height_notify_add(callback)
self.portrait.width_notify_add(callback)
self.portrait.height_notify_add(callback)
class Landscape(ConfigObject):
def _init_keys(self):
self.schema = SCHEMA_ICP_LANDSCAPE
self.sysdef_section = "icon-palette.landscape"
self.add_key("x", DEFAULT_ICP_X)
self.add_key("y", DEFAULT_ICP_Y)
self.add_key("width", DEFAULT_ICP_WIDTH)
self.add_key("height", DEFAULT_ICP_HEIGHT)
class Portrait(ConfigObject):
def _init_keys(self):
self.schema = SCHEMA_ICP_PORTRAIT
self.sysdef_section = "icon-palette.portrait"
self.add_key("x", DEFAULT_ICP_X)
self.add_key("y", DEFAULT_ICP_Y)
self.add_key("width", DEFAULT_ICP_WIDTH)
self.add_key("height", DEFAULT_ICP_HEIGHT)
class ConfigAutoShow(ConfigObject):
""" auto_show configuration """
def _init_keys(self):
self.schema = SCHEMA_AUTO_SHOW
self.sysdef_section = "auto-show"
self.add_key("enabled", False)
self.add_key("widget-clearance", (25.0, 55.0, 25.0, 40.0))
def _gsettings_get_widget_clearance(self, gskey):
return gskey.settings.get_value(gskey.key).unpack()
def _gsettings_set_widget_clearance(self, gskey, value):
gskey.settings.set_value(gskey.key, GLib.Variant('(dddd)', value))
class ConfigUniversalAccess(ConfigObject):
""" universal_access configuration """
def _init_keys(self):
self.schema = SCHEMA_UNIVERSAL_ACCESS
self.sysdef_section = "universal-access"
self.add_key("drag-threshold", -1)
self.add_key("hide-click-type-window", True)
self.add_key("enable-click-type-window-on-exit", True)
def _post_notify_hide_click_type_window(self):
""" called when changed in gsettings (preferences window) """
mousetweaks = self.parent.mousetweaks
if not mousetweaks:
return
if mousetweaks.is_active():
if self.hide_click_type_window:
mousetweaks.click_type_window_visible = False
else:
mousetweaks.click_type_window_visible = \
mousetweaks.old_click_type_window_visible
class ConfigTheme(ConfigObject):
""" Theme configuration """
def _init_keys(self):
self.schema = SCHEMA_THEME
self.sysdef_section = "theme-settings"
self.add_key("color-scheme", DEFAULT_COLOR_SCHEME,
prop="color_scheme_filename")
self.add_key("key-style", "flat")
self.add_key("roundrect-radius", 0.0)
self.add_key("key-size", 100.0)
self.add_key("key-fill-gradient", 0.0)
self.add_key("key-stroke-gradient", 0.0)
self.add_key("key-gradient-direction", 0.0)
self.key_label_font_key = \
self.add_key("key-label-font", "") # font for current theme
self.key_label_overrides_key = \
self.add_key("key-label-overrides", {}) # labels for current theme
##### property helpers #####
def theme_attributes_notify_add(self, callback):
self.key_style_notify_add(callback)
self.roundrect_radius_notify_add(callback)
self.key_fill_gradient_notify_add(callback)
self.key_stroke_gradient_notify_add(callback)
self.key_gradient_direction_notify_add(callback)
self.key_label_font_notify_add(callback)
self.key_label_overrides_notify_add(callback)
self.key_style_notify_add(callback)
def _can_set_color_scheme_filename(self, filename):
if not os.path.exists(filename):
_logger.warning(_("color scheme '{filename}' does not exist") \
.format(filename=filename))
return False
return True
def _gsettings_get_key_label_overrides(self, gskey):
return self.get_unpacked_string_list(gskey, "a{s[ss]}")
def _gsettings_set_key_label_overrides(self, gskey, value):
self.set_packed_string_list(gskey, value)
def get_key_label_overrides(self):
gskey = self.key_label_overrides_key
# merge with default value from onboard base config
value = dict(self.parent.key_label_overrides)
value.update(gskey.value)
return value
def get_key_label_font(self):
gskey = self.key_label_font_key
value = gskey.value
if not value:
# get default value from onboard base config instead
value = self.parent.key_label_font
return value
class ConfigLockdown(ConfigObject):
""" Lockdown/Kiosk mode configuration """
def _init_keys(self):
self.schema = SCHEMA_LOCKDOWN
self.sysdef_section = "lockdown"
self.add_key("disable-click-buttons", False)
self.add_key("disable-hover-click", False)
self.add_key("disable-preferences", False)
self.add_key("disable-quit", False)
self.add_key("disable-touch-handles", False)
def lockdown_notify_add(self, callback):
self.disable_click_buttons_notify_add(callback)
self.disable_hover_click_notify_add(callback)
self.disable_preferences_notify_add(callback)
self.disable_quit_notify_add(callback)
class ConfigGSS(ConfigObject):
""" gnome-screen-saver configuration keys"""
def _init_keys(self):
self.schema = SCHEMA_GSS
self.sysdef_section = "gnome-screen-saver"
self.add_key("embedded-keyboard-enabled", True)
self.add_key("embedded-keyboard-command", "")
class ConfigGDI(ConfigObject):
""" Key to enable Gnome Accessibility"""
def _init_keys(self):
self.schema = SCHEMA_GDI
self.sysdef_section = "gnome-desktop-interface"
self.add_key("toolkit-accessibility", False)
self.add_key("gtk-theme", "", writable=False) # read_only for safety
class ConfigScanner(ConfigObject):
""" Scanner configuration """
DEFAULT_INTERVAL = 1.20
DEFAULT_INTERVAL_FAST = 0.05
DEFAULT_MODE = 0 # AutoScan
DEFAULT_CYCLES = 2
DEFAULT_BACKTRACK = 5
DEFAULT_ALTERNATE = False
DEFAULT_USER_SCAN = False
DEFAULT_DEVICE_NAME = "Default"
DEFAULT_DEVICE_KEY_MAP = {}
DEFAULT_DEVICE_BUTTON_MAP = { 1: 0, 3: 5 } # Button 1: Step, Button 3: Activate
DEFAULT_FEEDBACK_FLASH = True
def _init_keys(self):
self.schema = SCHEMA_SCANNER
self.sysdef_section = "scanner"
self.add_key("enabled", False)
self.add_key("mode", self.DEFAULT_MODE)
self.add_key("interval", self.DEFAULT_INTERVAL)
self.add_key("interval-fast", self.DEFAULT_INTERVAL_FAST)
self.add_key("cycles", self.DEFAULT_CYCLES)
self.add_key("backtrack", self.DEFAULT_BACKTRACK)
self.add_key("alternate", self.DEFAULT_ALTERNATE)
self.add_key("user-scan", self.DEFAULT_USER_SCAN)
self.add_key("device-name", self.DEFAULT_DEVICE_NAME)
self.add_key("device-detach", False)
self.add_key("device-key-map", self.DEFAULT_DEVICE_KEY_MAP)
self.add_key("device-button-map", self.DEFAULT_DEVICE_BUTTON_MAP)
self.add_key("feedback-flash", self.DEFAULT_FEEDBACK_FLASH)
def _gsettings_get_mode(self, gskey):
return gskey.settings.get_enum(gskey.key)
def _gsettings_set_mode(self, gskey, value):
gskey.settings.set_enum(gskey.key, value)
def _gsettings_get_device_key_map(self, gskey):
return gskey.settings.get_value(gskey.key).unpack()
def _gsettings_set_device_key_map(self, gskey, value):
gskey.settings.set_value(gskey.key, GLib.Variant('a{ii}', value))
def _gsettings_get_device_button_map(self, gskey):
return gskey.settings.get_value(gskey.key).unpack()
def _gsettings_set_device_button_map(self, gskey, value):
gskey.settings.set_value(gskey.key, GLib.Variant('a{ii}', value))
|