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.
This commit is contained in:
parent
6ffdda4a3c
commit
a020cffec7
@ -157,8 +157,57 @@ class AttackDisplay(wx.ScrolledWindow):
|
|||||||
yn = int(virtualheight / step) + 1
|
yn = int(virtualheight / step) + 1
|
||||||
self.SetScrollbars(step,step,xn,yn,0,0)
|
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()
|
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):
|
class AttackWindow(wx.Frame):
|
||||||
|
Loading…
Reference in New Issue
Block a user