from juce_init import START_JUCE_COMPONENT import popsicle as juce class ChangeRobot(juce.Component): backgroundColour = juce.Colours.lightblue textColour = juce.Colours.black robots = [] robotsLabel = juce.Label("", "Выберите робота") robotsRadio = [] robotsControls = [robotsLabel] + robotsRadio robotButtonsId = 1001 def __init__(self, robots, updateRobot): super().__init__() self.robots = robots or [] self.updateRobot = updateRobot for r in self.robots: self.robotsRadio.append( juce.ToggleButton(r["name"]), ) self.robotsControls = [self.robotsLabel] + self.robotsRadio for s in self.robotsControls: self.addAndMakeVisible(s) for s in self.robotsRadio: s.setRadioGroupId(self.robotButtonsId, juce.dontSendNotification) s.onClick = self.updateToggleState s.setClickingTogglesState(True) def paint(self, g: juce.Graphics): g.fillAll(self.backgroundColour) for i, s in enumerate(self.robotsControls): s.setColour(s.textColourId, self.textColour) if hasattr(s, "tickDisabledColourId"): s.setColour(s.tickColourId, self.textColour) s.setColour(s.tickDisabledColourId, self.textColour) s.setBounds(10 if i == 0 else 20, (i * 20), self.getWidth() - 20, 20) def updateToggleState(self): for i, s in enumerate(self.robotsRadio): if s.getToggleState() == True: if self.updateRobot: self.updateRobot(self.robots[i]) else: print(self.robots[i]) break class RightPanel(juce.Component): def __init__(self, panels): super().__init__() self.panels = panels for p in self.panels: self.addAndMakeVisible(p) def paint(self, g): g.fillAll(juce.Colours.blue) def resized(self): bounds = self.getLocalBounds() for p in self.panels: p.setBounds( bounds.removeFromTop(self.proportionOfHeight(1 / len(self.panels))) ) pass class MainPanel(juce.Component): def __init__(self): super().__init__() def paint(self, g): g.fillAll(juce.Colours.hotpink) class MainContentComponent(juce.Component): def __init__(self, **kwargs): super().__init__() robotArgs = kwargs.get("robotPanel") robotPanel = ChangeRobot(**robotArgs) self.rightPanel = RightPanel(panels=[robotPanel]) self.mainPanel = MainPanel() self.addAndMakeVisible(self.rightPanel) self.addAndMakeVisible(self.mainPanel) self.setSize(800, 600) # self.setResizable(False, False) def paint(self, g): g.fillAll( self.getLookAndFeel().findColour(juce.ResizableWindow.backgroundColourId) ) def resized(self): bounds = self.getLocalBounds() self.rightPanel.setBounds( bounds.removeFromRight( self.proportionOfWidth(0.25), ), ) self.mainPanel.setBounds(bounds) if __name__ == "__main__": START_JUCE_COMPONENT(MainContentComponent, name="ROBOT GUI")