import Jokosher.Extension import gtk import gtk.glade import os import pkg_resources import Globals class APIConsole: def OnMenuItemClick(self,arg): xmlString = pkg_resources.resource_string(__name__,"APIConsole.glade") wTree = gtk.glade.xml_new_from_buffer(xmlString, len(xmlString),"APITestDialog") signal = {"on_Activate" : self.Execute} wTree.signal_autoconnect(signal) window = wTree.get_widget("APITestDialog") self.command = wTree.get_widget("entry1") self.output = wTree.get_widget("textview1") self.scrollwindow = wTree.get_widget("scrolledwindow1") self.output_text = gtk.TextBuffer() self.output_text.insert_at_cursor("dir - a list of API functions\n" + "help - show documentation for a function\n" + "clear - clear text buffer\n" "--------------------------------\n") self.output.set_buffer(self.output_text) self.output.scroll_mark_onscreen(self.output_text.get_insert()) window.show_all() def Execute(self, arg): self.output_text.insert_at_cursor(">>>>"+self.command.get_text()+"\n") if self.command.get_text() == "dir" or self.command.get_text() == "ls": outputList = [] for i in dir(self.API): i = getattr(self.API, i) if callable(i): outputList.append(i.__name__) self.output_text.insert_at_cursor("\n".join(outputList)+"\n\n") elif self.command.get_text().startswith("help"): cmd = self.command.get_text()[4:].strip() if hasattr(self.API, cmd): i = getattr(self.API, cmd) self.output_text.insert_at_cursor(i.__name__+":\n"+i.__doc__+"\n\n") elif self.command.get_text() == "clear": self.output_text.set_text("dir - a list of API functions\n" + "help - show documentation for a function\n" + "clear - clear text buffer\n" "--------------------------------\n") else: try: rvalue = eval("self.API."+self.command.get_text()) if rvalue: self.output_text.insert_at_cursor(str(rvalue)+"\n\n") except: self.output_text.insert_at_cursor("Malformed function call, unimplimented function, or some random exception!\n\n") self.command.set_text("") self.output.set_buffer(self.output_text) self.output.scroll_mark_onscreen(self.output_text.get_insert()) #You know you're a Newfie when: You think the first day of salmon fishing season is a provincial holiday def startup(self, api): self.API = api self.API.add_menu_item("API Console", self.OnMenuItemClick) Globals.debug("API Console Started Up")