在根目录创建gui包,包下会生成一个__init__.py文件,然后在该包下创建目录preview,并在目录中创建preview.py,内容如下:

ui/preview/preview.py
def load_preview(main):
"""
装载预览界面
:param main:
:return:
"""
# 初始化界面变量
declaring_variable(main)
# 初始化界面布局
init_preview(main)
# 初始化 QGIS
init_qgis_map(main)
# 绑定方法
bind_func(main)


def declaring_variable(main):
main.preview_canvas = None # 图层显示器
main.preview_tool_pan = None
main.preview_tool_zoom_in = None
main.preview_tool_zoom_out = None


def init_preview(main):
# 设置splitter缩放因子
main.ui.splitter.setStretchFactor(0, 3)
main.ui.splitter.setStretchFactor(1, 5)


def init_qgis_map(main):
pass


def bind_func(main):
pass

ui__init__.py文件中写入下面代码

ui/__init__.py
import gui.preview.preview as GUIPreview

main.py中装载 preview 模块

main.py
import gui as GUI

class PyQgisSEApp(QMainWindow, Ui_MainWindow):
def __init__(self, app: QgsApplication):
super(PyQgisSEApp, self).__init__()
self.app = app
self.ui = Ui_MainWindow()
self.ui.setupUi(self)

# 装载模块
GUI.GUIPreview.load_preview(self)