def unlockUI(title = "Enter unlock code"): code = showComboDialog(title) while True: if (code == None): return False if (code == common.getCode()): return True code = showComboDialog("Incorrect, try again")
def chooseAction(): lines = ["Change Code" if common.getCode() else "Set Code", "TV: " + common.getTVRating() + ("" if common.getTVRating(). startswith("All") else " and below"), "Movies: " + common.getMovieRating() + ("" if common.getMovieRating().startswith("All") else " and below"), "Choose Plugins to Protect" ] return dialog.select("Parental Controls", lines)
def unlockUI(title="Enter unlock code"): code = showComboDialog(title) while True: if (code == None): return False if (code == common.getCode()): return True code = showComboDialog("Incorrect, try again")
def setCodeUI(title="Enter New Code"): if (common.getCode()): if (not unlockUI("Enter Current Code")): return False while True: code1 = showComboDialog(title) if (code1 == None): return False code2 = showComboDialog("Re-enter Code") if (code2 == None): return False if (code1 == code2): if (len(code1)>0): common.setCode(code1) common.msg("Code has been set") return True else: common.msg("Code may not be empty") else: common.msg("Codes did not match")
def setCodeUI(title="Enter New Code"): if (common.getCode()): if (not unlockUI("Enter Current Code")): return False while True: code1 = showComboDialog(title) if (code1 == None): return False code2 = showComboDialog("Re-enter Code") if (code2 == None): return False if (code1 == code2): if (len(code1) > 0): common.setCode(code1) common.msg("Code has been set") return True else: common.msg("Code may not be empty") else: common.msg("Codes did not match")
def controlAddonsUI(): while True: plugins = hook.getVideoPlugins() items = [p['name'] + (" [Protected]" if p['hooked'] and p['uptodate'] else " [Protected, Needs Update]" if p['hooked'] else " [Unprotected]") for p in plugins] choice = dialog.select("Choose Plugins to Protect",items) if (choice < 0): return p = plugins[choice] if (p['hooked'] and p['uptodate']): common.removeProtectedPlugin(p['id']) hook.unhookPlugin(p['id']) else: hook.hookPlugin(p['id']) common.addProtectedPlugin(p['id']) if (common.getCode()): allowed=codeui.unlockUI('Enter your code') else: #prompt to choose code if first time allowed=codeui.setCodeUI("Choose a Code") #prompt to protect plugins if (allowed): controlAddonsUI() #present main settings window while (allowed): action = chooseAction() if (action == 0): codeui.setCodeUI() elif (action == 1):
def draw(self, text, scale=0.1, precision=10, space=0.1, ignoreLimit=False): # 使用geometry转换fontTools生成的svg path source = "测试demo" if type(text) != str: text = str(text) if len(text) > 0: source = text source = re.sub(r"[^ ^\n\S]", " ", source) # 不可见的那些特殊符号当成空格处理 source = source.replace("\\", "\\\\") if not ignoreLimit: if len(source) > 45: source = source[:45] logConsole.warning( FutureWarning("单行模式暂时只支持45字符以内的文本. 内容`%s`被忽略" % text[46:])) elif len(text) == 0: logConsole.warning(Warning("输入不能为空. 默认内容为`测试demo`")) self.clean() # 每次draw前清理一下 self.source = list(source) cursor = [0, 0] for i, char in enumerate(source): # 依次绘制每个字符 if char != "\n": # 换行符直接跳过 try: # 这个版本暂时没做failedback字体的功能 # TODO: 加上failedback字体 charName = self.bestcmap[ord(char)] glyph = self.glyphSet[charName] charWidth, charHeight = self.getCharSize(glyph=glyph, scale=scale) except Exception as e: logConsole.warning(f"取字`{char}`信息失败: {e}") charName = self.bestcmap[ord("口")] glyph = self.glyphSet[charName] charWidth, charHeight = self.getCharSize(glyph=glyph, scale=scale) if i == 0: self.charPos.append([0, 0]) # 每个字的起始总是上一个字的起始加上(字宽+间距) cursor = [(charWidth * (1 + space)), 0] else: self.charPos.append([cursor[0], cursor[1] * charHeight]) cursor[0] += (charWidth * (1 + space)) else: cursor[0] = 0 # \r cursor[1] += 1 # \n continue try: pen = SVGPathPen( self.glyphSet ) # TODO: 待搞明白: 以前的看的例程都是传参`None`, 但实际使用发现这样会造成少数字符无法绘制的情况, 尚未找到原因. glyph.draw(pen) penCommandList = pen._commands except Exception as e: logConsole.error(f"绘制`{char}`错误: {e}") print(FutureWarning(f"绘制字符`{char}`时出错({e}), 跳过...")) continue x_previous = y_previous = 0.0 # 上一步操作的结果记录 x_current = y_current = 0.0 # 当前正在操作的过程 x_start = y_start = 0.0 # 每个路径的起点 items = [] # 临时储存字的笔画 for command in penCommandList: cmd = common.getCode(command) vec = common.getVert(command) flag_absolute = (cmd == cmd.upper()) cmd = cmd.upper() if cmd == 'M': # MoveTo x_start = x_previous = vec[0] y_start = y_previous = vec[1] if flag_absolute is True: x_current = vec[0] y_current = vec[1] else: x_current = x_previous + vec[0] y_current = y_previous + vec[1] items.append(MoveTo(Point(x_current, y_current))) x_previous, y_previous = x_current, y_current elif cmd in 'LHV': # LineTo, Horizontal 和 Vertical line # H和V需要单独取顶点 if flag_absolute is True: x_current, y_current = x_previous, y_previous else: x_current, y_current = [0, 0] if cmd == "H": # 水平线共用Y, 更新X x_current = vec[0] y_current = y_previous if cmd == "V": # 垂直线更新Y x_current = x_previous y_current = vec[0] if cmd == "L" and len(vec) == 2: x_current, y_current = vec if flag_absolute is False: x_current += x_previous y_current += y_previous items.append( Segment(Point(x_previous, y_previous), Point(x_current, y_current))) x_previous, y_previous = x_current, y_current elif cmd in 'CQ': dimension = {'Q': 2, 'C': 3} bezier_pts = [] bezier_pts.append(Point(x_previous, y_previous)) for i in range(dimension[cmd]): x_current = vec[2 * i] y_current = vec[2 * i + 1] if flag_absolute is False: x_current += x_previous y_current += y_previous bezier_pts.append(Point(x_current, y_current)) items.append(Bezier(bezier_pts)) x_previous, y_previous = x_current, y_current elif cmd == 'Z': # 闭合 items.append( Segment(Point(x_previous, y_previous), Point(x_start, y_start))) else: pass # A暂时不能处理 for item in items: item.scale(scale) self.Items.append(items)