Пример #1
0
    def _CreateCanvas(self, parent):
        self._canvas = ogl.ShapeCanvas(parent)
        wx.EVT_LEFT_DOWN(self._canvas, self.OnLeftClick)
        wx.EVT_LEFT_UP(self._canvas, self.OnLeftUp)
        wx.EVT_MOTION(self._canvas, self.OnLeftDrag)
        wx.EVT_LEFT_DCLICK(self._canvas, self.OnLeftDoubleClick)
        wx.EVT_KEY_DOWN(self._canvas, self.OnKeyPressed)

        # need this otherwise mouse clicks don't set focus to this view
        wx.EVT_LEFT_DOWN(self._canvas, self.FocusOnClick)
        wx.EVT_LEFT_DCLICK(self._canvas, self.FocusOnClick)
        wx.EVT_RIGHT_DOWN(self._canvas, self.FocusOnClick)
        wx.EVT_RIGHT_DCLICK(self._canvas, self.FocusOnClick)
        wx.EVT_MIDDLE_DOWN(self._canvas, self.FocusOnClick)
        wx.EVT_MIDDLE_DCLICK(self._canvas, self.FocusOnClick)

        wx.EVT_KILL_FOCUS(self._canvas, self.OnKillFocus)
        wx.EVT_SET_FOCUS(self._canvas, self.OnFocus)

        self._canvas.SetScrollbars(20, 20, self._maxWidth / 20,
                                   self._maxHeight / 20)

        self._canvas.SetBackgroundColour(self._backgroundColor)
        self._diagram = ogl.Diagram()
        self._canvas.SetDiagram(self._diagram)
        self._diagram.SetCanvas(self._canvas)
        self._canvas.SetFont(NORMALFONT)
Пример #2
0
    def OnCreate(self, doc, flags):
        if len(doc.GetFilename()) == 0:
            wx.MessageBox(_("Cannot create a new image file.\n%s has no paint capability.") % wx.GetApp().GetAppName(),
                                _("New Image File"),
                                wx.OK | wx.ICON_EXCLAMATION)
            return False
            
        try:
            self._bitmap = wx.Image(doc.GetFilename()).ConvertToBitmap()
        except:
            wx.MessageBox(_("Error loading '%s'. %s") % (doc.GetPrintableName(), sys.exc_value),
                                _("Open Image File"),
                                wx.OK | wx.ICON_EXCLAMATION)
            return False

        frame = wx.GetApp().CreateDocumentFrame(self, doc, flags)
        panel = wx.Panel(frame, -1)            
        self._ctrl = wx.StaticBitmap(panel, -1, self._bitmap, (0,0), (self._bitmap.GetWidth(), self._bitmap.GetHeight()))
        wx.EVT_LEFT_DOWN(self._ctrl, self.OnFocus)
        wx.EVT_LEFT_DCLICK(self._ctrl, self.OnFocus)
        wx.EVT_RIGHT_DOWN(self._ctrl, self.OnFocus)
        wx.EVT_RIGHT_DCLICK(self._ctrl, self.OnFocus)
        wx.EVT_MIDDLE_DOWN(self._ctrl, self.OnFocus)
        wx.EVT_MIDDLE_DCLICK(self._ctrl, self.OnFocus)
        panel.SetClientSize(self._bitmap.GetSize())
        frame.SetClientSize(panel.GetSize())
        self.Activate()
        return True
Пример #3
0
	def __init__(self, parent):
		attribList = (glcanvas.WX_GL_RGBA, glcanvas.WX_GL_DOUBLEBUFFER, glcanvas.WX_GL_DEPTH_SIZE, 24, glcanvas.WX_GL_STENCIL_SIZE, 8, 0)
		glcanvas.GLCanvas.__init__(self, parent, style=wx.WANTS_CHARS, attribList = attribList)
		self._base = self
		self._focus = None
		self._container = None
		self._container = glGuiContainer(self, (0,0))
		self._shownError = False

		self._context = glcanvas.GLContext(self)
		self._glButtonsTexture = None
		self._glRobotTexture = None
		self._buttonSize = 64

		self._animationList = []
		self.glReleaseList = []
		self._refreshQueued = False
		self._idleCalled = False

		wx.EVT_PAINT(self, self._OnGuiPaint)
		wx.EVT_SIZE(self, self._OnSize)
		wx.EVT_ERASE_BACKGROUND(self, self._OnEraseBackground)
		wx.EVT_LEFT_DOWN(self, self._OnGuiMouseDown)
		wx.EVT_LEFT_DCLICK(self, self._OnGuiMouseDown)
		wx.EVT_LEFT_UP(self, self._OnGuiMouseUp)
		wx.EVT_RIGHT_DOWN(self, self._OnGuiMouseDown)
		wx.EVT_RIGHT_DCLICK(self, self._OnGuiMouseDown)
		wx.EVT_RIGHT_UP(self, self._OnGuiMouseUp)
		wx.EVT_MIDDLE_DOWN(self, self._OnGuiMouseDown)
		wx.EVT_MIDDLE_DCLICK(self, self._OnGuiMouseDown)
		wx.EVT_MIDDLE_UP(self, self._OnGuiMouseUp)
		wx.EVT_MOTION(self, self._OnGuiMouseMotion)
		wx.EVT_CHAR(self, self._OnGuiKeyChar)
		wx.EVT_KILL_FOCUS(self, self.OnFocusLost)
		wx.EVT_IDLE(self, self._OnIdle)
Пример #4
0
 def _on_close(self, event):
     # Might be scrollbars or other native components under
     # us that are generating this event
     if event.GetWindow() == self.control:
         self._gc = None
         wx.EVT_ERASE_BACKGROUND(self.control, None)
         wx.EVT_PAINT(self.control, None)
         wx.EVT_SIZE(self.control, None)
         wx.EVT_LEFT_DOWN(self.control, None)
         wx.EVT_LEFT_UP(self.control, None)
         wx.EVT_LEFT_DCLICK(self.control, None)
         wx.EVT_MIDDLE_DOWN(self.control, None)
         wx.EVT_MIDDLE_UP(self.control, None)
         wx.EVT_MIDDLE_DCLICK(self.control, None)
         wx.EVT_RIGHT_DOWN(self.control, None)
         wx.EVT_RIGHT_UP(self.control, None)
         wx.EVT_RIGHT_DCLICK(self.control, None)
         wx.EVT_MOTION(self.control, None)
         wx.EVT_ENTER_WINDOW(self.control, None)
         wx.EVT_LEAVE_WINDOW(self.control, None)
         wx.EVT_MOUSEWHEEL(self.control, None)
         wx.EVT_KEY_DOWN(self.control, None)
         wx.EVT_KEY_UP(self.control, None)
         wx.EVT_CHAR(self.control, None)
         wx.EVT_WINDOW_DESTROY(self.control, None)
         self.control.SetDropTarget(None)
         self.control = None
         self.component.cleanup(self)
         self.component.parent = None
         self.component.window = None
         self.component = None
     return
Пример #5
0
    def __init__(self, *args, **kwargs):
        # make sure the NO_FULL_REPAINT_ON_RESIZE style flag is set.
        kwargs['style'] = kwargs.setdefault(
            'style',
            wx.NO_FULL_REPAINT_ON_RESIZE) | wx.NO_FULL_REPAINT_ON_RESIZE
        wx.Window.__init__(self, *args, **kwargs)

        wx.EVT_PAINT(self, self.OnPaint)
        wx.EVT_SIZE(self, self.OnSize)
        wx.EVT_RIGHT_DCLICK(self, self.OnRightDclick)

        # OnSize called to make sure the buffer is initialized.
        # This might result in OnSize getting called twice on some
        # platforms at initialization, but little harm done.
        self.OnSize(None)
        self.paint_count = 0
        self.x_off = 0
        self.y_off = 0
Пример #6
0
    def __init__(self, parent):
        attrib_list = (glcanvas.WX_GL_RGBA, glcanvas.WX_GL_DOUBLEBUFFER,
                       glcanvas.WX_GL_DEPTH_SIZE, 24,
                       glcanvas.WX_GL_STENCIL_SIZE, 8, 0)
        glcanvas.GLCanvas.__init__(self,
                                   parent,
                                   style=wx.WANTS_CHARS,
                                   attribList=attrib_list)
        self._base = self
        self._focus = None
        self._container = None
        self._container = glGuiContainer(self, (0, 0))
        self._shown_error = False

        self._context = glcanvas.GLContext(self)
        self._button_size = 64

        self._animation_list = []
        self.gl_release_list = []
        self._refresh_queued = False
        self._idle_called = False

        wx.EVT_PAINT(self, self._on_gui_paint)
        wx.EVT_SIZE(self, self._on_size)
        wx.EVT_ERASE_BACKGROUND(self, self._on_erase_background)
        wx.EVT_LEFT_DOWN(self, self._on_gui_mouse_down)
        wx.EVT_LEFT_DCLICK(self, self._on_gui_mouse_down)
        wx.EVT_LEFT_UP(self, self._on_gui_mouse_up)
        wx.EVT_RIGHT_DOWN(self, self._on_gui_mouse_down)
        wx.EVT_RIGHT_DCLICK(self, self._on_gui_mouse_down)
        wx.EVT_RIGHT_UP(self, self._on_gui_mouse_up)
        wx.EVT_MIDDLE_DOWN(self, self._on_gui_mouse_down)
        wx.EVT_MIDDLE_DCLICK(self, self._on_gui_mouse_down)
        wx.EVT_MIDDLE_UP(self, self._on_gui_mouse_up)
        wx.EVT_MOTION(self, self._on_gui_mouse_motion)
        wx.EVT_KEY_DOWN(self, self._on_gui_key_down)
        wx.EVT_KEY_UP(self, self._on_gui_key_up)
        wx.EVT_KILL_FOCUS(self, self._on_focus_lost)
        wx.EVT_IDLE(self, self._on_idle)
Пример #7
0
    def dispose(self):
        """ Disposes of the contents of an editor.
        """
        # Remove all of the wx event handlers:
        control = self.control
        parent = control.GetParent()
        id = control.GetId()
        wx.EVT_LIST_BEGIN_DRAG(parent, id, None)
        wx.EVT_LIST_BEGIN_LABEL_EDIT(parent, id, None)
        wx.EVT_LIST_END_LABEL_EDIT(parent, id, None)
        wx.EVT_LIST_ITEM_SELECTED(parent, id, None)
        wx.EVT_LIST_ITEM_DESELECTED(parent, id, None)
        wx.EVT_LIST_KEY_DOWN(parent, id, None)
        wx.EVT_LIST_ITEM_ACTIVATED(parent, id, None)
        wx.EVT_LIST_COL_END_DRAG(parent, id, None)
        wx.EVT_LIST_COL_RIGHT_CLICK(parent, id, None)
        wx.EVT_LIST_COL_CLICK(parent, id, None)
        wx.EVT_LEFT_DOWN(control, None)
        wx.EVT_LEFT_DCLICK(control, None)
        wx.EVT_RIGHT_DOWN(control, None)
        wx.EVT_RIGHT_DCLICK(control, None)
        wx.EVT_MOTION(control, None)
        wx.EVT_SIZE(control, None)

        self.context_object.on_trait_change(
            self.update_editor,
            self.extended_name + '_items',
            remove=True)

        if self.factory.auto_update:
            self.context_object.on_trait_change(
                self.refresh_editor, self.extended_name + '.-', remove=True)

        self.on_trait_change(self._refresh, 'adapter.+update', remove=True)
        self.on_trait_change(self._rebuild_all, 'adapter.columns',
                             remove=True)

        super(TabularEditor, self).dispose()
Пример #8
0
    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        factory = self.factory

        # Set up the adapter to use:
        self.adapter = factory.adapter

        # Determine the style to use for the list control:
        style = wx.LC_REPORT | wx.LC_VIRTUAL | wx.BORDER_NONE

        if factory.editable_labels:
            style |= wx.LC_EDIT_LABELS

        if factory.horizontal_lines:
            style |= wx.LC_HRULES

        if factory.vertical_lines:
            style |= wx.LC_VRULES

        if not factory.multi_select:
            style |= wx.LC_SINGLE_SEL

        if not factory.show_titles:
            style |= wx.LC_NO_HEADER

        # Create the list control and link it back to us:
        self.control = control = wxListCtrl(
            parent,
            -1,
            style=style,
            can_edit=factory.editable,
            edit_labels=factory.editable_labels)
        control._editor = self

        # Create the list control column:
        #fixme: what do we do here?
        #control.InsertColumn( 0, '' )

        # Set up the list control's event handlers:
        id = control.GetId()
        wx.EVT_LIST_BEGIN_DRAG(parent, id, self._begin_drag)
        wx.EVT_LIST_BEGIN_LABEL_EDIT(parent, id, self._begin_label_edit)
        wx.EVT_LIST_END_LABEL_EDIT(parent, id, self._end_label_edit)
        wx.EVT_LIST_ITEM_SELECTED(parent, id, self._item_selected)
        wx.EVT_LIST_ITEM_DESELECTED(parent, id, self._item_selected)
        wx.EVT_LIST_KEY_DOWN(parent, id, self._key_down)
        wx.EVT_LIST_ITEM_ACTIVATED(parent, id, self._item_activated)
        wx.EVT_LIST_COL_END_DRAG(parent, id, self._size_modified)
        wx.EVT_LIST_COL_RIGHT_CLICK(parent, id, self._column_right_clicked)
        wx.EVT_LIST_COL_CLICK(parent, id, self._column_clicked)
        wx.EVT_LEFT_DOWN(control, self._left_down)
        wx.EVT_LEFT_DCLICK(control, self._left_dclick)
        wx.EVT_RIGHT_DOWN(control, self._right_down)
        wx.EVT_RIGHT_DCLICK(control, self._right_dclick)
        wx.EVT_MOTION(control, self._motion)
        wx.EVT_SIZE(control, self._size_modified)

        # Set up the drag and drop target:
        if PythonDropTarget is not None:
            control.SetDropTarget(PythonDropTarget(self))

        # Set up the selection listener (if necessary):
        if factory.multi_select:
            self.sync_value(factory.selected,
                            'multi_selected',
                            'both',
                            is_list=True)
            self.sync_value(factory.selected_row,
                            'multi_selected_rows',
                            'both',
                            is_list=True)
        else:
            self.sync_value(factory.selected, 'selected', 'both')
            self.sync_value(factory.selected_row, 'selected_row', 'both')

        # Synchronize other interesting traits as necessary:
        self.sync_value(factory.update, 'update', 'from')

        self.sync_value(factory.activated, 'activated', 'to')
        self.sync_value(factory.activated_row, 'activated_row', 'to')

        self.sync_value(factory.clicked, 'clicked', 'to')
        self.sync_value(factory.dclicked, 'dclicked', 'to')

        self.sync_value(factory.right_clicked, 'right_clicked', 'to')
        self.sync_value(factory.right_dclicked, 'right_dclicked', 'to')

        self.sync_value(factory.column_clicked, 'column_clicked', 'to')

        # Make sure we listen for 'items' changes as well as complete list
        # replacements:
        try:
            self.context_object.on_trait_change(self.update_editor,
                                                self.extended_name + '_items',
                                                dispatch='ui')
        except:
            pass

        # If the user has requested automatic update, attempt to set up the
        # appropriate listeners:
        if factory.auto_update:
            self.context_object.on_trait_change(self.refresh_editor,
                                                self.extended_name + '.-',
                                                dispatch='ui')

        # Create the mapping from user supplied images to wx.ImageList indices:
        for image_resource in factory.images:
            self._add_image(image_resource)

        # Refresh the editor whenever the adapter changes:
        self.on_trait_change(self._refresh, 'adapter.+update', dispatch='ui')

        # Rebuild the editor columns and headers whenever the adapter's
        # 'columns' changes:
        self.on_trait_change(self._rebuild_all,
                             'adapter.columns',
                             dispatch='ui')

        # Make sure the tabular view gets initialized:
        self._rebuild()

        # Set the list control's tooltip:
        self.set_tooltip()
Пример #9
0
    def __init__(self,
                 parent,
                 wid=-1,
                 pos=wx.DefaultPosition,
                 size=wx.DefaultSize,
                 **traits):
        AbstractWindow.__init__(self, **traits)
        self._timer = None
        self._mouse_captured = False

        # Due to wx wonkiness, we don't reliably get cursor position from
        # a wx KeyEvent.  Thus, we manually keep track of when we last saw
        # the mouse and use that information instead.  These coordinates are
        # in the wx coordinate space, i.e. pre-self._flip_y().
        self._last_mouse_pos = (0, 0)

        # Create the delegate:
        self.control = control = self._create_control(parent, wid, pos, size)

        # Set up the 'erase background' event handler:
        wx.EVT_ERASE_BACKGROUND(control, self._on_erase_background)

        # Set up the 'paint' event handler:
        wx.EVT_PAINT(control, self._paint)
        wx.EVT_SIZE(control, self._on_size)

        # Set up mouse event handlers:
        wx.EVT_LEFT_DOWN(control, self._on_left_down)
        wx.EVT_LEFT_UP(control, self._on_left_up)
        wx.EVT_LEFT_DCLICK(control, self._on_left_dclick)
        wx.EVT_MIDDLE_DOWN(control, self._on_middle_down)
        wx.EVT_MIDDLE_UP(control, self._on_middle_up)
        wx.EVT_MIDDLE_DCLICK(control, self._on_middle_dclick)
        wx.EVT_RIGHT_DOWN(control, self._on_right_down)
        wx.EVT_RIGHT_UP(control, self._on_right_up)
        wx.EVT_RIGHT_DCLICK(control, self._on_right_dclick)
        wx.EVT_MOTION(control, self._on_mouse_move)
        wx.EVT_ENTER_WINDOW(control, self._on_window_enter)
        wx.EVT_LEAVE_WINDOW(control, self._on_window_leave)
        wx.EVT_MOUSEWHEEL(control, self._on_mouse_wheel)

        # Handle key up/down events:
        wx.EVT_KEY_DOWN(control, self._on_key_pressed)
        wx.EVT_KEY_UP(control, self._on_key_released)
        wx.EVT_CHAR(control, self._on_character)

        # Attempt to allow wxPython drag and drop events to be mapped to
        # Enable drag events:

        # Handle window close and cleanup
        wx.EVT_WINDOW_DESTROY(control, self._on_close)

        if PythonDropTarget is not None:
            control.SetDropTarget(LessSuckyDropTarget(self))
            self._drag_over = []

        # In some cases, on the Mac at least, we never get an initial EVT_SIZE
        # since the initial size is correct. Because of this we call _on_size
        # here to initialize our bounds.
        self._on_size(None)

        return