def edit(self, text, jumpIndex=None, highlight=None): """ Calls the editor and thus allows the user to change the text. Returns the modified text. Halts the thread's operation until the editor is closed. Returns None if the user didn't save the text file in his text editor. Parameters: * text - a Unicode string * jumpIndex - an integer: position at which to put the caret * highlight - a substring; each occurence will be highlighted """ text = self.convertLinebreaks(text) if config.get("editor"): tempFilename = "%s.%s" % (tempfile.mktemp(), config.get("editor_filename_extension")) tempFile = open(tempFilename, "w") tempFile.write(text.encode(config.get("editor_encoding"))) tempFile.close() creationDate = os.stat(tempFilename).st_mtime command = self.command(tempFilename, text, jumpIndex) os.system(command) lastChangeDate = os.stat(tempFilename).st_mtime if lastChangeDate == creationDate: # Nothing changed return None else: newcontent = open(tempFilename).read().decode(config.get("editor_encoding")) os.unlink(tempFilename) return self.restoreLinebreaks(newcontent) else: return self.restoreLinebreaks(wikipedia.ui.editText(text, jumpIndex=jumpIndex, highlight=highlight))
def main_loop(): screen_width = config.get("screen_width") screen_height = config.get("screen_height") screen = UI.Screen(fps=30, width=screen_width, height=screen_height) main = main_screen.MainScreen(screen_width, screen_height) screen.add_child(main) while True: for event in pygame.event.get(): process_event(event, screen) screen.Draw()
def command(self, tempFilename, text, jumpIndex=None): command = config.get("editor") if jumpIndex: # Some editors make it possible to mark occurences of substrings, or # to jump to the line of the first occurence. # TODO: Find a better solution than hardcoding these, e.g. a config # option. line = text[:jumpIndex].count("\n") column = jumpIndex - (text[:jumpIndex].rfind("\n") + 1) else: line = column = 0 # Linux editors. We use startswith() because some users might use parameters. if config.get("editor").startswith("kate"): command += " -l %i -c %i" % (line, column) elif config.get("editor").startswith("gedit"): command += " +%i" % (line + 1) # seems not to support columns elif config.get("editor").startswith("emacs"): command += " +%i" % (line + 1) # seems not to support columns elif config.get("editor").startswith("jedit"): command += " +line:%i" % (line + 1) # seems not to support columns elif config.get("editor").startswith("vim"): command += " +%i" % (line + 1) # seems not to support columns elif config.get("editor").startswith("nano"): command += " +%i,%i" % (line + 1, column + 1) # Windows editors elif config.get("editor").lower().endswith("notepad++.exe"): command += " -n%i" % (line + 1) # seems not to support columns command += " %s" % tempFilename # print command return command
def inputunicode(question, password=False): """ Works like raw_input(), but returns a unicode string instead of ASCII. Unlike raw_input, this function automatically adds a space after the question. """ # TODO: make sure this is logged as well print question + " " if password: import getpass text = getpass.getpass("") else: text = raw_input() text = unicode(text, config.get("console_encoding")) return text
out.write( codecs.BOM_UTF8 ) for i in success: out.write( i.encode( "utf-8" ) ) out.close() out = file( "log_fail.txt", "w" ) out.write( codecs.BOM_UTF8 ) for i in failure: out.write( i.encode( "utf-8" ) ) out.close() import atexit atexit.register(savecounter) if __name__ == '__main__': print "Connecting as %s to http://%s%s" % (config.get("username"), config.get("site"), config.get("path")) site = mwclient.Site(config.get("site"), path=config.get("path")) site.login(config.get("username"),config.get("password")) namespaces = { 0 :"Main", 1 :"Talk", 2 :"User", 3 :"User talk", 4 :"HealthWiki", 5 :"HealthWiki talk", 6 :"Image", 7 :"Image talk", 8 :"MediaWiki", 9 :"MediaWiki talk", 10:"Template",
def LoadPlugins(): """Load plugins from config data""" p = config.get("plugins") print(p) return {}
def __init__(self): self.set_options() self.site = mwclient.Site(config.get("site"), config.get("path")) self.site.login(config.get("username"), config.get("password")) self.setpage()
def load_skin(name="default"): global __Colors, __name # Set some default values __Colors["background"] = (32, 32, 32) __Colors["high"] = (51, 166, 255) __Colors["text"] = (83, 83, 83) __Colors["front"] = (131, 199, 219) __Colors["url"] = (51, 166, 255) __Colors["line"] = (169, 169, 169) __Colors["title_bg"] = (228, 228, 228) __Colors["active"] = (175, 90, 0) __Colors["white"] = (255, 255, 255) __name = name # Now read from skin file cfg = configparser.ConfigParser() skin_folder = os.path.join(config.get("skinfolder"), name) cfgfile = os.path.join(skin_folder, "config.cfg") try: cfg.read(cfgfile) except Exception as e: if __name == "default": print("INTERNAL ERROR: Can't load default skin. Aborting") sys.exit(-1) # TODO: Turn that into a message box print( "Skin configuration file for '{name}' is invalid, loading default skin" .format(name=name)) load_skin("default") return # Load skin colors if __SKIN_CFG_COLORS_TAG in cfg.sections(): config_color = cfg.options(__SKIN_CFG_COLORS_TAG) for color in config_color: try: __Colors[color.lower()] = __convert_html_color( cfg.get(__SKIN_CFG_COLORS_TAG, color)) except Exception: print( "WARN: Skin '{name}': color value for '{color}' is invalid" .format(name=name, color=color)) # Load skin fonts if __SKIN_CFG_FONTS_TAG in cfg.sections(): config_fonts = cfg.options(__SKIN_CFG_FONTS_TAG) for font in config_fonts: UI.FontManager.add_fontfile( font, os.path.join(skin_folder, __SKIN_FONT_FOLDER, cfg.get(__SKIN_CFG_FONTS_TAG, font))) # Load skin images if __SKIN_CFG_IMAGES_TAG in cfg.sections(): config_images = cfg.options(__SKIN_CFG_IMAGES_TAG) for image in config_images: UI.ImageManager.add_image( image, os.path.join(skin_folder, __SKIN_IMAGE_FOLDER, cfg.get(__SKIN_CFG_IMAGES_TAG, image)))