Skip to content

Commit a4c41d8

Browse files
Version 2.0.4-1: configuration can be changed via cmdline.
1 parent 8bb60ad commit a4c41d8

File tree

5 files changed

+102
-78
lines changed

5 files changed

+102
-78
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = umlsequence2
3-
version = 2.0.3-3
3+
version = 2.0.4-1
44
author = Pascal Bauermeister
55
author_email = [email protected]
66
description = UML Sequence diagram generator from text input

src/umlsequence2/config.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
'TEXT_MARGIN_Y',
4040
))
4141

42-
CONFIG = Config(
42+
_CONFIG = Config(
4343
ACTIVITY_WIDTH = 0.20,
4444

4545
ACTOR_ASCENT = 0.25,
@@ -72,3 +72,10 @@
7272
TEXT_MARGIN_X = 0.20,
7373
TEXT_MARGIN_Y = 0.15,
7474
)
75+
76+
def set_config(cfg):
77+
global _CONFIG
78+
_CONFIG = cfg
79+
80+
def get_config():
81+
return _CONFIG

src/umlsequence2/main.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from .converter import convert
2424
from .uml_builder import UmlBuilder
2525
from .parser import Parser
26+
from .config import Config, set_config, get_config
2627

2728

2829
def generate_svg(input_fp, output_path, percent_zoom, debug, bgcolor):
@@ -102,9 +103,24 @@ def main():
102103
default=False,
103104
help='emits debug messages')
104105

106+
# add config float values, e.g. COLUMN_WIDTH as --COLUMN-WIDTH
107+
cfg = get_config()._asdict()
108+
conf_keys = [k for k, v in cfg.items() if isinstance(v, float)]
109+
for k in conf_keys:
110+
parser.add_argument('--' + k.replace('_', '-'),
111+
metavar='FLOAT', type=float,
112+
help=f'change {k} (default {cfg[k]})')
113+
105114
args = parser.parse_args()
106115
args.format = args.format.lower()
107116

117+
# parse back config modifiers args
118+
conf_args = {k:args.__dict__[k] for k in conf_keys
119+
if args.__dict__[k] is not None}
120+
if conf_args:
121+
cfg.update(conf_args)
122+
set_config(Config(**cfg))
123+
108124
# treat input
109125
if args.INPUT_FILE is None:
110126
inp = sys.stdin

src/umlsequence2/svg_renderer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import svgwrite
33
from svgwrite import cm, mm
44

5-
from .config import CONFIG
5+
from .config import get_config
66

77

88
def cm2px(cm):
@@ -61,7 +61,7 @@ def polyline(self, points, grey=False, filled=False):
6161
points_px = [(cm2px(x), cm2px(y)) for x, y in points]
6262
a = dict(points=points_px,
6363
fill='white' if filled else 'none',
64-
stroke=CONFIG.COLOR_GREY if grey else 'black')
64+
stroke=get_config().COLOR_GREY if grey else 'black')
6565
self.add(self.dwg.polyline(**a))
6666
for xp, yp in points_px:
6767
self.set_max(xp, yp)
@@ -75,15 +75,15 @@ def polygon(self, points):
7575

7676
def get_text_width(self, text):
7777
#FIXME
78-
return CONFIG.TEXT_CHAR_WIDTH * len(text)
78+
return get_config().TEXT_CHAR_WIDTH * len(text)
7979

8080
def text(self, x, y, text, underline=False,
8181
start=False, middle=False, end=False,
8282
light=False):
8383
xp, yp = cm2px(x), cm2px(y)
8484
a = dict(fill='#444' if light else 'black',
8585
insert=(xp, yp),
86-
**CONFIG.TEXT_FONT)
86+
**get_config().TEXT_FONT)
8787
l = cm2px(self.get_text_width(text))
8888
if start or not start and not middle and not end:
8989
a['text_anchor'] = 'start'
@@ -105,7 +105,7 @@ def rect(self, x, y, w, h,
105105
a = dict(insert=(xp, yp),
106106
size=(wp, hp),
107107
fill='none' if transparent else 'white',
108-
stroke=CONFIG.COLOR_GREY if grey else 'black',
108+
stroke=get_config().COLOR_GREY if grey else 'black',
109109
stroke_width=1)
110110
self.add(self.dwg.rect(**a))
111111
self.set_max(xp + wp, yp + hp)
@@ -118,7 +118,7 @@ def line(self, x1, y1, x2, y2,
118118
x2p, y2p = cm2px(x2), cm2px(y2)
119119
a = dict(start=(x1p, y1p),
120120
end=(x2p, y2p),
121-
stroke=CONFIG.COLOR_GREY if grey else 'black',
121+
stroke=get_config().COLOR_GREY if grey else 'black',
122122
stroke_width=2 if thick else 1)
123123
if dashed:
124124
a['stroke_dasharray'] = '4'

0 commit comments

Comments
 (0)