From a020cffec74a3af8993a94a292f67620a694b49f Mon Sep 17 00:00:00 2001 From: Cas Cremers Date: Tue, 26 Aug 2008 17:14:08 +0200 Subject: [PATCH] GUI: Added popup menu to save graphviz (.dot) data. A long requested feature was the option to print graphs more nicely. This is a solution for knowledgeable users: the dot data is more basic and can be converted in various ways. TODO: Simple image export. --- gui/Gui/Attackwindow.py | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/gui/Gui/Attackwindow.py b/gui/Gui/Attackwindow.py index f470170..5a4b3ce 100644 --- a/gui/Gui/Attackwindow.py +++ b/gui/Gui/Attackwindow.py @@ -157,8 +157,57 @@ class AttackDisplay(wx.ScrolledWindow): yn = int(virtualheight / step) + 1 self.SetScrollbars(step,step,xn,yn,0,0) + """ + Pop up menu + """ + self.popupmenu = wx.Menu() + #item = self.popupmenu.Append(-1,"Export image") + #self.Bind(wx.EVT_MENU, self.OnExportImage, item) + item = self.popupmenu.Append(-1,"Export graphviz data (.dot)") + self.Bind(wx.EVT_MENU, self.OnExportDot, item) + + self.Bind(wx.EVT_CONTEXT_MENU, self.OnShowPopup) + self.Refresh() + def OnShowPopup(self, event): + pos = event.GetPosition() + pos = self.Image.ScreenToClient(pos) + self.PopupMenu(self.popupmenu, pos) + + def OnPopupItemSelected(self, event): + item = self.popupmenu.FindItemById(event.GetId()) + text = item.GetText() + wx.MessageBox("You selected item %s" % text) + + def askUserForFilename(self, **dialogOptions): + dialog = wx.FileDialog(self, **dialogOptions) + if dialog.ShowModal() == wx.ID_OK: + res = "%s/%s" % (dialog.GetDirectory(), dialog.GetFilename()) + else: + res = None + dialog.Destroy() + return res + + def saveFileType(self, ext, data): + (p,r,l) = self.win.claim.triplet() + prefix = "pattern-%s_%s_%s-%s" % (p,r,l,self.attack.id) + suggested = "%s.%s" % (prefix,ext) + res = self.askUserForFilename(style=wx.SAVE, wildcard="*.%s" % (ext), defaultFile = "%s" % (suggested)) + if res != None: + fp = open(res,'w') + fp.write(data) + fp.close() + + def OnExportImage(self, event): + self.saveFileType("ps",self.attack.scytherDot) + + def OnExportDot(self, event): + self.saveFileType("dot",self.attack.scytherDot) + + + + #--------------------------------------------------------------------------- class AttackWindow(wx.Frame):