diff options
Diffstat (limited to 'bin/ui-rules-enforcer.py')
-rwxr-xr-x | bin/ui-rules-enforcer.py | 108 |
1 files changed, 98 insertions, 10 deletions
diff --git a/bin/ui-rules-enforcer.py b/bin/ui-rules-enforcer.py index 7c20ee0a6db7..f3514d212276 100755 --- a/bin/ui-rules-enforcer.py +++ b/bin/ui-rules-enforcer.py @@ -24,7 +24,7 @@ def add_truncate_multiline(current): insertpos = 0 for child in current: add_truncate_multiline(child) - insertpos = insertpos + 1; + insertpos = insertpos + 1 if not istarget: continue if child.tag == "property": @@ -87,7 +87,7 @@ def replace_button_use_stock(current): insertpos = 0 for child in current: replace_button_use_stock(child) - insertpos = insertpos + 1; + insertpos = insertpos + 1 if not isbutton: continue if child.tag == "property": @@ -137,6 +137,8 @@ def do_replace_image_stock(current, stock): stock.text = "go-last" elif stock.text == 'gtk-new': stock.text = "document-new" + elif stock.text == 'gtk-open': + stock.text = "document-open" elif stock.text == 'gtk-media-stop': stock.text = "media-playback-stop" elif stock.text == 'gtk-media-play': @@ -240,6 +242,22 @@ def remove_spin_button_input_purpose(current): if input_purpose != None: current.remove(input_purpose) +def remove_caps_lock_warning(current): + caps_lock_warning = None + iscandidate = current.get('class') == "GtkSpinButton" or current.get('class') == "GtkEntry" + for child in current: + remove_caps_lock_warning(child) + if not iscandidate: + continue + if child.tag == "property": + attributes = child.attrib + if attributes.get("name") == "caps_lock_warning" or attributes.get("name") == "caps-lock-warning": + caps_lock_warning = child + + if iscandidate: + if caps_lock_warning != None: + current.remove(caps_lock_warning) + def remove_spin_button_max_length(current): max_length = None isspinbutton = current.get('class') == "GtkSpinButton" @@ -256,6 +274,22 @@ def remove_spin_button_max_length(current): if max_length != None: current.remove(max_length) +def remove_entry_shadow_type(current): + shadow_type = None + isentry = current.get('class') == "GtkEntry" + for child in current: + remove_entry_shadow_type(child) + if not isentry: + continue + if child.tag == "property": + attributes = child.attrib + if attributes.get("name") == "shadow_type" or attributes.get("name") == "shadow-type": + shadow_type = child + + if isentry: + if shadow_type!= None: + current.remove(shadow_type) + def remove_label_pad(current): xpad = None ypad = None @@ -276,6 +310,21 @@ def remove_label_pad(current): if ypad != None: current.remove(ypad) +def remove_label_angle(current): + angle = None + islabel = current.get('class') == "GtkLabel" + for child in current: + remove_label_angle(child) + if not islabel: + continue + if child.tag == "property": + attributes = child.attrib + if attributes.get("name") == "angle": + angle = child + + if angle != None: + current.remove(angle) + def remove_track_visited_links(current): track_visited_links = None islabel = current.get('class') == "GtkLabel" @@ -293,8 +342,8 @@ def remove_track_visited_links(current): def remove_toolbutton_focus(current): can_focus = None - classname = current.get('class'); - istoolbutton = classname and classname.endswith("ToolButton"); + classname = current.get('class') + istoolbutton = classname and classname.endswith("ToolButton") for child in current: remove_toolbutton_focus(child) if not istoolbutton: @@ -319,6 +368,18 @@ def remove_double_buffered(current): if double_buffered != None: current.remove(double_buffered) +def remove_label_yalign(current): + label_yalign = None + for child in current: + remove_label_yalign(child) + if child.tag == "property": + attributes = child.attrib + if attributes.get("name") == "label_yalign" or attributes.get("name") == "label-yalign": + label_yalign = child + + if label_yalign != None: + current.remove(label_yalign) + def remove_skip_pager_hint(current): skip_pager_hint = None for child in current: @@ -331,6 +392,18 @@ def remove_skip_pager_hint(current): if skip_pager_hint != None: current.remove(skip_pager_hint) +def remove_gravity(current): + gravity = None + for child in current: + remove_gravity(child) + if child.tag == "property": + attributes = child.attrib + if attributes.get("name") == "gravity": + gravity = child + + if gravity != None: + current.remove(gravity) + def remove_expander_label_fill(current): label_fill = None isexpander = current.get('class') == "GtkExpander" @@ -371,7 +444,7 @@ def enforce_menubutton_indicator_consistency(current): if not ismenubutton: continue if child.tag == "property": - insertpos = insertpos + 1; + insertpos = insertpos + 1 attributes = child.attrib if attributes.get("name") == "draw_indicator" or attributes.get("name") == "draw-indicator": draw_indicator = child @@ -403,7 +476,7 @@ def enforce_active_in_group_consistency(current): if not isradiobutton: continue if child.tag == "property": - insertpos = insertpos + 1; + insertpos = insertpos + 1 attributes = child.attrib if attributes.get("name") == "group": group = child @@ -433,7 +506,7 @@ def enforce_toolbar_can_focus(current): if not istoolbar: continue if child.tag == "property": - insertpos = insertpos + 1; + insertpos = insertpos + 1 attributes = child.attrib if attributes.get("name") == "can-focus" or attributes.get("name") == "can_focus": can_focus = child @@ -458,7 +531,7 @@ def enforce_entry_text_column_id_column_for_gtkcombobox(current): if not isgtkcombobox: continue if child.tag == "property": - insertpos = insertpos + 1; + insertpos = insertpos + 1 attributes = child.attrib if attributes.get("name") == "entry_text_column" or attributes.get("name") == "entry-text-column": entrytextcolumn = child @@ -477,7 +550,7 @@ def enforce_entry_text_column_id_column_for_gtkcombobox(current): attributes["name"] = "entry-text-column" entrytextcolumn.text = "0" current.insert(insertpos, entrytextcolumn) - insertpos = insertpos + 1; + insertpos = insertpos + 1 if idcolumn == None: # if there is no id_column, create one idcolumn = etree.Element("property") @@ -496,7 +569,7 @@ def enforce_button_always_show_image(current): if not isbutton: continue if child.tag == "property": - insertpos = insertpos + 1; + insertpos = insertpos + 1 attributes = child.attrib if attributes.get("name") == "always_show_image" or attributes.get("name") == "always-show-image": always_show_image = child @@ -523,6 +596,15 @@ def enforce_noshared_adjustments(current, adjustments): raise Exception(sys.argv[1] + ': adjustment used more than once', child.text) adjustments.add(child.text) +def enforce_no_productname_in_accessible_description(current, adjustments): + for child in current: + enforce_no_productname_in_accessible_description(child, adjustments) + if child.tag == "property": + attributes = child.attrib + if attributes.get("name") == "AtkObject::accessible-description": + if "%PRODUCTNAME" in child.text: + raise Exception(sys.argv[1] + ': %PRODUCTNAME used in accessible-description:' , child.text) + with open(sys.argv[1], encoding="utf-8") as f: header = f.readline() f.seek(0) @@ -546,20 +628,26 @@ remove_check_button_align(root) remove_check_button_relief(root) remove_check_button_image_position(root) remove_spin_button_input_purpose(root) +remove_caps_lock_warning(root) remove_spin_button_max_length(root) remove_track_visited_links(root) remove_label_pad(root) +remove_label_angle(root) remove_expander_label_fill(root) remove_expander_spacing(root) enforce_menubutton_indicator_consistency(root) enforce_active_in_group_consistency(root) enforce_entry_text_column_id_column_for_gtkcombobox(root) +remove_entry_shadow_type(root) remove_double_buffered(root) +remove_label_yalign(root) remove_skip_pager_hint(root) +remove_gravity(root) remove_toolbutton_focus(root) enforce_toolbar_can_focus(root) enforce_button_always_show_image(root) enforce_noshared_adjustments(root, set()) +enforce_no_productname_in_accessible_description(root, set()) with open(sys.argv[1], 'wb') as o: # without encoding='unicode' (and the matching encode("utf8")) we get &#XXXX replacements for non-ascii characters |