Пример #1
0
 def executeCommand(self, command, addToHistory=False):
     logging.info("Proof command entered: %s", command)
     pvscomm.PVSCommandManager().proofCommand(command)
     if addToHistory:
         self.history.append(command)
         self.historyBox.Insert(command, 1)
     self.commandTextControl.SetValue("")
Пример #2
0
 def onCommandEntered(self, event):
     text = self.commandTextControl.GetValue()
     if text.endswith(constants.NEWLINE):
         command = text.strip()
         logging.info("Proof command entered: %s", command)
         pvscomm.PVSCommandManager().proofCommand(command)
         self.commandTextControl.Clear()
     event.Skip()
Пример #3
0
def onChangeContext(event):
    """called to handle 'change context' request"""
    frame = util.getMainFrame()
    preferences = preference.Preferences()
    newContext = frame.chooseDirectory("Select a directory",
                                       preferences.getRecentContexts()[0])
    if newContext is not None:
        pvscomm.PVSCommandManager().changeContext(newContext)
Пример #4
0
 def addContext(self, context):
     root = self.tree.GetRootItem()
     image = self.imageIndices[
         LCONTEXT] if context == pvscomm.PVSCommandManager(
         ).pvsContext else self.imageIndices[LINACTIVECONTEXT]
     self.tree.AppendItem(
         root, context, image, -1,
         wx.TreeItemData({
             LCONTEXT: context,
             KIND: LCONTEXT
         }))
Пример #5
0
 def onStartProver(self, event):
     """onTypecheckFile is called when the user selects Typecheck in the context menu"""
     node = self.tree.GetSelection()
     parent = self.tree.GetItemParent(self.tree.GetItemParent(node))
     data = self.tree.GetItemPyData(node)
     parentData = self.tree.GetItemPyData(parent)
     theoryName = data[THEORY.lower()]
     formulaName = data[ID_L]
     fullname = parentData[FULLNAME]
     pvscomm.PVSCommandManager().startProver(fullname, theoryName,
                                             formulaName)
Пример #6
0
 def addPluginToViewMenu(self, name, callBackFunction):
     logging.debug("Name: %s", name)
     frame = util.getMainFrame()
     item = self.pluginMenu.Append(wx.ID_ANY, name, EMPTY_STRING,
                                   wx.ITEM_CHECK)
     self.plugins[name] = item
     self.pluginMenu.Check(
         item.GetId(),
         PluginManager().shouldPluginBeVisible(
             name,
             pvscomm.PVSCommandManager().pvsMode))
     frame.Bind(wx.EVT_MENU, callBackFunction, item)
Пример #7
0
 def getContextMenuItemsForPVSContext(self, pvsMode, data):
     items = []
     if pvsMode == PVS_MODE_OFF:
         pass
     elif pvsMode == PVS_MODE_LISP or pvsMode == PVS_MODE_UNKNOWN:
         nodeContext = self.getSelectedNodeData()[LCONTEXT]
         if nodeContext != pvscomm.PVSCommandManager().pvsContext:
             items.append(
                 ("Make Active Context", self.onSetAsActiveContext))
     elif pvsMode == PVS_MODE_PROVER:
         pass
     items.append(("Close Context", self.onCloseContext))
     logging.debug("%d many items added to the context menu", len(items))
     return items
Пример #8
0
 def onPVSInText(self, event):
     """This method is called whenever PVS sends some text to the Editor"""
     #logging.info("Event handler `onPVSInTextEntered' not implemented")
     text = event.GetString()
     if text.endswith("\n"):
         if util.isS_Expression(text):
             command = text.strip()
             logging.info("Command is %s", command)
             self.appendToOut(self.prompt, color=wx.BLUE)
             self.appendToOut(command, newLine=True)
             self.clearIn()
             self.history.append(command)
             self.historyBox.Insert(command, 1)
             result = pvscomm.PVSCommandManager().lisp(command)
             if result is not None:
                 self.appendToOut(result, newLine=True)
Пример #9
0
 def getContextMenuItemsForFile(self, pvsMode, data):
     fullname = data[FULLNAME]
     directory = os.path.split(fullname)[0]
     items = []
     if pvsMode == PVS_MODE_OFF:
         pass
     elif pvsMode == PVS_MODE_LISP and directory == pvscomm.PVSCommandManager(
     ).pvsContext:
         items.append((LABEL_TYPECHECK, self.onTypecheckFile))
     elif pvsMode == PVS_MODE_PROVER:
         pass
     elif pvsMode == PVS_MODE_UNKNOWN:
         pass
     items.append((LABEL_CLOSEFILE, self.onCloseFile))
     logging.debug("%d many items added to the context menu", len(items))
     return items
Пример #10
0
 def create(self, pluginDefinition):
     name = pluginDefinition[PluginManager.NAME]
     module = importlib.import_module(
         pluginDefinition[PluginManager.MODULE])
     panelClass = getattr(module, pluginDefinition[PluginManager.CLASS])
     size = pluginDefinition[PluginManager.SIZE]
     panel = panelClass(util.getMainFrame(), pluginDefinition)
     location = pluginDefinition[
         PluginManager.
         LOCATION] if PluginManager.LOCATION in pluginDefinition else PluginManager.FLOAT
     auiManager = util.auiManager()
     paneInfo = aui.AuiPaneInfo()
     paneInfo = paneInfo.Caption(name).Name(name).BestSize(size)
     if location == PluginManager.TOP:
         paneInfo = paneInfo.Top()
     elif location == PluginManager.BOTTOM:
         paneInfo = paneInfo.Bottom()
     elif location == PluginManager.LEFT:
         paneInfo = paneInfo.Left()
     elif location == PluginManager.RIGHT:
         paneInfo = paneInfo.Right()
     elif location == PluginManager.FLOAT:
         paneInfo = paneInfo.Float()
     elif location == PluginManager.CENTER:
         paneInfo = paneInfo.Center()
     else:
         logging.error("Unknown Location: %s", location)
         paneInfo = paneInfo.Float()
     auiManager.AddPane(panel, paneInfo)
     if PluginManager.VISIBLE in pluginDefinition:
         self.showPlugin(
             name,
             pvscomm.PVSCommandManager().pvsMode
             in pluginDefinition[PluginManager.VISIBLE])
     else:
         self.showPlugin(name, False)
     auiManager.Update()
     pub.sendMessage(
         PUB_ADDITEMTOVIEWMENU,
         name=name,
         callBackFunction=(lambda ce: self.togglePluginVisibility(name)))
     return None
Пример #11
0
 def showContextMenu(self, event):
     """display a relevant context menu when the user right-clicks on a node"""
     item = event.GetItem()
     data = self.tree.GetItemPyData(item)
     logging.debug("Event data: %s", data)
     kind = data[
         KIND] if KIND in data else None  #TODO: Figure out what to do when KIND is absent (may be a PVS issue)
     menu = wx.Menu()
     pvsMode = pvscomm.PVSCommandManager().pvsMode
     items = self.getContextMenuItems(
         pvsMode, kind, data
     )  # each item should be a pair of a label and a callback function.
     for label, callback in items:
         if isinstance(callback, wx.Menu):
             menu.AppendMenu(wx.ID_ANY, label, callback)
         else:
             ID = menu.Append(wx.ID_ANY, label, EMPTY_STRING,
                              wx.ITEM_NORMAL).GetId()
             wx.EVT_MENU(menu, ID, callback)
     self.tree.GetParent().PopupMenu(menu, event.GetPoint())
     menu.Destroy()
Пример #12
0
def onResetPVS(event):
    logging.debug("Starting")
    pvscomm.PVSCommandManager().reset()
Пример #13
0
 def onSetAsActiveContext(self, event):
     """onSetAsActiveContext is called when the user wants to change the PVS context"""
     context = self.getSelectedNodeData()[LCONTEXT]
     pvscomm.PVSCommandManager().changeContext(context)
Пример #14
0
def onTypecheck(event):
    """called to handle 'typecheck' request"""
    logging.debug("Starting")
    fullname = remgr.RichEditorManager().getFocusedRichEditor().getFilename()
    pvscomm.PVSCommandManager().typecheck(fullname)
Пример #15
0
 def OnPostponeCommand(self, event):
     pvscomm.PVSCommandManager().proofCommand("(postpone)")
     event.Skip()
Пример #16
0
 def OnQuitProver(self, event):
     pvscomm.PVSCommandManager().proofCommand("(quit)")
     event.Skip()
Пример #17
0
 def OnUndoLastCommand(self, event):
     pvscomm.PVSCommandManager().proofCommand("(undo)")
     event.Skip()
Пример #18
0
 def onTypecheckFile(self, event):
     """onTypecheckFile is called when the user selects Typecheck in the context menu"""
     nodeFullname = self.getSelectedNodeData()[FULLNAME]
     pvscomm.PVSCommandManager().typecheck(nodeFullname)
Пример #19
0
    def test_pvscalls(self):
        def _verifyPlace(_dict, key):
            self.assertTrue(key in _dict.keys())
            self.assertTrue(_dict[key] is None or len(_dict[key]) == 4)

        def _verifyString(_dict, thing, optional=False):
            if optional:
                if thing in _dict:
                    self.assertTrue(
                        isinstance(_dict[thing], str)
                        or isinstance(_dict[thing], unicode))
            else:
                self.assertTrue(thing in _dict)
                self.assertTrue(
                    isinstance(_dict[thing], str)
                    or isinstance(_dict[thing], unicode))

        def _testing_ping():
            result = pm.ping()
            self.assertEqual(result, "3")

        def _testing_lisp():
            result = pm.lisp("(* 7 5)")
            self.assertEqual(result, "35")

        def _testing_change_context():
            result = pm.changeContext(self.testContext)
            self.assertEqual(result, self.testContext)
            self.assertEqual(pm.pvsContext, self.testContext)
            self.assertEqual(pm.pvsMode, constants.PVS_MODE_LISP)

        def _testing_typecheck():
            result = pm.typecheck(self.testPVSFile)
            for theory in result:
                theoryInfo = theory[constants.LTHEORY]
                decls = theoryInfo[constants.DECLS]
                for decl in decls:
                    _verifyString(decl, constants.ID_L)
                    _verifyString(decl, constants.LKIND)
                    _verifyString(decl, constants.LTYPE, optional=True)
                    _verifyPlace(decl, constants.LPLACE)
            self.assertEqual(pm.pvsContext, self.testContext)
            self.assertEqual(pm.pvsMode, constants.PVS_MODE_LISP)

        def _testing_names_info():
            result = pm.namesInfo(self.testPVSFile)
            for inf in result:
                _verifyPlace(inf, constants.LPLACE)
                _verifyPlace(inf, constants.DECLPLACE)
                _verifyString(inf, constants.ID_L)
                _verifyString(inf, constants.DECLFILE)
                _verifyString(inf, constants.DECL)
            self.assertEqual(pm.pvsContext, self.testContext)
            self.assertEqual(pm.pvsMode, constants.PVS_MODE_LISP)

        def _testing_start_prover():
            result = pm.startProver(*self.tobeProved)
            self.assertTrue("sequent" in result)
            self.assertTrue("label" in result)
            self.assertEqual(pm.pvsContext, self.testContext)
            self.assertEqual(pm.pvsMode, constants.PVS_MODE_PROVER)

        def _testing_proof_command():
            result = pm.proofCommand(self.proofCommand)
            self.assertEqual(pm.pvsContext, self.testContext)
            self.assertEqual(pm.pvsMode, constants.PVS_MODE_PROVER)

        self._initialize()
        pm = pvscomm.PVSCommandManager()
        theTests = [_testing_ping, \
                 _testing_lisp, \
                 _testing_change_context, \
                 _testing_typecheck, \
                 _testing_names_info, \
                 _testing_start_prover, \
                 _testing_proof_command, \
                 ]
        for aTest in theTests:
            print "Testing %s..." % (aTest.__name__)
            aTest()
        self._clean()
Пример #20
0
    def __init__(self, parent, definition):
        PluginPanel.__init__(self, parent, definition)
        commandManager = pvscomm.PVSCommandManager()

        toolbarInfo = [ \
                          ["module.png", "Parse the active file", commandManager.parse], \
                          ["typecheck16.png", "Typecheck the active file", commandManager.typecheck], \
        ]

        toolbar = wx.ToolBar(self,
                             wx.ID_ANY,
                             style=wx.TB_VERTICAL | wx.NO_BORDER)
        self.toolbarButton = {}
        for imageName, tooltipText, command in toolbarInfo:
            buttonID = wx.NewId()
            toolbar.AddTool(buttonID, ui.images.getBitmap(imageName))
            wx.EVT_TOOL(self, buttonID, self.onToolboxButtonClicked)
            self.toolbarButton[buttonID] = command
        toolbar.Realize()

        splitter = wx.SplitterWindow(self, style=wx.SP_NOBORDER)
        splitter.SetMinimumPaneSize(35)
        self.pvsout = wx.richtext.RichTextCtrl(splitter,
                                               wx.ID_ANY,
                                               EMPTY_STRING,
                                               style=wx.TE_MULTILINE
                                               | wx.TE_READONLY)

        belowPanel = wx.Panel(splitter)
        self.pvsin = wx.TextCtrl(belowPanel,
                                 wx.ID_ANY,
                                 EMPTY_STRING,
                                 style=wx.TE_MULTILINE)
        self.historyBox = wx.ComboBox(belowPanel,
                                      wx.ID_ANY,
                                      choices=[],
                                      style=wx.CB_READONLY)

        belowSizer = wx.BoxSizer(wx.HORIZONTAL)
        belowSizer.Add(self.pvsin, 5,
                       wx.EXPAND | wx.UP | wx.DOWN | wx.ALIGN_CENTRE_VERTICAL,
                       5)
        belowSizer.Add(
            self.historyBox, 1,
            wx.EXPAND | wx.LEFT | wx.UP | wx.DOWN | wx.ALIGN_CENTRE_VERTICAL,
            5)
        belowPanel.SetSizer(belowSizer)
        splitter.SplitHorizontally(self.pvsout, belowPanel)
        splitter.SetSashPosition(120)

        consoleSizer = wx.BoxSizer(wx.HORIZONTAL)
        consoleSizer.Add(splitter, 1, wx.EXPAND | wx.ALL, 5)
        consoleSizer.Add(toolbar, 0, wx.EXPAND | wx.ALL, 5)

        self.SetSizer(consoleSizer)

        self.Bind(wx.EVT_TEXT, self.onPVSInText, self.pvsin)
        self.historyBox.Bind(wx.EVT_COMBOBOX, self.OnSelectHistory)
        pub.subscribe(self.clearIn, PUB_CONSOLECLEARIN)
        pub.subscribe(self.initializeConsole, PUB_CONSOLEINITIALIZE)
        pub.subscribe(self.writeLine, PUB_CONSOLEWRITELINE)
        pub.subscribe(self.writePrompt, PUB_CONSOLEWRITEPROMPT)
        pub.subscribe(self.pvsModeUpdated, PUB_UPDATEPVSMODE)
        self.initializeConsole()
Пример #21
0
 def onRecentContextSelected(self, event):
     context = self._recentContexts[event.GetId()]
     pvscomm.PVSCommandManager().changeContext(context)