/usr/share/dia/python/allprops.py is in dia-common 0.97.2-5.
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 | # PyDia Self Documentation Series - Part IV : All Objects Properties
# Copyright (c) 2008, Hans Breuer <hans@breuer.org>
#
# generates a new diagram which contains all the currently
# known std-props, that is iterates all objects for their properties
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
import sys, dia, string
def allprops_cb(data, flags) :
# copied from otypes.py
if data :
diagram = None # we may be running w/o GUI
else :
diagram = dia.new("All Object Properties.dia")
data = diagram.data
layer = data.active_layer
props_by_name = {}
otypes = dia.registered_types()
name_type_clashes = []
for oname in otypes :
try :
obj, h1, h2 = dia.get_object_type(oname).create (0, 0)
except :
print "Huh?", oname
continue
prop_keys = obj.properties.keys()
for k in prop_keys :
p = obj.properties[k]
if props_by_name.has_key(k) :
# check if it is the same type
p0, names = props_by_name[k]
try :
if p0.type != p.type :
# construct a unique name
uname = p.name + "<" + p.type + ">"
if props_by_name.has_key(uname) :
props_by_name[uname][1].append(oname)
else :
props_by_name[uname] = (p, [oname])
name_type_clashes.append (oname + " as " + p0.type + " and " + p.type)
else :
# remember the origin of the propety
props_by_name[k][1].append(oname)
except KeyError :
print oname, "::", k, p, "?"
else :
props_by_name[k] = (p, [oname])
obj.destroy() # unsave delete, any method call will fail/crash afterweards
obj = None
grid = {} # one type per row
dx = 1.0
dy = 5.0
ot = dia.get_object_type("UML - Class")
props_keys = props_by_name.keys()
# alpha-numeric sorting by type; after by number of users
props_keys.sort (lambda a,b : len(props_by_name[b][1]) - len(props_by_name[a][1]))
props_keys.sort (lambda a,b : cmp(props_by_name[a][0].type, props_by_name[b][0].type))
almost_all = 98 * len(otypes) / 100 # 98 %
for pname in props_keys :
p, names = props_by_name[pname]
x = 0.0
y = 0.0
if grid.has_key(p.type) :
x, y = grid[p.type]
else :
x = 0.0
y = len(grid.keys()) * dy
o, h1, h2 = ot.create (x,y)
o.properties["name"] = pname
o.properties["template"] = 1
o.properties["templates"] = [(p.type, '')]
# coloring depending on use
if len(names) > almost_all :
o.properties["fill_colour"] = "lightgreen"
elif len(names) > 100 :
o.properties["fill_colour"] = "lightblue"
elif len(names) > 2 :
o.properties["fill_colour"] = "lightcyan"
elif len(names) > 1 :
o.properties["fill_colour"] = "lightyellow"
# if there is only one user show it
if len(names) == 1 :
o.properties["comment"] = names[0]
o.properties["visible_comments"] = 1
o.properties["comment_line_length"] = 60
else :
o.properties["comment"] = string.join(names, "; ")
o.properties["visible_comments"] = 0
o.properties["comment_line_length"] = 60
# store position for next in row
x += (dx + o.properties["elem_width"].value)
grid[p.type] = (x,y)
layer.add_object(o)
layer.update_extents()
data.update_extents()
if diagram :
diagram.display()
diagram.flush()
if len(name_type_clashes) > 0 :
dia.message(0, "One name, one type?!\n" + string.join(name_type_clashes, "\n"))
return data
dia.register_action ("HelpAllPropts", "All Object Properties",
"/ToolboxMenu/Help/HelpExtensionStart",
allprops_cb)
|