コード例 #1
0
    def _update(self, *largs):
        '''(internal) Check if a data is loaded, and pass to the client'''
        # want to start it ?
        if self._start_wanted:
            if not self._running:
                self.start()
            self._start_wanted = False

        while True:
            try:
                filename, data = self._q_done.pop()
            except IndexError:
                return

            # create the image
            image = data#ProxyImage(data)
            Cache.append('pymt.loader', filename, image)

            # update client
            for c_filename, client in self._client[:]:
                if filename != c_filename:
                    continue
                # got one client to update
                client.image = image
                client.loaded = True
                client.dispatch_event('on_load')
                self._client.remove((c_filename, client))
コード例 #2
0
ファイル: loader.py プロジェクト: bernt/pymt
    def _update(self, *largs):
        '''(internal) Check if a data is loaded, and pass to the client'''
        # want to start it ?
        if self._start_wanted:
            if not self._running:
                self.start()
            self._start_wanted = False

        while True:
            try:
                filename, data = self._q_done.pop()
            except:
                return

            # create the image
            image = data#ProxyImage(data)
            Cache.append('pymt.loader', filename, image)

            # update client
            for c_filename, client in self._client[:]:
                if filename != c_filename:
                    continue
                # got one client to update
                client.image = image
                client.loaded = True
                client.dispatch_event('on_load')
                self._client.remove((c_filename, client))
コード例 #3
0
    def image(self, filename, load_callback=None, post_callback=None):
        '''Load a image using loader. A Proxy image is returned
        with a loading image ::

            img = Loader.image(filename)
            # img will be a ProxyImage.
            # You'll use it the same as an Image class.
            # Later, when the image is really loaded,
            # the loader will change the img.image property
            # to the new loaded image

        '''
        data = Cache.get('pymt.loader', filename)
        if data not in (None, False):
            # found image
            return ProxyImage(data,
                    loading_image=self.loading_image,
                    loaded=True)

        client = ProxyImage(self.loading_image,
                    loading_image=self.loading_image)
        self._client.append((filename, client))

        if data is None:
            # if data is None, this is really the first time
            self._q_load.append((filename, load_callback, post_callback))
            Cache.append('pymt.loader', filename, False)
            self._start_wanted = True
        else:
            # already queued for loading
            pass

        return client
コード例 #4
0
ファイル: loader.py プロジェクト: bernt/pymt
    def image(self, filename, load_callback=None, post_callback=None):
        '''Load a image using loader. A Proxy image is returned
        with a loading image ::

            img = Loader.image(filename)
            # img will be a ProxyImage.
            # You'll use it the same as an Image class.
            # Later, when the image is really loaded,
            # the loader will change the img.image property
            # to the new loaded image

        '''
        data = Cache.get('pymt.loader', filename)
        if data not in (None, False):
            # found image
            return ProxyImage(data,
                    loading_image=self.loading_image,
                    loaded=True)

        client = ProxyImage(self.loading_image,
                    loading_image=self.loading_image)
        self._client.append((filename, client))

        if data is None:
            # if data is None, this is really the first time
            self._q_load.append((filename, load_callback, post_callback))
            Cache.append('pymt.loader', filename, False)
            self._start_wanted = True
        else:
            # already queued for loading
            pass

        return client
コード例 #5
0
ファイル: __init__.py プロジェクト: hansent/pymt
    def __init__(self, filename, **kwargs):
        self.filename = filename

        self.svg_data = Cache.get("pymt.svg", filename)
        if not self.svg_data:
            new_svg = self.load(filename)
            Cache.append("pymt.svg", filename, new_svg)
            self.svg_data = new_svg
コード例 #6
0
ファイル: __init__.py プロジェクト: triselectif/pymt
    def __init__(self, filename, **kwargs):
        self.filename = filename

        self.svg_data = Cache.get('_pymt_core_svg_cache', filename)
        if not self.svg_data:
            new_svg = self.load(filename)
            Cache.append('_pymt_core_svg_cache', filename, new_svg)
            self.svg_data = new_svg
コード例 #7
0
ファイル: __init__.py プロジェクト: gavine199/pymt
    def __init__(self, filename, **kwargs):
        self.filename = filename

        self.svg_data = Cache.get('pymt.svg', filename)
        if not self.svg_data:
            new_svg = self.load(filename)
            Cache.append('pymt.svg', filename, new_svg)
            self.svg_data = new_svg
コード例 #8
0
 def create_line_label(self, text):
     '''Create a label from a text, using line options
     '''
     ntext = text.replace('\n', '').replace('\t', ' ' * self.tab_width)
     kw = self.get_line_options()
     cid = '%s\0%s' % (ntext, str(kw))
     label = Cache.get('textarea.label', cid)
     if not label:
         label = Label(ntext, **kw)
         Cache.append('textarea.label', cid, label)
     return label
コード例 #9
0
def css_reload():
    pymt_logger.debug('CSS: Reloading CSS in progress')
    pymt_sheet.reset()
    for callback, args in _css_sources[:]:
        callback(*args, _reload=True)
    Cache.remove('pymt.css')
    for r in _css_widgets.copy():
        o = r()
        if o is None:
            _css_widgets.remove(r)
            continue
        o.reload_css()
    pymt_logger.info('CSS: CSS Reloaded')
コード例 #10
0
ファイル: draw.py プロジェクト: imc/pymt
def getLabel(label, **kwargs):
    '''Get a cached label object

    :Parameters:
        `label` : str
            Text to be draw
        `font_size` : int, default to 12
            Font size of label
        `center` : bool, default to True
            Indicate if pos is center or left-right of label

    getLabel() support all parameters from the Core label. Check `LabelBase`
    class to known all availables parameters.

    Used by drawLabel()
    '''
    kwargs.setdefault('markup', False)
    kwargs.setdefault('font_size', 12)
    kwargs.setdefault('center', True)
    if kwargs.get('center'):
        kwargs.setdefault('anchor_x', 'center')
        kwargs.setdefault('anchor_y', 'center')
    else:
        kwargs.setdefault('anchor_x', 'left')
        kwargs.setdefault('anchor_y', 'bottom')
    del kwargs['center']

    # create an uniq id for this label
    id = '%s##%s' % (label, str(kwargs))

    # get or store
    obj = Cache.get('pymt.label', id)
    if not obj:
        if kwargs.get('markup'):
            obj = pymt.MarkupLabel(label, **kwargs)
        else:
            obj = pymt.Label(label, **kwargs)
        if 'nocache' not in kwargs:
            Cache.append('pymt.label', id, obj)

    return obj
コード例 #11
0
ファイル: draw.py プロジェクト: gavine199/pymt
def getLabel(label, **kwargs):
    '''Get a cached label object

    :Parameters:
        `label`: str
            Text to be draw
        `font_size`: int, default to 12
            Font size of label
        `center`: bool, default to True
            Indicate if pos is center or left-right of label

    getLabel() support all parameters from the Core label. Check `LabelBase`
    class to known all availables parameters.

    Used by drawLabel()
    '''
    kwargs.setdefault('markup', False)
    kwargs.setdefault('font_size', 12)
    kwargs.setdefault('center', True)
    if kwargs.get('center'):
        kwargs.setdefault('anchor_x', 'center')
        kwargs.setdefault('anchor_y', 'center')
    else:
        kwargs.setdefault('anchor_x', 'left')
        kwargs.setdefault('anchor_y', 'bottom')
    del kwargs['center']

    # create an uniq id for this label
    id = '%s##%s' % (label, str(kwargs))

    # get or store
    obj = Cache.get('pymt.label', id)
    if not obj:
        if kwargs.get('markup'):
            obj = pymt.MarkupLabel(label, **kwargs)
        else:
            obj = pymt.Label(label, **kwargs)
        if 'nocache' not in kwargs:
            Cache.append('pymt.label', id, obj)

    return obj
コード例 #12
0
def css_get_style(widget):
    '''Return a dict() with all the style for the widget.

    :Parameters:
        `widget`: class
            Widget to search CSS
    '''

    global pymt_sheet

    ref = weakref.ref(widget)
    if not ref in _css_widgets:
        _css_widgets.add(ref)

    idwidget = css_get_widget_id(widget)
    styles = Cache.get('pymt.css', idwidget)
    if styles is not None:
        return styles

    styles = pymt_sheet.get_style(widget)
    Cache.append('pymt.css', idwidget, styles)
    return styles
コード例 #13
0
ファイル: draw.py プロジェクト: imc/pymt
from OpenGL.GLU import gluNewQuadric, gluDisk, gluPartialDisk
from paint import *
from statement import *
from colors import *

try:
    import _graphx
    pymt.pymt_logger.info('Graphx: Using accelerate graphx module')
except ImportError, e:
    _graphx = None
    pymt.pymt_logger.warning('Extensions: _graphx not available: <%s>' % e)

# create a cache for label
_temp_label = None
if not 'PYMT_DOC' in os.environ:
    Cache.register('pymt.label', timeout=1., limit=1000)

def _make_point_list(points):
    t = type(points)
    if not t in (tuple, list):
        raise Exception('Point list must be tuple or list of' +
                        'coordinates or points(tuple/list of 2D coords)')
    if type(points[0]) in (tuple, list, Vector):
        return [coord for point in points for coord in point]
    else:
        return list(points)

def getLabel(label, **kwargs):
    '''Get a cached label object

    :Parameters:
コード例 #14
0
ファイル: __init__.py プロジェクト: hansent/pymt
"""
SVG: handle loading of svg data
"""

__all__ = ("Svg",)

from pymt.core import core_register_libs
from pymt.baseobject import BaseObject
from pymt.cache import Cache
from pymt.graphx.statement import gx_matrix
from OpenGL.GL import glTranslate, glScale

Cache.register("pymt.svg", limit=50)


class SvgBase(object):
    """Base to implement an svg loader."""

    __slots__ = ("filename",)

    def __init__(self, filename, **kwargs):
        self.filename = filename

        self.svg_data = Cache.get("pymt.svg", filename)
        if not self.svg_data:
            new_svg = self.load(filename)
            Cache.append("pymt.svg", filename, new_svg)
            self.svg_data = new_svg

    def load(self, filename):
        """Load an svg"""
コード例 #15
0
ファイル: __init__.py プロジェクト: triselectif/pymt
'''
SVG: handle loading of svg data
'''

__all__ = ('Svg',)

from pymt.core import core_register_libs
from pymt.baseobject import BaseObject
from pymt.cache import Cache
from pymt.graphx.statement import gx_matrix
from OpenGL.GL import glTranslate, glScale

Cache.register('_pymt_core_svg_cache', limit=500, timeout=None)

class SvgBase(object):
    '''Base to implement an svg loader.'''

    __slots__ = ('filename')

    def __init__(self, filename, **kwargs):
        self.filename = filename

        self.svg_data = Cache.get('_pymt_core_svg_cache', filename)
        if not self.svg_data:
            new_svg = self.load(filename)
            Cache.append('_pymt_core_svg_cache', filename, new_svg)
            self.svg_data = new_svg

    def load(self, filename):
        '''Load an svg'''
        raise NotimplementedError("abstract class SvgLoaderBase: subclass must be implemented by svg provider")
コード例 #16
0
ファイル: loader.py プロジェクト: triselectif/pymt
from pymt import pymt_data_dir
from pymt.logger import pymt_logger
from pymt.clock import getClock
from pymt.cache import Cache
from pymt.utils import SafeList
from pymt.core.image import ImageLoader, Image
from pymt.event import EventDispatcher
from abc import ABCMeta, abstractmethod

import time
import collections
import os

# Register a cache for loader
Cache.register('loader', limit=500)

class ProxyImage(Image, EventDispatcher):
    '''Image returned by the Loader.image() function.

    :Events:
        `on_load`
            Fired when the image is loaded and changed
    '''
    def __init__(self, arg, **kwargs):
        Image.__init__(self, arg, **kwargs)
        EventDispatcher.__init__(self)

        self.register_event_type('on_load')

    def on_load(self):
コード例 #17
0
ファイル: css.py プロジェクト: triselectif/pymt
def drawCSSRectangle(pos=(0,0), size=(100,100), style={}, prefix=None, state=None):
    '''Draw a rectangle with CSS
    
    :Parameters:
        `state`: if a certain state string is passed, we will use styles with this postifx instead.
            for example:  style[bg-color] and style[bg-color-down] are both set.
            if state == "down", we wil use bg-color-down instead of bg-color

    :Styles:
        * alpha-background (color)
        * border-radius (float)
        * border-radius-precision (float)
        * border-width (float)
        * draw-alpha-background (bool)
        * draw-background (bool)
        * draw-border (bool)

    '''

    bg_image = style.get('bg-image-'+str(state))
    if not bg_image:
        bg_image = style.get('bg-image')

    # Check if we have a cached version
    cache_id = '%s:%s:%s:%s:%s' % (pos, size, style, prefix, state)
    cache = Cache.get('css_rect', cache_id)
    if cache:
        cache.draw()
        if bg_image:
            bg_image.size = size
            bg_image.pos = pos
            bg_image.draw()
        return


    # lets use the ones for given state,
    # and ignore the regular ones if the state ones are there
    if state:
        state = "-" + state
        newstyle = {}
        overwrites = []
        for s in style:
            if state in s:
                overwrite  = s.replace(state, '')
                newstyle[overwrite] = style[s]
                overwrites.append(overwrite)
            if s not in overwrites:
                newstyle[s] = style[s]
        style = newstyle

    # hack to remove prefix in style
    if prefix is not None:
        prefix += '-'
        newstyle = {}
        for k in style:
            newstyle[k] = style[k]
        for k in style:
            if prefix in k:
                newstyle[k.replace(prefix, '')] = style[k]
        style = newstyle

    style.setdefault('border-width', 1.5)
    style.setdefault('border-radius', 0)
    style.setdefault('border-radius-precision', .1)
    style.setdefault('draw-border', 0)
    style.setdefault('draw-background', 1)
    style.setdefault('draw-alpha-background', 0)
    style.setdefault('alpha-background', (1, 1, .5, .5))

    k = { 'pos': pos, 'size': size }

    new_cache = GlDisplayList()
    with new_cache:

        if state:
            set_color(*style['bg-color']) #hack becasue old widgets set this themselves

        linewidth = style.get('border-width')

        bordercolor = None
        if 'border-color' in style:
            bordercolor = style['border-color']

        if style['border-radius'] > 0:
            k.update({
                'radius': style['border-radius'],
                'precision': style['border-radius-precision']
            })
            if style['draw-background']:
                drawRoundedRectangle(**k)
            if style['draw-border']:
                if linewidth:
                    glPushAttrib(GL_LINE_BIT)
                    glLineWidth(linewidth)
                if bordercolor:
                    with gx_color(*bordercolor):
                        drawRoundedRectangle(style=GL_LINE_LOOP, **k)
                else:
                    drawRoundedRectangle(style=GL_LINE_LOOP, **k)
                if linewidth:
                    glPopAttrib()
            if style['draw-alpha-background']:
                drawRoundedRectangleAlpha(alpha=style['alpha-background'], **k)
        else:
            if style['draw-background']:
                drawRectangle(**k)
            if style['draw-border']:
                if linewidth:
                    glPushAttrib(GL_LINE_BIT)
                    glLineWidth(linewidth)
                if bordercolor:
                    with gx_color(*bordercolor):
                        drawRectangle(style=GL_LINE_LOOP, **k)
                else:
                    drawRectangle(style=GL_LINE_LOOP, **k)
                if linewidth:
                    glPopAttrib()
            if style['draw-alpha-background']:
                drawRectangleAlpha(alpha=style['alpha-background'], **k)


    # if the drawCSSRectangle is already inside a display list
    # compilation will not happen, but drawing yes.
    # so, store only if a cache is created !
    if new_cache.is_compiled():
        Cache.append('css_rect', cache_id, new_cache)
        new_cache.draw()

    if bg_image:
        bg_image.size = size
        bg_image.pos = pos
        bg_image.draw()
コード例 #18
0
ファイル: css.py プロジェクト: vidriloco/pymt
def drawCSSRectangle(pos=(0,0), size=(100,100), style={}, prefix=None):
    '''Draw a rectangle with CSS

    :Styles:
        * alpha-background (color)
        * border-radius (float)
        * border-radius-precision (float)
        * border-width (float)
        * draw-alpha-background (bool)
        * draw-background (bool)
        * draw-border (bool)

    '''
    # Check if we have a cached version
    cache_id = '%s:%s:%s:%s' % (pos, size, style, prefix)
    cache = Cache.get('css_rect', cache_id)
    if cache:
        cache.draw()
        return

    # hack to remove prefix in style
    if prefix is not None:
        prefix += '-'
        newstyle = {}
        for k in style:
            if prefix in k:
                newstyle[k.replace(prefix, '')] = style[k]
        style = newstyle

    style.setdefault('border-width', 1.5)
    style.setdefault('border-radius', 0)
    style.setdefault('border-radius-precision', .1)
    style.setdefault('draw-border', 0)
    style.setdefault('draw-background', 1)
    style.setdefault('draw-alpha-background', 0)
    style.setdefault('alpha-background', (1, 1, .5, .5))

    k = { 'pos': pos, 'size': size }

    new_cache = GlDisplayList()
    with new_cache:

        linewidth = None
        old_linewidth = glGetIntegerv(GL_ALIASED_LINE_WIDTH_RANGE)[1]
        if style.get('border-width') != old_linewidth:
            linewidth = style.get('border-width')
        del style['border-width']

        bordercolor = None
        if 'border-color' in style:
            bordercolor = style['border-color']

        if style['border-radius'] > 0:
            k.update({
                'radius': style['border-radius'],
                'precision': style['border-radius-precision']
            })
            if style['draw-background']:
                drawRoundedRectangle(**k)
            if style['draw-border']:
                if linewidth:
                    glLineWidth(linewidth)
                if bordercolor:
                    with gx_color(*bordercolor):
                        drawRoundedRectangle(style=GL_LINE_LOOP, **k)
                else:
                    drawRoundedRectangle(style=GL_LINE_LOOP, **k)
                if linewidth:
                    glLineWidth(old_linewidth)
            if style['draw-alpha-background']:
                drawRoundedRectangleAlpha(alpha=style['alpha-background'], **k)
        else:
            if style['draw-background']:
                drawRectangle(**k)
            if style['draw-border']:
                if linewidth:
                    glLineWidth(linewidth)
                if bordercolor:
                    with gx_color(*bordercolor):
                        drawRectangle(style=GL_LINE_LOOP, **k)
                else:
                    drawRectangle(style=GL_LINE_LOOP, **k)
                if linewidth:
                    glLineWidth(old_linewidth)
            if style['draw-alpha-background']:
                drawRectangleAlpha(alpha=style['alpha-background'], **k)

    # if the drawCSSRectangle is already inside a display list
    # compilation will not happen, but drawing yes.
    # so, store only if a cache is created !
    if new_cache.is_compiled():
        Cache.append('css_rect', cache_id, new_cache)
        new_cache.draw()
コード例 #19
0
ファイル: css.py プロジェクト: bernt/pymt
CSS: Draw shapes with css attributes !
"""

__all__ = ["drawCSSRectangle"]

import os
from draw import *
from colors import set_color
from pymt.cache import Cache
from statement import GlDisplayList, gx_color
from OpenGL.GL import *
from pymt.core.svg import Svg


if not "PYMT_DOC" in os.environ:
    Cache.register("pymt.cssrect", limit=100, timeout=60)


def drawCSSRectangle(pos=(0, 0), size=(100, 100), style={}, prefix=None, state=None):
    """Draw a rectangle with CSS
    
    :Parameters:
        `state`: if a certain state string is passed, we will use styles with this postifx instead.
            for example:  style[bg-color] and style[bg-color-down] are both set.
            if state == "down", we wil use bg-color-down instead of bg-color

    :Styles:
        * alpha-background (color)
        * border-radius (float)
        * border-radius-precision (float)
        * border-width (float)
コード例 #20
0
ファイル: css.py プロジェクト: gavine199/pymt
CSS: Draw shapes with css attributes !
'''

__all__ = ('drawCSSRectangle', )

import os
from pymt.graphx.draw import drawRectangleAlpha, drawRectangle, \
        drawRoundedRectangle, drawRoundedRectangleAlpha
from pymt.graphx.colors import set_color
from pymt.cache import Cache
from pymt.graphx.statement import GlDisplayList, gx_color
from OpenGL.GL import GL_LINE_BIT, GL_LINE_LOOP, \
        glPushAttrib, glPopAttrib, glLineWidth

if not 'PYMT_DOC' in os.environ:
    Cache.register('pymt.cssrect', limit=100, timeout=60)


def drawCSSRectangle(pos=(0, 0), size=(100, 100), style=dict(), prefix=None, state=None):
    '''Draw a rectangle with CSS
    
    :Parameters:
        `state`: if a certain state string is passed, we will use styles with this postifx instead.
            for example:  style[bg-color] and style[bg-color-down] are both set.
            if state == "down", we wil use bg-color-down instead of bg-color

    :Styles:
        * alpha-background (color)
        * border-radius (float)
        * border-radius-precision (float)
        * border-width (float)
コード例 #21
0
__all__ = ('MTTextArea', )

import re
from pymt.cache import Cache
from pymt.graphx import set_color, drawLine
from pymt.base import getFrameDt, getWindow
from pymt.graphx import drawRectangle
from pymt.core.text import Label
from pymt.core.clipboard import Clipboard
from pymt.utils import boundary
from pymt.ui.widgets.composed.textinput import MTTextInput

FL_IS_NEWLINE = 0x01

# add a cache, really not sure about the usage right now.
Cache.register('textarea.label', timeout=60.)

class MTTextArea(MTTextInput):
    '''A multi line text input widget

    :Parameters:
        `tab_width`: int, default to 4
            Indicate how much space should take a tabulation. 1 = size of one
            space.
    '''
    def __init__(self, **kwargs):
        self._glyph_size = {}
        self._scroll_x = 0
        self._scroll_y = 5
        self._selection = False
        self._selection_text = ''
コード例 #22
0
ファイル: css.py プロジェクト: gavine199/pymt
def drawCSSRectangle(pos=(0, 0), size=(100, 100), style=dict(), prefix=None, state=None):
    '''Draw a rectangle with CSS
    
    :Parameters:
        `state`: if a certain state string is passed, we will use styles with this postifx instead.
            for example:  style[bg-color] and style[bg-color-down] are both set.
            if state == "down", we wil use bg-color-down instead of bg-color

    :Styles:
        * alpha-background (color)
        * border-radius (float)
        * border-radius-precision (float)
        * border-width (float)
        * draw-alpha-background (bool)
        * draw-background (bool)
        * draw-border (bool)

    '''

    bg_image = style.get('bg-image-'+str(state))
    if not bg_image:
        bg_image = style.get('bg-image')

    # Check if we have a cached version
    cache_id = '%s:%s:%s:%s:%s' % (pos, size, style, prefix, state)
    cache = Cache.get('pymt.cssrect', cache_id)
    if cache:
        cache.draw()
        if bg_image:
            bg_image.size = size
            bg_image.pos = pos
            bg_image.draw()
        return


    # lets use the ones for given state,
    # and ignore the regular ones if the state ones are there
    if state:
        state = "-" + state
        newstyle = {}
        overwrites = []
        for s in style:
            if state in s:
                overwrite  = s.replace(state, '')
                newstyle[overwrite] = style[s]
                overwrites.append(overwrite)
            if s not in overwrites:
                newstyle[s] = style[s]
        style = newstyle

    # hack to remove prefix in style
    if prefix is not None:
        prefix += '-'
        newstyle = {}
        for k in style:
            newstyle[k] = style[k]
        for k in style:
            if prefix in k:
                newstyle[k.replace(prefix, '')] = style[k]
        style = newstyle

    style.setdefault('border-width', 1.5)
    style.setdefault('border-radius', 0)
    style.setdefault('border-radius-precision', .1)
    style.setdefault('draw-border', 0)
    style.setdefault('draw-background', 1)
    style.setdefault('draw-alpha-background', 0)
    style.setdefault('alpha-background', (1, 1, .5, .5))

    k = { 'pos': pos, 'size': size }

    new_cache = GlDisplayList()
    with new_cache:

        if state:
            set_color(*style['bg-color']) #hack becasue old widgets set this themselves

        linewidth = style.get('border-width')

        bordercolor = None
        if 'border-color' in style:
            bordercolor = style['border-color']

        if style['border-radius'] > 0:
            k.update({
                'radius': style['border-radius'],
                'precision': style['border-radius-precision']
            })
            if style['draw-background']:
                drawRoundedRectangle(**k)
            if style['draw-border']:
                if linewidth:
                    glPushAttrib(GL_LINE_BIT)
                    glLineWidth(linewidth)
                if bordercolor:
                    with gx_color(*bordercolor):
                        drawRoundedRectangle(style=GL_LINE_LOOP, **k)
                else:
                    drawRoundedRectangle(style=GL_LINE_LOOP, **k)
                if linewidth:
                    glPopAttrib()
            if style['draw-alpha-background']:
                drawRoundedRectangleAlpha(alpha=style['alpha-background'], **k)
        else:
            if style['draw-background']:
                drawRectangle(**k)
            if style['draw-border']:
                if linewidth:
                    glPushAttrib(GL_LINE_BIT)
                    glLineWidth(linewidth)
                if bordercolor:
                    with gx_color(*bordercolor):
                        drawRectangle(style=GL_LINE_LOOP, **k)
                else:
                    drawRectangle(style=GL_LINE_LOOP, **k)
                if linewidth:
                    glPopAttrib()
            if style['draw-alpha-background']:
                drawRectangleAlpha(alpha=style['alpha-background'], **k)


    # if the drawCSSRectangle is already inside a display list
    # compilation will not happen, but drawing yes.
    # so, store only if a cache is created !
    if new_cache.is_compiled():
        Cache.append('pymt.cssrect', cache_id, new_cache)
        new_cache.draw()

    if bg_image:
        bg_image.size = size
        bg_image.pos = pos
        bg_image.draw()
コード例 #23
0
ファイル: draw.py プロジェクト: gavine199/pymt
from OpenGL.GLU import gluNewQuadric, gluDisk, gluPartialDisk
from pymt.graphx.paint import *
from pymt.graphx.statement import *
from pymt.graphx.colors import *

try:
    import pymt.c_ext.c_graphx as c_graphx
    pymt.pymt_logger.info('Graphx: Using accelerate graphx module')
except ImportError, e:
    c_graphx = None
    pymt.pymt_logger.warning('Extensions: c_graphx not available: <%s>' % e)

# create a cache for label
_temp_label = None
if not 'PYMT_DOC' in os.environ:
    Cache.register('pymt.label', timeout=1., limit=1000)


def _make_point_list(points):
    t = type(points)
    if not t in (tuple, list):
        raise Exception('Point list must be tuple or list of' +
                        'coordinates or points(tuple/list of 2D coords)')
    if type(points[0]) in (tuple, list, Vector):
        return [coord for point in points for coord in point]
    else:
        return list(points)


def getLabel(label, **kwargs):
    '''Get a cached label object
コード例 #24
0
from pymt.logger import pymt_logger
from pymt.cache import Cache
from pymt.resources import resource_add_path
from pymt.parser import parse_color, parse_image, parse_float4, \
        parse_float, parse_bool, parse_int, parse_int2, parse_string, \
        parse_filename
from pymt import pymt_data_dir, pymt_home_dir
import os
import sys
import shutil
import logging
import re
import weakref

# Register CSS cache
Cache.register('pymt.css', limit=500, timeout=60)

#: Instance of the CSS sheet
pymt_sheet = None

#: State allowed to CSS rules (bg-color[-state] for eg)
pymt_css_states = ['-down', '-move', '-dragging', '-active', '-error',
                   '-validated', '-syskey']

#: Prefix allowed to CSS rules
pymt_css_prefix = ['key-', 'slider-', 'title-', 'cursor-', 'selection-']

# Privates vars for reload features
_css_sources = []
_css_widgets = set()
コード例 #25
0
ファイル: draw.py プロジェクト: triselectif/pymt
)

import os
import math
import pymt
from pymt.cache import Cache
from OpenGL.GL import *
from OpenGL.GLU import gluNewQuadric, gluDisk, gluPartialDisk
from paint import *
from statement import *
from colors import *

# create a cache for label
_temp_label = None
if not 'PYMT_DOC' in os.environ:
    Cache.register('drawlabel', timeout=1., limit=100)


def _make_point_list(points):
    t = type(points)
    if not t in (tuple, list):
        raise Exception("Point list must be tuple or list of coordinates or points(tuple/list of 2D coords)")
    if type(points[0]) in (tuple, list): #flatten the points
        return [coord for point in points for coord in point]
    else:
        return list(points)



def getLabel(label, **kwargs):
    '''Get a cached label object
コード例 #26
0
ファイル: loader.py プロジェクト: bernt/pymt
from pymt import pymt_data_dir
from pymt.logger import pymt_logger
from pymt.clock import getClock
from pymt.cache import Cache
from pymt.utils import SafeList
from pymt.core.image import ImageLoader, Image
from pymt.event import EventDispatcher
from abc import ABCMeta, abstractmethod

import time
import collections
import os

# Register a cache for loader
Cache.register('pymt.loader', limit=500, timeout=60)

class ProxyImage(Image, EventDispatcher):
    '''Image returned by the Loader.image() function.

    :Properties:
        `loaded`: bool, default to False
            It can be True if the image is already cached

    :Events:
        `on_load`
            Fired when the image is loaded and changed
    '''
    def __init__(self, arg, **kwargs):
        kwargs.setdefault('loaded', False)
        super(ProxyImage, self).__init__(arg, **kwargs)
コード例 #27
0
ファイル: __init__.py プロジェクト: imc/pymt
'''
SVG: handle loading of svg data
'''

__all__ = ('Svg',)

from pymt.core import core_register_libs
from pymt.baseobject import BaseObject
from pymt.cache import Cache
from pymt.graphx.statement import gx_matrix
from OpenGL.GL import glTranslate, glScale

Cache.register('pymt.svg', limit=50)

class SvgBase(object):
    '''Base to implement an svg loader.'''

    __slots__ = ('filename')

    def __init__(self, filename, **kwargs):
        self.filename = filename

        self.svg_data = Cache.get('pymt.svg', filename)
        if not self.svg_data:
            new_svg = self.load(filename)
            Cache.append('pymt.svg', filename, new_svg)
            self.svg_data = new_svg

    def load(self, filename):
        '''Load an svg'''
        raise NotimplementedError("abstract class SvgLoaderBase: subclass must be implemented by svg provider")
コード例 #28
0
ファイル: css.py プロジェクト: triselectif/pymt
CSS: Draw shapes with css attributes !
'''

__all__ = ['drawCSSRectangle']

import os
from draw import *
from colors import set_color
from pymt.cache import Cache
from statement import GlDisplayList, gx_color
from OpenGL.GL import *
from pymt.core.svg import Svg


if not 'PYMT_DOC' in os.environ:
    Cache.register('css_rect', limit=100, timeout=500)


def drawCSSRectangle(pos=(0,0), size=(100,100), style={}, prefix=None, state=None):
    '''Draw a rectangle with CSS
    
    :Parameters:
        `state`: if a certain state string is passed, we will use styles with this postifx instead.
            for example:  style[bg-color] and style[bg-color-down] are both set.
            if state == "down", we wil use bg-color-down instead of bg-color

    :Styles:
        * alpha-background (color)
        * border-radius (float)
        * border-radius-precision (float)
        * border-width (float)
コード例 #29
0
ファイル: __init__.py プロジェクト: gavine199/pymt
'''
SVG: handle loading of svg data
'''

__all__ = ('Svg', )

from pymt.core import core_register_libs
from pymt.baseobject import BaseObject
from pymt.cache import Cache
from pymt.graphx.statement import gx_matrix
from OpenGL.GL import glTranslate, glScale

Cache.register('pymt.svg', limit=50)


class SvgBase(object):
    '''Base to implement an svg loader.'''

    __slots__ = ('filename', )

    def __init__(self, filename, **kwargs):
        self.filename = filename

        self.svg_data = Cache.get('pymt.svg', filename)
        if not self.svg_data:
            new_svg = self.load(filename)
            Cache.append('pymt.svg', filename, new_svg)
            self.svg_data = new_svg

    def load(self, filename):
        '''Load an svg'''
コード例 #30
0
ファイル: loader.py プロジェクト: vidriloco/pymt
from pymt import pymt_data_dir
from pymt.logger import pymt_logger
from pymt.clock import getClock
from pymt.cache import Cache
from pymt.utils import SafeList
from pymt.core.image import ImageLoader, Image
from pymt.event import EventDispatcher
from abc import ABCMeta, abstractmethod

import time
import collections
import os

# Register a cache for loader
Cache.register("loader", limit=500)


class ProxyImage(Image, EventDispatcher):
    """Image returned by the Loader.image() function.
    
    :Events:
        `on_load`
            Fired when the image is loaded and changed
    """

    def __init__(self, arg, **kwargs):
        Image.__init__(self, arg, **kwargs)
        EventDispatcher.__init__(self)

        self.register_event_type("on_load")
コード例 #31
0
from pymt import pymt_data_dir
from pymt.logger import pymt_logger
from pymt.clock import getClock
from pymt.cache import Cache
from pymt.utils import SafeList
from pymt.core.image import ImageLoader, Image
from pymt.event import EventDispatcher
from abc import ABCMeta, abstractmethod

import time
import collections
import os

# Register a cache for loader
Cache.register('pymt.loader', limit=500, timeout=60)

class ProxyImage(Image, EventDispatcher):
    '''Image returned by the Loader.image() function.

    :Properties:
        `loaded`: bool, default to False
            It can be True if the image is already cached

    :Events:
        `on_load`
            Fired when the image is loaded and changed
    '''
    def __init__(self, arg, **kwargs):
        kwargs.setdefault('loaded', False)
        super(ProxyImage, self).__init__(arg, **kwargs)