pyforms是一个python框架,用于开发基于pyqt的gui应用程序
PyForms-GU的Python项目详细描述
如果您觉得这个项目有用,请不要忘记it。
pyforms图形用户界面
pyformsgui是一个软件层,是pyforms主库的一部分。这个层实现了pyforms应用程序作为windows gui的执行。
pyforms
pyforms是一个python 3跨环境框架,旨在提高开发效率。这个库在python中提供了一个api,用于开发可以在windows gui模式、web模式或终端模式下执行的应用程序。
优点
- 使用一个最小的api,可以使用一个简短的python代码轻松地定义接口。
- 避免在gui设计器和python ide之间不断切换。
- 它的设计允许以最小的努力对高级功能进行编码。
- 代码按模块组织,并准备好供其他应用程序重用。
- 它使应用程序的维护更容易。
- 使原型设计变得更加简单快捷。
- 由于它的简单性,它的学习曲线很低。
在pyforms gui中开发的应用程序示例
安装
查看pyforms.readthedocs.org和pyforms-gui.readthedocs.org上的文档
框架背后的基本原理
这个库的开发始于允许低编程技能的用户从我的python脚本编辑参数的必要性。 其思想是将已经开发好的脚本转换成gui应用程序,只需花费很少的精力和很短的时间。
例如,在我的计算机视觉应用程序中,大多数情况下,必须在每个视频的脚本中手动设置变量,以根据环境光照条件调整阈值、斑点大小和其他参数……要测试每一组参数,必须执行脚本。 使用gui应用程序,用户将能够使用gui界面设置参数,并立即可视化结果,而无需重新启动脚本。就是这个主意。
在研究了用于gui接口的几个python选项之后,pyqt似乎是快速开发qt designer的最佳工具,但是在qt中开发了一段时间之后,在设计器和python ide之间切换在时间上变得太昂贵了,因为接口在不断发展。
作为一个django开发人员,我确实从中得到了这个框架的灵感。在Django模型中,我们只需要在表单(在modeladmin中)中定义变量的类型及其配置,就可以生成用于数据编辑的html表单。 对于我想在python脚本中构建的gui,我希望具有相同的简单性,因此我可以专注于算法,而不是gui的开发。
其结果是您可以在下面的示例中看到简单性:
frompyforms.basewidgetimportBaseWidgetfrompyforms.controlsimportControlFilefrompyforms.controlsimportControlTextfrompyforms.controlsimportControlSliderfrompyforms.controlsimportControlPlayerfrompyforms.controlsimportControlButtonclassComputerVisionAlgorithm(BaseWidget):def__init__(self,*args,**kwargs):super().__init__('Computer vision algorithm example')self.set_margin(10)#Definition of the forms fieldsself._videofile=ControlFile('Video')self._outputfile=ControlText('Results output file')self._threshold=ControlSlider('Threshold',default=114,minimum=0,maximum=255)self._blobsize=ControlSlider('Minimum blob size',default=110,minimum=100,maximum=2000)self._player=ControlPlayer('Player')self._runbutton=ControlButton('Run')#Define the function that will be called when a file is selectedself._videofile.changed_event=self.__videoFileSelectionEvent#Define the event that will be called when the run button is processedself._runbutton.value=self.__runEvent#Define the event called before showing the image in the playerself._player.process_frame_event=self.__process_frame#Define the organization of the Form Controlsself._formset=[('_videofile','_outputfile'),'_threshold',('_blobsize','_runbutton'),'_player']def__videoFileSelectionEvent(self):""" When the videofile is selected instanciate the video in the player """self._player.value=self._videofile.valuedef__process_frame(self,frame):""" Do some processing to the frame and return the result frame """returnframedef__runEvent(self):""" After setting the best parameters run the full algorithm """passif__name__=='__main__':frompyformsimportstart_appstart_app(ComputerVisionAlgorithm)
在终端运行应用程序的结果:
$> python test.py