class CustomSliderView(NSSlider): def init(self): self = super(CustomSliderView, self).init() self.layout_manager = LayoutManager() return self def isOpaque(self): return wrappermap.wrapper(self).is_opaque() def knobThickness(self): return wrappermap.wrapper(self).slider_size() def isVertical(self): return not wrappermap.wrapper(self).is_horizontal() def drawRect_(self, rect): context = drawing.DrawingContext(self, self.bounds(), rect) context.style = drawing.DrawingStyle() wrappermap.wrapper(self).draw(context, self.layout_manager) self.layout_manager.reset() def sendAction_to_(self, action, to): # We override the Cocoa machinery here and just send it to our wrapper # widget. wrappermap.wrapper(self).emit('changed', self.floatValue()) return YES
def init(self): self = super(DrawableButton, self).init() self.layout_manager = LayoutManager() self.tracking_area = None self.mouse_inside = False self.custom_cursor = None return self
class CustomTableCell(NSCell): def init(self): self = super(CustomTableCell, self).init() self.layout_manager = LayoutManager() self.hotspot = None self.default_drawing_style = DrawingStyle() return self def highlightColorWithFrame_inView_(self, frame, view): return nil def calcHeight_(self, view): self.layout_manager.reset() self.set_wrapper_data() cell_size = self.wrapper.get_size(self.default_drawing_style, self.layout_manager) return cell_size[1] def make_drawing_style(self, frame, view): text_color = None if (self.isHighlighted() and frame is not None and (view.isDescendantOf_(view.window().firstResponder()) or view.gradientHighlight)): text_color = NSColor.whiteColor() return DrawingStyle(text_color=text_color) def drawInteriorWithFrame_inView_(self, frame, view): NSGraphicsContext.currentContext().saveGraphicsState() if self.wrapper.outline_column: pad_left = EXPANDER_PADDING else: pad_left = 0 drawing_rect = NSMakeRect(frame.origin.x + pad_left, frame.origin.y, frame.size.width - pad_left, frame.size.height) context = DrawingContext(view, drawing_rect, drawing_rect) context.style = self.make_drawing_style(frame, view) self.layout_manager.reset() self.set_wrapper_data() self.wrapper.render(context, self.layout_manager, self.isHighlighted(), self.hotspot, view.cell_is_hovered(self.row, self.column)) NSGraphicsContext.currentContext().restoreGraphicsState() def setObjectValue_(self, value_dict): self.value_dict = value_dict def set_wrapper_data(self): self.wrapper.__dict__.update(self.value_dict)
class CustomSliderView(NSSlider): def init(self): self = super(CustomSliderView, self).init() self.layout_manager = LayoutManager() self.custom_cursor = None return self def resetCursorRects(self): if self.custom_cursor is not None: self.addCursorRect_cursor_(self.visibleRect(), self.custom_cursor) self.custom_cursor.setOnMouseEntered_(YES) def isOpaque(self): return wrappermap.wrapper(self).is_opaque() def knobThickness(self): return wrappermap.wrapper(self).slider_size() def isVertical(self): return not wrappermap.wrapper(self).is_horizontal() def drawRect_(self, rect): context = drawing.DrawingContext(self, self.bounds(), rect) context.style = drawing.DrawingStyle() wrappermap.wrapper(self).draw(context, self.layout_manager) self.layout_manager.reset() def sendAction_to_(self, action, to): # We override the Cocoa machinery here and just send it to our wrapper # widget. wrapper = wrappermap.wrapper(self) disabled = wrapper.get_disabled() if not disabled: wrapper.emit('changed', self.floatValue()) # Total Cocoa we handled it anyway to prevent the event passed to # upper layer. return YES
def init(self): self = super(CustomSliderView, self).init() self.layout_manager = LayoutManager() self.custom_cursor = None return self
class DrawableButton(NSButton): def init(self): self = super(DrawableButton, self).init() self.layout_manager = LayoutManager() self.tracking_area = None self.mouse_inside = False self.custom_cursor = None return self def resetCursorRects(self): if self.custom_cursor is not None: self.addCursorRect_cursor_(self.visibleRect(), self.custom_cursor) self.custom_cursor.setOnMouseEntered_(YES) def updateTrackingAreas(self): # remove existing tracking area if needed if self.tracking_area: self.removeTrackingArea_(self.tracking_area) # create a new tracking area for the entire view. This allows us to # get mouseMoved events whenever the mouse is inside our view. self.tracking_area = NSTrackingArea.alloc() self.tracking_area.initWithRect_options_owner_userInfo_( self.visibleRect(), NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveInKeyWindow, self, nil) self.addTrackingArea_(self.tracking_area) def mouseEntered_(self, event): window = self.window() if window is not nil and window.isMainWindow(): self.mouse_inside = True self.setNeedsDisplay_(YES) def mouseExited_(self, event): window = self.window() if window is not nil and window.isMainWindow(): self.mouse_inside = False self.setNeedsDisplay_(YES) def isOpaque(self): return wrappermap.wrapper(self).is_opaque() def drawRect_(self, rect): context = drawing.DrawingContext(self, self.bounds(), rect) context.style = drawing.DrawingStyle() wrapper = wrappermap.wrapper(self) wrapper.state = 'normal' disabled = wrapper.get_disabled() if not disabled: if self.state() == NSOnState: wrapper.state = 'pressed' elif self.mouse_inside: wrapper.state = 'hover' else: wrapper.state = 'normal' wrapper.draw(context, self.layout_manager) self.layout_manager.reset() def sendAction_to_(self, action, to): # We override the Cocoa machinery here and just send it to our wrapper # widget. wrapper = wrappermap.wrapper(self) disabled = wrapper.get_disabled() if not disabled: wrapper.emit('clicked') # Tell Cocoa we handled it anyway, just not emit the actual clicked # event. return YES
def init(self): self = super(DrawableButton, self).init() self.layout_manager = LayoutManager() self.tracking_rect = None self.mouse_inside = False return self
class DrawableButton(NSButton): def init(self): self = super(DrawableButton, self).init() self.layout_manager = LayoutManager() self.tracking_rect = None self.mouse_inside = False return self def remove_tracking_rect(self): if self.tracking_rect is not None: self.removeTrackingRect_(self.tracking_rect) self.tracking_rect = None def viewDidMoveToWindow(self): self.reset_tracking_rect() def setFrame_(self, rect): NSButton.setFrame_(self, rect) self.reset_tracking_rect() def setBounds_(self, rect): NSButton.setBounds_(self, rect) self.reset_tracking_rect() def reset_tracking_rect(self): self.remove_tracking_rect() if self.window() is not None: self.tracking_rect = self.addTrackingRect_owner_userData_assumeInside_( self.bounds(), self, 0, NO) def mouseEntered_(self, event): window = self.window() if window is not nil and window.isMainWindow(): self.mouse_inside = True self.setNeedsDisplay_(YES) def mouseExited_(self, event): window = self.window() if window is not nil and window.isMainWindow(): self.mouse_inside = False self.setNeedsDisplay_(YES) def isOpaque(self): return wrappermap.wrapper(self).is_opaque() def drawRect_(self, rect): context = drawing.DrawingContext(self, self.bounds(), rect) context.style = drawing.DrawingStyle() wrapper = wrappermap.wrapper(self) if self.state() == NSOnState: wrapper.state = 'pressed' elif self.mouse_inside: wrapper.state = 'hover' else: wrapper.state = 'normal' wrappermap.wrapper(self).draw(context, self.layout_manager) self.layout_manager.reset() def sendAction_to_(self, action, to): # We override the Cocoa machinery here and just send it to our wrapper # widget. wrappermap.wrapper(self).emit('clicked') return YES
def init(self): self = super(CustomSliderView, self).init() self.layout_manager = LayoutManager() return self
def init(self): self = super(DrawingView, self).init() self.layout_manager = LayoutManager() return self
def init(self): self = super(CustomTableCell, self).init() self.layout_manager = LayoutManager() self.hotspot = None self.default_drawing_style = DrawingStyle() return self
class CustomSliderView(NSSlider): def init(self): self = super(CustomSliderView, self).init() self.layout_manager = LayoutManager() self.custom_cursor = None self.mouse_tracking_info = None return self def get_slider_pos(self, value=None): return self.cell().get_slider_pos(self, value) def resetCursorRects(self): if self.custom_cursor is not None: self.addCursorRect_cursor_(self.visibleRect(), self.custom_cursor) self.custom_cursor.setOnMouseEntered_(YES) def isOpaque(self): return wrappermap.wrapper(self).is_opaque() def knobThickness(self): return wrappermap.wrapper(self).slider_size() def scrollWheel_(self, event): wrapper = wrappermap.wrapper(self) if wrapper.get_disabled(): return # NOTE: we ignore the scroll_step value passed into set_increments() # and calculate the change using deltaY, which is in device # coordinates. slider_size = wrapper.slider_size() if wrapper.is_horizontal(): size = self.bounds().size.width else: size = self.bounds().size.height size -= slider_size range = self.maxValue() - self.minValue() value_change = (event.deltaY() / size) * range self.setFloatValue_(self.floatValue() + value_change) wrapper.emit('pressed') wrapper.emit('changed', self.floatValue()) wrapper.emit('released') def isVertical(self): return not wrappermap.wrapper(self).is_horizontal() def drawRect_(self, rect): context = drawing.DrawingContext(self, self.bounds(), rect) context.style = drawing.DrawingStyle() wrappermap.wrapper(self).draw(context, self.layout_manager) self.layout_manager.reset() def sendAction_to_(self, action, to): # We override the Cocoa machinery here and just send it to our wrapper # widget. wrapper = wrappermap.wrapper(self) disabled = wrapper.get_disabled() if not disabled: wrapper.emit('changed', self.floatValue()) # Total Cocoa we handled it anyway to prevent the event passed to # upper layer. return YES