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
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:
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)
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):
''' 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")
''' 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")
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)
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")
__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 = ''
) 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
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()
''' 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'''
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)
""" 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"""
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)