示例#1
0
 def __init__(self, parent, id=-1, style = wx.NO_FULL_REPAINT_ON_RESIZE):
     STCTextEditor.TextCtrl.__init__(self, parent, id,bind_left_up_event = False, style=style)
     self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
     accelTbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('A'), wx.ID_SELECTALL),(wx.ACCEL_CTRL, ord('C'), wx.ID_COPY),(wx.ACCEL_CTRL, ord('V'), wx.ID_PASTE)])  
     self.SetAcceleratorTable(accelTbl)
     self._first_input = True
     self._input_start_pos = 0
     wx.EVT_MOUSE_CAPTURE_LOST(self,self.OnMouseCaptureLost)
示例#2
0
    def _CreateControl(self, parent, id):
        txtCtrl = STCTextEditor.TextCtrl(parent, id, bind_left_up_event = False)
        txtCtrl.SetMarginWidth(1, 0)  # hide line numbers
        txtCtrl.SetReadOnly(True)
        txtCtrl.SetEdgeMode(wx.stc.STC_EDGE_NONE)

        if wx.Platform == '__WXMSW__':
            font = "Courier New"
        else:
            font = "Courier"
        txtCtrl.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = font))
        txtCtrl.SetFontColor(wx.BLACK)
        txtCtrl.StyleClearAll()
        txtCtrl.UpdateStyles()
        wx.EVT_SET_FOCUS(txtCtrl, self.OnFocus)
        #fix the bug when double click the file line and show messagebox which cause wxEVT_MOUSE_CAPTURE_LOST problem
        wx.EVT_MOUSE_CAPTURE_LOST(txtCtrl,self.OnMouseCaptureLost)
        return txtCtrl
示例#3
0
    def handle_interaction(self, pixel_data):
        '''Run a UI that gets an angle from the user'''
        import wx

        if pixel_data.ndim == 2:
            # make a color matrix for consistency
            pixel_data = np.dstack((pixel_data, pixel_data, pixel_data))
        pd_min = np.min(pixel_data)
        pd_max = np.max(pixel_data)
        if pd_min == pd_max:
            pixel_data[:, :, :] = 0
        else:
            pixel_data = ((pixel_data - pd_min) * 255.0 / (pd_max - pd_min))
        #
        # Make a 100 x 100 image so it's manageable
        #
        isize = 200
        i, j, k = np.mgrid[0:isize, 0:int(isize * pixel_data.shape[1] /
                                          pixel_data.shape[0]),
                           0:3].astype(float)
        i *= float(pixel_data.shape[0]) / float(isize)
        j *= float(pixel_data.shape[0]) / float(isize)
        pixel_data = scind.map_coordinates(pixel_data, (i, j, k))
        #
        # Make a dialog box that contains the image
        #
        dialog = wx.Dialog(None, title="Rotate image")
        sizer = wx.BoxSizer(wx.VERTICAL)
        dialog.SetSizer(sizer)
        sizer.Add(
            wx.StaticText(dialog,
                          label="Drag image to rotate, hit OK to continue"), 0,
            wx.ALIGN_CENTER_HORIZONTAL)
        canvas = wx.StaticBitmap(dialog)
        canvas.SetDoubleBuffered(True)
        canvas.BackgroundColour = wx.Colour(0, 0, 0, wx.ALPHA_TRANSPARENT)
        sizer.Add(
            canvas, 0,
            wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
        angle = [0]
        angle_text = wx.StaticText(dialog, label="Angle: %d" % angle[0])
        sizer.Add(angle_text, 0, wx.ALIGN_CENTER_HORIZONTAL)

        def imshow():
            angle_text.Label = "Angle: %d" % int(angle[0])
            angle_text.Refresh()
            my_angle = -angle[0] * np.pi / 180.0
            transform = np.array([[np.cos(my_angle), -np.sin(my_angle)],
                                  [np.sin(my_angle),
                                   np.cos(my_angle)]])
            # Make it rotate about the center
            offset = affine_offset(pixel_data.shape, transform)
            x = np.dstack((scind.affine_transform(pixel_data[:, :, 0],
                                                  transform,
                                                  offset,
                                                  order=0),
                           scind.affine_transform(pixel_data[:, :, 1],
                                                  transform,
                                                  offset,
                                                  order=0),
                           scind.affine_transform(pixel_data[:, :, 2],
                                                  transform,
                                                  offset,
                                                  order=0)))
            buff = x.astype(np.uint8).tostring()
            bitmap = wx.BitmapFromBuffer(x.shape[1], x.shape[0], buff)
            canvas.SetBitmap(bitmap)

        imshow()
        #
        # Install handlers for mouse down, mouse move and mouse up
        #
        dragging = [False]
        initial_angle = [0]
        hand_cursor = wx.StockCursor(wx.CURSOR_HAND)
        arrow_cursor = wx.StockCursor(wx.CURSOR_ARROW)

        def get_angle(event):
            center = np.array(canvas.Size) / 2
            point = np.array(event.GetPositionTuple())
            offset = point - center
            return -np.arctan2(offset[1], offset[0]) * 180.0 / np.pi

        def on_mouse_down(event):
            canvas.Cursor = hand_cursor
            dragging[0] = True
            initial_angle[0] = get_angle(event) - angle[0]
            canvas.CaptureMouse()

        wx.EVT_LEFT_DOWN(canvas, on_mouse_down)

        def on_mouse_up(event):
            if dragging[0]:
                canvas.ReleaseMouse()
                dragging[0] = False
                canvas.Cursor = arrow_cursor

        wx.EVT_LEFT_UP(canvas, on_mouse_up)

        def on_mouse_lost(event):
            dragging[0] = False
            canvas.Cursor = arrow_cursor

        wx.EVT_MOUSE_CAPTURE_LOST(canvas, on_mouse_lost)

        def on_mouse_move(event):
            if dragging[0]:
                angle[0] = get_angle(event) - initial_angle[0]
                imshow()
                canvas.Refresh(eraseBackground=False)

        wx.EVT_MOTION(canvas, on_mouse_move)
        #
        # Put the OK and Cancel buttons on the bottom
        #
        btnsizer = wx.StdDialogButtonSizer()

        btn = wx.Button(dialog, wx.ID_OK)
        btn.SetDefault()
        btnsizer.AddButton(btn)

        btn = wx.Button(dialog, wx.ID_CANCEL)
        btnsizer.AddButton(btn)
        btnsizer.Realize()

        sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5)
        dialog.Fit()
        result = dialog.ShowModal()
        dialog.Destroy()
        if result == wx.ID_OK:
            return angle[0]
        raise ValueError("Canceled by user in FlipAndRotate")