Beispiel #1
0
def Help_Contents(ae):
    if Help_Contents.help == None:
        htmldoc = Help_Contents.element.getChildElements()
        ndebug( htmldoc.get(0).toXML() )
        Help_Contents.help = JFrame(title="GnitPick Help Contents")
        viewSize = controller.view.getSize()
        Help_Contents.help.setSize( java.lang.Float(viewSize.width*0.80).intValue(), java.lang.Float(viewSize.height*0.90).intValue() )
        Help_Contents.help.setLayout( BorderLayout() )
        textpane=JEditorPane( "text/html", htmldoc.get(0).toXML() )
        textpane.setEditable(0)
        scrollpane=JScrollPane(textpane)
        Help_Contents.help.getContentPane().add( scrollpane, BorderLayout.CENTER ) 
        Help_Contents.help.defaultCloseOperation=JFrame.HIDE_ON_CLOSE
        Help_Contents.help.setLocationRelativeTo(controller.view)
    Help_Contents.help.setVisible(1)
    def openProject(self, projectdir):   # File projectdir
            # Check to see that no other project is open at the moment
            # It would be interesting to allow multiple projects but this would complicate the view        
        if self.model.getCurrentProject() != None:
            self.view.status("Cannot but open one project at a time, bucko!")
            return None
        
        if projectdir == None: 
            return None
            
        self.view.status( "Processing directory "+projectdir.getName() )
        self.model.openProject( 0, projectdir)
           # Jython doesn't have listdir; use Java instead
        # for item in filter( lambda x: re.search(".*\.story",x), listdir( projectdir.getPath() ) ):
        myitems = filter( self.filefilter, projectdir.listFiles() )
        if len(myitems) > 0:
            for fileitem in myitems:
                inputfile=open(fileitem.getPath(),"r")
                unparsedcontent=inputfile.read()
                inputfile.close()
                try:
                    self.view.status("Examining file "+fileitem.getName() )
                    doc = Builder().build( fileitem )
                    summary = XQueryUtil.xquery(doc, "/story/@title").get(0).getValue()
                    content = doc.toXML()
                    self.model.addItemToProject( fileitem, summary, content )
                except XMLException, e:
                    ndebug(unparsedcontent)
                    self.view.status("Can't find an XML parser: "+e.toString() )
                    ndebug("Can't find an XML parser: "+e.toString() )
                    self.model.addItemToProject( fileitem, fileitem.getName() + " (Warning: not well-formed: ``"+e.toString()+"'')" , unparsedcontent )
                except ParsingException, e:
# Yawn! Jython can't seem to call FileReader successfully. It always returns empty content.
# Maybe something to do with wrapping the arguments. 
#                    myunparsedcontent=""
#                    filereader=FileReader( fileitem )
#                    filereader.read(myunparsedcontent)                    
                    ndebug(unparsedcontent)
                    self.view.status("The XML Parser reports errors on the file " + fileitem.getName() + ": "+e.toString() )
                    ndebug("The XML Parser reports errors on the file " + fileitem.getName() + ": "+e.toString() )
                    self.model.addItemToProject( fileitem, fileitem.getName() + " (Warning: parser errors: ``"+e.toString()+"'')" , unparsedcontent )
                    
#                   ndebug("My Junk:" + myjunk)
                    
                except IOException, e:
                    self.view.status("The file "+fileitem.getName()+" could not be opened: "+e.toString() )
                    ndebug("The file "+fileitem.getName()+" could not be opened: "+e.toString() )
                    self.model.addItemToProject( fileitem, fileitem.getName() + " (Error: file may be truncated ``"+e.toString()+"'')" , unparsedcontent )
 def openNewItem(self,itempath):
     itempath=self.normalizeItemFileName(itempath)
     # Construct a sane default instance of an item
     defaultcontent = self.defaultItemContent
     # Add the item to the current model
     # ... use xom to create a new document model object with default content
     # then open the new item from the model
     fileitem = File(itempath)
     unparsedcontent=defaultcontent
     
     try:
         self.view.status("Examining file "+fileitem.name )
         doc = Builder().build( unparsedcontent, "" )
         summary = XQueryUtil.xquery(doc, "/story/@title").get(0).getValue()
         content = doc.toXML()
         self.model.addItemToProject( fileitem, summary, content )
     except XMLException, e:
         ndebug(unparsedcontent)
         self.view.status("Can't find an XML parser: "+e.toString() )
         ndebug("Can't find an XML parser: "+e.toString() )
         self.model.addItemToProject( fileitem, fileitem.getName() + " (Warning: not well-formed: ``"+e.toString()+"'')" , unparsedcontent )
Beispiel #4
0
    def openNewItem(self, itempath):
        itempath = self.normalizeItemFileName(itempath)
        # Construct a sane default instance of an item
        defaultcontent = self.defaultItemContent
        # Add the item to the current model
        # ... use xom to create a new document model object with default content
        # then open the new item from the model
        fileitem = File(itempath)
        unparsedcontent = defaultcontent

        try:
            self.view.status("Examining file " + fileitem.name)
            doc = Builder().build(unparsedcontent, "")
            summary = XQueryUtil.xquery(doc, "/story/@title").get(0).getValue()
            content = doc.toXML()
            self.model.addItemToProject(fileitem, summary, content)
        except XMLException, e:
            ndebug(unparsedcontent)
            self.view.status("Can't find an XML parser: " + e.toString())
            ndebug("Can't find an XML parser: " + e.toString())
            self.model.addItemToProject(
                fileitem,
                fileitem.getName() + " (Warning: not well-formed: ``" +
                e.toString() + "'')", unparsedcontent)
 def notifyCurrentItem(self, itemfile):
     if itemfile == self.model.currentProject:
         ndebug("Current file now project " + itemfile.getName())
         self.view.gnitPickMenuBar.setMenuOff( "File_CloseItem" )
         self.view.gnitPickMenuBar.setMenuOff( "File_SaveItem" )
         self.view.gnitPickMenuBar.setMenuOff( "Edit_Undo" )
         self.view.gnitPickMenuBar.setMenuOff( "Edit_Redo" )    
         self.view.gnitPickMenuBar.setMenuOff( "Tools_QueryDomain_All" )
         self.view.gnitPickMenuBar.setMenuOff( "Tools_QueryDomain_Current" )
         self.view.gnitPickMenuBar.setMenuOff( "Tools_Query" )            
         self.model.currentItem = None
     elif itemfile != None:
         ndebug("Current file not project, not None " + itemfile.getName())
         self.view.gnitPickMenuBar.setMenuOn( "File_CloseItem" )
         self.view.gnitPickMenuBar.setMenuOn( "File_SaveItem" )
         self.view.gnitPickMenuBar.setMenuOn( "File_CloseProject" )
         self.view.gnitPickMenuBar.setMenuOn( "Tools_QueryDomain_All" )
         self.view.gnitPickMenuBar.setMenuOn( "Tools_QueryDomain_Current" )
         self.view.gnitPickMenuBar.setMenuOn( "Tools_Query" )            
         self.model.currentItem = itemfile
         
         if self.view.checkUndoable():
             self.view.gnitPickMenuBar.setMenuOn( "Edit_Undo" )                    
         else:
             self.view.gnitPickMenuBar.setMenuOff( "Edit_Undo" )
                                 
         if self.view.checkRedoable():
             self.view.gnitPickMenuBar.setMenuOn( "Edit_Redo" )                    
         else:
             self.view.gnitPickMenuBar.setMenuOff( "Edit_Redo" )      
     else:
         ndebug("Current file not project, must be None " + itemfile.getName())
         self.view.gnitPickMenuBar.setMenuOff( "File_SaveItem" )
         self.view.gnitPickMenuBar.setMenuOff( "File_CloseItem" )
         self.view.gnitPickMenuBar.setMenuOff( "File_CloseProject" )
         self.view.gnitPickMenuBar.setMenuOff( "Edit_Undo" )
         self.view.gnitPickMenuBar.setMenuOff( "Edit_Redo" )
         self.view.gnitPickMenuBar.setMenuOff( "Tools_QueryDomain_All" )
         self.view.gnitPickMenuBar.setMenuOff( "Tools_QueryDomain_Current" )
         self.view.gnitPickMenuBar.setMenuOff( "Tools_Query" )            
             
                     
     if self.view.tabbedPane.getTabCount() < 2:
        self.view.gnitPickMenuBar.setMenuOff( "View_NextTab")
        self.view.gnitPickMenuBar.setMenuOff( "View_PriorTab")
     else:
        self.view.gnitPickMenuBar.setMenuOn( "View_NextTab")
        self.view.gnitPickMenuBar.setMenuOn( "View_PriorTab") 
Beispiel #6
0
    def notifyCurrentItem(self, itemfile):
        if itemfile == self.model.currentProject:
            ndebug("Current file now project " + itemfile.getName())
            self.view.gnitPickMenuBar.setMenuOff("File_CloseItem")
            self.view.gnitPickMenuBar.setMenuOff("File_SaveItem")
            self.view.gnitPickMenuBar.setMenuOff("Edit_Undo")
            self.view.gnitPickMenuBar.setMenuOff("Edit_Redo")
            self.view.gnitPickMenuBar.setMenuOff("Tools_QueryDomain_All")
            self.view.gnitPickMenuBar.setMenuOff("Tools_QueryDomain_Current")
            self.view.gnitPickMenuBar.setMenuOff("Tools_Query")
            self.model.currentItem = None
        elif itemfile != None:
            ndebug("Current file not project, not None " + itemfile.getName())
            self.view.gnitPickMenuBar.setMenuOn("File_CloseItem")
            self.view.gnitPickMenuBar.setMenuOn("File_SaveItem")
            self.view.gnitPickMenuBar.setMenuOn("File_CloseProject")
            self.view.gnitPickMenuBar.setMenuOn("Tools_QueryDomain_All")
            self.view.gnitPickMenuBar.setMenuOn("Tools_QueryDomain_Current")
            self.view.gnitPickMenuBar.setMenuOn("Tools_Query")
            self.model.currentItem = itemfile

            if self.view.checkUndoable():
                self.view.gnitPickMenuBar.setMenuOn("Edit_Undo")
            else:
                self.view.gnitPickMenuBar.setMenuOff("Edit_Undo")

            if self.view.checkRedoable():
                self.view.gnitPickMenuBar.setMenuOn("Edit_Redo")
            else:
                self.view.gnitPickMenuBar.setMenuOff("Edit_Redo")
        else:
            ndebug("Current file not project, must be None " +
                   itemfile.getName())
            self.view.gnitPickMenuBar.setMenuOff("File_SaveItem")
            self.view.gnitPickMenuBar.setMenuOff("File_CloseItem")
            self.view.gnitPickMenuBar.setMenuOff("File_CloseProject")
            self.view.gnitPickMenuBar.setMenuOff("Edit_Undo")
            self.view.gnitPickMenuBar.setMenuOff("Edit_Redo")
            self.view.gnitPickMenuBar.setMenuOff("Tools_QueryDomain_All")
            self.view.gnitPickMenuBar.setMenuOff("Tools_QueryDomain_Current")
            self.view.gnitPickMenuBar.setMenuOff("Tools_Query")

        if self.view.tabbedPane.getTabCount() < 2:
            self.view.gnitPickMenuBar.setMenuOff("View_NextTab")
            self.view.gnitPickMenuBar.setMenuOff("View_PriorTab")
        else:
            self.view.gnitPickMenuBar.setMenuOn("View_NextTab")
            self.view.gnitPickMenuBar.setMenuOn("View_PriorTab")
Beispiel #7
0
def Tools_QueryDomain_Current(ae):
    ndebug("Invoked QueryDomain_Current")
    controller.view.queryall=0
Beispiel #8
0
def Tools_QueryDomain_All(ae):
    ndebug("Invoked QueryDomain_All")
    controller.view.queryall=1
        fileitem = File(itempath)
        unparsedcontent=defaultcontent
        
        try:
            self.view.status("Examining file "+fileitem.name )
            doc = Builder().build( unparsedcontent, "" )
            summary = XQueryUtil.xquery(doc, "/story/@title").get(0).getValue()
            content = doc.toXML()
            self.model.addItemToProject( fileitem, summary, content )
        except XMLException, e:
            ndebug(unparsedcontent)
            self.view.status("Can't find an XML parser: "+e.toString() )
            ndebug("Can't find an XML parser: "+e.toString() )
            self.model.addItemToProject( fileitem, fileitem.getName() + " (Warning: not well-formed: ``"+e.toString()+"'')" , unparsedcontent )
        except ParsingException, e:                   
            ndebug(unparsedcontent)
            self.view.status("The XML Parser reports errors on the file " + fileitem.getName() + ": "+e.toString() )
            ndebug("The XML Parser reports errors on the file " + fileitem.getName() + ": "+e.toString() )
            self.model.addItemToProject( fileitem, fileitem.getName() + " (Warning: parser errors: ``"+e.toString()+"'')" , unparsedcontent )
        
        self.openItem(fileitem)
        
        self.view.updateProjectTab(  self.model.getCurrentProject(), self.model.getItemsOfProject( self.model.getCurrentProject()) )
        self.view.status( "Opened project ''"+ self.model.getCurrentProject().getName()+"''" )

        
        # In order to undo or redo, the request needs to be associated with a tab (or other widget) that
        # implements its own undo management. Fortunately, this is always the current item tab (if set)
    def undo(self):
        projectdir = self.model.getCurrentProject()
        if projectdir == None: 
Beispiel #10
0
    def openProject(self, projectdir):  # File projectdir
        # Check to see that no other project is open at the moment
        # It would be interesting to allow multiple projects but this would complicate the view
        if self.model.getCurrentProject() != None:
            self.view.status("Cannot but open one project at a time, bucko!")
            return None

        if projectdir == None:
            return None

        self.view.status("Processing directory " + projectdir.getName())
        self.model.openProject(0, projectdir)
        # Jython doesn't have listdir; use Java instead
        # for item in filter( lambda x: re.search(".*\.story",x), listdir( projectdir.getPath() ) ):
        myitems = filter(self.filefilter, projectdir.listFiles())
        if len(myitems) > 0:
            for fileitem in myitems:
                inputfile = open(fileitem.getPath(), "r")
                unparsedcontent = inputfile.read()
                inputfile.close()
                try:
                    self.view.status("Examining file " + fileitem.getName())
                    doc = Builder().build(fileitem)
                    summary = XQueryUtil.xquery(
                        doc, "/story/@title").get(0).getValue()
                    content = doc.toXML()
                    self.model.addItemToProject(fileitem, summary, content)
                except XMLException, e:
                    ndebug(unparsedcontent)
                    self.view.status("Can't find an XML parser: " +
                                     e.toString())
                    ndebug("Can't find an XML parser: " + e.toString())
                    self.model.addItemToProject(
                        fileitem,
                        fileitem.getName() + " (Warning: not well-formed: ``" +
                        e.toString() + "'')", unparsedcontent)
                except ParsingException, e:
                    # Yawn! Jython can't seem to call FileReader successfully. It always returns empty content.
                    # Maybe something to do with wrapping the arguments.
                    #                    myunparsedcontent=""
                    #                    filereader=FileReader( fileitem )
                    #                    filereader.read(myunparsedcontent)
                    ndebug(unparsedcontent)
                    self.view.status(
                        "The XML Parser reports errors on the file " +
                        fileitem.getName() + ": " + e.toString())
                    ndebug("The XML Parser reports errors on the file " +
                           fileitem.getName() + ": " + e.toString())
                    self.model.addItemToProject(
                        fileitem,
                        fileitem.getName() + " (Warning: parser errors: ``" +
                        e.toString() + "'')", unparsedcontent)

#                   ndebug("My Junk:" + myjunk)

                except IOException, e:
                    self.view.status("The file " + fileitem.getName() +
                                     " could not be opened: " + e.toString())
                    ndebug("The file " + fileitem.getName() +
                           " could not be opened: " + e.toString())
                    self.model.addItemToProject(
                        fileitem,
                        fileitem.getName() +
                        " (Error: file may be truncated ``" + e.toString() +
                        "'')", unparsedcontent)
Beispiel #11
0
        try:
            self.view.status("Examining file " + fileitem.name)
            doc = Builder().build(unparsedcontent, "")
            summary = XQueryUtil.xquery(doc, "/story/@title").get(0).getValue()
            content = doc.toXML()
            self.model.addItemToProject(fileitem, summary, content)
        except XMLException, e:
            ndebug(unparsedcontent)
            self.view.status("Can't find an XML parser: " + e.toString())
            ndebug("Can't find an XML parser: " + e.toString())
            self.model.addItemToProject(
                fileitem,
                fileitem.getName() + " (Warning: not well-formed: ``" +
                e.toString() + "'')", unparsedcontent)
        except ParsingException, e:
            ndebug(unparsedcontent)
            self.view.status("The XML Parser reports errors on the file " +
                             fileitem.getName() + ": " + e.toString())
            ndebug("The XML Parser reports errors on the file " +
                   fileitem.getName() + ": " + e.toString())
            self.model.addItemToProject(
                fileitem,
                fileitem.getName() + " (Warning: parser errors: ``" +
                e.toString() + "'')", unparsedcontent)

        self.openItem(fileitem)

        self.view.updateProjectTab(
            self.model.getCurrentProject(),
            self.model.getItemsOfProject(self.model.getCurrentProject()))
        self.view.status("Opened project ''" +