Image Viewer-py

# This file is image_viewer.py

import sys

from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QFileDialog

from PyQt5.QtCore import QRect

from PyQt5.QtGui import QPainter, QPaintEvent, QPixmap

from main_win import Ui_MainWindow

import exifread

from PIL import Image, ImageQt

###

class tag_list():

  #

  def __init__(self, f):

    self.tag = []

    self.f_name = f

    self.filter_str = ['EXIF UserComment', 'EXIF MakerNote']

  #

  def get_tag_list(self):

    self.fd = self._open_file(self.f_name)

    while(True):

      c = self.fd.readline()

      if c == '':

        break

      else:

        self.tag.append(c.strip('\n'))

    self.fd.close()

    return self.tag

  #

  def filter_tag(self, str_list):

    pass

  #

  def _open_file_(self, f):

    try:

      fd = open(f, 'r')

    except Exception as e:

      print(e)

      return None

    return fd

###

  class image_viewer(QMainWindow, Ui_MainWindow):

      #

      def __init__(self, parent=None):

        super(image_viewer, self).__init__(parent)

        self.setupUi(self)

        self.create_actions()

      #

      def create_actions(self):

        self.actionFileOpen.triggered.connect(self.open_file)

        self.actionFileClose.triggered.connect(self.close_file)

        self.actionFileOpen2.triggered.connect(self.open_file)

      #

      def _open_file_(self):

        try:

          fd = open(self.img_file, 'rb')

        except Exception as e:

          print(e)

          return None

        return fd

      #

      def get_tag_dict(self, fd):

        self.tag = exifread.process_file(fd)

        fd.close()

      #

      def get_img_size(self):

        w = int(self.tag['EXIF ExifImageWidth'].printable)

        h = int(self.tag['EXIF ExifImageHeight'].printable)

        return (w, h)

      #

      

猜你喜欢

转载自www.cnblogs.com/suohaicheng/p/11778639.html