@@ -21,20 +21,60 @@ def init_app(self):
21
21
"""
22
22
Called as the application is being initialized
23
23
"""
24
-
25
24
# first, we use the special import_module command to access the app module
26
25
# that resides inside the python folder in the app. This is where the actual UI
27
26
# and business logic of the app is kept. By using the import_module command,
28
27
# toolkit's code reload mechanism will work properly.
29
28
app_payload = self .import_module ("app" )
30
29
31
- # now register a *command*, which is normally a menu entry of some kind on a Shotgun
32
- # menu (but it depends on the engine). The engine will manage this command and
33
- # whenever the user requests the command, it will call out to the callback.
30
+ # now register a panel, this is to tell the engine about the our panel ui
31
+ # that the engine can automatically create the panel - this happens for
32
+ # example when a saved window layout is restored in Nuke or at startup.
33
+ self ._unique_panel_id = self .engine .register_panel (self .create_panel )
34
+
35
+ # keep track of the last dialog we have created
36
+ # in order to support the DIALOG mode for the navigate() method
37
+ self ._current_dialog = None
38
+
39
+ # also register a menu entry on the shotgun menu so that users
40
+ # can launch the panel
41
+ self .engine .register_command ("Shotgun Chat..." ,
42
+ self .create_panel ,
43
+ {"type" : "panel" ,
44
+ "short_name" : "shotgun_chat" })
34
45
35
- # first, set up our callback, calling out to a method inside the app module contained
36
- # in the python folder of the app
37
- menu_callback = lambda : app_payload .dialog .show_dialog (self )
46
+ def create_dialog (self ):
47
+ """
48
+ Shows the panel as a dialog.
49
+
50
+ Contrary to the create_panel() method, multiple calls
51
+ to this method will result in multiple windows appearing.
52
+
53
+ :returns: The widget associated with the dialog.
54
+ """
55
+ app_payload = self .import_module ("app" )
56
+ widget = self .engine .show_dialog ("Chat" , self , app_payload .AppDialog )
57
+ self ._current_dialog = widget
58
+ return widget
38
59
39
- # now register the command with the engine
40
- self .engine .register_command ("Show Starter Template App..." , menu_callback )
60
+ def create_panel (self ):
61
+ """
62
+ Shows the UI as a panel.
63
+ Note that since panels are singletons by nature,
64
+ calling this more than once will only result in one panel.
65
+
66
+ :returns: The widget associated with the panel.
67
+ """
68
+ app_payload = self .import_module ("app" )
69
+
70
+ # start the UI
71
+ try :
72
+ widget = self .engine .show_panel (self ._unique_panel_id , "Chat" , self , app_payload .AppDialog )
73
+ except AttributeError , e :
74
+ # just to gracefully handle older engines and older cores
75
+ self .log_warning ("Could not execute show_panel method - please upgrade "
76
+ "to latest core and engine! Falling back on show_dialog. "
77
+ "Error: %s" % e )
78
+ widget = self .create_dialog ()
79
+
80
+ return widget
0 commit comments