Example #1
0
 def __init__(self, default=False, x=0, y=0, id=None, **kwargs):
     """ A checkbox control that fires Flag.on_action() when checked.
         The checkbox value can be retrieved with Flag.value.
     """
     Control.__init__(self, x=x, y=y, id=id, **kwargs)
     self.default = bool(default) # Flag default value.
     self.value   = bool(default) # Flag current value.
     self.src = {
         "face" : Image(theme["flag"]),
      "checked" : Image(theme["flag-checked"]),
     }
     self._pack()
Example #2
0
 def __init__(self, default=0, limit=True, x=0, y=0, id=None, **kwargs):
     """ A twistable knob that will fire Knob.on_action() when dragged.
         The knob's angle can be retrieved with Knob.value (in degrees, 0-360).
         With CTRL pressed, twists by a very small amount.
     """
     Control.__init__(self, x=x, y=y, id=id, **kwargs)
     self.default = default # Knob default angle.
     self.value   = default # Knob current angle.
     self._limit  = limit   # Constrain between 0-360 or scroll endlessly?
     self.src = {
         "face" : Image(theme["knob"]),
       "socket" : Image(theme["knob-socket"]),
     }
     self._pack()
 def imagesize(self, path, data=None):
     if data is not None:
         from nodebox.graphics import Image
         arg = Image.fromData(data).awtImage
     else:
         arg = path
     return CanvasContext.imagesize(self, arg)
 def image(self, path, x, y, width=None, height=None, alpha=1.0, data=None, draw=True, **kwargs):
     if data is not None:
         from nodebox.graphics import Image
         arg = Image.fromData(data).awtImage
     else:
         arg = path
     img = CanvasContext.image(self, arg, x, y, width, height, alpha, Boolean(draw))
     # todo: handle data and kwargs
     return img
Example #5
0
 def __init__(self, default=0.5, min=0.0, max=1.0, steps=100, x=0, y=0, width=125, id=None, **kwargs):
     """ A draggable slider that will fire Slider.on_action() when dragged.
         The slider's value can be retrieved with Slider.value.
     """
     Control.__init__(self, x=x, y=y, width=width, id=id, **kwargs)
     self.min     = min     # Slider minimum value.
     self.max     = max     # Slider maximum value.
     self.default = default # Slider default value.
     self.value   = default # Slider current value.
     self.steps   = steps   # Number of steps from min to max.
     img, w = Image(theme["slider"]), 5
     self.src = {
         "face1" : crop(img, w, 0, 1, img.height),
         "face2" : crop(img, img.width-w, 0, 1, img.height),
          "cap1" : crop(img, 0, 0, w, img.height),
          "cap2" : crop(img, img.width-w, 0, w, img.height),
        "handle" : Image(theme["slider-handle"])
     }
     # The handle is a separate layer.
     self.append(Handle(self))
     self._pack()
Example #6
0
 def __init__(self, action=None, x=0, y=0, id=None, **kwargs):
     """ A clickable button that will fire Action.on_action() when clicked.
         Actions display an icon instead of a text caption.
         Actions are meant to be used for interface management:
         e.g. closing or minimizing a panel, navigating to the next page, ...
     """
     Control.__init__(self, x=x, y=y, id=id, **kwargs)
     self.src = {"face": Image(theme["action"])}
     self._pack()
     if action:
         # Override the Button.on_action() method from the given function.
         self.set_method(action, name="on_action")
Example #7
0
 def __init__(self, value="", hint="", action=None, x=0, y=0, width=125, padding=5, id=None, **kwargs):
     """ A single-line text input field.
         The string value can be retrieved with Field.value.
     """
     Editable.__init__(self, value, x=x, y=y, width=width, padding=(padding,0), wrap=False, id=id, **kwargs)
     img, w = Image(theme["field"]), 10
     self.src = {
         "face" : crop(img, w, 0, 1, img.height),
         "cap1" : crop(img, 0, 0, w, img.height),
         "cap2" : crop(img, img.width-w, 0, w, img.height),
     }
     if action:
         # Override the Button.on_action() method from the given function.
         self.set_method(action, name="on_action")
     self.default = value
     self.append(Label(hint, fill=Color(0, 0.4)))
     self._pack()
Example #8
0
 def __init__(self, caption="", action=None, x=0, y=0, width=125, id=None, **kwargs):
     """ A clickable button that will fire Button.on_action() when clicked.
         The action handler can be defined in a subclass, or given as a function.
     """
     Control.__init__(self, x=x, y=y, width=width, id=id, **kwargs)
     img, w = Image(theme["button"]), 20
     self.src = {
         "face" : crop(img, w, 0, 1, img.height),
         "cap1" : crop(img, 0, 0, w, img.height),
         "cap2" : crop(img, img.width-w, 0, w, img.height),
     }
     if action:
         # Override the Button.on_action() method from the given function.
         self.set_method(action, name="on_action")
     _popdefault(kwargs, "width")
     _popdefault(kwargs, "height")
     self.append(Label(caption, **kwargs))
     self._pack()
Example #9
0
 def __init__(self, caption="", fixed=False, modal=True, x=0, y=0, width=175, height=250, **kwargs):
     """ A panel containing other controls that can be dragged when Panel.fixed=False.
         Controls or (Layout groups) can be added with Panel.append().
     """
     Control.__init__(self, x=x, y=y, width=max(width,60), height=max(height,60), **kwargs)
     img, w = Image(theme["panel"]), 30
     self.src = {
        "cap1" : crop(img, 0, img.height-w, w, w),
        "cap2" : crop(img, img.width-w, img.height-w, w, w),
        "cap3" : crop(img, 0, 0, w, w),
        "cap4" : crop(img, img.width-w, 0, w, w),
         "top" : crop(img, w+1, img.height-w, 1, w),
      "bottom" : crop(img, w+1, 0, 1, w),
        "left" : crop(img, 0, w+1, w, 1),
       "right" : crop(img, img.width-w, w+1, w, 1),
        "face" : crop(img, w+1, w+1, 1, 1)
     }
     _popdefault(kwargs, "width")
     _popdefault(kwargs, "height")
     self.append(Label(caption, **kwargs))
     self.append(Close())
     self.fixed = fixed # Draggable?
     self.modal = modal # Closeable?
     self._pack()
Example #10
0
 def __init__(self, action=None, x=0, y=0, id=None, **kwargs):
     """ An action that hides the parent control (e.g. a Panel) when pressed.
     """
     Action.__init__(self, action, x=x, y=y, id=id, **kwargs)
     self.src["face"] = Image(theme["action-close"])