#!/bin/python3 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- # # This file is part of the LibreOffice project. # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
# for any existing .ui this should parse it and overwrite it with the same content # e.g. for a in `git ls-files "*.ui"`; do bin/ui-rules-enforcer.py $a; done
if ismenubutton: if draw_indicator isNone: if image isNone: # if there is no draw indicator and no image there should be a draw indicator
draw_indicator = etree.Element("property")
attributes = draw_indicator.attrib
attributes["name"] = "draw-indicator"
draw_indicator.text = "True"
current.insert(insertpos, draw_indicator) else: # if there is no draw indicator but there is an image that image should be open-menu-symbolic or x-office-calendar for status_elem in tree.xpath("/interface/object[@id='" + image.text + "']/property[@name='icon_name' or @name='icon-name']"): if status_elem.text != 'x-office-calendar':
status_elem.text = "open-menu-symbolic"
def enforce_active_in_group_consistency(current):
group = None
active = None
isradiobutton = current.get('class') == "GtkRadioButton"
insertpos = 0 for child in current:
enforce_active_in_group_consistency(child) ifnot isradiobutton: continue if child.tag == "property":
insertpos = insertpos + 1
attributes = child.attrib if attributes.get("name") == "group":
group = child if attributes.get("name") == "active":
active = child
if isradiobutton: if active isnotNoneand active.text != "True": raise Exception(sys.argv[1] + ': non-standard active value', active.text) if group isnotNoneand active isnotNone: # if there is a group then we are not the leader and should not be active
current.remove(active) elif group isNoneand active isNone: # if there is no group then we are the leader and should be active
active = etree.Element("property")
attributes = active.attrib
attributes["name"] = "active"
active.text = "True"
current.insert(insertpos, active)
if isbutton and image isnotNone: if always_show_image isNone:
always_show_image = etree.Element("property")
attributes = always_show_image.attrib
attributes["name"] = "always-show-image"
always_show_image.text = "True"
current.insert(insertpos, always_show_image) else:
always_show_image.text = "True"
def enforce_noshared_adjustments(current, adjustments): for child in current:
enforce_noshared_adjustments(child, adjustments) if child.tag == "property":
attributes = child.attrib if attributes.get("name") == "adjustment": if child.text in 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)
def enforce_menuitem_id(current): # gtk4 VCL plugin requires "id" attribute for menu items for child in current:
enforce_menuitem_id(child) if child.get('class') in ("GtkMenuItem", "GtkRadioMenuItem"): ifnot child.attrib.get("id"): raise Exception(sys.argv[1] + ': menu item does not have an id set' , child.text)
with open(sys.argv[1], encoding="utf-8") as f:
header = f.readline()
f.seek(0) # remove_blank_text so pretty-printed input doesn't disrupt pretty-printed # output if nodes are added or removed
parser = etree.XMLParser(remove_blank_text=True)
tree = etree.parse(f, parser) # make sure <property name="label" translatable="no"></property> stays like that # and doesn't change to <property name="label" translatable="no"/> for status_elem in tree.xpath("//property[@name='label' and string() = '']"):
status_elem.text = ""
root = tree.getroot()
# do some targeted conversion here # tdf#138848 Copy-and-Paste in input box should not append an ENTER character ifnot sys.argv[1].endswith('/multiline.ui'): # let this one alone not truncate multiline pastes
add_truncate_multiline(root)
replace_button_use_stock(root)
replace_image_stock(root)
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_menuitem_id(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 XXX replacements for non-ascii characters # which we don't want to see changed in the output
o.write(etree.tostring(tree, pretty_print=True, method='xml', encoding='unicode', doctype=header[0:-1]).encode("utf8"))
# vim: set shiftwidth=4 softtabstop=4 expandtab:
¤ Dauer der Verarbeitung: 0.19 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.