diff options
Diffstat (limited to 'lvc')
-rw-r--r-- | lvc/widgets/osx/simple.py | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/lvc/widgets/osx/simple.py b/lvc/widgets/osx/simple.py index 37407a1..fccd56e 100644 --- a/lvc/widgets/osx/simple.py +++ b/lvc/widgets/osx/simple.py @@ -43,8 +43,10 @@ import wrappermap """A collection of various simple widgets.""" + class Image(object): - """See https://develop.participatoryculture.org/index.php/WidgetAPI for a description of the API for this class.""" + """See https://develop.participatoryculture.org/index.php/WidgetAPI + for a description of the API for this class.""" def __init__(self, path): self._set_image(NSImage.alloc().initByReferencingFile_( filename_to_unicode(path))) @@ -54,17 +56,18 @@ class Image(object): self.width = self.nsimage.size().width self.height = self.nsimage.size().height if self.width * self.height == 0: - raise ValueError('Image has invalid size: (%d, %d)' % ( - self.width, self.height)) + raise ValueError('Image has invalid size: (%d, %d)' % + (self.width, self.height)) def resize(self, width, height): return ResizedImage(self, width, height) - def crop_and_scale(self, src_x, src_y, src_width, src_height, dest_width, - dest_height): + def crop_and_scale(self, src_x, src_y, + src_width, src_height, + dest_width, dest_height): if dest_width <= 0 or dest_height <= 0: - logging.stacktrace("invalid dest sizes: %s %s" % (dest_width, - dest_height)) + logging.stacktrace("invalid dest sizes: %s %s" % + (dest_width, dest_height)) return TransformedImage(self.nsimage) source_rect = NSMakeRect(src_x, src_y, src_width, src_height) @@ -74,9 +77,8 @@ class Image(object): dest.lockFocus() try: NSGraphicsContext.currentContext().setImageInterpolation_( - NSImageInterpolationHigh) - self.nsimage.drawInRect_fromRect_operation_fraction_(dest_rect, - source_rect, NSCompositeCopy, 1.0) + NSImageInterpolationHigh) + self.nsimage.drawInRect_fromRect_operation_fraction_(dest_rect, source_rect, NSCompositeCopy, 1.0) finally: dest.unlockFocus() return TransformedImage(dest) @@ -98,6 +100,7 @@ class Image(object): ratio = min(width / self.width, height / self.height) return self.resize(ratio * self.width, ratio * self.height) + class ResizedImage(Image): def __init__(self, image, width, height): nsimage = image.nsimage.copy() @@ -106,10 +109,12 @@ class ResizedImage(Image): nsimage.setSize_(NSSize(width, height)) self._set_image(nsimage) + class TransformedImage(Image): def __init__(self, nsimage): self._set_image(nsimage) + class NSImageDisplay(NSView): def init(self): self = super(NSImageDisplay, self).init() @@ -156,17 +161,19 @@ class NSImageDisplay(NSView): y_scale = float(self.image.height) / view_size.height return NSMakeRect(dest_rect.origin.x * x_scale, - dest_rect.origin.y * y_scale, - dest_rect.size.width * x_scale, - dest_rect.size.height * y_scale) + dest_rect.origin.y * y_scale, + dest_rect.size.width * x_scale, + dest_rect.size.height * y_scale) # XXX FIXME: should track mouse movement - mouseDown is not the correct # event. def mouseDown_(self, event): wrappermap.wrapper(self).emit('clicked') + class ImageDisplay(Widget): - """See https://develop.participatoryculture.org/index.php/WidgetAPI for a description of the API for this class.""" + """See https://develop.participatoryculture.org/index.php/WidgetAPI + for a description of the API for this class.""" def __init__(self, image=None): Widget.__init__(self) self.create_signal('clicked') @@ -189,6 +196,7 @@ class ImageDisplay(Widget): else: return 0, 0 + class ClickableImageButton(ImageDisplay): def __init__(self, image_path, max_width=None, max_height=None): ImageDisplay.__init__(self) @@ -212,15 +220,17 @@ class ClickableImageButton(ImageDisplay): else: return ImageDisplay.calc_size_request(self) + class MiroImageView(NSImageView): def viewWillMoveToWindow_(self, aWindow): self.setAnimates_(not aWindow == nil) + class AnimatedImageDisplay(Widget): def __init__(self, path): Widget.__init__(self) self.nsimage = NSImage.alloc().initByReferencingFile_( - filename_to_unicode(path)) + filename_to_unicode(path)) self.view = MiroImageView.alloc().init() self.view.setImage_(self.nsimage) # enabled when viewWillMoveToWindow:aWindow invoked @@ -229,8 +239,10 @@ class AnimatedImageDisplay(Widget): def calc_size_request(self): return self.nsimage.size().width, self.nsimage.size().height + class Label(Widget): - """See https://develop.participatoryculture.org/index.php/WidgetAPI for a description of the API for this class.""" + """See https://develop.participatoryculture.org/index.php/WidgetAPI + for a description of the API for this class.""" def __init__(self, text="", wrap=False, color=None): Widget.__init__(self) self.view = NSTextField.alloc().init() @@ -283,7 +295,7 @@ class Label(Widget): if self.bold: font = NSFont.boldSystemFontOfSize_(self.size) else: - font= NSFont.systemFontOfSize_(self.size) + font = NSFont.systemFontOfSize_(self.size) self.view.setFont_(font) self.sizer_cell.setFont_(font) self.invalidate_size_request() @@ -292,8 +304,8 @@ class Label(Widget): if (self.wrap and self.manual_size_request is not None and self.manual_size_request[0] > 0): wrap_width = self.manual_size_request[0] - size = self.sizer_cell.cellSizeForBounds_(NSMakeRect(0, 0, - wrap_width, 10000)) + size = self.sizer_cell.cellSizeForBounds_(NSMakeRect + (0, 0, wrap_width, 10000)) else: size = self.sizer_cell.cellSize() return math.ceil(size.width), math.ceil(size.height) @@ -335,8 +347,9 @@ class Label(Widget): self.view.setTextColor_(self.__color.colorWithAlphaComponent_(0.5)) self.view.setEnabled_(False) + class SolidBackground(SimpleBin): - def __init__(self, color=None): + def __init__(self, color=None): SimpleBin.__init__(self) self.view = FlippedView.alloc().init() if color is not None: @@ -345,6 +358,7 @@ class SolidBackground(SimpleBin): def set_background_color(self, color): self.view.setBackgroundColor_(self.make_color(color)) + class ProgressBar(Widget): def __init__(self): Widget.__init__(self) @@ -366,6 +380,7 @@ class ProgressBar(Widget): def stop_pulsing(self): self.view.stopAnimation_(nil) + class HLine(Widget): def __init__(self): Widget.__init__(self) |