Example #1
0
    def __init__(self, parent = None, flow_analysis = None,  *args, **kwargs):
        self.log = logging.getLogger('OneFrame')
        kwargs['parent'] = parent
        wx.Frame.__init__(self, *args, **kwargs)

        # Storage of data
        if flow_analysis is None:
            self.fa = FlowAnalysis()
        else:
            self.fa = flow_analysis
        
        # Default Variables: these are not to be written to,
        # as the memory is shared throughout the program
        self._channel = 0
        self._sample = [0]
        self.parent = parent
        self.log.debug('Parent {}'.format(self.parent))
        self.children = []
        ######################################################################## 
        # Create the toolbar on the main window
        ######################################################################## 

        # Create wxIDs
        tb_back_ID = wx.NewId()
        tb_forward_ID = wx.NewId()
        tb_tag_list_ID = wx.NewId()
        tb_save_ID = wx.NewId()
        tb_export_ID = wx.NewId()
        tb_load_ID = wx.NewId()
        tb_new_window_ID = wx.NewId()
        tb_gate_bound_ID = wx.NewId()

        # Toolbar
        self.toolbar = self.CreateToolBar(wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT)
        tb_size = (24,24)
        self.toolbar.SetToolBitmapSize(tb_size)
        tb_back =  wx.ArtProvider.GetBitmap(wx.ART_GO_BACK, wx.ART_TOOLBAR, tb_size)
        tb_forward =  wx.ArtProvider.GetBitmap(wx.ART_GO_FORWARD, wx.ART_TOOLBAR, tb_size)
        tb_save = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, tb_size)
        tb_load = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tb_size)
        tb_new_window = wx.Image('icons/1400108720_filefind.png',wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        #wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, tb_size)
        # List of Tags
        self.tag_list = wx.ComboBox(self.toolbar, tb_tag_list_ID, size = (300,-1), style = wx.CB_DROPDOWN | wx.CB_READONLY)

        self.toolbar.AddLabelTool(tb_new_window_ID, "New Window", tb_new_window)
        self.toolbar.AddLabelTool(tb_load_ID, "Load", tb_load, shortHelp = "Load FCS", longHelp = "")
        self.toolbar.AddLabelTool(tb_save_ID, "Export Plot", tb_save, shortHelp = "Export Plot to PNG, JPG, etc", longHelp = "")
        self.toolbar.AddLabelTool(tb_gate_bound_ID, "Bound Gate", tb_new_window)
        self.toolbar.AddStretchableSpace()
        self.toolbar.AddControl(self.tag_list)
        self.toolbar.AddStretchableSpace()
        self.toolbar.AddLabelTool(tb_back_ID, "Back", tb_back, shortHelp = "Go Back One Tag")
        self.toolbar.AddLabelTool(tb_forward_ID, "Forward", tb_forward, shortHelp = "Go Forward One Tag")

        self.toolbar.Realize()
        
        ######################################################################## 
        # Create Status Bar
        ######################################################################## 
        self.statusbar = self.CreateStatusBar()

        ######################################################################## 
        # Generate the Plot window
        ######################################################################## 
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.figure = OnePlot(self)
        sizer.Add(self.figure, 5, wx.EXPAND)

        ######################################################################## 
        # Controls
        ######################################################################## 
       
        self.cp = cp = wx.CollapsiblePane(self, label="Plotting Controls", style=wx.CP_DEFAULT_STYLE)
        self.control = OneControl(cp.GetPane(), self.figure, self.fa)
        sizer.Add(self.cp, 0, wx.EXPAND)
        self.cp2 = cp2 = wx.CollapsiblePane(self, label="Gating Tree", style=wx.CP_DEFAULT_STYLE)
        self.tree = TreeData(cp2.GetPane(), self)
        sizer.Add(self.cp2, 0, wx.EXPAND)
        
        ######################################################################## 
        # Bind Events
        ######################################################################## 

        self.Bind(wx.EVT_TOOL, self.new_window, id = tb_new_window_ID) 
        self.Bind(wx.EVT_TOOL, self.load_dialog, id = tb_load_ID) 
        self.Bind(wx.EVT_TOOL, self.on_gate_bound, id = tb_gate_bound_ID)

        self.Bind(wx.EVT_TOOL, self.plus_channel, id = tb_forward_ID)
        self.Bind(wx.EVT_TOOL, self.minus_channel, id = tb_back_ID)
        self.Bind(wx.EVT_COMBOBOX, self.on_tag_list, id = tb_tag_list_ID)
        self.Bind(wx.EVT_CHAR_HOOK, self.on_key)
        ######################################################################## 
        # Finalize setup
        ########################################################################  
        self.SetSizer(sizer)
Example #2
0
class OneFrame(wx.Frame):
    def __init__(self, parent = None, flow_analysis = None,  *args, **kwargs):
        self.log = logging.getLogger('OneFrame')
        kwargs['parent'] = parent
        wx.Frame.__init__(self, *args, **kwargs)

        # Storage of data
        if flow_analysis is None:
            self.fa = FlowAnalysis()
        else:
            self.fa = flow_analysis
        
        # Default Variables: these are not to be written to,
        # as the memory is shared throughout the program
        self._channel = 0
        self._sample = [0]
        self.parent = parent
        self.log.debug('Parent {}'.format(self.parent))
        self.children = []
        ######################################################################## 
        # Create the toolbar on the main window
        ######################################################################## 

        # Create wxIDs
        tb_back_ID = wx.NewId()
        tb_forward_ID = wx.NewId()
        tb_tag_list_ID = wx.NewId()
        tb_save_ID = wx.NewId()
        tb_export_ID = wx.NewId()
        tb_load_ID = wx.NewId()
        tb_new_window_ID = wx.NewId()
        tb_gate_bound_ID = wx.NewId()

        # Toolbar
        self.toolbar = self.CreateToolBar(wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT)
        tb_size = (24,24)
        self.toolbar.SetToolBitmapSize(tb_size)
        tb_back =  wx.ArtProvider.GetBitmap(wx.ART_GO_BACK, wx.ART_TOOLBAR, tb_size)
        tb_forward =  wx.ArtProvider.GetBitmap(wx.ART_GO_FORWARD, wx.ART_TOOLBAR, tb_size)
        tb_save = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, tb_size)
        tb_load = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tb_size)
        tb_new_window = wx.Image('icons/1400108720_filefind.png',wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        #wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, tb_size)
        # List of Tags
        self.tag_list = wx.ComboBox(self.toolbar, tb_tag_list_ID, size = (300,-1), style = wx.CB_DROPDOWN | wx.CB_READONLY)

        self.toolbar.AddLabelTool(tb_new_window_ID, "New Window", tb_new_window)
        self.toolbar.AddLabelTool(tb_load_ID, "Load", tb_load, shortHelp = "Load FCS", longHelp = "")
        self.toolbar.AddLabelTool(tb_save_ID, "Export Plot", tb_save, shortHelp = "Export Plot to PNG, JPG, etc", longHelp = "")
        self.toolbar.AddLabelTool(tb_gate_bound_ID, "Bound Gate", tb_new_window)
        self.toolbar.AddStretchableSpace()
        self.toolbar.AddControl(self.tag_list)
        self.toolbar.AddStretchableSpace()
        self.toolbar.AddLabelTool(tb_back_ID, "Back", tb_back, shortHelp = "Go Back One Tag")
        self.toolbar.AddLabelTool(tb_forward_ID, "Forward", tb_forward, shortHelp = "Go Forward One Tag")

        self.toolbar.Realize()
        
        ######################################################################## 
        # Create Status Bar
        ######################################################################## 
        self.statusbar = self.CreateStatusBar()

        ######################################################################## 
        # Generate the Plot window
        ######################################################################## 
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.figure = OnePlot(self)
        sizer.Add(self.figure, 5, wx.EXPAND)

        ######################################################################## 
        # Controls
        ######################################################################## 
       
        self.cp = cp = wx.CollapsiblePane(self, label="Plotting Controls", style=wx.CP_DEFAULT_STYLE)
        self.control = OneControl(cp.GetPane(), self.figure, self.fa)
        sizer.Add(self.cp, 0, wx.EXPAND)
        self.cp2 = cp2 = wx.CollapsiblePane(self, label="Gating Tree", style=wx.CP_DEFAULT_STYLE)
        self.tree = TreeData(cp2.GetPane(), self)
        sizer.Add(self.cp2, 0, wx.EXPAND)
        
        ######################################################################## 
        # Bind Events
        ######################################################################## 

        self.Bind(wx.EVT_TOOL, self.new_window, id = tb_new_window_ID) 
        self.Bind(wx.EVT_TOOL, self.load_dialog, id = tb_load_ID) 
        self.Bind(wx.EVT_TOOL, self.on_gate_bound, id = tb_gate_bound_ID)

        self.Bind(wx.EVT_TOOL, self.plus_channel, id = tb_forward_ID)
        self.Bind(wx.EVT_TOOL, self.minus_channel, id = tb_back_ID)
        self.Bind(wx.EVT_COMBOBOX, self.on_tag_list, id = tb_tag_list_ID)
        self.Bind(wx.EVT_CHAR_HOOK, self.on_key)
        ######################################################################## 
        # Finalize setup
        ########################################################################  
        self.SetSizer(sizer)

    def load(self, filename):
        self.fa.load(filename)
        self.tree.update()
        self.index = len(self.fa)-1
        self.update_tag_list()
    
    def load_dialog(self, event):
        dlg = wx.FileDialog(self, "Choose an FCS file", os.getcwd(), "", "*.fcs", wx.OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            path = dlg.GetPath()
            self.load(path) 
        dlg.Destroy()

    def new_window(self, event):
        """
            Generate a new window to look at data.
            Currently, we implement this as a set of children off the parent window
            to avoid graph traversing (although that may be necessary later).
        """
        if self.parent is None: 
            child = OneFrame(self, flow_analysis = self.fa, title = 'Child', size=(640,480))
            self.children.append(child)
            self.log.debug('New window: {} children'.format(len(self.children)))
            child.tree.update()
            child.update_tag_list()
            child.Show()
        else:
            self.parent.new_window(event)

    def update_tree(self):
        self.tree.update()

    def update_plot(self):
        self.control.plot()
        #self.control._get_bandwidth()
        #self.figure.plot()
        #self.control._load_axes
        self.figure.draw()


    @property
    def channel(self):
        return self._channel
    @property
    def sample(self):
        return self._sample


    def plus_channel(self, event = None):
        self._channel = (self._channel + 1) % self.fa[self.sample[0]].nparameters
        self.set_channel()
    
    def minus_channel(self, event = None):
        self._channel = (self._channel - 1) % self.fa[self.sample[0]].nparameters
        self.set_channel()

    def set_channel(self, channel = None):
        if channel is None:
            channel = self._channel
        self._channel = channel

        self.tag_list.SetSelection(self.channel)
        # TODO: This will need to call the saved variables
        # and update with current values
        self.control.channel = channel

    def update_tag_list(self):
        self.tag_list.Clear()
        fd = self.fa[self.sample[0]]
        tags = fd.tags
        markers = fd.markers

        labels = []
        for j in range(fd.nparameters):
            labels.append(tags[j] + ' :: ' + markers[j])

        self.tag_list.AppendItems(labels)
        self.tag_list.SetSelection(0)

    def on_tag_list(self, event):
        self.set_channel(self.tag_list.GetSelection())

    def on_key(self, event):
        """ Handle keyboard bindings"""
        # If we are in a window that has its own text control, 
        # we let that class determine what to do
        self.log.debug('Focus object: {}, window focus {}'.format(self.FindFocus().__class__, self.IsActive()))

        if self.IsActive():
            if not issubclass(self.FindFocus().__class__, wx.TextCtrl):
                if event.GetKeyCode() == wx.WXK_LEFT:
                    self.minus_channel()
                elif event.GetKeyCode() == wx.WXK_RIGHT:
                    self.plus_channel()
        event.Skip()

    def on_color(self, event = None, active = False):
        # A plot has changed colors, apply globally
        #TODO BUGS ARE HERE

        
        if not self.parent is None and not active:
            self.parent.on_color(active = True)

        if self.parent is None and not active:
            self.on_color(active = True)

        if self.parent is None and active:
            for c in self.children:
                c.on_color(active = True)

        if active:
            self.figure.on_color()
            self.tree.update()
           
    def on_gate_bound(self, event = None):
        dlg = GateBoundWindow(self)
        dlg.Show()
        #if dlg.ShowModal() == wx.ID_OK:
            # get data
        #    pass 
        dlg.Destroy()