def mouse_down(self, e):
     l, t, r, b = self.viewed_rect()
     x, y = e.position
     red = float(x - l) / float(r - l)
     green = float(r - x) / float(r - l)
     blue = float(y - b) / float(t - b)
     self.model.set_color(rgb(red, green, blue))
Beispiel #2
0
 def mouse_down(self, e):
     l, t, r, b = self.viewed_rect()
     x, y = e.position
     red = float(x - l) / float(r - l)
     green = float(r - x) / float(r - l)
     blue = float(y - b) / float(t - b)
     self.model.set_color(rgb(red, green, blue))
Beispiel #3
0
class TestDoc(Document):

    color = rgb(0.5, 0.5, 0.5)

    def set_color(self, c):
        self.color = c
        self.changed()
        self.notify_views()
Beispiel #4
0
 def draw(self, c, r):
     #print "Draw" ###
     c.forecolor = rgb(0.5, 0.75, 1.0)
     c.fill_rect(self.viewed_rect())
     c.forecolor = black
     pm = self.pixmap
     sr = pm.bounds
     for i in range(3):
         dr = offset_rect(sr, (10 + i * 50, 10 + i * 60))
         pm.draw(c, sr, dr)
 def draw(self, c, r):
     #print "Draw" ###
     c.forecolor = rgb(0.5, 0.75, 1.0)
     c.fill_rect(self.viewed_rect())
     c.forecolor = black
     pm = self.pixmap
     sr = pm.bounds
     for i in range(3):
         dr = offset_rect(sr, (10 + i * 50, 10 + i * 60))
         pm.draw(c, sr, dr)
from GUI import Window, View, application, rgb
from GUI.Geometry import offset_rect, rect_sized
from GUI.StdColors import yellow
from GUI.PIL import image_from_pil_image
import Image
from testing import say

from GUI import PIL
PIL.debug_pil = True

skyblue = rgb(102/255.0, 204/255.0, 1.0)

class ImageTestView(View):

    def draw(self, c, r):
        c.backcolor = skyblue
        c.erase_rect(r)
        main_image_pos = (50, 50)
        src_rect = image.bounds
        #say("Image bounds =", src_rect)
        dst_rect = offset_rect(src_rect, main_image_pos)
        #say("Drawing", src_rect, "in", dst_rect)
        image.draw(c, src_rect, dst_rect)

import os, sys
here = sys.path[0]
image_path = os.path.join(here, "pill.png")
pil_image = Image.open(image_path)
print "PIL Image: size =", pil_image.size, "mode =", pil_image.mode
image = image_from_pil_image(pil_image)
def report():
  say("Check box set to", box.on)
 
def change_auto_toggle():
    box.auto_toggle = auto.on
    say("Auto toggling =", box.auto_toggle)

box = CheckBox(
    x = 20, y = 20,
    title = "Check Box", action = report)

auto = CheckBox(x = 20, y = box.bottom + 10,
    title = "Auto Toggle",
    action = change_auto_toggle,
    color = rgb(1, 0, 0),
    on = 1)

def update_allow_mixed():
    state = allow_mixed.on
    box.mixed = state
    mixed.enabled = state

allow_mixed = CheckBox(x = 20, y = auto.bottom + 10,
    title = "Allow Mixed",
    action = update_allow_mixed)
    
def make_mixed():
    try:
        box.on = 'mixed'
    except ValueError:
Beispiel #8
0
class GridView(ScrollableView):
    """A ScrollableView consisting of a grid of equal-sized cells."""

    num_columns = overridable_property('num_columns',
                                       "Width of the view in columns")

    num_rows = overridable_property('num_rows', "Height of the view in rows")

    cell_size = overridable_property('cell_size', "Size of each cell")

    backcolor = overridable_property('backcolor', "Background fill colour")

    _cell_size = (32, 32)
    _num_rows = 0
    _num_columns = 0
    _backcolor = rgb(1, 1, 1, 1)

    def __init__(self, num_rows, num_columns, cell_size, **kwds):
        ScrollableView.__init__(self)
        self._num_rows = num_rows
        self._num_columns = num_columns
        self._cell_size = cell_size
        self._update_extent()
        self.set(**kwds)

    def get_cell_size(self):
        return self._cell_size

    def set_cell_size(self, x):
        self._cell_size = x
        self._update_extent()

    def get_num_rows(self):
        return self._num_rows

    def set_num_rows(self, x):
        self._num_rows = x
        self._update_extent()

    def get_num_columns(self):
        return self._num_columns

    def set_num_columns(self, x):
        self._num_columns = x
        self._update_extent()

    def _update_extent(self):
        cw, ch = self._cell_size
        nr = self._num_rows
        nc = self._num_columns
        self.extent = (cw * nc, ch * nr)

    def cell_rect(self, row, col):
        w, h = self._cell_size
        l = col * w
        t = row * h
        return (l, t, l + w, t + h)

    def get_backcolor(self):
        return self._backcolor

    def set_backcolor(self, x):
        self._backcolor = x

    def cell_containing_point(self, p):
        x, y = p
        cw, ch = self.cell_size
        return (int(y // ch), int(x // cw))

    def draw(self, canvas, update_rect):
        canvas.backcolor = self.backcolor
        canvas.erase_rect(update_rect)
        ul, ut, ur, ub = update_rect
        nr = self._num_rows
        nc = self._num_columns
        cw, ch = self.cell_size
        row0 = max(0, int(ut // ch))
        row1 = min(nr, int(ub // ch) + 1)
        col0 = max(0, int(ul // cw))
        col1 = min(nc, int(ur // cw) + 1)
        row_range = xrange(row0, row1)
        col_range = xrange(col0, col1)
        for row in row_range:
            for col in col_range:
                rect = self.cell_rect(row, col)
                self.draw_cell(canvas, row, col, rect)

    def draw_cell(self, canvas, row, col, rect):
        """Should draw the cell at the given row and colum inside the given rect."""
        pass

    def mouse_down(self, event):
        row, col = self.cell_containing_point(event.position)
        nr = self._num_rows
        nc = self._num_columns
        if 0 <= row < nr and 0 <= col < nc:
            self.click_cell(row, col, event)

    def click_cell(self, row, col, event):
        """Called when a mouse_down event has occured in the indicated cell."""
        pass
Beispiel #9
0
def report():
    say("Check box set to", box.on)


def change_auto_toggle():
    box.auto_toggle = auto.on
    say("Auto toggling =", box.auto_toggle)


box = CheckBox(x=20, y=20, title="Check Box", action=report)

auto = CheckBox(x=20,
                y=box.bottom + 10,
                title="Auto Toggle",
                action=change_auto_toggle,
                color=rgb(1, 0, 0),
                on=1)


def update_allow_mixed():
    state = allow_mixed.on
    box.mixed = state
    mixed.enabled = state


allow_mixed = CheckBox(x=20,
                       y=auto.bottom + 10,
                       title="Allow Mixed",
                       action=update_allow_mixed)

Beispiel #10
0
from GUI import Window, View, application, rgb
from GUI.Geometry import offset_rect, rect_sized
from GUI.StdColors import yellow
from GUI.PIL import image_from_pil_image
import Image
from testing import say

from GUI import PIL
PIL.debug_pil = True

skyblue = rgb(102 / 255.0, 204 / 255.0, 1.0)


class ImageTestView(View):
    def draw(self, c, r):
        c.backcolor = skyblue
        c.erase_rect(r)
        main_image_pos = (50, 50)
        src_rect = image.bounds
        #say("Image bounds =", src_rect)
        dst_rect = offset_rect(src_rect, main_image_pos)
        #say("Drawing", src_rect, "in", dst_rect)
        image.draw(c, src_rect, dst_rect)


import os, sys
here = sys.path[0]
image_path = os.path.join(here, "pill.png")
pil_image = Image.open(image_path)
print "PIL Image: size =", pil_image.size, "mode =", pil_image.mode
image = image_from_pil_image(pil_image)
Beispiel #11
0
from __future__ import division
from math import sin, pi
from numpy import zeros, uint8
from GUI import Window, View, application, rgb
from GUI.StdColors import yellow
from GUI.Numerical import image_from_ndarray
from GUI.Geometry import offset_rect
from testing import say

background = rgb(0.25, 0.25, 0.25)

width = 300
height = 100


def plot(a, f, c):
    h = height // 2
    A = h - 1
    for x in xrange(width):
        y = h + int(round(A * sin(2 * pi * f * x / width)))
        a[y, x] = c


def make_array():
    a = zeros((height, width, 4), uint8)
    plot(a, 1, (255, 0, 0, 255))
    plot(a, 2, (255, 255, 0, 255))
    plot(a, 3, (0, 255, 0, 255))
    return a

from __future__ import division
from math import sin, pi
from numpy import zeros, uint8
from GUI import Window, View, application, rgb
from GUI.StdColors import yellow
from GUI.Numerical import image_from_ndarray
from GUI.Geometry import offset_rect
from testing import say

background = rgb(0.25, 0.25, 0.25)

width = 300
height = 100

def plot(a, f, c):
    h = height // 2
    A = h - 1
    for x in xrange(width):
        y = h + int(round(A * sin(2 * pi * f * x / width)))
        a[y, x] = c

def make_array():
    a = zeros((height, width, 4), uint8)
    plot(a, 1, (255, 0, 0, 255))
    plot(a, 2, (255, 255, 0, 255))
    plot(a, 3, (0, 255, 0, 255))
    return a

the_array = make_array()
the_image = image_from_ndarray(the_array, 'RGBA')