def pushText(self, text, speaker = None, continuous = False, text_speed = None, fadein = None, rate = 1.0,read = False): '''添加文字 进行判断并改变文字 parameters: speaker: A string contains the speaker's name. (None means no speaker) read: see if the text is already read ''' if self.currentTextLabel and self.currentTextLabel.isWaiting(): self.currentTextLabel.quickFinish() #The text is necessary if not text: return text = text.rstrip('\n') text_speed = (text_speed or base.getStyle('textbox')['text_speed'] or runtime_data.game_settings['text_speed']) * rate if fadein is None: fadein = base.getStyle('textbox')['text_fadein_duration'] fadein_style = base.getStyle('textbox')['text_fadein_style'] if self._currentStyle == GameTextBoxStyle.Normal: if not continuous: self.currentTextLabel.clear() elif self._currentStyle == GameTextBoxStyle.Large: if not continuous and self.currentTextLabel.hasContent(): self.currentTextLabel.appendText('\n') #Inserting an empty line if continuous: #When continuous, ignore the speaker speaker = None #self.currentSpeaker = '' else: self.currentSpeaker = speaker if self._currentStyle == GameTextBoxStyle.Normal: if not continuous: if speaker: self._normal_speakerLabel.setText(self.currentSpeaker) #TODO: use SogalText else: self._normal_speakerLabel.setText(' ') elif self._currentStyle == GameTextBoxStyle.Large: if speaker: self.currentTextLabel.appendText(self.currentSpeaker,custom = True, newLine = True, textScale = self.__namescale) self.newText = text #This is *very* useful safeprint(self.newText) if not read: self.currentTextLabel.appendText(self.newText, speed = text_speed , newLine = (not continuous) , fadein = fadein, fadeinType = fadein_style) else: self.currentTextLabel.appendText(self.newText, speed = text_speed , newLine = (not continuous) , fadein = fadein, fadeinType = fadein_style, custom = True, fg = self.properties['read_fg']) self.currentText = self.currentTextLabel.getCopiedText()
def setTextBoxStyle(self, style): if style.strip() == 'normal': self._currentStyle = GameTextBoxStyle.Normal elif style.strip() == 'large': self._currentStyle = GameTextBoxStyle.Large else: safeprint('Unknown style: ' + str(style)) self.properties['style'] = style
def getepisodelist(html, url): if '"loggedIn":true' not in html: raise Exception("you didn't log in!") base = re.search("(https?://[^/]+)", url).group(1) s = [] while True: safeprint(url) startpos = html.index('id="gmi-ResourceStream"') ex = re.compile('<a class="thumb[^"]*?" href="({}/art/.+?)" title="(.+?)"'.format(base)) r = ex.findall(html, startpos) for m in r: id = re.search("\d+$", m[0]).group() title = m[1].rpartition(" by ")[0] # WTF r u doing deviantArt? title = unescape(unescape(title)) e = comiccrawler.Episode() e.firstpageurl = m[0] e.title = "{} - {}".format(id, title) s.append(e) next = re.search('id="gmi-GPageButton"[^>]+?href="([^"]+?)"><span>Next</span>', html) if not next: break url = base + next.group(1).replace("&", "&") html = comiccrawler.grabhtml(url, header) return s[::-1]
def rename(file, format): with open(file, "rb") as f: source = f.read() dir, filename = os.path.split(file) safeprint("Parse {}...".format(filename)) article = Article(source) repl = {} repl["@title"] = article.getTitle() or "None" repl["@author"] = article.getAuthor() or "None" repl["@board"] = article.getBoard() or "None" tm = article.getTime() if tm: tm = time.strftime("%Y%m%d%H%M%S", tm) repl["@time"] = tm or "None" pattern = re.compile(r"(" + "|".join(repl.keys()) + ")") newFile = pattern.sub(lambda x: repl[x.group()], format) newFile = makeSafeFileName(newFile) safeprint("Rename to {}...\n".format(newFile)) safeRename(file, newFile)
def _loadSettings(self): if not exists(game_settings['save_folder']+ 'config.dat'): return try: settings = load_data(game_settings['save_folder'] + 'config.dat') except Exception as error: safeprint(error) return restoreSettings(settings)
def _loadGlobalData(self): if not exists(game_settings['save_folder']+ 'global.dat'): return try: gdata = load_data(game_settings['save_folder']+ 'global.dat') except Exception as exp: safeprint(exp) return restoreGlobalData(gdata)
def _loadReadText(self): if not exists(game_settings['save_folder']+ 'read.dat'): return try: read = load_data(game_settings['save_folder']+ 'read.dat') except Exception as exp: safeprint(exp) return restoreReadText(read)
def _loadSettings(self): if not exists(game_settings['save_folder'] + 'config.dat'): return try: settings = load_data(game_settings['save_folder'] + 'config.dat') except Exception as error: safeprint(error) return restoreSettings(settings)
def _loadGlobalData(self): if not exists(game_settings['save_folder'] + 'global.dat'): return try: gdata = load_data(game_settings['save_folder'] + 'global.dat') except Exception as exp: safeprint(exp) return restoreGlobalData(gdata)
def _loadReadText(self): if not exists(game_settings['save_folder'] + 'read.dat'): return try: read = load_data(game_settings['save_folder'] + 'read.dat') except Exception as exp: safeprint(exp) return restoreReadText(read)
def loadMemory(self,dumped): try: loaded = pickle.loads(dumped) except Exception as exp: safeprint(exp) return self.storyManager.destroy() self.audioPlayer.stopAll(0.5) restoreRuntimeData(loaded) self.audioPlayer.reload() self.storyManager = StoryManager()
def loadMemory(self, dumped): try: loaded = pickle.loads(dumped) except Exception as exp: safeprint(exp) return self.storyManager.destroy() self.audioPlayer.stopAll(0.5) restoreRuntimeData(loaded) self.audioPlayer.reload() self.storyManager = StoryManager()
def getepisodelist(html, url=""): # html = html.replace("\n","") ms = re.findall("<li><a href=\"(.+?)\" target=\"_blank\">(.+?)</a></li>", html, re.M) base = re.search("(https?://[^/]+)", url).group(1) safeprint(ms) s = [] for m in ms: url, title = m e = comiccrawler.Episode() title = re.sub("<.+?>","",title) e.title = title e.firstpageurl = base + url s.append(e) return s[::-1]
def getimgurls(html, **kw): if '"loggedIn":true' not in html: raise Exception("you didn't log in!") loggedin = re.search('"loggedIn":true', html) if not loggedin: safeprint("Warning! You didn't log in.") html = html.replace("\n", "") try: i = re.search('dev-page-download"\s+href="([^"]+)"',html).group(1) return [unescape(i)] except Exception: pass i = re.search('<img[^>]+src="([^"]+)"[^>]+class="dev-content-full">', html).group(1) return [i]
def save(self,saving,fileName,message): info = SavingInfo(message,datetime.now()) try: save_data(game_settings['save_folder'] + fileName + game_settings['save_type'], saving) save_data(game_settings['save_folder'] + fileName + game_settings['save_infotype'], info) except Exception as error: safeprint(error) return self.saveForm.reloadMember(fileName) self.loadForm.reloadMember(fileName) self._saveReadText() self._saveGlobalData()
def load(self,fileName): try: savedData = load_data(game_settings['save_folder'] + fileName + game_settings['save_type']) except Exception as error: safeprint(error) return if self.mainMenu: self.mainMenu.close() if self.storyManager: self.storyManager.destroy() self.audioPlayer.stopAll(0.5) restoreRuntimeData(savedData) self.audioPlayer.reload() self.storyManager = StoryManager()
def load(self, fileName): try: savedData = load_data(game_settings['save_folder'] + fileName + game_settings['save_type']) except Exception as error: safeprint(error) return if self.mainMenu: self.mainMenu.close() if self.storyManager: self.storyManager.destroy() self.audioPlayer.stopAll(0.5) restoreRuntimeData(savedData) self.audioPlayer.reload() self.storyManager = StoryManager()
def save(self, saving, fileName, message): info = SavingInfo(message, datetime.now()) try: save_data( game_settings['save_folder'] + fileName + game_settings['save_type'], saving) save_data( game_settings['save_folder'] + fileName + game_settings['save_infotype'], info) except Exception as error: safeprint(error) return self.saveForm.reloadMember(fileName) self.loadForm.reloadMember(fileName) self._saveReadText() self._saveGlobalData()
def getepisodelist(html, url="", **kw): s = [] base = re.search("(https?://[^/]+)", url).group(1) while True: ms = re.findall(r'href="(/(?:[^/]*/)?post/show/(\d+))"', html) for m in ms: url, pid = m e = Episode() e.title = pid e.firstpageurl = base + url s.append(e) m = re.search('next-page-url="([^"]+)"', html) if not m: break u = unescape(m.group(1)) safeprint(base + u) html = grabhtml(base + u, header) return s[::-1]
def getepisodelist(html, url=""): s = [] base = re.search("(https?://[^/]+)", url).group(1) while True: for match in re.finditer(r'href="(/posts/(\d+)[^"]*)"', html): u = match.group(1) title = match.group(2) e = cc.Episode() e.title = title e.firstpageurl = base + u s.append(e) # safeprint(u) u = re.search(r'"([^"]+)" rel="next"', html) if not u: break u = base + unescape(u.group(1)) safeprint(u) html = cc.grabhtml(u) return s[::-1]
def getepisodelist(html, url=""): s = [] root = re.search("https?://[^/]+", url).group() base = re.search("https?://[^?]+", url).group() while True: ms = re.findall(r'<a href="([^"]+)"><h1 class="title" title="([^"]+)">', html) # safeprint(ms) for m in ms: url, title = m uid = re.search("id=(\d+)", url).group(1) e = Episode() e.title = "{} - {}".format(uid, title) e.firstpageurl = root + url s.append(e) un = re.search("href=\"([^\"]+)\" rel=\"next\"", html) if un is None: break u = un.group(1).replace("&", "&") safeprint(base + u) html = grabhtml(base + u, hd=header) return s[::-1]
def getepisodelist(html, url=""): s = [] base = re.search("(https?://[^/]+)", url).group(1) while True: ms = re.findall('<a class="thumb" href="([^"]+)"', html) # safeprint(ms) for m in ms: url = m # print(url) uid = re.search(r"show/(\d+)", url).group(1) e = comiccrawler.Episode() e.title = uid e.firstpageurl = base + url s.append(e) un = re.search('<a class="next_page" rel="next" href="([^"]+)">', html) if un is None: break u = unescape(un.group(1)) safeprint(base + u) html = comiccrawler.grabhtml(base + u, hd=header) # safeprint(s) return s[::-1]
def getepisodelist(html, url=""): # html = html.replace("\n","") # print("test") s = [] base = re.search("(https?://[^/]+)", url).group(1) while True: ms = re.findall("<a onclick=\"_gaq.push\(\['_trackEvent', '詳情頁-lists','[^']+','[^']+'\]\);\" target=\"_blank\" href=\"([^\"]+)\" title=\"[^\"]+\">(.+?)</a>", html, re.M) safeprint(str(ms)) for m in ms: url, title = m e = comiccrawler.Episode() # title = re.sub("<.+?>","",title) e.title = title e.firstpageurl = base + url s.append(e) un = re.search("ref=\"([^\"]+?)\" title='下一頁'", html) if un is None: break safeprint(base + un.group(1)) html = comiccrawler.grabhtml(base + un.group(1), hd=header) return s[::-1]
def _saveReadText(self): try: save_data(game_settings['save_folder'] + 'read.dat', read_text) except Exception as exp: safeprint(exp)
def _saveReadText(self): try: save_data(game_settings['save_folder']+ 'read.dat', read_text) except Exception as exp: safeprint(exp)
def _saveGlobalData(self): try: save_data(game_settings['save_folder'] + 'global.dat', global_data) except Exception as exp: safeprint(exp)
def _saveSettings(self): try: save_data(game_settings['save_folder'] + 'config.dat', game_settings) except Exception as exp: safeprint(exp)
def _saveGlobalData(self): try: save_data(game_settings['save_folder']+ 'global.dat', global_data) except Exception as exp: safeprint(exp)
def pushText(self, text, speaker=None, continuous=False, text_speed=None, fadein=None, rate=1.0, read=False): '''添加文字 进行判断并改变文字 parameters: speaker: A string contains the speaker's name. (None means no speaker) read: see if the text is already read ''' if self.currentTextLabel and self.currentTextLabel.isWaiting(): self.currentTextLabel.quickFinish() #The text is necessary if not text: return text = text.rstrip('\n') text_speed = (text_speed or base.getStyle('textbox')['text_speed'] or runtime_data.game_settings['text_speed']) * rate if fadein is None: fadein = base.getStyle('textbox')['text_fadein_duration'] fadein_style = base.getStyle('textbox')['text_fadein_style'] if self._currentStyle == GameTextBoxStyle.Normal: if not continuous: self.currentTextLabel.clear() elif self._currentStyle == GameTextBoxStyle.Large: if not continuous and self.currentTextLabel.hasContent(): self.currentTextLabel.appendText( '\n') #Inserting an empty line if continuous: #When continuous, ignore the speaker speaker = None #self.currentSpeaker = '' else: self.currentSpeaker = speaker if self._currentStyle == GameTextBoxStyle.Normal: if not continuous: if speaker: self._normal_speakerLabel.setText( self.currentSpeaker) #TODO: use SogalText else: self._normal_speakerLabel.setText(' ') elif self._currentStyle == GameTextBoxStyle.Large: if speaker: self.currentTextLabel.appendText(self.currentSpeaker, custom=True, newLine=True, textScale=self.__namescale) self.newText = text #This is *very* useful safeprint(self.newText) if not read: self.currentTextLabel.appendText(self.newText, speed=text_speed, newLine=(not continuous), fadein=fadein, fadeinType=fadein_style) else: self.currentTextLabel.appendText(self.newText, speed=text_speed, newLine=(not continuous), fadein=fadein, fadeinType=fadein_style, custom=True, fg=self.properties['read_fg']) self.currentText = self.currentTextLabel.getCopiedText()
def _saveSettings(self): try: save_data(game_settings['save_folder']+ 'config.dat', game_settings) except Exception as exp: safeprint(exp)