def save_to_file(self): file_browser = FileBrowser() file_browser.saveFileDialog() filename = file_browser.file file = open(filename, 'w') for line in self.split_code: if len(line) == 3: file.write(line[0] + " " + line[1] + ", " + line[2] + "\n") elif len(line) == 2: file.write(line[0] + " " + line[1] + "\n") elif len(line) == 1: file.write(line[0] + "\n") file.close()
class PlideTabExpdir(PlideTab): """Plide tab for browsing expdirs. """ def __init__(self, notebook, expdir): PlideTab.__init__(self, notebook) self.expdir = expdir self.w_frame_left = gtk.Frame() self.w_frame_left.set_property("shadow-type", gtk.SHADOW_IN) self.w_frame_right = gtk.Frame() self.w_frame_right.set_property("shadow-type", gtk.SHADOW_IN) self.browser = FileBrowser(expdir, [".metadata"]) self.browser.set_double_click_callback(self.double_click_callback) self.w_frame_left.add(self.browser.get_widget()) self.w_pane = gtk.HPaned() self.w_pane.pack1(self.w_frame_left) self.w_pane.pack2(self.w_frame_right) self.w_pane.set_property("position", 350) self.w_pane.set_property("position-set", True) self.w_pane.show_all() self.append_to_notebook(self.w_pane, os.path.basename(self.expdir), PlideTab.TAB_TYPE_DIRECTORY) def get_directory(self): return self.expdir def double_click_callback(self, browser, pathname, isdir): if not isdir: ext = os.path.splitext(pathname)[1] viewer = None if ext == ".pmat": pmat = PMatListModel(PMat(pathname, openmode='r')) viewer = MatrixViewer(pmat).get_widget() else: f = open(pathname) contents = f.read() f.close() viewer = PlideTabScintilla.scintilla_widget(contents, True) if ext in [".py", ".pymat", ".pyplearn", ".plearn", ".psave"]: PlideTabPython.set_scintilla_style_for_python(viewer) if viewer: container_remove_children(self.w_frame_right) viewer.show_all() self.w_frame_right.add(viewer)
class PlideTabExpdir( PlideTab ): """Plide tab for browsing expdirs. """ def __init__(self, notebook, expdir): PlideTab.__init__(self, notebook) self.expdir = expdir self.w_frame_left = gtk.Frame() self.w_frame_left.set_property("shadow-type", gtk.SHADOW_IN) self.w_frame_right = gtk.Frame() self.w_frame_right.set_property("shadow-type", gtk.SHADOW_IN) self.browser = FileBrowser(expdir, [ ".metadata" ]) self.browser.set_double_click_callback(self.double_click_callback) self.w_frame_left.add(self.browser.get_widget()) self.w_pane = gtk.HPaned() self.w_pane.pack1(self.w_frame_left) self.w_pane.pack2(self.w_frame_right) self.w_pane.set_property("position", 350) self.w_pane.set_property("position-set", True) self.w_pane.show_all() self.append_to_notebook(self.w_pane, os.path.basename(self.expdir), PlideTab.TAB_TYPE_DIRECTORY) def get_directory( self ): return self.expdir def double_click_callback( self, browser, pathname, isdir ): if not isdir: ext = os.path.splitext(pathname)[1] viewer = None if ext == ".pmat": pmat = PMatListModel(PMat(pathname, openmode='r')) viewer = MatrixViewer(pmat).get_widget() else: f = open(pathname) contents = f.read() f.close() viewer = PlideTabScintilla.scintilla_widget(contents, True) if ext in [ ".py", ".pymat", ".pyplearn", ".plearn", ".psave" ]: PlideTabPython.set_scintilla_style_for_python(viewer) if viewer: container_remove_children(self.w_frame_right) viewer.show_all() self.w_frame_right.add(viewer)
def main(): try: opts, args = getopt.getopt(sys.argv[1:], "hd:e:", ["help", "basedir", "extension"]) except getopt.GetoptError as err: print(str(err)) usage() sys.exit(2) extension = '*.java' base_dir = os.path.dirname(os.path.abspath(__file__)) for o, a in opts: if o in ("-h", "--help"): usage() sys.exit() elif o in ("-d", "--basedir"): base_dir = a elif o in ("-e", "--extension"): extension = a else: assert False, "unhandled option" files = FileBrowser.get_files(basedir=base_dir, extension=extension) parser = CodeParser() for f in files: parser.get_requirements_and_test_cases(f) writer = MatrixWriter(parser.req_test_mapping) writer.write()
def load_from_file(self): """ Zaladowanie kodu z pliku o nazwie file_name i zapisanie go do listy split_code (z instrukcjami rozdzielonymi od argumentów) """ file_browser = FileBrowser() file_browser.openFileNameDialog() filename = file_browser.file self.delete_program() file = open(filename, 'r') lines = file.readlines() for line in lines: split_line = re.split(' |, |;|\n', line) split_line = split_line[:3] if split_line[-1] == '': split_line.pop() if split_line[-1] == '': split_line.pop() self.split_code.append(split_line) file.close() self.show_program()
def __init__(self, notebook, expdir): PlideTab.__init__(self, notebook) self.expdir = expdir self.w_frame_left = gtk.Frame() self.w_frame_left.set_property("shadow-type", gtk.SHADOW_IN) self.w_frame_right = gtk.Frame() self.w_frame_right.set_property("shadow-type", gtk.SHADOW_IN) self.browser = FileBrowser(expdir, [".metadata"]) self.browser.set_double_click_callback(self.double_click_callback) self.w_frame_left.add(self.browser.get_widget()) self.w_pane = gtk.HPaned() self.w_pane.pack1(self.w_frame_left) self.w_pane.pack2(self.w_frame_right) self.w_pane.set_property("position", 350) self.w_pane.set_property("position-set", True) self.w_pane.show_all() self.append_to_notebook(self.w_pane, os.path.basename(self.expdir), PlideTab.TAB_TYPE_DIRECTORY)
def edit(self): # Render #print "BookEditor.edit()" bookSection = self.__bookSection.render() fileBrowserSection = FileBrowser(self.iceContext).render( self.__fileBrowserPath, display=False) htmlTemplate = self.iceContext.HtmlTemplate(templateFile=self.TEMPLATE_FILE, allowMissing=True) dataDict = { "textToHtml":self.iceContext.textToHtml, "isServer":self.iceContext.isServer, "bookSection":bookSection, "fileBrowserSection": fileBrowserSection, } html = htmlTemplate.transform(dataDict) return html
def __init__(self, notebook, expdir): PlideTab.__init__(self, notebook) self.expdir = expdir self.w_frame_left = gtk.Frame() self.w_frame_left.set_property("shadow-type", gtk.SHADOW_IN) self.w_frame_right = gtk.Frame() self.w_frame_right.set_property("shadow-type", gtk.SHADOW_IN) self.browser = FileBrowser(expdir, [ ".metadata" ]) self.browser.set_double_click_callback(self.double_click_callback) self.w_frame_left.add(self.browser.get_widget()) self.w_pane = gtk.HPaned() self.w_pane.pack1(self.w_frame_left) self.w_pane.pack2(self.w_frame_right) self.w_pane.set_property("position", 350) self.w_pane.set_property("position-set", True) self.w_pane.show_all() self.append_to_notebook(self.w_pane, os.path.basename(self.expdir), PlideTab.TAB_TYPE_DIRECTORY)
def ajaxCallback(iceContext): mimeType = "text/html" path = iceContext.path bookFileItem = iceContext.rep.getItemForUri(path) data = "<div>BookEditor Ajax result path='%s'</div>" % path toc = None requestData = iceContext.requestData cmd = requestData.value("cmd", "") arg1 = requestData.value("arg1", "") arg2 = requestData.value("arg2", "") #print "-bookEditor ajax call (cmd='%s')" % cmd #print "-BookEditor Ajax callback cmd='%s', arg1='%s', arg2='%s'" % (cmd, arg1, arg2) if cmd=="changePath": data = FileBrowser(iceContext).render(arg1) else: # get packageRoot pItem = bookFileItem while pItem is not None and not pItem.isPackageRoot: pItem = pItem.parentItem packageItem = pItem try: arg1i = int(arg1) except: arg1i = 0 bookSection = BookSection(iceContext, bookFileItem, packageItem) if cmd=="remove": try: bookSection.removeDocument(arg1i) except Exception, e: bookSection.message = "Error: %s" % str(e) elif cmd=="addFile": try: bookSection.insertFile(index=arg1i, relPath=arg2) except Exception, e: bookSection.message = "Error: %s" % str(e)
def test_get_files(self): files = FileBrowser.get_files(extension='*.java') self.assertEqual(3, len(files))