qt test
This commit is contained in:
parent
69f2fd810d
commit
de92e54a6c
|
@ -0,0 +1,180 @@
|
|||
from juce_init import START_JUCE_COMPONENT
|
||||
import popsicle as juce
|
||||
import time
|
||||
|
||||
|
||||
class ChangeRobot(juce.Component, juce.Timer):
|
||||
backgroundColour = juce.Colours.lightblue
|
||||
textColour = juce.Colours.black
|
||||
|
||||
robots = []
|
||||
|
||||
robotsLabel = juce.Label("", "Выберите робота")
|
||||
robotsRadio = []
|
||||
robotsControls = [robotsLabel] + robotsRadio
|
||||
robotButtonsId = 1001
|
||||
|
||||
connectButton = juce.TextButton("Соединить")
|
||||
|
||||
old_status = None
|
||||
counter = 0
|
||||
|
||||
def __init__(self, robots, updateRobot, status):
|
||||
super().__init__()
|
||||
juce.Timer.__init__(self)
|
||||
|
||||
self.robots = robots or []
|
||||
self.updateRobot = updateRobot
|
||||
self.status = status
|
||||
|
||||
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.onClick = self.setConnectText
|
||||
s.setRadioGroupId(self.robotButtonsId, juce.dontSendNotification)
|
||||
s.setClickingTogglesState(True)
|
||||
|
||||
self.addAndMakeVisible(self.connectButton)
|
||||
self.connectButton.onClick = self.connectRobot
|
||||
|
||||
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)
|
||||
|
||||
h = i + 2
|
||||
self.connectButton.setBounds(10, (h * 20), self.getWidth() - 20, 20)
|
||||
|
||||
def setConnectText(self):
|
||||
if self.status() == "not_connected":
|
||||
self.connectButton.setButtonText("Connect")
|
||||
if self.status() == "connected":
|
||||
self.connectButton.setButtonText("Disconnect")
|
||||
|
||||
def timerCallback(self):
|
||||
new_status = self.status()
|
||||
self.counter += 1
|
||||
if new_status == self.old_status and self.counter <= 10:
|
||||
self.connectButton.setButtonText(self.connectButton.getButtonText() + ".")
|
||||
else:
|
||||
self.old_status = None
|
||||
self.stopTimer()
|
||||
self.setConnectText()
|
||||
|
||||
def connectRobot(self):
|
||||
self.setConnectText()
|
||||
res = None
|
||||
for i, s in enumerate(self.robotsRadio):
|
||||
if s.getToggleState() == True:
|
||||
res = i
|
||||
break
|
||||
|
||||
if res == None:
|
||||
self.connectButton.setButtonText("Выберите робота")
|
||||
return
|
||||
|
||||
self.old_status = self.status()
|
||||
self.startTimer(500)
|
||||
time.sleep(0.3)
|
||||
self.updateRobot(self.robots[i])
|
||||
|
||||
|
||||
class Status(juce.Component, juce.Timer):
|
||||
backgroundColour = juce.Colours.lightgrey
|
||||
textColour = juce.Colours.black
|
||||
|
||||
def __init__(self, status):
|
||||
super().__init__()
|
||||
juce.Timer.__init__(self)
|
||||
|
||||
self.status = status
|
||||
|
||||
self.statusLabel = juce.Label(self.status())
|
||||
self.addAndMakeVisible(self.statusLabel)
|
||||
|
||||
def paint(self, g: juce.Graphics):
|
||||
g.fillAll(self.backgroundColour)
|
||||
self.statusLabel.setColour(self.statusLabel.textColourId, self.textColour)
|
||||
self.statusLabel.setBounds(10, 0, self.getWidth() - 10, 20)
|
||||
|
||||
def timerCallback(self):
|
||||
# self.setConnectText()
|
||||
pass
|
||||
|
||||
|
||||
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)
|
||||
statusArgs = kwargs.get("statusPanel")
|
||||
statusPanel = Status(**statusArgs)
|
||||
self.rightPanel = RightPanel(panels=[robotPanel, statusPanel])
|
||||
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")
|
220
gui_test.py
220
gui_test.py
|
@ -1,180 +1,92 @@
|
|||
from juce_init import START_JUCE_COMPONENT
|
||||
import popsicle as juce
|
||||
import time
|
||||
import sys
|
||||
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtGui import QColor, QPalette
|
||||
|
||||
|
||||
class ChangeRobot(juce.Component, juce.Timer):
|
||||
backgroundColour = juce.Colours.lightblue
|
||||
textColour = juce.Colours.black
|
||||
|
||||
robots = []
|
||||
|
||||
robotsLabel = juce.Label("", "Выберите робота")
|
||||
robotsRadio = []
|
||||
robotsControls = [robotsLabel] + robotsRadio
|
||||
robotButtonsId = 1001
|
||||
|
||||
connectButton = juce.TextButton("Соединить")
|
||||
|
||||
old_status = None
|
||||
counter = 0
|
||||
|
||||
def __init__(self, robots, updateRobot, status):
|
||||
class ChangeRobot(QWidget):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__()
|
||||
juce.Timer.__init__(self)
|
||||
self.initUI()
|
||||
|
||||
self.robots = robots or []
|
||||
self.updateRobot = updateRobot
|
||||
self.status = status
|
||||
def initUI(self):
|
||||
palette = self.palette()
|
||||
palette.setColor(QPalette.Window, QColor(173, 216, 230)) # LightBlue
|
||||
self.setAutoFillBackground(True)
|
||||
self.setPalette(palette)
|
||||
|
||||
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.onClick = self.setConnectText
|
||||
s.setRadioGroupId(self.robotButtonsId, juce.dontSendNotification)
|
||||
s.setClickingTogglesState(True)
|
||||
|
||||
self.addAndMakeVisible(self.connectButton)
|
||||
self.connectButton.onClick = self.connectRobot
|
||||
|
||||
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)
|
||||
|
||||
h = i + 2
|
||||
self.connectButton.setBounds(10, (h * 20), self.getWidth() - 20, 20)
|
||||
|
||||
def setConnectText(self):
|
||||
if self.status() == "not_connected":
|
||||
self.connectButton.setButtonText("Connect")
|
||||
if self.status() == "connected":
|
||||
self.connectButton.setButtonText("Disconnect")
|
||||
|
||||
def timerCallback(self):
|
||||
new_status = self.status()
|
||||
self.counter += 1
|
||||
if new_status == self.old_status and self.counter <= 10:
|
||||
self.connectButton.setButtonText(self.connectButton.getButtonText() + ".")
|
||||
else:
|
||||
self.old_status = None
|
||||
self.stopTimer()
|
||||
self.setConnectText()
|
||||
|
||||
def connectRobot(self):
|
||||
self.setConnectText()
|
||||
res = None
|
||||
for i, s in enumerate(self.robotsRadio):
|
||||
if s.getToggleState() == True:
|
||||
res = i
|
||||
break
|
||||
|
||||
if res == None:
|
||||
self.connectButton.setButtonText("Выберите робота")
|
||||
return
|
||||
|
||||
self.old_status = self.status()
|
||||
self.startTimer(500)
|
||||
time.sleep(0.3)
|
||||
self.updateRobot(self.robots[i])
|
||||
|
||||
|
||||
class Status(juce.Component, juce.Timer):
|
||||
backgroundColour = juce.Colours.lightgrey
|
||||
textColour = juce.Colours.black
|
||||
|
||||
def __init__(self, status):
|
||||
class Status(QWidget):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__()
|
||||
juce.Timer.__init__(self)
|
||||
self.initUI()
|
||||
|
||||
self.status = status
|
||||
def initUI(self):
|
||||
palette = self.palette()
|
||||
palette.setColor(QPalette.Window, QColor(144, 238, 144)) # LightGreen
|
||||
self.setAutoFillBackground(True)
|
||||
self.setPalette(palette)
|
||||
|
||||
self.statusLabel = juce.Label(self.status())
|
||||
self.addAndMakeVisible(self.statusLabel)
|
||||
|
||||
def paint(self, g: juce.Graphics):
|
||||
g.fillAll(self.backgroundColour)
|
||||
self.statusLabel.setColour(self.statusLabel.textColourId, self.textColour)
|
||||
self.statusLabel.setBounds(10, 0, self.getWidth() - 10, 20)
|
||||
|
||||
def timerCallback(self):
|
||||
# self.setConnectText()
|
||||
pass
|
||||
|
||||
|
||||
class RightPanel(juce.Component):
|
||||
class RightPanel(QWidget):
|
||||
def __init__(self, panels):
|
||||
super().__init__()
|
||||
self.panels = panels
|
||||
layout = QVBoxLayout()
|
||||
for panel in panels:
|
||||
# panel.setFixedHeight(200)
|
||||
layout.addWidget(panel)
|
||||
self.setLayout(layout)
|
||||
self.initUI()
|
||||
|
||||
for p in self.panels:
|
||||
self.addAndMakeVisible(p)
|
||||
def initUI(self):
|
||||
palette = self.palette()
|
||||
palette.setColor(QPalette.Window, QColor(169, 169, 169)) # DarkGray
|
||||
self.setAutoFillBackground(True)
|
||||
self.setPalette(palette)
|
||||
|
||||
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(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.initUI()
|
||||
|
||||
def paint(self, g):
|
||||
g.fillAll(juce.Colours.hotpink)
|
||||
def initUI(self):
|
||||
palette = self.palette()
|
||||
palette.setColor(QPalette.Window, QColor(255, 255, 255)) # White
|
||||
self.setAutoFillBackground(True)
|
||||
self.setPalette(palette)
|
||||
|
||||
|
||||
class MainContentComponent(juce.Component):
|
||||
class MainContentComponent(QWidget):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__()
|
||||
|
||||
robotArgs = kwargs.get("robotPanel")
|
||||
robotArgs = kwargs.get("robotPanel", {})
|
||||
robotPanel = ChangeRobot(**robotArgs)
|
||||
statusArgs = kwargs.get("statusPanel")
|
||||
statusArgs = kwargs.get("statusPanel", {})
|
||||
statusPanel = Status(**statusArgs)
|
||||
self.rightPanel = RightPanel(panels=[robotPanel, statusPanel])
|
||||
self.mainPanel = MainPanel()
|
||||
|
||||
self.addAndMakeVisible(self.rightPanel)
|
||||
self.addAndMakeVisible(self.mainPanel)
|
||||
layout = QHBoxLayout()
|
||||
layout.addWidget(self.mainPanel)
|
||||
layout.addWidget(self.rightPanel)
|
||||
|
||||
self.setSize(800, 600)
|
||||
# self.setResizable(False, False)
|
||||
self.setLayout(layout)
|
||||
self.setFixedSize(800, 600)
|
||||
self.initUI()
|
||||
|
||||
def paint(self, g):
|
||||
g.fillAll(
|
||||
self.getLookAndFeel().findColour(juce.ResizableWindow.backgroundColourId)
|
||||
def initUI(self):
|
||||
palette = QPalette()
|
||||
palette.setColor(QPalette.Background, QColor(240, 240, 240))
|
||||
self.setPalette(palette)
|
||||
|
||||
def resizeEvent(self, event):
|
||||
width = self.width()
|
||||
rightPanelWidth = int(width * 0.25)
|
||||
self.rightPanel.setFixedWidth(rightPanelWidth)
|
||||
super().resizeEvent(event)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QApplication(sys.argv)
|
||||
mainWindow = MainContentComponent(
|
||||
robotPanel={'arg1': 'value1'},
|
||||
statusPanel={'arg1': 'value1'}
|
||||
)
|
||||
|
||||
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")
|
||||
mainWindow.show()
|
||||
sys.exit(app.exec_())
|
||||
|
|
25
main.py
25
main.py
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
from juce_init import START_JUCE_COMPONENT
|
||||
import sys
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
from gui_test import MainContentComponent
|
||||
from client_socket import SocketRobotArm
|
||||
import time
|
||||
|
@ -13,19 +14,31 @@ class MyApp:
|
|||
self.startRobot()
|
||||
self.startGui()
|
||||
|
||||
def get_status(self):
|
||||
if self.robot_app:
|
||||
return self.robot_app.get_status
|
||||
else:
|
||||
return self.def_robot_status
|
||||
|
||||
def def_robot_status(self):
|
||||
return SocketRobotArm.Status[1]
|
||||
|
||||
def startGui(self):
|
||||
self.gui_app = START_JUCE_COMPONENT(
|
||||
MainContentComponent,
|
||||
name="ROBOT GUI",
|
||||
app = QApplication(sys.argv)
|
||||
mainWindow = MainContentComponent(
|
||||
robotPanel={
|
||||
"robots": self.robots,
|
||||
"updateRobot": self.updateRobot,
|
||||
"status": self.robot_app.get_status,
|
||||
"status": self.get_status,
|
||||
},
|
||||
statusPanel={
|
||||
"status": self.robot_app.get_status,
|
||||
"status": self.get_status,
|
||||
}
|
||||
)
|
||||
mainWindow.setWindowTitle("ROBOT GUI")
|
||||
mainWindow.show()
|
||||
|
||||
sys.exit(app.exec_())
|
||||
|
||||
def startRobot(self):
|
||||
self.robot_app = SocketRobotArm()
|
||||
|
|
Loading…
Reference in New Issue