robot panel
This commit is contained in:
parent
3a101821b7
commit
8babbd50f5
|
@ -58,7 +58,6 @@ class SocketRobotArm:
|
||||||
|
|
||||||
threading.Thread(target=self.run_pybullet, daemon=True).start()
|
threading.Thread(target=self.run_pybullet, daemon=True).start()
|
||||||
|
|
||||||
print((self.port, self.host))
|
|
||||||
self.socket.connect((self.host, self.port))
|
self.socket.connect((self.host, self.port))
|
||||||
self.cycle_base()
|
self.cycle_base()
|
||||||
|
|
||||||
|
|
57
gui_test.py
57
gui_test.py
|
@ -2,7 +2,7 @@ from juce_init import START_JUCE_COMPONENT
|
||||||
import popsicle as juce
|
import popsicle as juce
|
||||||
|
|
||||||
|
|
||||||
class SidePanel(juce.Component):
|
class ChangeRobot(juce.Component):
|
||||||
backgroundColour = juce.Colours.lightblue
|
backgroundColour = juce.Colours.lightblue
|
||||||
textColour = juce.Colours.black
|
textColour = juce.Colours.black
|
||||||
|
|
||||||
|
@ -14,9 +14,10 @@ class SidePanel(juce.Component):
|
||||||
|
|
||||||
robotButtonsId = 1001
|
robotButtonsId = 1001
|
||||||
|
|
||||||
def __init__(self, robots=[]):
|
def __init__(self, robots, updateRobot):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.robots = robots
|
self.robots = robots or []
|
||||||
|
self.updateRobot = updateRobot
|
||||||
|
|
||||||
for r in self.robots:
|
for r in self.robots:
|
||||||
self.robotsRadio.append(
|
self.robotsRadio.append(
|
||||||
|
@ -46,34 +47,50 @@ class SidePanel(juce.Component):
|
||||||
def updateToggleState(self):
|
def updateToggleState(self):
|
||||||
for i, s in enumerate(self.robotsRadio):
|
for i, s in enumerate(self.robotsRadio):
|
||||||
if s.getToggleState() == True:
|
if s.getToggleState() == True:
|
||||||
|
if self.updateRobot:
|
||||||
|
self.updateRobot(self.robots[i])
|
||||||
|
else:
|
||||||
print(self.robots[i])
|
print(self.robots[i])
|
||||||
break;
|
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):
|
class MainPanel(juce.Component):
|
||||||
sliders = []
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
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):
|
def paint(self, g):
|
||||||
g.fillAll(juce.Colours.hotpink)
|
g.fillAll(juce.Colours.hotpink)
|
||||||
|
|
||||||
|
|
||||||
class MainContentComponent(juce.Component):
|
class MainContentComponent(juce.Component):
|
||||||
def __init__(self, robots):
|
def __init__(self, **kwargs):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.rightPanel = SidePanel(robots)
|
robotArgs = kwargs.get("robotPanel")
|
||||||
|
robotPanel = ChangeRobot(**robotArgs)
|
||||||
|
|
||||||
|
self.rightPanel = RightPanel(panels=[robotPanel])
|
||||||
self.mainPanel = MainPanel()
|
self.mainPanel = MainPanel()
|
||||||
|
|
||||||
self.addAndMakeVisible(self.rightPanel)
|
self.addAndMakeVisible(self.rightPanel)
|
||||||
|
@ -89,7 +106,11 @@ class MainContentComponent(juce.Component):
|
||||||
|
|
||||||
def resized(self):
|
def resized(self):
|
||||||
bounds = self.getLocalBounds()
|
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)
|
self.mainPanel.setBounds(bounds)
|
||||||
|
|
||||||
|
|
||||||
|
|
22
juce_init.py
22
juce_init.py
|
@ -11,7 +11,7 @@ try:
|
||||||
import popsicle as juce
|
import popsicle as juce
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
folder = (Path(__file__).parent.parent / "build")
|
folder = Path(__file__).parent.parent / "build"
|
||||||
for ext in ["*.so", "*.pyd"]:
|
for ext in ["*.so", "*.pyd"]:
|
||||||
path_to_search = folder / "**" / ext
|
path_to_search = folder / "**" / ext
|
||||||
for f in glob.iglob(str(path_to_search), recursive=True):
|
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):
|
def __init__(self):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
juce.JUCEApplication.getInstance().getApplicationName(),
|
juce.JUCEApplication.getInstance().getApplicationName(),
|
||||||
juce.Desktop.getInstance().getDefaultLookAndFeel()
|
juce.Desktop.getInstance()
|
||||||
|
.getDefaultLookAndFeel()
|
||||||
.findColour(juce.ResizableWindow.backgroundColourId),
|
.findColour(juce.ResizableWindow.backgroundColourId),
|
||||||
juce.DocumentWindow.allButtons,
|
juce.DocumentWindow.allButtons,
|
||||||
True)
|
True,
|
||||||
|
)
|
||||||
|
|
||||||
self.component = ComponentClass(kwargs.get("robots", []))
|
self.component = ComponentClass(**kwargs)
|
||||||
|
|
||||||
self.setResizable(True, True)
|
self.setResizable(True, True)
|
||||||
self.setContentNonOwned(self.component, 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.setAlwaysOnTop(kwargs.get("alwaysOnTop", False))
|
||||||
self.setVisible(True)
|
self.setVisible(True)
|
||||||
|
|
||||||
|
@ -86,7 +91,8 @@ def START_JUCE_COMPONENT(ComponentClass, name, **kwargs):
|
||||||
|
|
||||||
juce.START_JUCE_APPLICATION(
|
juce.START_JUCE_APPLICATION(
|
||||||
DefaultApplication,
|
DefaultApplication,
|
||||||
catchExceptionsAndContinue=kwargs.get("catchExceptionsAndContinue", False))
|
catchExceptionsAndContinue=kwargs.get("catchExceptionsAndContinue", False),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def timeit(func):
|
def timeit(func):
|
||||||
|
@ -95,7 +101,9 @@ def timeit(func):
|
||||||
start_time = time.perf_counter()
|
start_time = time.perf_counter()
|
||||||
result = func(*args, **kwargs)
|
result = func(*args, **kwargs)
|
||||||
total_time = time.perf_counter() - start_time
|
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 result
|
||||||
|
|
||||||
return timeit_wrapper
|
return timeit_wrapper
|
21
main.py
21
main.py
|
@ -2,18 +2,31 @@ import threading
|
||||||
from juce_init import START_JUCE_COMPONENT
|
from juce_init import START_JUCE_COMPONENT
|
||||||
from gui_test import MainContentComponent
|
from gui_test import MainContentComponent
|
||||||
|
|
||||||
|
|
||||||
class MyApp:
|
class MyApp:
|
||||||
robots = [
|
robots = [
|
||||||
{"name": "big", "host": "192.168.70.55", "slave_id": 11},
|
{"name": "big", "host": "192.168.70.55", "slave_id": 11},
|
||||||
{"name": "small", "host": "192.168.70.65", "slave_id": 22},
|
{"name": "small", "host": "192.168.70.65", "slave_id": 22},
|
||||||
]
|
]
|
||||||
|
selected_robot = 0
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
robot = self.robots[0]
|
self.startGui()
|
||||||
self.start_gui()
|
|
||||||
|
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
|
||||||
|
|
||||||
def start_gui(self):
|
|
||||||
START_JUCE_COMPONENT(MainContentComponent, name="ROBOT GUI", robots=self.robots)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
MyApp()
|
MyApp()
|
||||||
|
|
Loading…
Reference in New Issue