基于PyQT的小工具框架

基于PyQT的小工具框架

  • 主界面
  • 环境
  • 工程源码
  • 功能描述
  • 依赖环境
  • 界面设计工具
  • 界面代码生产
  • main

主界面

基于PyQT的小工具框架_第1张图片

环境

    Windows 10 
    Python 3.7.5
    PyQT5

工程源码

https://github.com/ihad-zw/gpspro.git

功能描述

  1. GPS原始数据中经度、维度、高程数据的提取;
  2. log数据的显示和保存

依赖环境

pip install PyQt5
pip install pyqt5-tools

界面设计工具

designer

界面代码生产

1、主界面

pyuic5 -o mainwindow.py mainwindow.ui

2、资源文件

pyrcc5 -o mainwindow_rsc.py mainwindows_rsc.qrc

main

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import threading
import time;
import datetime;
import traceback;
import logging
from PyQt5 import QtWidgets
from qt.mainui import MainUI
from queue import Queue

from qt.log import LOG_PRINTF

from app.getgps import GetGPS

APP_NAME='imgacctest'

class MainThread:
    def __init__(self,mtq,qtq):
        self.mtq=mtq
        self.qtq=qtq

    def _cmd_start(self,data):
        LOG_PRINTF("[start]")
        qmsg = {
     'cmd':'progress',"data":10}
        self.qtq.put(qmsg)
        inFiles=data['inFiles']
        ouFiles=data['ouFiles']
        datatype = data['datatype']

        LOG_PRINTF("inFiles: " + inFiles)
        LOG_PRINTF("ouFiles: " + ouFiles)
        LOG_PRINTF("datatype: " + datatype)

        #extern interface add
        try:
            mm =GetGPS ();
            mm.run(inFiles,ouFiles,datatype)
        except:
            traceback.print_exc()

        time.sleep(1)
        qmsg.clear()
        qmsg = {
     'cmd': 'progress', "data": 99}
        self.qtq.put(qmsg)
        time.sleep(1)
        qmsg.clear()
        qmsg = {
     'cmd': 'finish'}
        self.qtq.put(qmsg)
        LOG_PRINTF("[finish]")

    def _cmd_close(self):
        print('_cmd_close')

    def run_thread(self):

        while True:
            if not self.mtq.empty():
                msg = self.mtq.get()
                if len(msg) > 0:
                    print('MainThread:',msg)
                    if msg['cmd'] == 'start':

                        self.th_run = threading.Thread(target=self._cmd_start, name="_cmd_start",args=(msg,))
                        self.th_run.setDaemon(True)
                        self.th_run.start()

                    elif msg['cmd'] == 'close':
                        self._cmd_close();

            else:
                time.sleep(1);

    def start(self):
        self.th_run = threading.Thread(target=self.run_thread, name="run_thread")
        self.th_run.setDaemon(True)
        self.th_run.start()


def run():


    mtq = Queue(100)
    qtq = Queue(100)

    mtobj=MainThread(mtq,qtq)
    mtobj.start();

    app = QtWidgets.QApplication(sys.argv)
    mmui=MainUI(mtq,qtq)
    mmui.show()
    #mmui.start()
    sys.exit(app.exec_())



def init():
    #format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
    logdir=r'f:\log'
    logfile=None

    now_time = datetime.datetime.now()
    time1_str = datetime.datetime.strftime(now_time, '%Y%m%dT%H%M%S')

    logfilename='log_'+APP_NAME+'_'+time1_str+'.txt'

    if os.path.exists(logdir):
        logfile=os.path.join(logdir,logfilename)
    else:
        logfile=logfilename

    logger = logging.getLogger()  # 不加名称设置root logger
    logging.basicConfig(level=logging.INFO,format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    # 使用FileHandler输出到文件
    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s: - %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S')

    fh = logging.FileHandler(logfile)
    fh.setLevel(logging.DEBUG)
    fh.setFormatter(formatter)

    # 使用StreamHandler输出到屏幕
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    ch.setFormatter(formatter)

    # 添加两个Handler
    logger.addHandler(ch)
    logger.addHandler(fh)


if __name__ == '__main__':
    init();
    run()




你可能感兴趣的:(嵌入式,python,PyQT5,Python)