乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      使用python代碼實(shí)現(xiàn) PDF 閱讀器

       印度阿三17 2021-01-19

      本文的文字及圖片來(lái)源于網(wǎng)絡(luò),僅供學(xué)習(xí)、交流使用,不具有任何商業(yè)用途,版權(quán)歸原作者所有,如有問(wèn)題請(qǐng)及時(shí)聯(lián)系我們以作處理

      本文章來(lái)自騰訊云 作者:Python進(jìn)階者

      想要學(xué)習(xí)Python?有問(wèn)題得不到第一時(shí)間解決?來(lái)看看這里“1039649593”滿足你的需求,資料都已經(jīng)上傳至文件中,可以自行下載!還有海量最新2020python學(xué)習(xí)資料。
      點(diǎn)擊查看
      在這里插入圖片描述

      在這里插入圖片描述
      在這里插入圖片描述
      書(shū)籍
      在這里插入圖片描述
      使用 Book 類(lèi)來(lái)保存書(shū)籍信息,比如元數(shù)據(jù)、頁(yè)數(shù)以及閱讀與否的信息。通過(guò)?eq?特殊方法,來(lái)判斷兩個(gè) book 實(shí)例是否為同一對(duì)象。

      class Book:
          def __init__(self, fname):
              # 文件名
              self.fname = fname
              # 是否被閱讀
              self.flag = None
              self._info = None
              self._page = 0
              self.get_meta_data(self.fname)
      
          def __eq__(self, other):
              if hasattr(other, 'fname'):
                  return self.fname == other.fname
              return False    

      ?

      同時(shí)閱讀
      在這里插入圖片描述
      通過(guò)內(nèi)部維護(hù)一個(gè) read_list 列表來(lái)實(shí)現(xiàn)同時(shí)閱讀多本書(shū)。列表儲(chǔ)存 book 對(duì)象,每個(gè) book 對(duì)象都有一個(gè) page 屬性。這樣,我們的程序就能記住每本書(shū)被翻到的頁(yè)數(shù)了。

      第二行代碼,是對(duì) read_list 進(jìn)行初始化。book.flag 用來(lái)判斷這本書(shū)上次關(guān)閉前是否處于閱讀的狀態(tài)。如果是,我們就把它放在閱讀列表中。

      self.read_list = [None]
      self.read_list.extend(book for book in self.booklist if book.flag)

      ?

      左鍵翻頁(yè)
      我們重寫(xiě) MyArea 類(lèi)的 mousePressEvent 方法。event.pos() 函數(shù)用來(lái)獲取鼠標(biāo)的坐標(biāo),x() 用來(lái)獲取橫坐標(biāo)。

      width 為 MyArea 區(qū)域的寬度,如果點(diǎn)擊鼠標(biāo)左鍵,且鼠標(biāo)位置的橫坐標(biāo)小于 1/3 區(qū)域?qū)挾?,那么向前翻?yè);大于 2/3 區(qū)域?qū)挾?,那么向后翻?yè)。

      # 鼠標(biāo)左鍵翻頁(yè)
      def mousePressEvent(self, event):
          pos = event.pos().x()
          width = self.size().width()
          if event.button() == Qt.LeftButton:
              if pos > width * 2 / 3:
                  self.right()
              elif pos < width / 3:
                  self.left()
      sqlite3

      ?

      sqlite3 是輕量型本地?cái)?shù)據(jù)庫(kù),具有無(wú)服務(wù)器、零配置、速度快等特點(diǎn)。

      PyReadon 啟動(dòng)時(shí),會(huì)從數(shù)據(jù)庫(kù)中讀取圖書(shū)信息。read_db 函數(shù)主要執(zhí)行以下功能:

      如果路徑中不存在 PDF.db 數(shù)據(jù)庫(kù),那么就新建 PDF.db 數(shù)據(jù)庫(kù),并且創(chuàng)建一個(gè) book_info 表格,該表格擁有三個(gè)屬性 path, page, flag;

      從 book_info 表格中讀取數(shù)據(jù),并創(chuàng)建 book 對(duì)象來(lái)接收這些數(shù)據(jù),最后通過(guò) yield 函數(shù)返回 book 對(duì)象。

      book_db = 'PDF.db'
      book_info = namedtuple('info',  'path page flag')
      
      
      def read_db():
          # 將路徑更改為該文件所處路徑
          os.chdir(os.path.dirname(os.path.realpath(__file__)))
          if not os.path.exists(book_db):
              conn = sqlite3.connect(book_db)
              conn.execute("CREATE TABLE book_info(path, page, flag)")
              conn.close()
          conn = sqlite3.connect(book_db)
          for row in conn.execute('SELECT * FROM book_info'):
              info = book_info(*row)
              book = Book(info.path)
              book.page = info.page
              book.flag = info.flag
              yield book
      
          conn.close()  

      ?

      將數(shù)據(jù)存儲(chǔ)到數(shù)據(jù)庫(kù)中:

      將書(shū)籍列表傳給 save2db 函數(shù),通過(guò)列表推導(dǎo)式創(chuàng)建 book 所在地址的列表。conn.executemany 函數(shù)將迭代生成器表達(dá)式,并獲得 書(shū)籍地址、閱讀頁(yè)數(shù)、是否在閱讀列表中 等信息,最后將這些信息存儲(chǔ)在數(shù)據(jù)庫(kù)中。

      def save2db(booklist):
          conn = sqlite3.connect(book_db)
          conn.executemany("INSERT INTO book_info Values (?,?,?)",
                      ((book.fname, book.page, book.flag) for book in booklist))
          conn.commit()
          conn.close()

      ?

      在進(jìn)行存儲(chǔ)數(shù)據(jù)之前,我們首先要將 book_info 數(shù)據(jù)庫(kù)中的內(nèi)容清空。

      def remove_db():
          conn = sqlite3.connect(book_db)
          conn.execute('DELETE FROM book_info')
          conn.commit()
          conn.close()

      ?

      查看書(shū)籍信息
      在這里插入圖片描述
      書(shū)籍支持查看右鍵菜單,我們使用 QMessageBox.about 函數(shù)來(lái)顯示書(shū)籍信息。

      elif action == item3:
          index = row_num * 8   col_num
          # 之后改成 book
          book = self.booklist[index]
          info = book.info
          fmt = f'路徑:{info.path}\n\n'         f'格式:{info.format}\n\n'         f'標(biāo)題:{info.title}\n\n'         f'作者:{info.author}\n\n'         f'Creator:{info.creator}\n\n'         f'Producer:{info.producer}\n\n'
      
      
          QMessageBox.about(self, '文檔信息', fmt)

      ?

      彈窗

      通過(guò) Qt Designer 設(shè)計(jì)了一個(gè)彈窗,并與主程序綁定:

      info 即為彈窗,點(diǎn)擊工具欄中的信息欄時(shí)會(huì)彈出窗口。

      info = Info()
      reader.infobar.triggered.connect(info.show)

      ?

      來(lái)源:https://www./content-1-827051.html

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約