简体   繁体   English

PyQt中的第三方Python模块

[英]3rd Party Python Modules in PyQt

I am trying to decide on a technology for developing a desktop application that can interface with the serial port. 我试图决定一种技术来开发可以与串行端口接口的桌面应用程序。 I have looked into python and it looks like a console based app would not be difficult - http://pyserial.sourceforge.net/ , and I have also looked at PyQt, which would fulfill the GUI portion of my project. 我已经调查蟒蛇,它看起来像一个基于控制台应用程序应该不难- http://pyserial.sourceforge.net/ ,我也看着PyQt的,这将满足我的项目的GUI部分。

But is it possible to include 3rd party modules like PySerial in PyQt? 但是是否可以在PyQt中包含第三方模块(例如PySerial)?

PyQt and pyserial play nice together (in fact, I'm using them in one of my apps.) The examples on the pyserial website are mostly simple console-like examples, but there's no reason you cannot take data from any of the pyserial objects and use them in PyQt. PyQt和pyserial可以很好地配合使用(事实上,我正在其中一个应用程序中使用它们。)pyserial网站上的示例大多是类似于控制台的简单示例,但是没有理由不能从任何pyserial对象获取数据并在PyQt中使用它们。 You could, for instance, take data that you received over a serial port and push it into a QByteArray or NumPy array or anything similar as fits your fancy. 例如,您可以获取通过串行端口接收到的数据,然后将其推入QByteArray或NumPy数组或其他任何适合您的幻想中。

A couple of caveats: if you use Serial.readline(), it is blocking until it gets a newline (\\n). 有两个警告:如果使用Serial.readline(),它将阻塞直到获得换行符(\\ n)。 This could be bad for your GUI. 这可能对您的GUI不利。 If you must use readline() instead of read(), I recommend putting your pyserial related activities in a separate thread. 如果必须使用readline()而不是read(),建议将与pyserial相关的活动放在单独的线程中。 How you do this is up to you, but I'd recommend using Qt's built in threading. 如何执行此操作取决于您,但是我建议您使用Qt的内置线程。 You can then do data conversions to Qt types and such inside the thread. 然后,您可以在线程内部将数据转换为Qt类型。 More info on threading in pyqt . 有关在pyqt中进行线程化的更多信息。

Edit : almost forgot. 编辑 :几乎忘了。 If anyone cares, you can use PyQt to write console apps too. 如果有人在乎,您也可以使用PyQt编写控制台应用程序。 Just use QCoreApplication instead of QApplication. 只需使用QCoreApplication而不是QApplication。 Not quite sure why one would do that in python, however, unless you were really fond of Qt's data types... in this case you could use PyQt and pyserial to write a pure console app :D 不太确定为什么要在python中这样做,除非您真的很喜欢Qt的数据类型...在这种情况下,您可以使用PyQt和pyserial编写纯控制台应用程序:D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 阅读第三方模块的Python文档 - Reading Python Documentation for 3rd party modules Python 日志记录和第 3 方模块 - Python logging & 3rd party modules 在使用第三方模块时使用Python打印到控制台 - printing to console in Python while working with 3rd party modules 在 VSC 中安装第 3 方 python 模块时出现问题 - Problems Installing 3rd party python modules in VSC 通过Cloud9在AWS Lambda中使用Python 3rd Party模块 - Python 3rd Party Modules in AWS Lambda through Cloud9 在Ubuntu Linux机器上安装第三方Python模块? - Installing 3rd party Python modules on an Ubuntu Linux machine? 是否有适用于python的第三方编译器? - Is there a 3rd party compiler for python? Python 3.5:Sublime Text无法识别第三方模块…如何解决? - Python 3.5: Sublime Text Won't Recognize 3rd Party Modules…How to Fix? 检测开发人员编写的代码与通过 python 中的模块(第三方)引入的代码的方法 - Approach to instrument what code developers write vs what is brought in via modules (3rd party) in python 最好同时使用Python Windows Windows获取多个字符,最好不要使用第三方模块 - Python Windows Getting Multiple Characters pressed at same time preferably without 3rd party modules
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM