Example #1
0
    def on_note_icon_add(self):
	note_num = {}
	for tag in meta.global_settings: 
	    if tag.startswith('Notes'):
		timepoint = exp.get_tag_attribute(tag)
		if not timepoint in note_num:
		    note_num[timepoint] = 1
		else:
		    note_num[timepoint] += 1	
	if note_num:
	    self.NOTE_ICON_FACTOR = (max(note_num.values())+1) * self.ICON_SIZE
	    self._recalculate_min_size()
	    self.Refresh(eraseBackground=False)
	    self.Parent.FitInside()	
Example #2
0
    def __init__(self, parent, protocol, **kwargs):

        wx.ScrolledWindow.__init__(self, parent, **kwargs)
        self.SetScrollbars(20, 20, self.Size[0] + 20, self.Size[1] + 20, 0, 0)

        self.tag_stump = exp.get_tag_stump(protocol, 2)
        self.instance = exp.get_tag_attribute(protocol)

        # Attach a flexi sizer for the text controler and labels
        self.fgs = wx.FlexGridSizer(rows=15000, cols=6, hgap=5, vgap=5)

        #Create the first step as empty
        if not meta.get_field(self.tag_stump + '|Step1|%s' % self.instance):
            meta.set_field(self.tag_stump + '|Step1|%s' % self.instance,
                           ['', '', ''])

        self.showSteps()
Example #3
0
    def _on_click(self, evt):
        if self.hover_timepoint is not None:
            try:
                bench = wx.GetApp().get_bench()
            except: return
            bench.set_timepoint(self.hover_timepoint)
            bench.update_well_selections()
	
	if self.current_ntag is not None:
	    note_type = exp.get_tag_event(self.current_ntag)	    
	    timepoint = exp.get_tag_attribute(self.current_ntag)
	    self.page_counter = exp.get_tag_instance(self.current_ntag)
	    
	    
	    note_dia = NotePad(self, note_type, timepoint, self.page_counter)
	    if note_dia.ShowModal() == wx.ID_OK:
		    # Notes|<type>|<timepoint>|<instance> = value
		meta.set_field('Notes|%s|%s|%s' %(note_dia.noteType, timepoint, str(self.page_counter)), note_dia.noteDescrip.GetValue())   	    
Example #4
0
    def _on_paint(self, evt=None):
        '''Handler for paint events.
        '''
        if not self.timepoints:
            evt.Skip()
            return

        PAD = self.PAD + self.ICON_SIZE / 2.0
        ICON_SIZE = self.ICON_SIZE
        MIN_X_GAP = self.MIN_X_GAP
        TIC_SIZE = self.TIC_SIZE
        FONT_SIZE = self.FONT_SIZE
        MAX_TIMEPOINT = self.timepoints[-1]
	WIGGEL_NUM = 100
        self.hover_timepoint = None
	self.current_ntag = None
	self.on_note_icon_add()

        dc = wx.BufferedPaintDC(self)
        dc.Clear()
        dc.BeginDrawing()

        w_win, h_win = (float(self.Size[0]), float(self.Size[1]))
        if self.time_x:
            if MAX_TIMEPOINT == 0:
                px_per_time = 1
            else:
                px_per_time = max((w_win - PAD * 2.0) / MAX_TIMEPOINT,
                                  MIN_X_GAP)
	else:
	    px_per_time = 1
        
        if len(self.timepoints) == 1:
            x_gap = 1
        else:
            x_gap = max(MIN_X_GAP, 
                        (w_win - PAD * 2) / (len(self.timepoints) - 1))

        # y pos of line
        y = h_win - PAD - FONT_SIZE[1] - TIC_SIZE - 1
	
	
	def icon_hover(mouse_pos, icon_pos, icon_size):
	    '''returns whether the mouse is hovering over an icon
	    '''
	    if mouse_pos is None:
		return False
	    MX,MY = mouse_pos
	    X,Y = icon_pos
	    return (X - icon_size/2.0 < MX < X + icon_size/2.0 and 
	            Y - icon_size/2.0 < MY < Y + icon_size/2.0)	

	# draw the timeline
	if self.time_x:	    
	    dc.DrawLine(PAD, y, 
	                px_per_time * MAX_TIMEPOINT + PAD, y)
	else:   
	    dxs = range(WIGGEL_NUM+1)
	    dxs = [float(dx)/WIGGEL_NUM for dx in dxs]

	    x = PAD
	    for i, timepoint in enumerate(self.timepoints):
		if i > 0:
		    n = math.sqrt(((self.timepoints[i]-self.timepoints[i-1])))  #instead of log can use square root
		    ys = [5*(math.sin((math.pi)*dx))*math.sin(2*math.pi*dx*n) for dx in dxs] # 10 is px height fow wiggles can change it
		    for p, dx in enumerate(dxs[:-1]):
			dc.DrawLine(x+x_gap*dxs[p], y+ys[p], x+x_gap*dxs[p+1], y+ys[p+1])
		    x += x_gap

	font = dc.Font
	font.SetPixelSize(FONT_SIZE)
	dc.SetFont(font)
	
	# draw the ticks
        for i, timepoint in enumerate(self.timepoints):
	    # if data acquisition is the only event in this timepoint skip it
	    #evt_categories = list(set([exp.get_tag_stump(ev.get_welltag(), 1) for ev in self.events_by_timepoint[timepoint]]))
	    #if all(evt_categories[0] == cat and cat == 'DataAcquis' for cat in evt_categories):
		#continue
	
            # x position of timepoint on the line
            if self.time_x:
                x = timepoint * px_per_time + PAD
            else:
                x = i * x_gap + PAD
                
            if (self.cursor_pos is not None and 
                x - ICON_SIZE/2 < self.cursor_pos[0] < x + ICON_SIZE/2):
                dc.SetPen(wx.Pen(wx.BLACK, 3))
                self.hover_timepoint = timepoint
            else:
                dc.SetPen(wx.Pen(wx.BLACK, 1))
            # Draw tic marks
            dc.DrawLine(x, y - TIC_SIZE, 
                        x, y + TIC_SIZE)    
	    
	    # Draw the note icon above the tick
	    note_tags = [ tag for tag in meta.global_settings
	                  if tag.startswith('Notes') and exp.get_tag_attribute(tag) == str(timepoint)] 
	    #if note_tags:
		#self.on_note_icon_add()  #update the min_h of the panel
	    for i, ntag in enumerate(note_tags):
		    bmp = icons.note.Scale(ICON_SIZE, ICON_SIZE, quality=wx.IMAGE_QUALITY_HIGH).ConvertToBitmap() 		
		    dc.DrawBitmap(bmp, x - ICON_SIZE / 2.0, 
		                    y - ((i+1)*ICON_SIZE) - TIC_SIZE - 1)	
		    
		    if icon_hover(self.cursor_pos, (x - ICON_SIZE / 2.0, 
		                    y - ((i+1)*ICON_SIZE) - TIC_SIZE - 1), ICON_SIZE):
			self.current_ntag = ntag
					#highlight the note icon		    
            		
            # draw the timepoint beneath the line
            time_string = exp.format_time_string(timepoint)
            wtext = FONT_SIZE[0] * len(time_string)
	    htext = FONT_SIZE[1]
            dc.DrawText(time_string, x - wtext/2.0, y + TIC_SIZE + 1)
	    dc.DrawLine(x, y + TIC_SIZE + 1 + htext,  x, h_win)  # extension of tick towards the lineage panel
	    		   
        dc.EndDrawing()
    def __init__(self, parent, protocol, currpassageNo):
        wx.Dialog.__init__(self,
                           parent,
                           -1,
                           size=(700, 500),
                           style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
                           title='Passage %s' % str(currpassageNo))

        self.protocol = protocol
        self.currpassageNo = currpassageNo

        self.top_panel = wx.Panel(self)
        self.bot_panel = wx.ScrolledWindow(self)

        self.settings_controls = {}
        self.curr_protocol = {}
        self.admin_info = {}

        self.tag_stump = exp.get_tag_stump(self.protocol, 2)
        self.instance = exp.get_tag_attribute(self.protocol)

        if meta.get_field(
                self.tag_stump + '|Passage%s|%s' %
            (str(self.currpassageNo - 1), self.instance)) is None:
            self.curr_protocol = Default_Protocol
        else:
            #self.curr_protocol = meta.get_field(self.tag_stump+'|Passage%s|%s' %(str(self.currpassageNo-1), self.instance))
            d = meta.get_field(self.tag_stump + '|Passage%s|%s' %
                               (str(self.currpassageNo - 1), self.instance))
            for k, v in d:
                self.curr_protocol[k] = v

        today = datetime.date.today()
        self.myDate = '%02d/%02d/%4d' % (today.day, today.month, today.year)

        self.curr_protocol['ADMIN'][
            1] = self.myDate  # set todays date as current

        self.settings_controls['Admin|0'] = wx.TextCtrl(
            self.top_panel,
            size=(70, -1),
            value=self.curr_protocol['ADMIN'][0])
        self.settings_controls['Admin|1'] = wx.DatePickerCtrl(
            self.top_panel, style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
        self.settings_controls['Admin|2'] = wx.TextCtrl(
            self.top_panel,
            size=(20, -1),
            value=self.curr_protocol['ADMIN'][2])
        #self.settings_controls['Admin|3'] = wx.TextCtrl(self.top_panel, size=(20,-1), value=self.curr_protocol['ADMIN'][3])
        self.settings_controls['Admin|3'] = wx.lib.masked.NumCtrl(
            self.top_panel, size=(20, -1), style=wx.TE_PROCESS_ENTER)
        if isinstance(self.curr_protocol['ADMIN'][3], int):  #it had value
            self.settings_controls['Admin|3'].SetValue(
                self.curr_protocol['ADMIN'][3])
        unit_choices = ['nM2', 'uM2', 'mM2', 'Other']
        self.settings_controls['Admin|4'] = wx.ListBox(self.top_panel, -1,
                                                       wx.DefaultPosition,
                                                       (50, 20), unit_choices,
                                                       wx.LB_SINGLE)
        if self.curr_protocol['ADMIN'][4] is not None:
            self.settings_controls['Admin|4'].Append(
                self.curr_protocol['ADMIN'][4])
            self.settings_controls['Admin|4'].SetStringSelection(
                self.curr_protocol['ADMIN'][4])

        self.settings_controls['Admin|0'].Bind(wx.EVT_TEXT, self.OnSavingData)
        self.settings_controls['Admin|1'].Bind(wx.EVT_DATE_CHANGED,
                                               self.OnSavingData)
        self.settings_controls['Admin|2'].Bind(wx.EVT_TEXT, self.OnSavingData)
        self.settings_controls['Admin|3'].Bind(wx.EVT_TEXT, self.OnSavingData)
        self.settings_controls['Admin|4'].Bind(wx.EVT_LISTBOX,
                                               self.OnSavingData)

        self.selection_btn = wx.Button(self, wx.ID_OK, 'Record Passage')
        self.close_btn = wx.Button(self, wx.ID_CANCEL)

        # Sizers and layout
        top_fgs = wx.FlexGridSizer(cols=10, vgap=5)

        top_fgs.Add(wx.StaticText(self.top_panel, -1, 'Operator Name'), 0,
                    wx.RIGHT, 5)
        top_fgs.Add(self.settings_controls['Admin|0'], 0, wx.EXPAND)
        top_fgs.Add(wx.StaticText(self.top_panel, -1, 'Date'), 0,
                    wx.RIGHT | wx.LEFT, 5)
        top_fgs.Add(self.settings_controls['Admin|1'], 0, wx.EXPAND)
        top_fgs.Add(wx.StaticText(self.top_panel, -1, 'Split 1:'), 0, wx.LEFT,
                    5)
        top_fgs.Add(self.settings_controls['Admin|2'], 0, wx.EXPAND)
        top_fgs.Add(wx.StaticText(self.top_panel, -1, 'Cell Count'), 0,
                    wx.RIGHT | wx.LEFT, 5)
        top_fgs.Add(self.settings_controls['Admin|3'], 0, wx.EXPAND)
        top_fgs.Add(wx.StaticText(self.top_panel, -1, ' cells/'), 0)
        top_fgs.Add(self.settings_controls['Admin|4'], 0, wx.EXPAND)

        self.fgs = wx.FlexGridSizer(cols=7, hgap=5, vgap=5)
        self.showSteps()

        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
        btnSizer.Add(self.selection_btn, 0, wx.ALL, 5)
        btnSizer.Add(self.close_btn, 0, wx.ALL, 5)

        self.top_panel.SetSizer(top_fgs)
        self.bot_panel.SetSizer(self.fgs)
        self.bot_panel.SetScrollbars(20, 20, self.Size[0] + 20,
                                     self.Size[1] + 20, 0, 0)

        self.Sizer = wx.BoxSizer(wx.VERTICAL)
        self.Sizer.Add(self.top_panel, 0, wx.EXPAND | wx.ALL, 5)
        self.Sizer.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 5)
        self.Sizer.Add(self.bot_panel, 1, wx.EXPAND | wx.ALL, 10)
        self.Sizer.Add(btnSizer)
        self.Show()