コード例 #1
0
    def __init__( self, aGtkWindow ):
        self.theGtkWindow = gtk.Window()
        self.theGdkWindow = self.theGtkWindow.window
        self.theColorMap = self.theGtkWindow.get_colormap()
        self.theStyle = self.theGtkWindow.get_style()
        self.testCanvas = gnomecanvas.Canvas()
        self.testCanvasRoot = self.testCanvas.root()
        self.testText=self.testCanvasRoot.add(gnomecanvas.CanvasText, text = 'Hello', font="Sans 9" )

        self.opMatrix= n.array(((0,0,1,0,-1,0,0,0),(-1,0,0,0,0,0,1,0),(0,0,0,1,0,-1,0,0),(0,-1,0,0,0,0,0,1)))

        #for overlapping
        self.o1=n.array([[0,0,-1,0],[1,0,0,0],[0,0,0,-1],[0,1,0,0]])
        self.o2=n.array([[1,0,0,0],[0,0,-1,0],[0,1,0,0],[0,0,0,-1]])

        #for within
        self.o3=n.array([[-1,0,0,0],[0,0,1,0],[0,-1,0,0],[0,0,0,1]])
        self.o4=n.array([[1,0,0,0],[0,0,-1,0],[0,1,0,0],[0,0,0,-1]])

        #for resizing (x1,y1,x2,y2)
        self.resizeMap= {}

        self.mapPos={DIRECTION_LEFT:n.array([[-1,0],[0,0],[0,0],[0,0]]), 
                 DIRECTION_RIGHT:n.array([[0,0],[0,0],[1,0],[0,0]]),
                 DIRECTION_UP:n.array([[0,0],[0,-1],[0,0],[0,0]]), 
                 DIRECTION_DOWN:n.array([[0,0],[0,0],[0,0],[0,1]]),
                 DIRECTION_BOTTOM_RIGHT:n.array([[0,0],[0,0],[1,0],[0,1]]), 
                 DIRECTION_BOTTOM_LEFT:n.array([[-1,0],[0,0],[0,0],[0,1]]),
                 DIRECTION_TOP_RIGHT:n.array([[0,0],[0,-1],[1,0],[0,0]]), 
                 DIRECTION_TOP_LEFT:n.array([[-1,0],[0,-1],[0,0],[0,0]])}

        self.mapNeg={DIRECTION_LEFT:n.array([[1,0],[0,0],[0,0],[0,0]]), 
                 DIRECTION_RIGHT:n.array([[0,0],[0,0],[-1,0],[0,0]]),
                 DIRECTION_UP:n.array([[0,0],[0,1],[0,0],[0,0]]), 
                 DIRECTION_DOWN:n.array([[0,0],[0,0],[0,0],[0,-1]]),
                 DIRECTION_BOTTOM_RIGHT:n.array([[0,0],[0,0],[-1,0],[0,-1]]), 
                 DIRECTION_BOTTOM_LEFT:n.array([[1,0],[0,0],[0,0],[0,-1]]),
                 DIRECTION_TOP_RIGHT:n.array([[0,0],[0,1],[-1,0],[0,0]]), 
                 DIRECTION_TOP_LEFT:n.array([[1,0],[0,1],[0,0],[0,0]])}

        

        #each point (x1,y1,x2,y2):[x1,y1,x2,y2,posx,posy,negx,negy]
        self.twoRectMap={DIRECTION_BOTTOM_RIGHT:n.array([[[1,0,0,0,0,0,0,0],[0,0,0,1,0,0,0,-1],[0,0,1,0,1,0,0,0],[0,0,0,1,0,1,0,0]],[[0,0,1,0,0,0,-1,0],[0,1,0,0,0,0,0,0],[0,0,1,0,1,0,0,0],[0,0,0,1,0,1,0,0]]]),\
                 DIRECTION_BOTTOM_LEFT:n.array([[[1,0,0,0,-1,0,0,0],[0,0,0,1,0,0,0,-1],[0,0,1,0,0,0,0,0],[0,0,0,1,0,1,0,0]],[[1,0,0,0,-1,0,0,0],[0,1,0,0,0,0,0,0],[1,0,0,0,0,0,1,0],[0,0,0,1,0,1,0,0]]]),\
                 DIRECTION_TOP_RIGHT:n.array([[[1,0,0,0,0,0,0,0],[0,1,0,0,0,-1,0,0],[0,0,1,0,1,0,0,0],[0,1,0,0,0,0,0,1]],[[0,0,1,0,0,0,-1,0],[0,1,0,0,0,-1,0,0],[0,0,1,0,1,0,0,0],[0,0,0,1,0,0,0,0]]]),\
                 DIRECTION_TOP_LEFT:n.array([[[1,0,0,0,-1,0,0,0],[0,1,0,0,0,-1,0,0],[0,0,1,0,0,0,0,0],[0,1,0,0,0,0,0,1]],[[1,0,0,0,-1,0,0,0],[0,1,0,0,0,-1,0,0],[1,0,0,0,0,0,1,0],[0,0,0,1,0,0,0,0]]])}

        self.dotRectMap={DIRECTION_LEFT:[0], DIRECTION_RIGHT:[2],DIRECTION_UP:[1],DIRECTION_DOWN:[3],   
                 DIRECTION_BOTTOM_RIGHT:[2,3],DIRECTION_BOTTOM_LEFT:[0,3],DIRECTION_TOP_RIGHT:[2,1],    
                                 DIRECTION_TOP_LEFT:[0,1]}
コード例 #2
0
ファイル: TrackDots.py プロジェクト: tianchi03/Autotrace
    def __init__(self, imagefiles=[]):
        self.imagefiles = imagefiles
        if (len(self.imagefiles) == 0):
            self.INDEPENDENT = True
            self.onOpen()
        else:
            self.INDEPENDENT = False
        self.background = self.getAllThresh(self.imagefiles)

        self.gladefile = "trackdots.glade"
        self.wTree = gtk.glade.XML(self.gladefile, "window1")
        self.window = self.wTree.get_widget("window1")

        sigs = {
            "on_ok_clicked": self.onOK,
            "on_window1_destroy": self.onDestroy
        }
        self.wTree.signal_autoconnect(sigs)

        self.statusbar = self.wTree.get_widget("statusbar1")
        self.cbox = self.wTree.get_widget("canvashbox")
        self.canvas = gnomecanvas.Canvas(aa=True)

        img = cv.LoadImageM(self.background, iscolor=False)
        self.csize = shape(img)

        self.canvas.set_size_request(self.csize[1], self.csize[0])
        self.canvas.set_scroll_region(0, 0, self.csize[1], self.csize[0])
        self.cbox.add(self.canvas)
        self.canvas.connect("event", self.canvas_event)

        pixbuf = gtk.gdk.pixbuf_new_from_file(self.background)
        bg = self.canvas.root().add(gnomecanvas.CanvasPixbuf,
                                    x=0,
                                    y=0,
                                    pixbuf=pixbuf)

        self.DRAG = False
        self.pathtofiles = '/'.join(self.imagefiles[0].split('/')[:-1]) + '/'
        self.Rectangles = []
        self.RectanglePoints = []
        for r in range(4):
            self.Rectangles.append(self.get_rect(1, 1))
            self.RectanglePoints.append([1, 1, 1, 1])
        self.currentRect = 0

        self.window.show_all()

        self.context_id = self.statusbar.get_context_id("instructions")
        text = "Select the rectangles for each dot"
        self.statusbar.push(self.context_id, text)
コード例 #3
0
ファイル: HCView.py プロジェクト: tianchi03/Autotrace
    def __init__(self, imagefiles, independent=True):
        self.pathtofiles = '/'.join(imagefiles[0].split('/')[:-1]) + '/'
        self.imagefiles = imagefiles
        self.INDEPENDENT = independent
        self.mouse_down = False
        self.filenamesind = 0
        self.close_enough = False

        self.gladefile = "trackdots.glade"
        self.wTree = gtk.glade.XML(self.gladefile, "HCView")
        self.window = self.wTree.get_widget("HCView")

        sigs = {
            "on_tbNext_clicked": self.onNext,
            "on_tbPrev_clicked": self.onPrev,
            "on_HCView_destroy": self.onDestroy
        }
        self.wTree.signal_autoconnect(sigs)

        self.hbox = self.wTree.get_widget("hbox2")
        self.statusbar = self.wTree.get_widget("statusbar2")

        img = cv.LoadImageM(self.imagefiles[0], iscolor=False)
        self.csize = shape(img)

        self.canvas = gnomecanvas.Canvas(aa=True)
        self.canvas.set_size_request(self.csize[1], self.csize[0])
        self.canvas.set_scroll_region(0, 0, self.csize[1], self.csize[0])

        # Put it together
        self.hbox.add(self.canvas)
        self.window.set_resizable(False)
        self.window.show_all()

        self.canvas.connect("event", self.canvas_event)

        self.DrawPoints(self.filenamesind)
コード例 #4
0
    def openWindow(self):
        """
        in: nothing
        returns nothing
        """

        # superclass openwindow
        ListWindow.openWindow(self)

        # add signal handlers
        canv = gnomecanvas.Canvas()
        canv.show_all()
        self['scrolledwindow1'].add(canv)
        self.thePathwayCanvas = PathwayCanvas(self, canv)
        self.theLayout.attachToCanvas(self.thePathwayCanvas)

        self.addHandlers({
                'on_zoom_in_button_clicked' : self.__zoom_in,\
                'on_zoom_out_button_clicked' : self.__zoom_out,\
                'on_zoom_to_fit_button_clicked' : self.__zoom_to_fit,\
                'on_print_button_clicked' : self.__print,\
                'on_selector_button_toggled' : self.__palette_toggled,\
                'on_variable_button_toggled' : self.__palette_toggled, \
                'on_system_button_toggled' : self.__palette_toggled,\
                'on_process_button_toggled' : self.__palette_toggled,\
                'on_text_button_toggled' : self.__palette_toggled,\
                'on_layout_name_entry_activate' : self.__rename_layout,\
                'on_layout_name_entry_editing_done' : self.__rename_layout,\
                #'on_layout_name_entry_focus_out_event' : self.__rename_layout,

                'on_delete_button_clicked': self.__DeleteLayoutButton_clicked,\
                'on_clone_button_clicked': self.__CloneLayoutButton_clicked,\
                'on_custom_button_toggled' : self.__palette_toggled,\
                'on_search_entry_activate' : self.__search,\
                'on_rename_button_clicked': self.__editLabel,\
                'on_search_entry_editing_done' : self.__search })

        self.theHBox = self['hbox7']
        self.theLabel = self['layout_name_label']
        self.theEntry = self['layout_name_entry']
        self['top_frame'].remove(self.theHBox)
        self.theHBox.remove(self.theEntry)

        self.update()

        #get Palette Button Widgets

        selector = ListWindow.getWidget(self, 'selector_button')
        selector.set_active(True)
        variable = ListWindow.getWidget(self, 'variable_button')
        process = ListWindow.getWidget(self, 'process_button')
        system = ListWindow.getWidget(self, 'system_button')
        custom = ListWindow.getWidget(self, 'custom_button')
        text = ListWindow.getWidget(self, 'text_button')

        self.zoomin = ListWindow.getWidget(self, 'zoom_in_button')
        self.zoomout = ListWindow.getWidget(self, 'zoom_out_button')
        self.zoomtofit = ListWindow.getWidget(self, 'zoom_to_fit_button')

        self.theButtonDict = {
            'selector': PE_SELECTOR,
            'variable': PE_VARIABLE,
            'process': PE_PROCESS,
            'system': PE_SYSTEM,
            'custom': PE_CUSTOM,
            'text': PE_TEXT
        }
        self.thePaletteButtonDict = {
            'selector': selector,
            'variable': variable,
            'process': process,
            'system': system,
            'custom': custom,
            'text': text
        }
        self.theButtonKeys = self.thePaletteButtonDict.keys().sort()

        # Sets the return PaletteButton value
        self.__CurrPaletteButton = 'selector'
        self.__PrevPaletteButton = None
        self.isFirst = True
コード例 #5
0
 def __init__(self):
     self.canvas = gnomecanvas.Canvas(aa=True)
コード例 #6
0
ファイル: LabelWindow.py プロジェクト: tianchi03/Autotrace
    def __init__(self, csvs, SHOW_LING, SHOW_NEUT, SHOW_WAVE, SHOW_SPEC):
        filename = 'labelwindowbackground.png'
        title = csvs[0]
        thisdir = '/'.join(title.split('/')[:-1]) + '/'
        t = nc.NeutralTongue(title, thisdir + 'neutral.csv', SHOW_LING,
                             SHOW_NEUT, SHOW_WAVE, SHOW_SPEC)
        t.saveNcrop('labelwindowbackground.png')
        numFrames = len(t.X)
        t.win.destroy()

        self.gladefile = "LinguaViewer.glade"
        self.wTree = gtk.glade.XML(self.gladefile, "LabelWindow")
        self.window = self.wTree.get_widget("LabelWindow")
        self.window.connect('destroy', self.onDestroy)
        self.window.set_title(title)
        self.numFrames = numFrames
        self.title = title
        self.static_dir = os.getcwd() + '/'
        self.wavname = title[:-4] + ".wav"

        dic = {
            "on_tbSave1_clicked": self.onSave,
            "on_tbPlay1_clicked": self.playSound,
            "on_entry1_activate": self.updateText
        }
        self.wTree.signal_autoconnect(dic)

        self.textentry = self.wTree.get_widget("entry1")
        self.dorsumentry = self.wTree.get_widget("entry2")
        self.tipentry = self.wTree.get_widget("entry3")
        self.statusbar = self.wTree.get_widget("statusbar3")
        self.vbox = self.wTree.get_widget("hbox4")

        self.canvas = gnomecanvas.Canvas(aa=True)

        self.vbox.add(self.canvas)
        self.window.set_resizable(False)
        self.window.show_all()

        self.canvas.connect("event", self.canvas_event)

        #add a bit of whitespace to the image to put the text labels
        cmd = ['convert', '-size', '600x75', 'xc:white', 'white.png']
        proc = subprocess.Popen(cmd)
        status = proc.wait()
        cmd = [
            'montage', 'white.png', filename, '-mode', 'Concatenate', '-tile',
            '1x', 'canvas.png'
        ]
        proc = subprocess.Popen(cmd)
        status = proc.wait()

        pixbuf = gtk.gdk.pixbuf_new_from_file('canvas.png')
        itemType = gnomecanvas.CanvasPixbuf
        self.background = self.canvas.root().add(itemType,
                                                 x=0,
                                                 y=0,
                                                 pixbuf=pixbuf)
        self.width = pixbuf.get_width()
        self.height = pixbuf.get_height()

        #self.textview.set_size_request(self.width, 100)
        self.canvas.set_size_request(self.width, self.height)
        self.canvas.set_scroll_region(0, 0, self.width, self.height)

        #set the border lines
        self.leftedge = 75.0
        self.rightedge = 540.0
        self.canvas.root().add(gnomecanvas.CanvasLine, points=[self.leftedge, self.height, self.leftedge, 0], \
                fill_color_rgba=0x000000FF, width_units=1.0)
        self.canvas.root().add(gnomecanvas.CanvasLine, points=[self.rightedge, self.height, self.rightedge, 0], \
                fill_color_rgba=0x000000FF, width_units=1.0)

        #add a divider between the label portion and the image
        self.canvas.root().add(gnomecanvas.CanvasLine, points=[self.leftedge, 76.0, self.rightedge, 76.0], \
                fill_color_rgba=0x00000099, width_units=1.0)

        self.canvas.root().add(gnomecanvas.CanvasText, x=35, y=35, text="Label", fill_color_rgba=0x000000FF, \
                justification=gtk.JUSTIFY_CENTER)

        self.dragging = False
        self.previous_value = False
        self.boundaries = []
        self.boundary_values = []

        self.label_limit = 99
        self.label_text = []
        self.label_centers = []
        self.labels = []
        for i in range(self.label_limit):
            self.label_text.append('')
            self.label_centers.append(i + 75)
            self.labels.append(self.canvas.root().add(gnomecanvas.CanvasText, x=self.label_centers[i], y=35, \
                text=self.label_text[i], fill_color_rgba=0x000000FF, justification=gtk.JUSTIFY_CENTER))

        self.intervals = [[self.leftedge, self.rightedge]]
        self.selected_interval = 0
        self.sorted_boundaries = [self.leftedge, self.rightedge]

        self.selected_mask = None
        self.loadLabel()
コード例 #7
0
	def __init__(self):
		self.onOpen()
		self.wTree = gtk.glade.XML("roi.glade", "window1")
		self.window = self.wTree.get_widget("window1")
		
		sigs = {"on_window1_destroy" : gtk.main_quit,
				"on_button1_clicked" : self.onSave,
				"on_button2_clicked" : self.onReset,
				"on_topentry_activate" : self.resetByText,
				"on_bottomentry_activate" : self.resetByText,
				"on_leftentry_activate" : self.resetByText,
				"on_rightentry_activate" : self.resetByText}
		self.wTree.signal_autoconnect(sigs)
		
		self.statusbar = self.wTree.get_widget("statusbar1")
		self.machineCBox = self.wTree.get_widget("combobox1")
		self.machineCBox.set_active(-1) #initialize as "UNKNOWN"
		self.topentry = self.wTree.get_widget("topentry")
		self.bottomentry = self.wTree.get_widget("bottomentry")
		self.leftentry = self.wTree.get_widget("leftentry")
		self.rightentry = self.wTree.get_widget("rightentry")
		
		self.cbox = self.wTree.get_widget("canvashbox")
		self.canvas = gnomecanvas.Canvas(aa=True)
		
		#open an image to see the size
		img = cv.LoadImageM(self.datafiles[0], iscolor=False)
		self.csize = shape(img)
		
		self.canvas.set_size_request(self.csize[1], self.csize[0])
		self.canvas.set_scroll_region(0, 0, self.csize[1], self.csize[0])
		self.cbox.add(self.canvas)
		self.canvas.connect("event", self.canvas_event)
		
		self.DRAG = False
		
		self.pathtofiles = '/'.join(self.datafiles[0].split('/')[:-1]) + '/'

		#Read ROI_config.txt if it exists
		#self.config = os.path.join(self.pathtofiles, 'ROI_config.txt')
		self.config = 'ROI_config.txt'
		#if (os.path.isfile(self.config)):
		if os.path.isfile(os.path.join(self.pathtofiles, self.config)):
			c = open(self.config, 'r').readlines()
			self.top = int(c[1][:-1].split('\t')[1])
			self.bottom = int(c[2][:-1].split('\t')[1])
			self.left = int(c[3][:-1].split('\t')[1])
			self.right = int(c[4][:-1].split('\t')[1])
		else:
			self.top = 140 #default settings for the Sonosite Titan
			self.bottom = 320
			self.left = 250
			self.right = 580
		
		self.getSumImage()
		pixbuf = gtk.gdk.pixbuf_new_from_file(self.pathtofiles+'SumImage.png')
		self.background = self.canvas.root().add(gnomecanvas.CanvasPixbuf, x=0, y=0, pixbuf=pixbuf)
		
		self.reset()
		subprocess.Popen(['rm', self.pathtofiles+'SumImage.png'])
		
		self.window.show_all()
コード例 #8
0
    def __init__(self, filenames, tracerinfo):
        # Create window
        self.gladefile = "LinguaViewer.glade"
        self.wTree = gtk.glade.XML(self.gladefile, "PGLite")
        self.window = self.wTree.get_widget("PGLite")
        self.window.connect('destroy', self.onDestroy)

        self.filenamesind = 0
        self.filenames = filenames
        self.interpolated = []
        for i in self.filenames:
            self.interpolated.append(False)
            #self.interpolated.append(True)

        self.tracercode = tracerinfo  #for new files
        self.get_tracenames()  #for existing files

        self.bootstrapList = []
        self.bootstrapCounter = 0

        self.bootstrapDisplay = self.wTree.get_widget("bootstrapentry")
        self.hbox = self.wTree.get_widget("hbox2")
        self.statusbar = self.wTree.get_widget("statusbar2")

        # Create 720x480 antialised drawing canvas
        img = cv.LoadImageM(filenames[0], iscolor=False)
        self.csize = shape(img)

        self.canvas = gnomecanvas.Canvas(aa=True)
        self.canvas.set_size_request(self.csize[1], self.csize[0])
        self.canvas.set_scroll_region(0, 0, self.csize[1], self.csize[0])

        # Put it together
        self.hbox.add(self.canvas)
        self.window.set_resizable(False)
        self.window.show_all()

        self.pathtofiles = '/'.join(self.filenames[0].split('/')[:-1]) + '/'
        self.config = self.pathtofiles + 'ROI_config.txt'
        print self.config
        if (os.path.isfile(self.config)):
            print "Found ROI_config.txt"
            c = open(self.config, 'r').readlines()
            self.machine = c[0][:-1].split('\t')[1]
            if self.machine == '':
                self.machine = 'Sonosite Titan'
            print "Using machine: " + self.machine
        else:
            self.machine = 'Sonosite Titan'  #default

        # Add new grid definitions here and in the glade file roi.glade
        self.machineOptions = {
            'Sonosite Titan': [[115., 167., 357., 392.],
                               [421., 172., 667., 392.]],
            'Toshiba': [[155., 187., 286., 437.], [432., 187., 575., 437.]]
        }

        # Event Handling
        dic = {
            "on_tbGrid_clicked": self.on_set_grid,
            "on_tbNext_clicked": self.nextImage,
            "on_tbPrev_clicked": self.prevImage,
            "on_tbBoot_clicked": self.add_to_bootstrap_list
        }
        self.wTree.signal_autoconnect(dic)

        self.canvas.connect("event", self.canvas_event)
        self.dragging = False
        self.tracing = False
        self.delete_points = False

        self.options = {
            'set_grid': self.set_grid,
            'trace_contour': self.trace_contour
        }
        self.SET_GRID = False
        self.GRID_EXISTS = False
        self.numGridLines = 32
        self.gridCount = 0

        self.DrawPoints(0)