def updateFilters(self): totalFilters = 0 updatedFilters = 0 filtersDir = directories.getFiltersDir() try: os.mkdir(os.path.join(filtersDir, "updates")) except OSError: pass for module in self.filterModules.values(): totalFilters += 1 if hasattr(module, "UPDATE_URL") and hasattr(module, "VERSION"): if isinstance(module.UPDATE_URL, (str, unicode)) and isinstance( module.VERSION, (str, unicode)): versionJSON = json.loads( urllib2.urlopen(module.UPDATE_URL).read()) if module.VERSION != versionJSON["Version"]: urllib.urlretrieve( versionJSON["Download-URL"], os.path.join(filtersDir, "updates", versionJSON["Name"])) updatedFilters += 1 for f in os.listdir(os.path.join(filtersDir, "updates")): shutil.copy(os.path.join(filtersDir, "updates", f), filtersDir) shutil.rmtree(os.path.join(filtersDir, "updates")) finishedUpdatingWidget = Widget() lbl = Label("Updated %s filter(s) out of %s" % (updatedFilters, totalFilters)) closeBTN = Button("Close this message", action=finishedUpdatingWidget.dismiss) col = Column((lbl, closeBTN)) finishedUpdatingWidget.bg_color = (0.0, 0.0, 0.6) finishedUpdatingWidget.add(col) finishedUpdatingWidget.shrink_wrap() finishedUpdatingWidget.present()
def updateFilters(self): totalFilters = 0 updatedFilters = 0 filtersDir = directories.getFiltersDir() try: os.mkdir(os.path.join(filtersDir, "updates")) except OSError: pass for module in self.filterModules.values(): totalFilters += 1 if hasattr(module, "UPDATE_URL") and hasattr(module, "VERSION"): if isinstance(module.UPDATE_URL, (str, unicode)) and isinstance(module.VERSION, (str, unicode)): versionJSON = json.loads(urllib2.urlopen(module.UPDATE_URL).read()) if module.VERSION != versionJSON["Version"]: urllib.urlretrieve(versionJSON["Download-URL"], os.path.join(filtersDir, "updates", versionJSON["Name"])) updatedFilters += 1 for f in os.listdir(os.path.join(filtersDir, "updates")): shutil.copy(os.path.join(filtersDir, "updates", f), filtersDir) shutil.rmtree(os.path.join(filtersDir, "updates")) finishedUpdatingWidget = Widget() lbl = Label("Updated %s filter(s) out of %s" % (updatedFilters, totalFilters)) closeBTN = Button("Close this message", action=finishedUpdatingWidget.dismiss) col = Column((lbl, closeBTN)) finishedUpdatingWidget.bg_color = (0.0, 0.0, 0.6) finishedUpdatingWidget.add(col) finishedUpdatingWidget.shrink_wrap() finishedUpdatingWidget.present()
def perform(level, box, options): op = options["Operation"] #print dir(level.scoreboard.Objectives) #print level.init_scoreboard().PlayerScores["Chevalerie94"] print "Test Filter Ran" if op == "Yes/No Dialog": choice = editor.YesNoWidget("Place a sponge block here?") if choice: yesFunc(level, box) raise Exception("Response was Yes") else: raise Exception("Response was No") elif op == "Custom Dialog (Hi Button)": widget = Widget() widget.bg_color = (0.0, 0.0, 0.6) lbl = Label("Test Message from a External Widget") btn = Button("Hi", action=hiAction) widget.add(lbl) widget.add(btn) widget.shrink_wrap() editor.addExternalWidget(widget) elif op == "Scoreboard Editing (Objective)": scoreboard = level.init_scoreboard() test_objective = TAG_Compound() test_objective["Name"] = TAG_String("FilterObjective") test_objective["DisplayName"] = TAG_String("FilterObjective") test_objective["CriteriaName"] = TAG_String("dummy") test_objective["RenderType"] = TAG_String("integer") scoreboard["data"]["Objectives"].append(test_objective) level.save_scoreboard(scorebaord) for objective in score.Objectives: print "Objective Name: " + str(objective["Name"].value) elif op == "Scoreboard Editing (Team)": if level.scoreboard != None: for team in level.scoreboard.Teams: print "Team Name: " + str(team.DisplayName) elif op == "Player Data": players = level.init_player_data() for p in players: print p.name for item in p.inventory: print item["id"].value print "===" p.save()
def perform(level, box, options): op = options["Operation"] #print dir(level.scoreboard.Objectives) print "Test Filter Ran" if op == "Yes/No Dialog": choice = editor.YesNoWidget("Place a sponge block here?") if choice: yesFunc(level, box) raise Exception("Response was Yes") else: raise Exception("Response was No") elif op == "Custom Dialog (Hi Button)": widget = Widget() widget.bg_color = (0.0, 0.0, 0.6) lbl = Label("Test Message from a External Widget") btn = Button("Hi", action=hiAction) widget.add(lbl) widget.add(btn) widget.shrink_wrap() editor.addExternalWidget(widget) elif op == "Scoreboard Editing (Objective)": if level.scoreboard != None: test_objective = TAG_Compound() test_objective["Name"] = TAG_String("FilterObjective") test_objective["DisplayName"] = TAG_String("FilterObjective") test_objective["CriteriaName"] = TAG_String("dummy") test_objective["RenderType"] = TAG_String("integer") test_objective = scoreboard.Objective(test_objective) level.scoreboard.Objectives.append(test_objective) level.scoreboard.save(level) for objective in level.scoreboard.Objectives: print "Objective Name: " + str(objective.Name) elif op == "Scoreboard Editing (Team)": if level.scoreboard != None: for team in level.scoreboard.Teams: print "Team Name: " + str(team.DisplayName)