[go: up one dir, main page]

Menu

[r868]: / Segtool / SegmentTool.py  Maximize  Restore  History

Download this file

164 lines (131 with data), 5.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env python
modules = {'DrawingArea' : [0, '', 'none://DrawingArea.py' ],
'Section' : [0, '', 'none://Section.py' ]
}
import wx
import os
from lxml import etree
from Section import *
from DrawingArea import DrawingArea
class MainWindow (wx.Frame):
def __init__ (self, parent, id, title):
wx.Frame.__init__(self,parent,id, title, size=(600,600))
self.CreateMenu()
self.CreateToolbar()
self.CreateDisplay()
self.nimages = 0
self.current_slice = None
self.current_set = None
self.current_set_name = None
def CreateMenu(self):
menuBar = wx.MenuBar()
Filemenu = wx.Menu()
FileOpenSet = Filemenu.Append(wx.ID_NEW, "&New Set")
FileOpenSet = Filemenu.Append(wx.ID_OPEN, "&Open Set")
FileSaveSet = Filemenu.Append(wx.ID_SAVE, "&Save Set")
FileSaveSetAs = Filemenu.Append(wx.ID_SAVEAS, "Save Set &As")
Filemenu.AppendSeparator()
FileOpenImage = Filemenu.Append(-1, "Import &Images")
Filemenu.AppendSeparator()
FileExit = Filemenu.Append(wx.ID_EXIT, "E&xit")
menuBar.Append(Filemenu, "&File")
self.SetMenuBar(menuBar)
self.Bind(wx.EVT_MENU, self.OnFileExit, FileExit)
self.Bind(wx.EVT_MENU, self.OnFileOpenImage, FileOpenImage)
self.Bind(wx.EVT_MENU, self.OnFileOpenSet, FileOpenSet)
self.Bind(wx.EVT_MENU, self.OnFileSaveSet, FileSaveSet)
self.Bind(wx.EVT_MENU, self.OnFileSaveSetAs, FileSaveSetAs)
def CreateToolbar(self):
ap = wx.ArtProvider()
toolbar = self.CreateToolBar()
toolbar.AddSimpleTool(wx.ID_NEW, ap.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR), \
"New", "Create a new working set")
toolbar.AddSimpleTool(wx.ID_OPEN, ap.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR),\
"Open", "Open a new working set")
toolbar.AddSimpleTool(wx.ID_SAVE, ap.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR), \
"Save", "Save the current working set")
toolbar.AddSimpleTool(wx.ID_SAVEAS, ap.GetBitmap(wx.ART_FILE_SAVE_AS, wx.ART_TOOLBAR), \
"Save", "Save the current working set")
toolbar.AddSeparator()
toolbar.AddSimpleTool(wx.ID_EXIT, ap.GetBitmap(wx.ART_QUIT, wx.ART_TOOLBAR),\
"Exit", "Exit program")
toolbar.Realize()
def CreateDisplay(self):
sizer = wx.BoxSizer(wx.HORIZONTAL)
self.ImageNumSelect = wx.Slider(self, 0, 0, 0, 1, \
style=wx.SL_LABELS|wx.SL_VERTICAL)
self.ImageNumSelect.SetPageSize(1)
self.ImageNumSelect.SetMinSize((16,512))
sizer.Add(self.ImageNumSelect, flag=wx.ALIGN_LEFT)
self.Bind(wx.EVT_SLIDER, self.OnChangeImage, self.ImageNumSelect)
self.da = DrawingArea(self)
self.da.SetMinSize((800,800))
sizer.Add(self.da, flag=wx.ALIGN_LEFT)
self.SetSizer(sizer)
self.Fit()
def OnChangeImage(self, event):
image_nr = self.ImageNumSelect.GetValue()
if image_nr < self.nimages:
self.current_slice = self.current_set.GetFrame(image_nr)
self.da.SetSlice( self.current_slice )
def OnFileExit(self, event):
self.Close(True)
def OnFileOpenImage(self, event):
wildcard = "PNG Images (*.png)|*.png|All Files (*.*)|*.*"
flags = wx.OPEN | wx.MULTIPLE
files = self.FileOpen("Open Image files", wildcard, True)
if not files:
return
self.current_set = WorkSet(images=files)
nimages = self.current_set.GetFrameNumber()
self.ImageNumSelect.SetRange(0, nimages - 1)
if nimages > 0:
self.da.SetCurrentBitmap(self.current_set.GetFrame(0))
def FileOpen(self, message, wildcard, multiple):
if multiple:
flags = wx.OPEN |wx.MULTIPLE
else:
flags = wx.OPEN
dialog = wx.FileDialog(self, message, os.getcwd(),"", wildcard, flags)
if dialog.ShowModal() == wx.ID_OK:
if multiple:
files = dialog.GetPaths()
else:
files = dialog.GetPath()
else:
files = None
dialog.Destroy()
return files
def OnFileOpenSet(self, event):
wildcard = "Workset (*.set)|*.set|All Files (*.*)|*.*"
file = self.FileOpen("Open Working set", wildcard, False)
print file
def SaveSet(self):
data = self.current_set.Save()
file = open(self.current_set_name, "w")
file.write(data)
file.close()
def OnFileSaveSet(self, event):
if not self.current_set_name:
self.OnFileSaveSetAs(self, event)
else:
self.SaveSet()
def OnFileSaveSetAs(self, event):
wildcard = "Workset Images (*.set)|*.set"
flags = wx.SAVE
dialog = wx.FileDialog(self, "Save Workset", os.getcwd(),"", wildcard, wx.SAVE)
if dialog.ShowModal() == wx.ID_OK:
self.current_set_name = dialog.GetPath()
if self.current_set[-4:0]!= ".set":
self.current_set_name = self.current_set + ".set"
self.SaveSet()
dialog.Destroy()
class App(wx.App):
def OnInit(self):
self.frame = MainWindow(parent=None, id=-1, title='Segment')
self.frame.Show()
self.SetTopWindow(self.frame)
return True
if __name__ == '__main__':
app = App()
app.MainLoop()