This repository has been archived by the owner on Jun 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
282 lines (227 loc) · 7.64 KB
/
gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/bin/usr/env pyhton
from Tkinter import *
from PIL import Image,ImageTk
import requests as req
from bs4 import BeautifulSoup
from StringIO import StringIO
import os
import tkMessageBox
import subprocess
import shutil
import threading
#global
chapterButtonNames = ["Download Chapter","Download all Chapters","Read Chapter(not save)"]
chapterButtonWidgets = []
currentChapterLink = ""
currentMangaName = ""
if not os.path.isfile('linkFile.txt'):
print "Loading Manga's"
p = subprocess.Popen('python listGetter.py',shell=True)
p.wait()
root = Tk()
root.state('zoomed')
root.title = "SkiManga"
root.minsize(300,300)
path = os.path.dirname(os.path.abspath(__file__))+'/'
mangaDict = {}
chapterDict = {"None":"None"}
status = Label(root, text = "", bd = 1, relief = SUNKEN, anchor = W)
status.pack(side = BOTTOM, fill = X)
path = os.path.dirname(os.path.abspath(__file__))
def updateMangaList():
os.system("python listGetter.py")
def ask_quit():
status.config(text="Quiting")
if tkMessageBox.askyesno("Quit", "Do you want to Quit?"):
if tkMessageBox.askyesno("Delete Temporary Files", "Do you want to remove the temporary files?"):
path = os.path.dirname(os.path.abspath(__file__))+'/temp/'
if os.path.exists(path):
shutil.rmtree(path)
root.destroy()
def onSelect(*args):
status.config(text="selecting manga")
key = selectedItem.get()
mangaLink = mangaDict[key]
imageName = '_'.join(key.split(' '))
if not os.path.isfile('temp/'+imageName+'.gif'):
status.config(text="Fetching information")
downloadImage(mangaLink)
else:
imageUpdate(mangaLink)
global currentMangaName
currentMangaName = imageName
path = os.path.dirname(os.path.abspath(__file__))+'/temp/'+imageName+'/chapters.txt'
if not os.path.exists(path):
getChapterList(mangaLink,imageName)
else:
updateChapterList(imageName)
def getChapterList(mangaLink, mangaName):
global chapterDict
command = "python chapterGetter.py "+mangaLink+' '+mangaName
p = subprocess.Popen(command,shell=True)
p.wait()
with open(path+'/temp/'+mangaName+'/chapters.txt','r') as f:
status.config(text="getting chapter list for manga")
chapterDict = eval(f.read())
chapterSelected.set(chapterDict.keys()[0])
updateOptionMenu()
def updateChapterList(mangaName):
global chapterDict
with open(path+'/temp/'+mangaName+'/chapters.txt','r') as f:
status.config(text="getting chapter list for manga")
chapterDict = eval(f.read())
chapterSelected.set(chapterDict.keys()[0])
updateOptionMenu()
def updateOptionMenu():
global chapterDict
chapterOptionMenu['menu'].delete(0,'end')
for chapters in chapterDict:
chapterOptionMenu['menu'].add_command(label=chapters,command=lambda chapters = chapters:chapterSelected.set(chapters))
def onChapterSelected(*args):
global chapterDict
chapterName = chapterSelected.get()
chapterLink = chapterDict[chapterName]
global currentChapterLink
currentChapterLink = chapterLink
def addButtons():
global chapterButtonNames
global chapterButtonWidgets
if(len(chapterButtonWidgets) == 0):
for idx,buttonName in enumerate(chapterButtonNames):
chapterButtonWidgets.append(Button(buttonFrames, text=buttonName))
chapterButtonWidgets[idx].pack()
addCommands()
else:
del chapterButtonWidgets[:]
addButtons()
def addCommands():
global chapterButtonWidgets
chapterButtonWidgets[0].configure(command = downloadChapter)
chapterButtonWidgets[1].configure(command = downloadAllChapters)
chapterButtonWidgets[2].configure(command = readThisChapter)
mangaImageLinks = []
def downloadChapter():
global chapterButtonWidgets
global currentChapterLink
global currentMangaName
if(len(currentMangaName)!=0):
status.config(text="Downloading "+str(currentMangaName))
command = 'python chapterDownloader.py '+currentChapterLink+' '+currentMangaName
p = subprocess.Popen(command,shell=True)
else:
status.config(text="Manga Not Selected")
def downloadAllChapters():
global currentMangaName
if(len(currentMangaName)!=0):
print "A"
else:
status.config(text="Manga Not Selected")
def readThisChapter():
global currentChapterLink
global currentMangaName
if(len(currentMangaName)!=0):
folderName = currentChapterLink.split('/')[-1]
command = 'python imageViewer.py '+folderName+' '+currentMangaName
p = subprocess.Popen(command,shell=True)
else:
status.config(text="Manga Not Selected")
def downloadImage(mangaLink):
status.config(text="Getting information")
try:
html = req.get(mangaLink)
except req.exceptions.RequestException as e:
print e
status.config(text="Check internet connection")
return
soup = BeautifulSoup(html.text)
imageUrl = soup.find(id="mangaimg").img.get('src')
try:
imagePage = req.get(imageUrl)
image = Image.open(StringIO(imagePage.content))
except req.exceptions.RequestException as e:
print e
status.config(text="Check internet connection")
return
path = os.path.dirname(os.path.abspath(__file__))+'/temp/'
if not os.path.exists(path):
os.makedirs(path)
try:
imageName = '_'.join(selectedItem.get().split(' '))
image.save(path+imageName+'.gif',"GIF")
status.config(text="success")
imageUpdate(mangaLink)
except Exception as e:
print "Error "+str(e)+" "+selectedItem.get()
status.config(text="error")
return
def imageUpdate(mangaLink):
imageName = '_'.join(selectedItem.get().split(' '))+'.gif'
path = os.path.dirname(os.path.abspath(__file__))+'/temp/'
myImage = ImageTk.PhotoImage(Image.open(path+imageName))
imageLabel.config(image = myImage)
imageLabel.image = myImage
status.config(text="Getting Summary")
getSummary(mangaLink)
def getSummary(mangaLink):
try:
html = req.get(mangaLink)
except req.exceptions.RequestException as e:
print e
status.config(text="error")
return
soup = BeautifulSoup(html.text)
div = soup.find(id="readmangasum")
summary = div.p.contents
if len(summary)>0:
summary = summary[0].encode('utf-8')
updateSummary(summary)
def updateSummary(summary):
global summaryVar
if len(summary)>0:
summaryVar.set(summary)
else:
summaryVar.set("Summary not available")
with open("linkFile.txt") as f:
status.config(text="Reading Temporary files")
mangaDict = eval(f.read())
selectedItem = StringVar()
chapterSelected = StringVar()
chapterSelected.set(chapterDict.keys()[0])
selectedItem.set(mangaDict.keys()[0])
optionFrame = Frame(root, bd=1, relief=SUNKEN, padx=2, pady=2, height=3)
option = OptionMenu(optionFrame, selectedItem,*mangaDict.keys())
buttonFrames = Frame(root,bd=1,relief=SUNKEN, padx=2, pady=2)
buttonFrames.pack(side=TOP)
updateMangaButton = Button(buttonFrames,text="update manga list",command=updateMangaList)
updateMangaButton.pack(side=TOP)
infoFrame = Frame(root, bd=1, relief=SUNKEN, padx=2, pady=2)
infoFrame.pack(side=LEFT)
imageFrame = Frame(infoFrame, bd=1, relief=SUNKEN, padx=2, pady=2)
imageFrame.pack(side=TOP)
option.pack(side=LEFT)
optionFrame.pack(side=RIGHT)
#Chapter Information
chapterFrame = Frame(root,bd=1,relief=SUNKEN,padx=2,pady=2)
chapterFrame.pack(side=BOTTOM)
chapterLabel = Label(chapterFrame, text="Chapter List")
chapterLabel.pack()
chapterOptionMenu = OptionMenu(chapterFrame, chapterSelected, *chapterDict)
chapterOptionMenu.pack()
#Summary information
summaryFrame = Frame(infoFrame, bd=1, relief=SUNKEN, padx=2, pady=2)
summaryFrame.pack(side=BOTTOM)
summaryVar = StringVar()
summaryLabel = Label(summaryFrame, textvariable=summaryVar, wraplength=300)
summaryVar.set("summary")
summaryLabel.pack()
#Manga Image
imageLabel = Label(imageFrame, text="manga image")
imageLabel.pack()
selectedItem.trace("w", onSelect)
chapterSelected.trace("w", onChapterSelected)
root.protocol('WM_DELETE_WINDOW', ask_quit)
addButtons()
w,h = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0"%(w,h))
root.lift()
root.mainloop()