Objects
Object Creation
object_from_library
src.drawpyo.diagram.objects.object_from_library(library, obj_name, **kwargs)
This function generates an Object from a library. The library can either be custom imported from a TOML or the name of one of the built-in Draw.io libraries.
Any keyword arguments that can be passed in to a Object creation can be passed into this function and it will format the base object. These keyword arguments will overwrite any attributes defined in the library.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
library |
str or dict
|
The library containing the object |
required |
obj_name |
str
|
The name of the object in the library to generate |
required |
Returns:
Name | Type | Description |
---|---|---|
Object |
An object with the style from the library |
Source code in src/drawpyo/diagram/objects.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
Object
src.drawpyo.diagram.objects.Object
Bases: DiagramBase
The Object class is the base object for all shapes in Draw.io.
More information about objects are in the Usage documents at Usage - Objects.
Source code in src/drawpyo/diagram/objects.py
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 |
|
center_position
property
writable
The position of the object on the page. This is the center of the object. It's set with a tuple of ints, X and Y respectively.
(X, Y)
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple of ints describing the center position of the object |
dashPattern
property
writable
This is one of the properties that defines the line style. Along with dashed, it can be overriden by setting line_pattern or set directly.
Returns:
Name | Type | Description |
---|---|---|
str |
What style the object stroke is dashed with. |
dashed
property
writable
This is one of the properties that defines the line style. Along with dashPattern, it can be overriden by setting line_pattern or set directly.
Returns:
Name | Type | Description |
---|---|---|
str |
Whether the object stroke is dashed. |
height
property
writable
This property makes geometry.height available to the owning class for ease of access.
line_pattern
property
writable
Two properties are enumerated together into line_pattern: dashed and dashPattern. line_pattern simplifies this with an external database that contains the dropdown options from the Draw.io app then outputs the correct combination of dashed and dashPattern.
However in some cases dashed and dashpattern need to be set individually, such as when formatting from a style string. In that case, the setters for those two attributes will disable the other.
Returns:
Name | Type | Description |
---|---|---|
str |
The line style |
parent
property
writable
The parent object that owns this object. This is usually a container of some kind but can be any other object.
Returns:
Name | Type | Description |
---|---|---|
Object |
the parent object. |
position
property
writable
The position of the object on the page. This is the top left corner. It's set with a tuple of ints, X and Y respectively.
(X, Y)
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple of ints describing the top left corner position of the object |
position_rel_to_parent
property
writable
The position of the object relative to its parent (container). If there's no parent this will be relative to the page. This is the top left corner. It's set with a tuple of ints, X and Y respectively.
(X, Y)
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple of ints describing the top left corner position of the object |
width
property
writable
This property makes geometry.width available to the owning class for ease of access.
xml
property
Returns the XML object for the Object: the opening tag with the style attributes, the value, and the closing tag.
Example:
Returns:
Name | Type | Description |
---|---|---|
str |
A single XML tag containing the object name, style attributes, and a closer. |
__init__(value='', position=(0, 0), **kwargs)
A Object can be initialized with as many or as few of its styling attributes as is desired.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
str
|
The text to fill the object with. Defaults to "". |
''
|
position |
tuple
|
The position of the object in pixels, in (X, Y). Defaults to (0, 0). |
(0, 0)
|
Other Parameters:
Name | Type | Description |
---|---|---|
position_rel_to_parent |
tuple
|
The position of the object relative to the parent in pixels, in (X, Y). # TODO document |
width |
int
|
The width of the object in pixels. Defaults to 120. |
height |
int
|
The height of the object in pixels. Defaults to 80. |
parent |
Object
|
The parent object (container, etc) of this object. Defaults to None. # TODO document |
children |
array of Objects
|
The subobjects to add to this object as a parent. Defaults to []. # TODO document |
autosize_to_children |
bool
|
Whether to autoexpand when child objects are added. Defaults to false. # TODO document |
autocontract |
bool
|
Whether to contract to fit the child objects. Defaults to false. |
autosize_margin |
int
|
What margin in pixels to leave around the child objects. Defaults to 20px. # TODO document |
template_object |
Object
|
Another object to copy the style_attributes from |
rounded |
bool
|
Whether to round the corners of the shape |
whiteSpace |
str
|
white space |
fillColor |
str
|
The object fill color in a hex color code (#ffffff) |
opacity |
(int
|
The object's opacity, 0-100 |
strokeColor |
The object stroke color in a hex color code (#ffffff) |
|
glass |
bool
|
Apply glass styling to the object |
shadow |
bool
|
Add a shadow to the object |
sketch |
bool
|
Add sketch styling to the object |
comic |
bool
|
Add comic styling to the object |
line_pattern |
str
|
The stroke style of the object. |
Source code in src/drawpyo/diagram/objects.py
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
add_in_edge(edge)
Add an edge into the object. If an edge is created with this object set as the target this function will be called automatically.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edge |
Edge
|
An Edge object ending at this object |
required |
Source code in src/drawpyo/diagram/objects.py
588 589 590 591 592 593 594 |
|
add_object(child_object)
Adds a child object to this object, sets the child objects parent, and autoexpands this object if set to.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
child_object |
Object
|
object to add as a child |
required |
Source code in src/drawpyo/diagram/objects.py
469 470 471 472 473 474 475 476 477 478 |
|
add_out_edge(edge)
Add an edge out of the object. If an edge is created with this object set as the source this function will be called automatically.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edge |
Edge
|
An Edge object originating at this object |
required |
Source code in src/drawpyo/diagram/objects.py
572 573 574 575 576 577 578 |
|
create_from_library(library, obj_name)
classmethod
This function generates a Object from a library. The library can either be custom imported from a TOML or the name of one of the built-in Draw.io libraries.
Any keyword arguments that can be passed in to a Object creation can be passed into this function and it will format the base object. However, the styling in the library will overwrite that formatting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
library |
str or dict
|
The library containing the object |
required |
obj_name |
str
|
The name of the object in the library to generate |
required |
Returns:
Name | Type | Description |
---|---|---|
Object |
An object with the style from the library |
Source code in src/drawpyo/diagram/objects.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
create_from_style_string(style_string)
classmethod
Objects can be instantiated from a style string. These strings are most easily found in the Draw.io app, by styling an object as desired then right-clicking and selecting "Edit Style". Copying that text into this function will generate an object styled the same.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
style_string |
str
|
A Draw.io generated style string. |
required |
Returns:
Name | Type | Description |
---|---|---|
Object |
An object formatted with the style string |
Source code in src/drawpyo/diagram/objects.py
219 220 221 222 223 224 225 226 227 228 229 230 |
|
create_from_template_object(template_object, value=None, position=None, page=None)
classmethod
Object can be instantiated from another object. This will initialize the Object with the same formatting, then set a new position and value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
template_object |
Object
|
Another drawpyo Object to use as a template |
required |
value |
str
|
The text contents of the object. Defaults to None. |
None
|
position |
tuple
|
The position where the object should be placed. Defaults to (0, 0). |
None
|
page |
Page
|
The Page object to place the object on. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Object |
The newly created object |
Source code in src/drawpyo/diagram/objects.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|
format_as_library_object(library, obj_name)
This function applies the style from a library to an existing object. The library can either be custom imported from a TOML or the name of one of the built-in Draw.io libraries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
library |
str or dict
|
The library containing the object |
required |
obj_name |
str
|
The name of the object in the library to generate |
required |
Source code in src/drawpyo/diagram/objects.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
move_wo_children(position)
Move the parent object relative to the page without moving the children relative to the page.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position |
Tuple of Ints
|
The target position for the parent object. |
required |
Source code in src/drawpyo/diagram/objects.py
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
|
remove_in_edge(edge)
Remove an edge into the object. If an edge linked to this object has the target changed or removed this function will be called automatically.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edge |
Edge
|
An Edge object ending at this object |
required |
Source code in src/drawpyo/diagram/objects.py
596 597 598 599 600 601 602 |
|
remove_object(child_object)
Removes a child object from this object, clears the child objects parent, and autoexpands this object if set to.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
child_object |
Object
|
object to remove as a child |
required |
Source code in src/drawpyo/diagram/objects.py
480 481 482 483 484 485 486 487 488 489 |
|
remove_out_edge(edge)
Remove an edge out of the object. If an edge linked to this object has the source changed or removed this function will be called automatically.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edge |
Edge
|
An Edge object originating at this object |
required |
Source code in src/drawpyo/diagram/objects.py
580 581 582 583 584 585 586 |
|
resize_to_children()
If the object contains children (is a container, parent, etc) then expand the size and position to fit all of the children.
By default this function will never shrink the size of the object, only expand it. The contract input can be set for that behavior.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
contract |
bool
|
Contract the parent object to hug the children. Defaults to False. |
required |
Source code in src/drawpyo/diagram/objects.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
|
update_parent()
If a parent object is set and the parent is set to autoexpand, then autoexpand it.
Source code in src/drawpyo/diagram/objects.py
491 492 493 494 495 496 497 498 499 500 501 |
|
Group
src.drawpyo.diagram.objects.Group
This class allows objects to be grouped together. It then provides a number of geometry functions and properties to move the entire group around.
Currently this object doesn't replicate any of the functionality of groups in the Draw.io app but it may be extended to have that capability in the future.
Source code in src/drawpyo/diagram/objects.py
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 |
|
bottom
property
The bottommost Y-coordinate of the objects in the group
Returns:
Name | Type | Description |
---|---|---|
int |
The bottom edge of the group |
center_position
property
writable
The center position of the group. Returns a tuple of ints, with the X and Y coordinate. When this property is set, the coordinates of every object in the group are updated.
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple of ints (X, Y) |
height
property
The height of all the objects in the group
Returns:
Name | Type | Description |
---|---|---|
int |
Height of the group |
left
property
The leftmost X-coordinate of the objects in the group
Returns:
Name | Type | Description |
---|---|---|
int |
Left edge of the group |
position
property
writable
The top left position of the group. Returns a tuple of ints, with the X and Y coordinate. When this property is set, the coordinates of every object in the group are updated.
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple of ints (X, Y) |
right
property
The rightmost X-coordinate of the objects in the group
Returns:
Name | Type | Description |
---|---|---|
int |
Right edge of the group |
size
property
The size of the group. Returns a tuple of ints, with the width and height.
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple of ints (width, height) |
top
property
The topmost Y-coordinate of the objects in the group
Returns:
Name | Type | Description |
---|---|---|
int |
Top edge of the group |
width
property
The width of all the objects in the group
Returns:
Name | Type | Description |
---|---|---|
int |
Width of the group |
add_object(object)
Adds one or more objects to the group and updates the geometry of the group.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
object |
Object or list
|
Object or list of objects to be added to the group |
required |
Source code in src/drawpyo/diagram/objects.py
637 638 639 640 641 642 643 644 645 646 647 648 |
|
update_geometry()
Update the geometry of the group. This includes the left and top coordinates and the width and height of the entire group.
Source code in src/drawpyo/diagram/objects.py
650 651 652 653 654 655 |
|