PyQtImageViewer 项目教程

PyQtImageViewer 项目教程

PyQtImageViewerPyQt image viewer widget with mouse zooming and panning.项目地址:https://gitcode.com/gh_mirrors/py/PyQtImageViewer

1. 项目的目录结构及介绍

PyQtImageViewer 项目的目录结构如下:

PyQtImageViewer/
├── LICENSE
├── README.md
├── QtImageViewer.py
├── QtImageStackViewer.py
├── setup.py
└── gitignore

目录结构介绍

  • LICENSE: 项目许可证文件,采用 MIT 许可证。
  • README.md: 项目说明文档,包含项目的基本介绍和使用方法。
  • QtImageViewer.py: 核心文件,包含图像查看器的主要功能。
  • QtImageStackViewer.py: 多页图像查看器,基于 QtImageViewer.py 实现。
  • setup.py: 项目安装脚本。
  • gitignore: Git 忽略文件配置。

2. 项目的启动文件介绍

项目的启动文件是 QtImageViewer.pyQtImageStackViewer.py

QtImageViewer.py

QtImageViewer.py 是项目的核心文件,包含图像查看器的主要功能。以下是启动该文件的示例代码:

import sys
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QApplication
from QtImageViewer import QtImageViewer

# 自定义鼠标点击处理槽函数
def handleLeftClick(x, y):
    row = int(y)
    column = int(x)
    print(f"Pixel (row={row}, column={column})")

if __name__ == '__main__':
    # 创建 QApplication 实例
    app = QApplication(sys.argv)
    # 创建图像查看器实例
    viewer = QtImageViewer()
    # 连接鼠标点击信号到自定义槽函数
    viewer.leftMouseButtonReleased.connect(handleLeftClick)
    # 显示查看器并运行应用程序
    viewer.show()
    sys.exit(app.exec())

QtImageStackViewer.py

QtImageStackViewer.py 是多页图像查看器,基于 QtImageViewer.py 实现。以下是启动该文件的示例代码:

import sys
from PyQt6.QtWidgets import QApplication
from QtImageStackViewer import QtImageStackViewer

if __name__ == '__main__':
    # 创建 QApplication 实例
    app = QApplication(sys.argv)
    # 创建多页图像查看器实例
    viewer = QtImageStackViewer()
    # 加载图像堆栈文件(会弹出文件对话框)
    viewer.open()
    # 显示查看器并运行应用程序
    viewer.show()
    sys.exit(app.exec())

3. 项目的配置文件介绍

项目的配置文件主要是 setup.py,它用于项目的安装和分发。

setup.py

setup.py 文件的内容如下:

from setuptools import setup

setup(
    name='PyQtImageViewer',
    version='0.1',
    description='PyQt image viewer widget with mouse zooming and panning',
    author='Marcel Goldschen-Ohm',
    author_email='marcel.goldschen@gmail.com',
    url='https://github.com/marcel-goldschen-ohm/PyQtImageViewer',
    py_modules=['QtImageViewer', 'QtImageStackViewer'],
    install_requires=[
        'PyQt6',
        'numpy',
        'Pillow'
    ],
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
        'Programming Language :: Python :: 3.8',
        'Programming Language :: Python :: 3.9',
    ],
)

配置文件介绍

  • name: 项目名称。
  • version: 项目版本。
  • description: 项目描述。
  • author: 项目作者。
  • author_email: 作者邮箱。
  • url: 项目仓库地址。
  • py_modules: 项目包含的模块。
  • install_requires: 项目依赖

PyQtImageViewerPyQt image viewer widget with mouse zooming and panning.项目地址:https://gitcode.com/gh_mirrors/py/PyQtImageViewer

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

富晓微Erik

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值