diff --git a/client_socket.py b/client_socket.py index 12da69d..50196bc 100644 --- a/client_socket.py +++ b/client_socket.py @@ -58,7 +58,6 @@ class SocketRobotArm: threading.Thread(target=self.run_pybullet, daemon=True).start() - print((self.port, self.host)) self.socket.connect((self.host, self.port)) self.cycle_base() diff --git a/gui_test.py b/gui_test.py index 477f0e6..9c0d76a 100644 --- a/gui_test.py +++ b/gui_test.py @@ -2,21 +2,22 @@ from juce_init import START_JUCE_COMPONENT import popsicle as juce -class SidePanel(juce.Component): +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=[]): + def __init__(self, robots, updateRobot): super().__init__() - self.robots = robots + self.robots = robots or [] + self.updateRobot = updateRobot for r in self.robots: self.robotsRadio.append( @@ -46,34 +47,50 @@ class SidePanel(juce.Component): def updateToggleState(self): for i, s in enumerate(self.robotsRadio): if s.getToggleState() == True: - print(self.robots[i]) - break; + 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): - sliders = [] - def __init__(self): super().__init__() - for _ in range(5): - slider = juce.Slider() - slider.setTextBoxStyle( - juce.Slider.TextEntryBoxPosition.NoTextBox, True, 0, 0 - ) - - self.sliders.append(slider) - self.addAndMakeVisible(slider) - def paint(self, g): g.fillAll(juce.Colours.hotpink) class MainContentComponent(juce.Component): - def __init__(self, robots): + def __init__(self, **kwargs): super().__init__() - self.rightPanel = SidePanel(robots) + robotArgs = kwargs.get("robotPanel") + robotPanel = ChangeRobot(**robotArgs) + + self.rightPanel = RightPanel(panels=[robotPanel]) self.mainPanel = MainPanel() self.addAndMakeVisible(self.rightPanel) @@ -89,7 +106,11 @@ class MainContentComponent(juce.Component): def resized(self): bounds = self.getLocalBounds() - self.rightPanel.setBounds(bounds.removeFromRight(self.proportionOfWidth(0.25))) + self.rightPanel.setBounds( + bounds.removeFromRight( + self.proportionOfWidth(0.25), + ), + ) self.mainPanel.setBounds(bounds) diff --git a/juce_init.py b/juce_init.py index 113412d..4963fc1 100644 --- a/juce_init.py +++ b/juce_init.py @@ -8,10 +8,10 @@ from functools import wraps try: - import popsicle as juce + import popsicle as juce except ImportError: - folder = (Path(__file__).parent.parent / "build") + folder = Path(__file__).parent.parent / "build" for ext in ["*.so", "*.pyd"]: path_to_search = folder / "**" / ext for f in glob.iglob(str(path_to_search), recursive=True): @@ -29,16 +29,21 @@ def START_JUCE_COMPONENT(ComponentClass, name, **kwargs): def __init__(self): super().__init__( juce.JUCEApplication.getInstance().getApplicationName(), - juce.Desktop.getInstance().getDefaultLookAndFeel() - .findColour(juce.ResizableWindow.backgroundColourId), + juce.Desktop.getInstance() + .getDefaultLookAndFeel() + .findColour(juce.ResizableWindow.backgroundColourId), juce.DocumentWindow.allButtons, - True) + True, + ) - self.component = ComponentClass(kwargs.get("robots", [])) + self.component = ComponentClass(**kwargs) self.setResizable(True, True) self.setContentNonOwned(self.component, True) - self.centreWithSize(self.component.getWidth(), self.component.getHeight() + self.getTitleBarHeight()) + self.centreWithSize( + self.component.getWidth(), + self.component.getHeight() + self.getTitleBarHeight(), + ) self.setAlwaysOnTop(kwargs.get("alwaysOnTop", False)) self.setVisible(True) @@ -86,7 +91,8 @@ def START_JUCE_COMPONENT(ComponentClass, name, **kwargs): juce.START_JUCE_APPLICATION( DefaultApplication, - catchExceptionsAndContinue=kwargs.get("catchExceptionsAndContinue", False)) + catchExceptionsAndContinue=kwargs.get("catchExceptionsAndContinue", False), + ) def timeit(func): @@ -95,7 +101,9 @@ def timeit(func): start_time = time.perf_counter() result = func(*args, **kwargs) total_time = time.perf_counter() - start_time - print(f'Function {func.__name__} Took {total_time:.4f} seconds') # {args} {kwargs} + print( + f"Function {func.__name__} Took {total_time:.4f} seconds" + ) # {args} {kwargs} return result - return timeit_wrapper \ No newline at end of file + return timeit_wrapper diff --git a/main.py b/main.py index 7dbb860..3273cfb 100644 --- a/main.py +++ b/main.py @@ -2,18 +2,31 @@ import threading from juce_init import START_JUCE_COMPONENT from gui_test import MainContentComponent + class MyApp: robots = [ {"name": "big", "host": "192.168.70.55", "slave_id": 11}, {"name": "small", "host": "192.168.70.65", "slave_id": 22}, ] + selected_robot = 0 def __init__(self): - robot = self.robots[0] - self.start_gui() - - def start_gui(self): - START_JUCE_COMPONENT(MainContentComponent, name="ROBOT GUI", robots=self.robots) - + self.startGui() + + def startGui(self): + START_JUCE_COMPONENT( + MainContentComponent, + name="ROBOT GUI", + robotPanel={ + "robots": self.robots, + "updateRobot": self.updateRobot, + }, + ) + + def updateRobot(self, robot): + if robot in self.robots: + self.selected_robot = robot + + if __name__ == "__main__": MyApp()