当前位置:网站首页>FBS (fman build system) packaging

FBS (fman build system) packaging

2022-04-23 14:07:00 Fresh strawberries

FBS(fman build system) pack

Apply to Pyside2 and PyQt5 project ( PySide6 and PyQt6 Pay for )

​ fbs It's based on Python Build tools for , For the use of PyQt or PySide The desktop application . It takes your source code and converts it into Windows、Mac or Linux Stand alone executable on . It also allows you to create an installer for your application .

  • Running environment :fbs stay Windows、macOS and Linux(Ubuntu、Arch or Fedora) Up operation . You also need Python 3.fbs Free version support for Python 3.5 and 3.6. After the Python Version needs to be fbs Pro.

install

 Create a virtual environment in the current directory :python3 -m venv venv
 then , Use one of the following commands to activate the environment :
# On Mac/Linux:
source venv/bin/activate
# On Windows:
call venv\scripts\activate.bat

 Next use pip install  fbs  And its dependencies :
pip install fbs PyQt6
 You can install... Similarly PySide6, PyQt5 or PySide2.  Use  PyQt6  or  PySide6  need  fbs Pro

command

fbs startproject	#  New projects 
	App Name:	#  Enter a name 
    Author:		#  Enter the author name 
    Mac bundle identifier:#  Input  Mac  Bound identifier 
 If the dependent environment is installed , Then it can run :fbs run
fbs freeze	#  Packaged as a formal project 
fbs freeze --debug	#  Package test version 

Directory structure

fbs The project uses the following directory structure . Brackets (...) Indicates that the file is optional .

-src/
	-build
    	-settings/
        	-base.json
            -(mac.json)
            -...
    -main
    	-icons
        -python
        -(resources)
    -(freeze)
    -(installer/)
    	-(windows/)
        -(mac/)
        -...
    -(requirements)
    	-(base.txt)
        -(linux.txt)
        -...

	-  When you use  fbs  when , You will see it target/ The name next to the above directory is   Generate output in the folder of . It can also create a file called  cache/  Folder , You can delete this folder at any time .

Yours Python Code

​ In order to make fbs Find it , Your Python The source code must be in src/main/python/. There? , You need a script to start your application ApplicationContext.src/main/python/main.py Runtime Generated default script fbs startproject As shown below :

from fbs_runtime.application_context.PyQt6 import ApplicationContext 
from PyQt6.QtWidgets import QMainWindow 

import sys 

if __name__ == '__main__': 
    appctxt = ApplicationContext() # 1.  Instantiation  ApplicationContext 
    window = QMainWindow() 
    window.resize(250, 150) 
    window.show () 
    exit_code = appctxt.app.exec() # 2.  call  appctxt.app.exec() 
    sys.exit(exit_code)

​ As your application becomes more and more complex , You may want to split its source code into multiple files . under these circumstances , It is recommended that you put them all in one package . for example , If your application is named My App, Then you can call the package my_app, The directory structure is shown below :

src/main/python/
	my_app/
    	__init__.py
        main.py
        module_a.py
        module_b.py

Resource file

Just put them in one of the following subfolders src/main/resources/

-base/	#  Files required for all operating systems 
-windows/	#  Only applicable to  Windows  Documents required 
-mac/	#  Empathy 
-linux-	#  Empathy 

    -  When you call   when fbs freeze,fbs  The applicable files will be automatically copied to the frozen directory of your application in the folder target/.
	-  From you to  Python  Code access resource files , Just call  ApplicationContext.get_resource(*rel_path) , This method returns   With the given name or ( relative ) The absolute path of the resource file .
	- src/main/resources/base/image.jpg  And call  get_resource('image.jpg'), This method returns the absolute path of the image . If the given file does not exist , The cause  FileNotFoundError.

版权声明
本文为[Fresh strawberries]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231400483455.html