dbpp.widgets package: GuiBaseClass - AutoScrollbar - Balloon - Ctext - LabEntry - RoText - Scrolled - SqlText - StatusBar - TableView - TextMixins - XTableView - XTreeView
dbpp.kroki - dbpp.kroki.KrokiEncoder - dbpp.utils - dbpp.utils.SqlUtils -
apps: dbpp.peditor
dbpp.kroki.KrokiEncoder - class to encode diagram code as krokio.io URL's and to decode them back to text.
This class provides methods to convert diagram code for tools like PlantUML, GraphViz or Ditaa to base64 encoded URL's ready to display them as web images using the https://kroki.io and ready to edit them online using the Niolesk web editor.
Examples:
from dbpp.kroki.KrokiEncoder import KrokiEncoder
kroki = KrokiEncoder()
kroki.text2kroki("A --> B")
kroki.text2kroki("class A { }",dia='plantuml',ext='svg')
kroki.dia2kroki('input.pml',dia='plantuml',ext='png')
Classes:
@startuml
class A
class B
A -> B
@enduml
>>> x = 1
>>> x + 1
2
>>> from dbpp.kroki.KrokiEncoder import KrokiEncoder
>>> kroki = KrokiEncoder()
>>> kroki.text2kroki("class A { }",dia='plantuml',ext='svg')
'https://kroki.io/plantuml/svg/eNpLzkksLlZwVKhWqAUAF10DsA=='
usage(args)
Usage information for the KrokiEncoder as a standalone application."
Args:
args
(list): argument list in order: appname, filename, dia, ext
main(args)
Starting the KrokiEncoder as standalone application using command line options. Can be directly called programatically like this:
Args:
args
(list): argument list in order: appname, filename, dia, ext
import KrokiEncoder
KrokiEncoder.main([None,'diagram.pml','plantuml','png'])
Here an example for converting a PlantUML file into a PNG image using the command line application interface:
$ KrokiEncoder.py diagram.pml plantuml png
Thereafter the file diagram.png
should be in parallel to the file diagram.pml
.
here a file diagram.pml
with the following content and below the output:
@startuml
class A {
var1
method1()
}
class B {
var2
method2()
}
A -> B
@enduml
Class to encode and decode diagram code using the https://kroki.io web service.
Here the methods of the class:
@startuml
class KrokiEncoder {
dia2file()
dia2kroki()
kroki2dia()
text2kroki()
}
@enduml
dia2file(diafile, dia='ditaa', ext='png', imagefile='')
Converts a diagram file to an image file.
Args:
diafile
(string): a diagram file, for instance with the pml extension for PlantUML code, defaults to Nonedia
(string): diagram type, either 'ditaa', 'plantuml', 'erd' or 'graphviz', defaults to 'ditaa'ext
(string): file extension, either 'png', 'svg' or 'pdf', not all extensions are supported for all diagram types, defaults to 'png'imagefile
(string): a output filename for the image file, if not given the diagram imagefile will have the basename of the diagram file nut with the image extension.
Returns: None
dia2kroki(filename, dia='ditaa', ext='png')
Converts a diagram file to a Kroki URL
Args:
filename
(string): a diagram file, for instance with the pml extension for PlantUML code, defaults to Nonedia
(string): diagram type, either 'ditaa', 'plantuml', 'erd' or 'graphviz', defaults to 'ditaa'ext
(string): file extension, either 'png', 'svg' or 'pdf', not all extensions are supported for all diagram types, defaults to 'png'
Returns: Kroki-URL (string)
kroki2dia(url)
Converts a Kroki URL back to diagram code.
Args:
url
(string): a kroki URL like https://kroki.io/plantuml/svg/eNpLzkksLlZwVOBKBjOcoLQzl6OCrhaQ66Sga6fgDADcPwn7, defaults to None
Returns: diagram code (string)
Examples:
import sys, os
sys.path.append(os.path.join(os.getcwd(),".."))
from KrokiEncoder import KrokiEncoder
kroki=KrokiEncoder()
text=kroki.kroki2dia('https://kroki.io/plantuml/svg/eNpLzkksLlZwVKhWqOXiSgZznCAcRwVdLQUnAJ-uCKI=')
print(text)
text2kroki(text, dia='ditaa', ext='png')
Converts a given diagram text to a Kroki URL.
Args:
text
(string): diagram text as string, for instance PlantUML code, defaults to Nonedia
(string): diagram type, either 'ditaa', 'plantuml', 'erd' or 'graphviz', defaults to 'ditaa'ext
(string): file extension, either 'png', 'svg' or 'pdf', not all extensions are supported for all diagram types, defaults to 'png'
Returns: Kroki-URL (string)
This file was automatically generated via lazydocs.