App
Bases: _Plugin
Bip Application class.
The App class provides convenient methods for creating a well-integrated
Bip application. It comes with the following features:
- Easy access to Bip data via link
.
- Bip-flavored window embedment, using Bip Qt stylesheet.
- Threaded loading.
- Support for hosted and standalone execution contexts.
- Bip widgets (MessageBox, Notifications...).
- Hosted address retrieving (see get_address()
method).
- Preset logger.
The recommended way to create a Bip application is to subclass and extend the App class. Then the instantiation of the App is handled by the sdk runner, which also executes the application.
Warning
Unless you are debugging,the subclassed application must be instantiated by the sdk runner.
This class provides special methods to override, such as init()
and
load()
, which are respectively called during the threaded
initialization (init()
), and immediately after (load()
)
When executed, the application will automatically perform the following actions: - Instance arguments validity - Check connection with database - Retrieve the current user - Retrieve the user's active project - Retrieve the server configuration
Examples:
from bip.sdk import App, run
from myapp.ui import Widget
from myapp.api import get_data
class SampleApp(App):
name = "Sample"
slug = "sample"
version = "v0.0.1"
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.widget = Widget()
self.set_widget(self.widget)
self.data = None
def init(self, callback):
# Executed at initialization (threaded).
self.data = get_data()
def load(self):
# Executed after initialization.
self.widget.load(self.data)
app = run(SampleApp)
See the demo Chocolatine application for a complete example: https://git.blinkink.co.uk/bip/apps/chocolatine.
Todo
Find a better error handling system. For now, common errors like
PermissionError and Connection error are handled in two different ways:
- When not threaded: with from @error_handler (which requires the
widget to have self.app).
- When threaded: with the Worker failed
signal.
Attributes:
Name | Type | Description |
---|---|---|
resizable |
bool
|
(class attribute) If True, the window can be resized. Defaults to |
closable |
bool
|
(class attribute) If True, the window can be closed. Defaults to |
minimizable |
bool
|
(class attribute) If True, the window can be minimized. Defaults to |
maximizable |
bool
|
(class attribute) If True, the window can be maximized. |
use_header |
bool
|
(class attribute) If True, the default Bip application window header is used. Defaults to |
floating_header |
bool
|
(class attribute) If True, the window header overlaps the main widget. Defaults to |
supported_contexts |
list
|
(class attribute) List of supported contexts for the application. Allowed context are:
- |
context |
str
|
Current execution context. Accepted values are |
logger |
Logger
|
Application logger. If the app has been executed with the sdk runner, the logger is handled by |
host |
Host
|
If the application is hosted or remote, Host plugin of the current DCC, else None. |
current_user |
User
|
Currently logged in Bip user. |
active_project |
Project
|
Active project of the currently logged in Bip user. |
config |
dict
|
Plugin configuration dictionary, if the plugin descriptor defines a config template. |
mapping |
dict
|
Plugin mapping dictionary, if the plugin descriptor defines a mapping template. |
default_settings |
dict
|
Plugin default settings dictionary, if the plugin descriptor defines a setting template. |
settings |
dict
|
Plugin user settings dictionary, if the plugin descriptor defines a setting template. |
Warning
If you extend the __init__
method behaviour, bear in mind that it
is run before the application gets executed ('execute()'). That means:
- The window is not yet shown, and any long operation ran there would be invisible, which is a bad UX design.
- The connection with the database has not yet been verified, which
means that any
link
call performed here could lead to an uncaught exception. - The attributes
current_user
,active_project
andconfig
are still undefined.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context |
str
|
Execution context. Accepted values are |
required |
host |
str
|
If the application is hosted, id of the host plugin to be run. |
None
|
silent |
bool
|
If |
False
|
Source code in client/bip/sdk/app.py
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 |
|
hosted
property
Is the application hosted.
The application is hosted if the application is executed from a DCC runtime.
Returns:
Name | Type | Description |
---|---|---|
bool |
True if hosted, False otherwise. |
last_used_version
property
Last version used.
Gives the latest version of the application that has been successfully started on the current machine.
If BIP_DEBUG_PLUGIN
is on, nothing is returned
Returns:
Name | Type | Description |
---|---|---|
str |
Version number. |
silent
property
Is the application silent.
If the application has been set to silent, is it running without showing the window.
Returns:
Name | Type | Description |
---|---|---|
bool |
True if silent, False otherwise. |
stylesheet
property
Complete stylesheet.
The complete compiled application stylesheet. It includes the SDK stylesheets, the bip.uink stylesheets as well as the custom stylesheet if any.
Returns:
Name | Type | Description |
---|---|---|
str |
Raw stylesheet. |
adjust_size()
Adjust the window size.
Source code in client/bip/sdk/app.py
335 336 337 |
|
center()
Center the window.
Source code in client/bip/sdk/app.py
331 332 333 |
|
close()
Close the window.
Source code in client/bip/sdk/app.py
327 328 329 |
|
close_loading()
Closes the currently opened loading overlay.
Source code in client/bip/sdk/app.py
476 477 478 |
|
close_popup()
Close the currently opened popup overlay.
Source code in client/bip/sdk/app.py
462 463 464 465 |
|
confirm_dialog(title, description, details=None, mode=Dialog.DOUBLE, choices=None, closable=True, overlay=True, hidden_details=False)
Convenient preset shortcut to App.dialog()
.
Level is set to Dialog.WARNING
and mode is set to Dialog.DOUBLE
.
Source code in client/bip/sdk/app.py
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 |
|
dialog(title, description, details=None, level=NEUTRAL, mode=Dialog.SINGLE, choices=None, closable=True, overlay=True, hidden_details=False, log=True)
Shows a message dialog.
Tip
- If an Exception is provided to the
details
argument, its traceback is automatically retrieved and added to the details text. - Any dialog message is automatically logged into the application logger. This can be deactivated by setting the log argument to False.
Examples:
Standard:
self.dialog(
title="Hello world",
description="This is a dialog demonstration.",
level=Dialog.INFO
)
Double choices:
title = "Forbidden operation"
description = (
"It is impossible to save this scene because you don't own this scene, "
"do you want to save a new version?"
)
result = self.dialog(
title=title,
description=description,
level=Dialog.WARNING,
mode=Dialog.DOUBLE,
choices=Dialog.YES_NO,
)
if result:
save_up()
Multiple choices:
title = "Save changes?"
description = "The current scene has been modified, what do you want to do?"
choices = {"Save": "save", "Ignore": "ignore", "Cancel": "cancel"}
result = self.dialog(
title=title,
description=description,
mode=Dialog.MULTIPLE,
level=Dialog.WARNING,
choices=choices,
)
if result == "save":
save()
elif result == "cancel":
return
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title |
str
|
Title of the dialog message. |
required |
description |
str
|
Description of the dialog message. |
required |
details |
str or Exception
|
Additional details displayed in a |
None
|
level |
str
|
Level of the dialog. Accepted values are |
NEUTRAL
|
mode |
str
|
Level of the dialog. Accepted values are |
SINGLE
|
choices |
str or dict
|
Button(s) choice(s). They can be a hint or a custom dictionary.
- Hint: Accepted values are |
None
|
closable |
bool
|
If |
True
|
overlay |
bool
|
If |
True
|
hidden_details |
bool
|
If |
False
|
log |
bool
|
If |
True
|
Raises:
Type | Description |
---|---|
TypeError
|
|
ValueError
|
|
Source code in client/bip/sdk/app.py
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 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 |
|
error_dialog(title, description, details=None, mode=Dialog.SINGLE, choices=None, closable=True, overlay=True, hidden_details=False)
Convenient preset shortcut to App.dialog()
.
Level is set to Dialog.ERROR
.
Source code in client/bip/sdk/app.py
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 |
|
execute()
Execute (start) the application.
Executing the application shows the window if the application is not silent, and performs the internal and custom initialization operation.
Warning
This can only be run once.
Source code in client/bip/sdk/app.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
get_address()
Returns a pink.Address object.
If the application is hosted, the Address object inspects the file currently loaded in the host, if any, and returns its Bip representation, if the file is a tracked Version.
Info
See the documentation of pink.Address
for further information.
Returns:
Name | Type | Description |
---|---|---|
Address |
Address object from the file currently loaded in the host. |
|
None |
If the application is not hosted. |
Source code in client/bip/sdk/app.py
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 |
|
get_changelog()
Get the extracted changelog.
If the package root file CHANGELOG.md is correctly formatted, a dict of the changelog for each version is returned.
The dictionary is structured like so:
{"v0.0.1":
{
"date": _current_date,
"url": _current_url,
"content": content
},
...
}
Returns:
Name | Type | Description |
---|---|---|
dict |
Collection of changelog data. |
Source code in client/bip/sdk/app.py
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 |
|
get_config()
Convenient shortcut to `link.config.get()
Source code in client/bip/sdk/app.py
808 809 810 |
|
get_projects()
Convenient shortcut to `link.project.get()
Source code in client/bip/sdk/app.py
800 801 802 |
|
get_users()
Convenient shortcut to `link.user.get()
Source code in client/bip/sdk/app.py
804 805 806 |
|
hide()
Hide the window.
Source code in client/bip/sdk/app.py
323 324 325 |
|
info_dialog(title, description, details=None, mode=Dialog.SINGLE, choices=None, closable=True, overlay=True, hidden_details=False)
Convenient preset shortcut to App.dialog()
.
Level is set to Dialog.INFO
.
Source code in client/bip/sdk/app.py
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 |
|
init(callback)
Overridable method for executing operation during initialization.
This is the recommended way to perform startup operation, such as data retrieving. It is particularly encouraged if this operation is time-consuming.
This method is executed at the end of the threaded loading, which means that at this smodele, the application window is shown and the loading overlay is visible, giving the user some visual feedback on what is going on.
The callback can be used to update the text of the loading overlay.
Info
Raising exception is the recommended way to properly interrupt the initialization.
Examples:
def init(self, callback):
callback("Loading data")
data = my_api.get()
callback("Inspect data")
if not my_api.inspect():
raise ValueError("The is are not valid")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
callback |
func(`str
|
Updates the loading overlay with a custom text. The callback is passed to the method by the execution thread. |
required |
Source code in client/bip/sdk/app.py
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 |
|
load()
Overridable method for executing operation after initialization.
This is the recommended way to perform post-initialization operation. This is
executed after the init()
method, and the main difference with init()
is
that load()
is not threaded.
Tip
The execution of this method is done is the main thread, which means it can be used to update the UI safely.
Source code in client/bip/sdk/app.py
270 271 272 273 274 275 276 277 278 279 280 281 |
|
neutral_dialog(title, description, details=None, mode=Dialog.SINGLE, choices=None, closable=True, overlay=True, hidden_details=False)
Convenient preset shortcut to App.dialog()
.
Level is set to Dialog.NEUTRAL
.
Source code in client/bip/sdk/app.py
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 |
|
notify(text, subtext=None, level=NEUTRAL, position=BOTTOM, auto_close=5)
Show an overlay notification.
Warning
Experimental feature: does not seem to work in hosted context.
NEUTRAL = NEUTRAL ERROR = ERROR WARNING = WARNING INFO = INFO SUCCESS = SUCCESS
Position
TOP = TOP MIDDLE = MIDDLE BOTTOM = BOTTOM
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
Text of the notification. |
required |
subtext |
str
|
Additional text. |
None
|
level |
str
|
Level of the notification. Accepted values are |
NEUTRAL
|
position |
str
|
Vertical alignment. Accepted values are |
BOTTOM
|
auto_close |
int
|
Auto-close delay value, in seconds. If set to 0, auto-close is disabled. Defaults to 5. |
5
|
Source code in client/bip/sdk/app.py
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 |
|
popup(widget, escape_allowed=True, escape_callback=None, expand=False, margin=None, transparent=False)
Add a popup widget.
A popup widget is a centered overlay on top of the main window. A typical use case is for modal dialogs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
QWidget
|
Widget to place in the overlay. |
required |
escape_allowed |
bool
|
If True, the overlay can be closed by clicking outside. Defaults to |
True
|
escape_callback |
func
|
If provided and if |
None
|
Source code in client/bip/sdk/app.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 |
|
quit()
Quit the application.
Source code in client/bip/sdk/app.py
369 370 371 372 373 374 375 376 377 |
|
refresh_active_project()
Force get currently logged-in user's active project.
It can be of use if an application is sleeping in the background and the active project could have changed between two calls.
Source code in client/bip/sdk/app.py
837 838 839 840 841 842 843 844 845 846 |
|
refresh_current_user()
Force get currently logged-in user.
It can be of use if an application is sleeping in the background and the current user could have changed between two calls.
Source code in client/bip/sdk/app.py
829 830 831 832 833 834 835 |
|
remote_order(order)
Overridable method for interpreting remote orders.
If a remote application needs to receive user instructions from the remote host during runtime,
those orders, sent with mink.remote.send()
, would be sent to this method.
Overriding with a case per order is the recommended way to apply those orders to the application.
Source code in client/bip/sdk/app.py
848 849 850 851 852 853 854 855 856 857 858 |
|
set_title(title)
Set the header title.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title |
str
|
Header title. |
required |
Source code in client/bip/sdk/app.py
302 303 304 305 306 307 308 |
|
set_widget(widget)
Set the main widget of the window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
QWidget
|
Main widget. |
required |
Source code in client/bip/sdk/app.py
283 284 285 286 287 288 289 290 |
|
set_window_size(height, width, centered=False)
Set the window size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width |
int
|
Width in pixels. |
required |
height |
int
|
Height in pixels. |
required |
centered |
bool
|
If True, the window will be centered relatively to its previous position. Defaults to |
False
|
Source code in client/bip/sdk/app.py
292 293 294 295 296 297 298 299 300 |
|
set_window_title(title)
Set the window title.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title |
str
|
Window title. |
required |
Source code in client/bip/sdk/app.py
310 311 312 313 314 315 316 |
|
show()
Show the window.
Source code in client/bip/sdk/app.py
318 319 320 321 |
|
show_changelog()
Show the changelog popup.
Source code in client/bip/sdk/app.py
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 |
|
show_loading(title, subtext=None)
Show a loading overlay.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title |
str
|
Title of the overlay. |
required |
subtext |
str
|
Subtext (description) of the overlay. |
None
|
Source code in client/bip/sdk/app.py
467 468 469 470 471 472 473 474 |
|
success_dialog(title, description, details=None, mode=Dialog.SINGLE, choices=None, closable=True, overlay=True, hidden_details=False)
Convenient preset shortcut to App.dialog()
.
Level is set to Dialog.SUCCESS
.
Source code in client/bip/sdk/app.py
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 |
|
warning_dialog(title, description, details=None, mode=Dialog.SINGLE, choices=None, closable=True, overlay=True, hidden_details=False)
Convenient preset shortcut to App.dialog()
.
Level is set to Dialog.WARNING
.
Source code in client/bip/sdk/app.py
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 |
|