Hello,
I’m using drawables for different parts of a UI “toolbar” called “MainToolbar” in my code.
I have a drawable “button” called “TrayToggle” that updates a global boolean called “show_tray” when clicked.
When I click this button it runs the following function (irrelevant code removed):
def DrawTrayGraphics(self, show_tray):
Rhino.RhinoApp.WriteLine("Draw Tray Graphics Executed")
Rhino.RhinoApp.WriteLine("show tray: " + str(show_tray))
self.show_tray = show_tray
# Create Background Tray Graphics
try:
if show_tray:
# Draw Background Tray Graphics
self.graphics.FillPath(brush_3, path_3) # Draw Tray
self.graphics.FillPath(g_brush_tb, path_3) # Draw Main Toolbar Shadow On Tray
else:
pass
except Exception as ex:
print(ex)
Rhino.RhinoApp.WriteLine("Draw Tray Graphics Completed")
MainToolbar Class (relevant code):
# Code For The Main Toolbar UI
class MainToolbar(Eto.Forms.Form):
def __init__(self):
super().__init__()
# Set Form General Settings
self.Title = "Main Toolbar"
self.tray_toggle = TrayToggle(self) # Create Instance Of Tray Toggle Tab/Button
# Subscribe DrawTrayGraphics to the OnMouseDown event of TrayToggle
self.tray_toggle.MouseDown += self.DrawTrayGraphics
def CreateBackgroundUI():
self.DrawTrayGraphics(show_tray)
self.DrawBackgroundGraphics() # Call The Function That Creates The Graphics
# Add Items To Layout
self.layout = Eto.Forms.PixelLayout()
# Add the Tray Toggle Control
self.layout.Add(self.tray_toggle, ((self.Width / 2) - (self.tray_toggle.Size.Width / 2)), tray_height - self.tray_toggle.Size.Height / 2) # Center On Form And Pass In Tray Toggle Button Size
self.Content = self.layout
CreateBackgroundUI()
DrawTrayGraphics relationship to MainToolbar Class:
# Code For The Main Toolbar UI
class MainToolbar(Eto.Forms.Form):
def __init__(self):
super().__init__()
# Set Form General Settings
self.Title = "Main Toolbar"
def CreateBackgroundUI():
def DrawTrayGraphics(self, show_tray):
However, I’m struggling in this regard:
my layout content exists in my MainToolbar class.
So how do I update the MainToolbar class layout to show/hide the tray graphics?
Or is the issue I need to have a seperate layout in my DrawTrayGraphics def and hide/show that instead?
Or do I just need to subscribe to the event somehow? I’m unsure how do this across classes.
I’m a bit confused and have tried a lot of things without success.
Currently in my code the show_tray boolean does work but the graphics are only draw either shown or “hidden” aka not drawn the 1st time the script is run but not dynamically each time the show_tray boolean changes it’s value from the TrayToggle button press.
The code is rather long which is why I only included these pieces where the “communication/update” needs to happen.
Here’s what the hidden tray state looks like:
Here’s the hover state of the TrayToggle button:
Here’s what the shown tray state looks like:
Thank you all for the help!