コード例 #1
0
    def add_row(self, row_class, rows, grid_sizer, can_delete):
        row = len(rows) + 1
        if row_class == WorkspaceViewObjectsRow:
            color = (get_primary_outline_color() if row == 1 else
                     get_secondary_outline_color() if row == 2 else
                     get_tertiary_outline_color() if row == 3 else wx.WHITE)
        else:
            color = (wx.BLUE if row == 1 else wx.GREEN
                     if row == 2 else wx.RED if row == 3 else wx.WHITE)
        vw_row = row_class(self, color, can_delete)

        grid_sizer.Add(vw_row.chooser, (row, C_CHOOSER), flag=wx.EXPAND)
        grid_sizer.Add(vw_row.color_ctrl, (row, C_COLOR), flag=wx.EXPAND)
        grid_sizer.Add(vw_row.show_check, (row, C_SHOW), flag=wx.ALIGN_CENTER)
        grid_sizer.Add(vw_row.remove_button, (row, C_REMOVE),
                       flag=wx.ALIGN_CENTER)
        rows.append(vw_row)
        if can_delete:

            def remove_this_row(
                event,
                rows=rows,
                grid_sizer=grid_sizer,
                remove_button=vw_row.remove_button,
            ):
                self.remove_row(rows, grid_sizer, remove_button)

            vw_row.remove_button.Bind(wx.EVT_BUTTON, remove_this_row)
        self.update_menu(self.frame.menu_subplots)
        self.layout()
コード例 #2
0
ファイル: maskobjects.py プロジェクト: orgonth/CellProfiler
    def display(self, workspace, figure):
        """Create an informative display for the module"""
        import matplotlib

        original_labels = workspace.display_data.original_labels
        final_labels = workspace.display_data.final_labels
        mask = workspace.display_data.mask
        #
        # Create a composition of the final labels and mask
        #
        outlines = outline(original_labels) > 0

        cm = figure.return_cmap()
        sm = matplotlib.cm.ScalarMappable(cmap=cm)
        #
        # Paint the labels in color
        #
        image = sm.to_rgba(final_labels, norm=False)[:, :, :3]
        image[final_labels == 0, :] = 0
        #
        # Make the mask a dark gray
        #
        image[(final_labels == 0) & mask, :] = 0.25
        #
        # Make the outlines of the kept objects the primary color
        # and the outlines of removed objects red.
        #
        final_outlines = outline(final_labels) > 0
        original_color = (
            np.array(cpprefs.get_secondary_outline_color()[0:3], float) / 255)
        final_color = np.array(cpprefs.get_primary_outline_color()[0:3],
                               float) / 255
        image[outlines, :] = original_color[np.newaxis, :]
        image[final_outlines, :] = final_color[np.newaxis, :]

        figure.set_subplots((2, 1))
        figure.subplot_imshow_labels(
            0,
            0,
            original_labels,
            title=self.object_name.value,
            colormap=sm,
        )
        figure.subplot_imshow_color(
            1,
            0,
            image,
            title=self.remaining_objects.value,
            sharexy=figure.subplot(0, 0),
            colormap=sm,
        )
コード例 #3
0
ファイル: crop.py プロジェクト: zwdiscover/CellProfiler
 def __init__(self, x, y, on_move):
     x = max(0, min(x, pixel_data.shape[1]))
     y = max(0, min(y, pixel_data.shape[0]))
     self.__selected = False
     self.__color = get_primary_outline_color()
     self.__color = numpy.hstack(self.__color).astype(float) / 255.0
     self.__on_move = on_move
     super(Handle, self).__init__(
         (x - self.width / 2, y - self.height / 2),
         self.width,
         self.height,
         edgecolor=self.__color,
         facecolor="none",
     )
     self.set_picker(True)
コード例 #4
0
ファイル: crop.py プロジェクト: zwdiscover/CellProfiler
 def __init__(self, center, radius):
     """Draw an ellipse with control points at the ellipse center and
     a given x and y radius"""
     self.center_x, self.center_y = center
     self.radius_x = self.center_x + radius[0] / 2
     self.radius_y = self.center_y + radius[1] / 2
     color = get_primary_outline_color()
     color = numpy.hstack(color).astype(float) / 255.0
     self.ellipse = matplotlib.patches.Ellipse(center,
                                               self.width,
                                               self.height,
                                               edgecolor=color,
                                               facecolor="none")
     self.center_handle = Handle(self.center_x, self.center_y,
                                 self.move_center)
     self.radius_handle = Handle(self.radius_x, self.radius_y,
                                 self.move_radius)
コード例 #5
0
ファイル: crop.py プロジェクト: zwdiscover/CellProfiler
 def __init__(self, top_left, bottom_right):
     self.__left, self.__top = top_left
     self.__right, self.__bottom = bottom_right
     color = get_primary_outline_color()
     color = numpy.hstack(color).astype(float) / 255.0
     self.rectangle = matplotlib.patches.Rectangle(
         (min(self.__left,
              self.__right), min(self.__bottom, self.__top)),
         abs(self.__right - self.__left),
         abs(self.__top - self.__bottom),
         edgecolor=color,
         facecolor="none",
     )
     self.top_left_handle = Handle(top_left[0], top_left[1],
                                   self.handle_top_left)
     self.bottom_right_handle = Handle(bottom_right[0],
                                       bottom_right[1],
                                       self.handle_bottom_right)
コード例 #6
0
    def OnPaint(self, event):
        dc = wx.BufferedPaintDC(self)
        try:
            dc.SetBackgroundMode(wx.PENSTYLE_SOLID)
            background_color = wx.SystemSettings.GetColour(
                wx.SYS_COLOUR_WINDOW)
            metadata_color = get_primary_outline_color()
            selected_background_color = wx.SystemSettings.GetColour(
                wx.SYS_COLOUR_HIGHLIGHT)
            selected_color = wx.SystemSettings.GetColour(
                wx.SYS_COLOUR_HIGHLIGHTTEXT)
            text_color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
            dc.SetBackground(wx.Brush(background_color))
            dc.SetFont(self.Font)
            dc.Clear()
            if self.native_border:
                renderer = wx.RendererNative.Get()
                style = 0
                if self.FindFocus() == self:
                    style |= wx.CONTROL_FOCUSED | wx.CONTROL_CURRENT
                if not self.Enabled:
                    style |= wx.CONTROL_DISABLED
                renderer.DrawTextCtrl(
                    self, dc, (0, 0, self.ClientSize[0], self.ClientSize[1]),
                    style)
                dc.SetClippingRegion((
                    self.padding,
                    self.padding,
                    self.ClientSize[0] - 2 * self.padding,
                    self.ClientSize[1] - 2 * self.padding,
                ))
            text = self.get_text(0, len(self.__tokens))
            positions = self.get_positions(dc)

            last_state = "unknown"
            text_list = []
            state_list = []
            position_list = []
            selection = None
            if self.selection is not None:
                selection = list(self.selection)
                selection.sort()
            for i, token in enumerate(self.__tokens):
                if isinstance(token, self.MetadataToken):
                    current_state = "metadata"
                elif self.selection is not None and selection[
                        0] <= i < selection[1]:
                    current_state = "selection"
                else:
                    current_state = "boring"
                if current_state != last_state:
                    state_list.append(current_state)
                    text_list.append("")
                    last_state = current_state
                    position_list.append((positions[i], self.padding))
                text_list[-1] += self.get_text(i, i + 1)
            colors = {
                "boring": (background_color, text_color),
                "selection": (selected_background_color, selected_color),
                "metadata": (metadata_color, text_color),
            }
            background_color = [colors[state][0] for state in state_list]
            foreground_color = [colors[state][1] for state in state_list]
            dc.SetBackgroundMode(wx.PENSTYLE_SOLID)
            for text, position, background, foreground in zip(
                    text_list, position_list, background_color,
                    foreground_color):
                dc.SetTextBackground(background)
                dc.SetTextForeground(foreground)
                dc.DrawText(text, position[0], position[1])
        finally:
            dc.Destroy()