基于PyQT5制作一個桌面摸魚工具
前言
現(xiàn)在我能一整天都嚴肅地盯著屏幕,看起來就像在很認真地工作,
利用摸魚,打開小說,可實行完美摸魚,實時保存進度
用PYQT5 Mock一個摸魚軟件 類似于Thief
按鍵功能控制
q 退出
B 書簽功能
F 增加字體大小
Shift F 減小字體
O 打開文件,現(xiàn)在僅僅支持 utf8格式的txt文件
主要功能
FlameLess Window 無邊框窗口
一鍵快速退出
ini 文件讀寫
右鍵上下文菜單
核心代碼
pyqt 實現(xiàn)功能還是比較順暢的,總體功能實現(xiàn)代碼量不到200行
from PyQt5 import QtCore from PyQt5.QtWidgets import * from PyQt5.QtGui import * from PyQt5.QtCore import Qt import sys,os import configparser # Q to quit app # B Bookmark # F increase Font size # Shift F decrease Font size # O Open *.txt file class FisherReader(QMainWindow): def __init__(self): super().__init__() # drag self.pos =[0,0] self.mouse_down = False self.down = [0,0] self.prev = [0,0] # text self.txtName = '' self.text = [] self.index = 0 # style self.show_info = False self.font_size = 8 self.bgColor = QColor(255,255,255) self.defPalette() # self.read_Txt() def mousePressEvent(self, event): current = [event.pos().x(),event.pos().y()] self.down = current self.mouse_down = True def mouseMoveEvent(self,event): current = [event.pos().x(),event.pos().y()] if self.mouse_down: delta = [current[0]-self.down[0],current[1]-self.down[1]] new = [self.pos[0]+delta[0],self.pos[1]+delta[1]] self.move(new[0],new[1]) self.pos = new # print(self.pos) self.prev = current def mouseReleaseEvent(self, event): self.mouse_down = False def keyPressEvent(self,event): if event.key() == Qt.Key_Q: app.quit() if event.key() == Qt.Key_Down: if self.index < len(self.text)-1: self.index = self.index+1 self.update() if event.key() == Qt.Key_Up: if self.index > 0: self.index = self.index-1 self.update() if event.key() == Qt.Key_F: if event.modifiers() & QtCore.Qt.ShiftModifier and self.font_size >2: self.font_size -= 2 else: self.font_size += 2 self.update() if event.key() == Qt.Key_I: self.show_info = not self.show_info self.update() if event.key() == Qt.Key_O: self.open() self.update() if event.key() == Qt.Key_B: self.addBookmark() if event.key() == Qt.Key_R: self.getBookmark() def defPalette(self): p = self.palette() p.setColor(QPalette.Background,self.bgColor) self.window().setPalette(p) def paintEvent(self,event): painter = QPainter(self) painter.setRenderHints(QPainter.Antialiasing) if len(self.text)>0: painter.setFont(QFont('SimSun',self.font_size)) painter.drawText(QtCore.QRectF(10,10,600,50),Qt.AlignLeft,self.text[self.index]) if self.show_info: painter.drawText(QtCore.QRectF(610,10,50,50),Qt.AlignLeft,"{}/{}".format(self.index+1,len(self.text))) def open(self): path, _ = QFileDialog.getOpenFileName(self, "打開文件",os.getcwd(), "Text files (*.txt)") if path: self.txtName = path self.read_Txt_smart(path) self.update() def read_Txt(self,file): with open(file,'r',encoding="UTF-8") as f: self.text = f.readlines() def cut(self,text,length): return [text[i:i+length] for i in range(0,len(text),length)] def wheelEvent(self, e): if e.angleDelta().y() < 0: if self.index < len(self.text)-1: self.index = self.index+1 elif e.angleDelta().y() > 0: if self.index > 0: self.index = self.index-1 self.update() def addBookmark(self): config = configparser.ConfigParser() path = "bookmark.ini" config.add_section('bookmark') config.set('bookmark','path',self.txtName) config.set('bookmark','bookmark',str(self.index)) config.write(open(path,'w')) def getBookmark(self): config = configparser.ConfigParser() path = "bookmark.ini" config.read(path) if config.has_option('bookmark','path'): self.txtName = config.get('bookmark','path') self.index = int(config.get('bookmark','bookmark')) self.read_Txt_smart(self.txtName); self.update() def read_Txt_smart(self,file): with open(file,'r',encoding="UTF-8") as f: text_buffer = [] lines = f.readlines() for line in lines: cline = self.cut(line,30) for cl in cline: if len(cl)>1: text_buffer.append(cl) self.text = text_buffer if __name__ == '__main__': app = QApplication(sys.argv) fisher = FisherReader() fisher.resize(660,45) fisher.setWindowFlags(Qt.FramelessWindowHint|Qt.WindowStaysOnTopHint) fisher.show() fisher.setWindowTitle("小魚") sys.exit(app.exec_())
到此這篇關(guān)于基于PyQT5制作一個桌面摸魚工具的文章就介紹到這了,更多相關(guān)PyQT5桌面摸魚工具內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用已經(jīng)得到的keras模型識別自己手寫的數(shù)字方式
這篇文章主要介紹了使用已經(jīng)得到的keras模型識別自己手寫的數(shù)字方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-06-06pytorch 中pad函數(shù)toch.nn.functional.pad()的用法
今天小編就為大家分享一篇pytorch 中pad函數(shù)toch.nn.functional.pad()的用法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-01-01Python實現(xiàn)批量讀取word中表格信息的方法
這篇文章主要介紹了Python實現(xiàn)批量讀取word中表格信息的方法,可實現(xiàn)針對word文檔的讀取功能,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07python使用隱式循環(huán)快速求和的實現(xiàn)示例
這篇文章主要介紹了python使用隱式循環(huán)快速求和的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09Python使用matplotlib實現(xiàn)在坐標(biāo)系中畫一個矩形的方法
這篇文章主要介紹了Python使用matplotlib實現(xiàn)在坐標(biāo)系中畫一個矩形的方法,涉及matplotlib模塊繪制圖形的相關(guān)技巧,需要的朋友可以參考下2015-05-05