"Python Project" a GUI comic reader designed to crawl comic scripts with Love Comics (i)

Source: Internet
Author: User
Tags emit

Blog Park The first pit, think of a little excitement =3=

The first is the address of the reptile:

"Original" recently wrote a relatively hack little reptile

Select tool:

Previously used QT, then choose Pyqt4 is also reasonable.

Clear requirements:

0, first of all, to read all the chapters of the comics come in, at the same time can choose the corresponding chapters.

1, second, enter the corresponding chapters, display the picture of the chapter, while there are "next page", "previous page", "Return to the main interface" and other basic functions

3, finally, it is better to have a bookmark function. The program should be able to position the corresponding picture according to the section and page number information

Finally, there is no time to implement the bookmark code:

#-*-Coding:utf-8-*-"The software has a total of four classes: 0, inheritance Qpushbutton MyButton class, mainly to implement the clicked event of sending parameters. 1, the Mainchapter class, displays the main interface 2, the bookmark class, is responsible for the communication between the Mainchapter class and the chapter class, is realizes the bookmark the key class. 3, Chapter class, responsible for displaying the communication between the picture classes: Mainchapter to BookMark: Chapter + pages. If you click on a chapter without clicking on a bookmark, the default page count is 0BookMark to Chapter: Picture path + Chapter + page. To prevent the current page from going out of bounds, in addition to sending the picture path to chapter, you also need to send the page value to the Chapterchapter to BookMark: Chapter + page. Request the corresponding chapter + page picture path to the bookmark. Chapter to Mainchapter: After hiding their own, notice mainchapter appear in order to achieve the bookmark function to build complex signal communication finally achieve completion. Miss the first version of the simple rough days in the bookmark OMG "from Pyqt4.qtgui import *from pyqt4.qtcore import *import sysimport Osmanhuadir = R ' D:/sketdanc E ' Manhuainx = Os.listdir (manhuadir) Manhuainx = [Key.decode (' GBK ') for key in Manhuainx]class MyButton (Qpushbutton): myclicked = pyqtsignal (int) def __init__ (Self,id,*args, **kwargs): Super (Mybutton,self). __init__ (*args, **kwargs) Self.id = Idself.connect (Self,signal (' clicked () '), self.emitmyclicked) def emitmyclicked (self): Self.myclicked.emit ( Self.id) class BookMark (qwidget): Sendaddr = pyqtsignal (qstring,int,int) #senddir = qtcore.pyqtsignal (str) def __init__ (self,parent = None): Super (Bookmark,self). __init__ (parent) Self.nowchapter = 0self.nowpage = 0self.flag = 0 # It's too ugly to write here. For efficiency, Setdictready should be executed as little as possible, so mark the first execution of Setdictready in the case of Def Connecttochapter (self,chapter): Self.chapter = Chapterself.connect (Self,signal (' Sendaddr (qstring,int,int) '), Self.chapter.setChapterPage) #self. Connect (self, SIGNAL (' Senddir (str) '), SELF.CHAPTER.SHOWIMG) def CMP (SELF,STR1,STR2): inx1 = Str1.find ('. ') Inx2 = Str2.find ('. ')     str1 = STR1[:INX1]STR2 = str2[:inx2]str1 = Int (str1) str2 = Int (str2) return str1-str2def Setdictready (self): Self.dir = Manhuainx[self.nowchapter]self.imglist = Os.listdir (Manhuadir + '/' + self.dir.encode (' GBK ')) Self.imgList.sort ( SELF.CMP) def setchapterpage (self,page,chapter): Self.nowpage = Pageif Self.flag = = 0: # Execute code that should be executed in the constructor Self.flag = 1self . Setdictready () if Self.nowchapter! = Chapter: # If you do not need to change the current folder, do not reset the working directory Self.nowchapter = Chapterself.setdictready () Self.target = self.generateaddr (page,chapter) self.sendAddr.emit (QstrinG (Self.target), Self.nowpage,self.nowchapter) def generateaddr (self,page,chapter): If page > Len (self.imglist): Self.nowchapter + = 1if self.nowchapter > Len (manhuainx): Self.nowchapter = 0self.nowpage = 0self.setdictready () elif Page < 0:self.nowpage = 0if Chapter > 1:self.nowchapter = Chapter-1else:self.nowchapter = 0self.setdictready () Else : Self.nowpage = Pagereturn manhuadir + '/' + Self.dir + '/' + Self.imglist[self.nowpage]class mainchapters (QWidget): AddrSi Gnal = Pyqtsignal (int,int) def __init__ (self,parent = None): Super (Mainchapters,self). __init__ (parent) self.resize ( 640,480) Self.button = [MyButton (inx,key,self) for Inx,key in Enumerate (Manhuainx)]for Inx,key in Enumerate (Self.button) : Self.connect (Key,signal (' myclicked (int) '), self.emitaddr) layout = Qgridlayout () Count = 0startX = 0for Inx,key in Enumerate (Self.button): Layout.addwidget (key,startx,inx% 7) Count + = 1if count >= 7:count = 0startX + = 1self.setwindowt Itle (' Imanhuareader ') self.setlayout (layout) def Connecttobook(Self,bookmark): Self.bookmark = Bookmarkself.connect (self,signal (' addrsignal (int,int) '), Self.bookmark.setChapterPage) def emitaddr (self,id): Self.hide () Self.addrSignal.emit (0,id) class Chapter (Qwidget): Gettarget = pyqtsignal (int,int) Ret2main = pyqtsignal () def __init__ (self,parent = None): Super (Chapter,self). __init__ (    Parent) self.resize (1024,768) Self.button = Qpushbutton (U ' main interface ', self) self.nextpa = Qpushbutton (U ' next page ', self) Self.prepa = Qpushbutton (U ' up page ', self) Self.imgscrol = Qscrollarea (self) Self.imglabel = Qlabel (Self.imgscrol) Self.imgScrol.setWidget (Self.imglabel) self.imgScrol.setWidgetResizable (True) # Key! Otherwise, layout = Qgridlayout (self) layout.addwidget (self.button,1,1) layout.addwidget (self.nextpa,1,0) will not display properly Layout.addwidget (self.prepa,1,2) layout.addwidget (self.imgscrol,0,0) self.setlayout (layout) def connectToMain (self , mainchapter): Self.mainchapter = Mainchapterself.connect (Self.button,signal (' clicked () '), Self.returntomain) Self.connect (Self,signal (' Ret2main () '), mainchapter.show) def ConnecTtobook (self,bookmark): Self.bookmark = Bookmarkself.connect (Self.nextpa,signal (' clicked () '), self.nextimg) # Signal cannot be repeatedly connected! Otherwise it will send two self.connect (Self.prepa,signal (' clicked () '), self.preimg) Self.connect (self,signal (' Gettarget (int,int) '), Self.bookmark.setChapterPage) def showimg (self): Self.target = Unicode (self.target) pixmap = Qpixmap (self.target) Self.imgLabel.setPixmap (PIXMAP) def setchapterpage (self,target,page,chapter): self.showmaximized () Self.chapter = Chapterself.page = Pageself.target = Targetself.showimg () def nextimg (self): Self.page + = 1 # Out of bounds in the bookmark handle Self.gettarg Et.emit (Self.page,self.chapter) def preimg (self): self.page-= 1self.gettarget.emit (Self.page,self.chapter) def Returntomain (self): Self.ret2Main.emit () self.hide () app = Qapplication (sys.argv) main = mainchapters () chap = Chapter () Book = BookMark () chap.connecttomain (main) chap.connecttobook (book) Main.connecttobook (book) Book.connecttochapter ( CHAP) Main.show () app.exec_ ()

  

Should add a temporary bookmark function, that is, after the exit, if it is section B page 13, then the next time you enter the program is section B page 13

"Python Project" a GUI comic reader designed to crawl comic scripts with Love Comics (i)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.