KApiDox

block.py
1 # -*- coding: utf-8 -*-
2 #
3 # SPDX-FileCopyrightText: 2014 Aurélien Gâteau <[email protected]>
4 #
5 # SPDX-License-Identifier: BSD-2-Clause
6 
7 from contextlib import contextmanager
8 
9 class Block(object):
10  INDENT_SIZE = 4
11 
12  def __init__(self, out, depth = 0):
13  self.out = out
14  self.depth = depth
15 
16  def writeln(self, text):
17  self.out.write(self.depth * Block.INDENT_SIZE * " " + text + "\n")
18 
19  def write_attrs(self, **attrs):
20  for key, value in attrs.items():
21  self.writeln('"{}" = "{}";'.format(key, value))
22 
23  def write_list_attrs(self, name, **attrs):
24  with self.square_block(name) as b:
25  for key, value in attrs.items():
26  b.writeln('"{}" = "{}"'.format(key, value))
27 
28  def write_nodes(self, nodes):
29  for node in sorted(nodes):
30  self.writeln('"{}";'.format(node))
31 
32  @contextmanager
33  def block(self, opener, closer, **attrs):
34  self.writeln(opener)
35  block = Block(self.out, depth=self.depth + 1)
36  block.write_attrs(**attrs)
37  yield block
38  self.writeln(closer)
39 
40  def square_block(self, prefix, **attrs):
41  return self.block(prefix + " [", "]", **attrs)
42 
43  def curly_block(self, prefix, **attrs):
44  return self.block(prefix + " {", "}", **attrs)
45 
46  def cluster_block(self, title, **attrs):
47  return self.curly_block("subgraph " + quote("cluster_" + title), label=title, **attrs)
48 
49 
50 def quote(txt):
51  return '"{}"'.format(txt)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Nov 30 2020 22:54:36 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.