python
from telnetlib import Telnet as telnet
from loguru import logger
__EXEC_END__ = "1002"
class TelnetCtr:
__telnet__ = telnet()
__user__ = None
__passwd__ = None
__Debug__ = None
__timeout__ = None
__record__ = tuple()
__url__ = ""
__port__ = 0
def __init__(self, url: str, port: int, **kwargs):
try:
self.__url__ = url
self.__port__ = port
self.__record__ = kwargs
self.__passwd__ = kwargs.pop("passwd", None)
self.__user__ = kwargs.pop("user", None)
self.__Debug__ = kwargs.pop("debug", None)
self.__timeout__ = kwargs.pop("timeout", None)
if self.__Debug__ is not None:
self.__telnet__.set_debuglevel(self.__Debug__)
if self.__timeout__ is not None:
self.__telnet__.open(url, port, timeout=self.__timeout__)
else:
self.__telnet__.open(url, port)
if self.__user__ is not None and self.__passwd__ is not None:
self.__telnet__.read_until(b"login: ", timeout=self.__timeout__)
self.__telnet__.write(
bytes(self.__user__.encode("utf-8") + "\r\n".encode("utf-8"))
)
self.__telnet__.read_until(b"Password: ", timeout=self.__timeout__)
self.__telnet__.write(
bytes(self.__passwd__.encode("utf-8") + "\r\n".encode("utf-8"))
)
except SystemError as err:
logger.error("TelnetCtrol: {}", err.args)
# {"command":"except result"}
def command(self, cmd: list) -> dict:
res = {}
try:
for it in cmd:
self.__telnet__.write(
bytes(
it.encode("utf-8")
+ "&& echo EXEC END $((1000+2)) \
|| echo EXEC END $((1000+2))".encode(
"utf-8"
)
+ "\r\n".encode("utf-8")
)
)
res[it] = self.__telnet__.read_until(
"EXEC END 1002".encode("utf-8"), timeout=30
).decode("utf-8")
except SystemError as e:
logger.error("telnet system error:{}".format(e.args))
return res
QT 显示 Matplot 的绘画图,位置怎么确定,可以自己构建 ,QT 组件,然后随意拖拽,就可以在自己的UI 界面中随意显示
需要做类的提升
参考这篇博文
https://blog.csdn.net/g11023225/article/details/119274622
绘图 类的模块应用,感谢 github丰富的 代码
python
from PyQt5.QtWidgets import*
from matplotlib.backends.backend_qt5agg import FigureCanvas
from matplotlib.figure import Figure
# TODO: MORE SUB PLOT NEED ADD
class matplot(QWidget):
def __init__(self, parent = None):
QWidget.__init__(self, parent)
self.canvas = FigureCanvas(Figure())
vertical_layout = QVBoxLayout()
vertical_layout.addWidget(self.canvas)
self.canvas.axes = self.canvas.figure.add_subplot(111)
self.setLayout(vertical_layout)
可以在 desigin 中 进行拖拽,复制模块儿