コード例 #1
0
ファイル: widgets.py プロジェクト: toscawidgets/tw2.yui
class LogReader(YuiWidget):
    resources = YuiWidget.resources + [
        twc.CSSLink(modname=__name__,
                    filename="static/" + yui_version +
                    "/logger/assets/skins/sam/logger.css"),
        twc.JSLink(modname=__name__,
                   filename="static/" + yui_version + "/logger/logger-min.js"),
    ]
    template = "genshi:tw2.yui.templates.logreader"
コード例 #2
0
ファイル: appearance.py プロジェクト: mitin123/tw2.core
class Index(twf.FormPage):
    title = 'tw2.forms Customising Appearance'
    resources = [twc.CSSLink(filename='appearance.css')]
    template = 'genshi:%s/appearance.html' % os.getcwd()

    class child(twf.TableForm):
        name = twf.TextField(validator=twc.Required)
        group = twf.SingleSelectField(options=['Red', 'Green', 'Blue'])
        notes = twf.TextArea()
        submit = twf.SubmitButton(value='Go!')
コード例 #3
0
ファイル: widgets.py プロジェクト: toscawidgets/tw2.yui
class Calendar(YuiWidget):
    resources = YuiWidget.resources + [
        twc.CSSLink(modname=__name__,
                    filename="static/" + yui_version +
                    "/calendar/assets/skins/sam/calendar.css"),
        twc.JSLink(
            modname=__name__,
            filename="static/" + yui_version + "/calendar/calendar-min.js"),
    ]
    template = "genshi:tw2.yui.templates.calendar"
コード例 #4
0
ファイル: widgets.py プロジェクト: toscawidgets/tw2.yui
class DataTable(YuiWidget, twc.CompoundWidget):
    resources = YuiWidget.resources + [
        twc.CSSLink(modname=__name__,
                    filename="static/" + yui_version +
                    "/datatable/assets/skins/sam/datatable.css"),
        twc.CSSLink(modname=__name__,
                    filename="static/" + yui_version +
                    "/button/assets/skins/sam/button.css"),
        twc.JSLink(modname=__name__,
                   filename="static/" + yui_version + "/dom/dom-min.js"),
        twc.JSLink(modname=__name__,
                   filename="static/" + yui_version + "/event/element-min.js"),
        twc.JSLink(
            modname=__name__,
            filename="static/" + yui_version + "/dragdrop/dragdrop-min.js"),
        twc.JSLink(
            modname=__name__,
            filename="static/" + yui_version + "/element/element-min.js"),
        twc.JSLink(modname=__name__,
                   filename="static/" + yui_version +
                   "/datasource/datasource-min.js"),
        twc.JSLink(modname=__name__,
                   filename="static/" + yui_version +
                   "/event-delegate/event-delegate-min.js"),
        twc.JSLink(
            modname=__name__,
            filename="static/" + yui_version + "/datatable/datatable-min.js"),
        twc.JSLink(modname=__name__,
                   filename="static/" + yui_version + "/button/button-min.js"),
    ]
    template = "genshi:tw2.yui.templates.datatable"
    children = twc.Param(
        'Columns for the table. These must be tw2.yui.Column widgets.')
    columns = twc.Variable()

    def prepare(self):
        super(DataTable, self).prepare()
        self.columns = twc.encoder.encode([c.options for c in self.c])
        self.buttons = twc.encoder.encode(
            dict(
                (c.id, c.link) for c in self.c if isinstance(c, ButtonColumn)))
        self.value = twc.encoder.encode(self.value)
コード例 #5
0
class ColorizedMessagesWidget(BusmonWidget):
    id = 'colorized-messages'
    template = "mako:busmon.templates.colorized_messages"
    resources = BusmonWidget.resources + [
        twc.CSSLink(link="css/monokai.css"),
        twc.JSLink(link="javascript/markup.js"),
    ]
    css_class = "hll"

    topic = "*"

    onmessage = """
コード例 #6
0
ファイル: widgets.py プロジェクト: garrettmc/TGWikiTutorial
class BaseLayout(twc.CompoundWidget):
    """
    The following CSS classes are used, on the element containing
    both a child widget and its label.

    `odd` / `even`
        On alternating rows. The first row is odd.

    `required`
        If the field is a required field.

    `error`
        If the field contains a validation error.
    """

    label = twc.ChildParam(
        'Label for the field. Auto generates this from the ' +
        'id; None supresses the label.',
        default=twc.Auto)
    help_text = twc.ChildParam('A longer description of the field',
                               default=None)
    hover_help = twc.Param('Whether to display help text as hover tips',
                           default=False)
    container_attrs = twc.ChildParam(
        'Extra attributes to include in the element containing ' +
        'the widget and its label.',
        default={})

    resources = [twc.CSSLink(modname='tw2.forms', filename='static/forms.css')]

    @property
    def children_hidden(self):
        return [c for c in self.children if isinstance(c, HiddenField)]

    @property
    def children_non_hidden(self):
        return [c for c in self.children if not isinstance(c, HiddenField)]

    @property
    def rollup_errors(self):
        errors = [
            c.error_msg for c in self.children
            if isinstance(c, HiddenField) and c.error_msg
        ]
        if self.error_msg:
            errors.insert(0, self.error_msg)
        return errors

    def prepare(self):
        super(BaseLayout, self).prepare()
        for c in self.children:
            if c.label is twc.Auto:
                c.label = c.id and twc.util.name2label(c.id) or ''
コード例 #7
0
class WbPage(twc.Page):
    _no_autoid = True
    resources = [
        twc.CSSLink(modname=__name__, filename='static/css/reset.css'),
        twc.CSSLink(modname=__name__, filename='static/css/core.css'),
        twc.CSSLink(modname=__name__, filename='static/css/grid.css'),
        twc.CSSLink(modname=__name__, filename='static/css/pygments.css'),
        twc.DirLink(modname=__name__, filename='static/')
    ]

    template = "genshi:tw2.devtools.templates.wb_page"

    def prepare(self):
        super(WbPage, self).prepare()
        self.modules = sorted(ep.module_name
                              for ep in pr.iter_entry_points('tw2.widgets')
                              if not ep.module_name.endswith('.samples'))
        self.pypi = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')

    @memoize.memoize
    def _pypi_versions(self, module):
        versions = self.pypi.package_releases(module, True)
        return versions

    @memoize.memoize
    def pypi_version(self, module):
        versions = self.pypi.package_releases(module)
        if len(versions):
            return versions[0]
        return '----'

    @memoize.memoize
    def pypi_downloads(self, module):
        return sum([
            sum([
                d['downloads']
                for d in self.pypi.release_urls(module, version)
            ]) for version in self._pypi_versions(module)
        ])
コード例 #8
0
    def setUp(self):
        global _request_local
        _request_local = {}
        self.mw = twc.make_middleware(self)
        self.app = wt.TestApp(self.mw)

        js = twc.JSLink(link='paj')
        css = twc.CSSLink(link='joe')
        TestWidget = twc.Widget(
            template='genshi:tw2.core.test_templates.inner_genshi',
            test='test',
        )
        self.inject_widget = TestWidget(id='a', resources=[js, css])
コード例 #9
0
class CalendarDatePicker(twf.widgets.InputField):
    """
    A JavaScript calendar system for picking dates. The date format can be configured on the validator.
    """
    resources = [
        twc.CSSLink(modname='tw2.dynforms',
                    filename='static/calendar/calendar-system.css'),
        twc.JSLink(modname='tw2.dynforms',
                   filename='static/calendar/calendar.js'),
        twc.JSLink(modname='tw2.dynforms',
                   filename='static/calendar/calendar-setup.js'),
        twc.Link(id='cal',
                 modname='tw2.dynforms',
                 filename='static/office-calendar.png'),
    ]
    language = twc.Param('Short country code for language to use, e.g. fr, de',
                         default='en')
    show_time = twc.Variable('Whether to display the time', default=False)
    value = twc.Param('The default value is the current date/time',
                      default=None)
    validator = twc.DateValidator
    template = "genshi:tw2.dynforms.templates.calendar"
    type = 'text'

    def prepare(self):

        if not self.value:
            # XXX -- Doing this instead of twc.Deferred consciously.
            # twc.Deferred is/was nice, but the execution in post_define(...) of
            #   cls._deferred = [k for k, v in cls.__dict__.iteritems()
            #                    if isinstance(v, pm.Deferred)]
            # with dir(..) instead of vars(..) is too costly.  This is the only
            # place I'm aware of that actually uses deferred params. - threebean
            self.value = dt.datetime.now()

        super(CalendarDatePicker, self).prepare()

        self.safe_modify('resources')
        self.resources.extend([
            twc.JSLink(parent=self.__class__,
                       modname='tw2.dynforms',
                       filename='static/calendar/lang/calendar-%s.js' %
                       self.language),
        ])
        self.add_call(
            twc.js_function('Calendar.setup')(dict(
                inputField=self.compound_id,
                ifFormat=self.validator.format,
                button=self.compound_id + ':trigger',
                showsTime=self.show_time)))
コード例 #10
0
ファイル: widgets.py プロジェクト: toscawidgets/tw2.yui
class TreeView(YuiWidget):
    resources = YuiWidget.resources + [
        twc.CSSLink(modname=__name__,
                    filename="static/" + yui_version +
                    "/treeview/assets/skins/sam/treeview.css"),
        twc.JSLink(
            modname=__name__,
            filename="static/" + yui_version + "/treeview/treeview-min.js"),
    ]
    template = "genshi:tw2.yui.templates.treeview"
    content = twc.Param('Content', default=[])

    def prepare(self):
        super(TreeView, self).prepare()
        self.content = twc.encoder.encode(self.content)
コード例 #11
0
ファイル: widgets.py プロジェクト: toscawidgets/tw2.yui
class Editor(twf.TextArea, YuiWidget):
    resources = YuiWidget.resources + [
        twc.CSSLink(modname=__name__,
                    filename="static/" + yui_version +
                    "/menu/assets/skins/sam/menu.css"),
        twc.CSSLink(modname=__name__,
                    filename="static/" + yui_version +
                    "/button/assets/skins/sam/button.css"),
        twc.CSSLink(modname=__name__,
                    filename="static/" + yui_version +
                    "/container/assets/skins/sam/container.css"),
        twc.CSSLink(modname=__name__,
                    filename="static/" + yui_version +
                    "/editor/assets/skins/sam/editor.css"),
        twc.JSLink(
            modname=__name__,
            filename="static/" + yui_version + "/animation/animation-min.js"),
        twc.JSLink(
            modname=__name__,
            filename="static/" + yui_version + "/element/element-min.js"),
        twc.JSLink(
            modname=__name__,
            filename="static/" + yui_version + "/container/container-min.js"),
        twc.JSLink(modname=__name__,
                   filename="static/" + yui_version + "/menu/menu-min.js"),
        twc.JSLink(modname=__name__,
                   filename="static/" + yui_version + "/button/button-min.js"),
        twc.JSLink(modname=__name__,
                   filename="static/" + yui_version + "/editor/editor-min.js"),
    ]
    template = "genshi:tw2.yui.templates.editor"
    options = {'handleSubmit': 1}

    # default to a fairly large size
    rows = 20
    cols = 100
コード例 #12
0
ファイル: widgets.py プロジェクト: toscawidgets/tw2.yui
class YuiWidget(twc.Widget):
    resources = [
        twc.DirLink(modname=__name__, filename="static/" + yui_version + "/"),
        twc.CSSLink(modname=__name__,
                    filename="static/" + yui_version + "/fonts/fonts-min.css"),
        twc.JSLink(modname=__name__,
                   filename="static/" + yui_version +
                   "/yahoo-dom-event/yahoo-dom-event.js"),
    ]
    options = twc.Param(
        'Configuration options for the widget. See the YUI docs for available options.',
        default={})

    def prepare(self):
        super(YuiWidget, self).prepare()
        self.options = twc.encoder.encode(self.options)
コード例 #13
0
ファイル: widgets.py プロジェクト: toscawidgets/tw2.yui
class TabView(twf.widgets.BaseLayout):
    resources = YuiWidget.resources + [
        twc.CSSLink(modname=__name__,
                    filename="static/" + yui_version +
                    "/tabview/assets/skins/sam/tabview.css"),
        twc.JSLink(
            modname=__name__,
            filename="static/" + yui_version + "/element/element-min.js"),
        twc.JSLink(
            modname=__name__,
            filename="static/" + yui_version + "/tabview/tabview-min.js"),
    ]
    template = "genshi:tw2.yui.templates.tabview"
    # These don't apply; hide from widget browser
    hover_help = twc.Variable()
    help_text = twc.Variable()
    container_attrs = twc.Variable()
コード例 #14
0
ファイル: widgets.py プロジェクト: toscawidgets/tw2.yui
class ColorPicker(YuiWidget):
    resources = YuiWidget.resources + [
        twc.CSSLink(modname=__name__,
                    filename="static/" + yui_version +
                    "/colorpicker/assets/skins/sam/colorpicker.css"),
        twc.JSLink(
            modname=__name__,
            filename="static/" + yui_version + "/dragdrop/dragdrop-min.js"),
        twc.JSLink(
            modname=__name__,
            filename="static/" + yui_version + "/animation/animation-min.js"),
        twc.JSLink(modname=__name__,
                   filename="static/" + yui_version + "/slider/slider-min.js"),
        twc.JSLink(
            modname=__name__,
            filename="static/" + yui_version + "/element/element-min.js"),
        twc.JSLink(modname=__name__,
                   filename="static/" + yui_version +
                   "/colorpicker/colorpicker-min.js"),
        twc.Link(id='picker_thumb',
                 modname=__name__,
                 filename="static/" + yui_version +
                 "/colorpicker/assets/picker_thumb.png"),
        twc.Link(id='hue_thumb',
                 modname=__name__,
                 filename="static/" + yui_version +
                 "/colorpicker/assets/hue_thumb.png"),
    ]
    template = "genshi:tw2.yui.templates.colorpicker"
    rgb = twc.Variable(default='[0xFF,0xFF,0xFF]')

    def prepare(self):
        self.safe_modify('options')
        if self.value and re.match('^#[0-9a-fA-F]{6}$', self.value):
            self.rgb = twc.encoder.encode(
                [int(self.value[i:i + 2], 16) for i in (1, 3, 5)])
        self.options['images'] = {
            'PICKER_THUMB':
            '/resources/tw2.yui.widgets/static/' + yui_version +
            '/colorpicker/assets/picker_thumb.png',
            'HUE_THUMB':
            '/resources/tw2.yui.widgets/static/' + yui_version +
            '/colorpicker/assets/hue_thumb.png',
        }
        super(ColorPicker, self).prepare()
コード例 #15
0
    def test_res_nodupe(self):
        wa = TestWidget(id='a', resources=[js])
        wb = TestWidget(id='b', resources=[twc.JSLink(link='paj')])
        wc = TestWidget(id='c', resources=[twc.JSLink(link='test')])
        wd = TestWidget(id='d', resources=[css])
        we = TestWidget(id='e', resources=[twc.CSSLink(link='joe')])

        rl = testapi.request(1, mw)
        wa.display()
        wb.display()
        rl = twc.core.request_local()
        r = rl['resources']
        assert (len(rl['resources']) == 1)
        wc.display()
        assert (len(rl['resources']) == 2)
        wd.display()
        we.display()
        assert (len(rl['resources']) == 3)
コード例 #16
0
ファイル: widgets.py プロジェクト: toscawidgets/tw2.yui
class Slider(YuiWidget):
    resources = YuiWidget.resources + [
        twc.CSSLink(modname=__name__,
                    filename="static/" + yui_version +
                    "/slider/assets/skins/sam/slider.css"),
        twc.JSLink(
            modname=__name__,
            filename="static/" + yui_version + "/animation/animation-min.js"),
        twc.JSLink(
            modname=__name__,
            filename="static/" + yui_version + "/dragdrop/dragdrop-min.js"),
        twc.JSLink(modname=__name__,
                   filename="static/" + yui_version + "/slider/slider-min.js"),
        twc.Link(
            id='thumb',
            modname=__name__,
            filename='static/' + yui_version + '/slider/assets/thumb-n.gif'),
    ]
    template = "genshi:tw2.yui.templates.slider"

    size = twc.Param('Size in pixels of control', default=200)
    min = twc.Param('Minimum effective value', default=0)
    max = twc.Param('Maximum effective value', default=100)
コード例 #17
0
ファイル: widgets.py プロジェクト: toscawidgets/tw2.yui
class AutoComplete(twf.TextField, YuiWidget):
    resources = YuiWidget.resources + [
        twc.CSSLink(modname=__name__,
                    filename="static/" + yui_version +
                    "/autocomplete/assets/skins/sam/autocomplete.css"),
        twc.JSLink(modname=__name__,
                   filename="static/" + yui_version + "/json/json-min.js"),
        twc.JSLink(
            modname=__name__,
            filename="static/" + yui_version + "/element/element-min.js"),
        twc.JSLink(
            modname=__name__,
            filename="static/" + yui_version + "/animation/animation-min.js"),
        twc.JSLink(modname=__name__,
                   filename="static/" + yui_version +
                   "/datasource/datasource-min.js"),
        twc.JSLink(modname=__name__,
                   filename="static/" + yui_version +
                   "/autocomplete/autocomplete-min.js"),
    ]
    template = "genshi:tw2.yui.templates.autocomplete"
    attrs = {'style': 'width:15em;'}
    datasrc = twc.Param('DataSource to use')
    value = twc.Param(attribute=True)

    @classmethod
    def post_define(cls):
        if hasattr(cls, 'datasrc'):
            cls.datasrc = cls.datasrc(parent=cls, id='datasrc')

    def __init__(self, **kw):
        super(AutoComplete, self).__init__(**kw)
        self.datasrc = self.datasrc.req()

    def prepare(self):
        super(AutoComplete, self).prepare()
        self.datasrc.prepare()
コード例 #18
0
ファイル: chat.py プロジェクト: decause/moksha
import tw2.core as twc
from tw2.jquery import jquery_js

from moksha.api.widgets.orbited import orbited_js

irc2_js = twc.JSLink(filename='static/irc2.js',
                 modname=__name__)

willowchat_js = twc.JSLink(filename='static/willowchat.js',
                       modname=__name__)

gui_js = twc.JSLink(filename='static/gui.js',
                modname=__name__)

willowchat_css = twc.CSSLink(filename='static/style.css', modname=__name__)

static_dir = twc.DirLink(filename='static', modname=__name__)


class LiveChatWidget(twc.Widget):
    name = 'Chat'
    template = 'mako:moksha.apps.chat.templates.chatwidget'
    bootstrap = twc.Param(default=twc.JSLink(link='/apps/chat/bootstrap'))
    visible = False
    resources = [static_dir]


class LiveChatFrameWidget(twc.Widget):
    template = 'mako:moksha.apps.chat.templates.chat'
    resources= [jquery_js, orbited_js, willowchat_js, irc2_js, gui_js,
コード例 #19
0
# This file is part of Moksha.
# Copyright (C) 2008-2010  Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
:mod:`moksha.widgets.jquery_ui_theme` - jQuery UI Theme
=======================================================

.. moduleauthor:: Luke Macken <*****@*****.**>
"""

# TODO -- can this be replaced with tw2.jqplugins.ui:set_ui_theme_name ?
import tw2.core as twc

ui_theme_css = twc.CSSLink(link='/css/jquery-ui/ui.theme.css',
                           modname=__name__)
ui_base_css = twc.CSSLink(link='/css/jquery-ui/ui.base.css',
                          css=[ui_theme_css],
                          modname=__name__)
コード例 #20
0
ファイル: container.py プロジェクト: decause/moksha
#
# Authors: Luke Macken <*****@*****.**>

import uuid
import tw2.core as twc
from tw2.core.resources import encoder
from tw2.jquery import jquery_js
from tw2.jquery.base import jQuery
from tw2.jqplugins.ui.base import jquery_ui_js

from moksha.api.widgets.live import LiveWidget
from moksha.api.widgets.live import subscribe_topics, unsubscribe_topics

container_js = twc.JSLink(filename='static/js/mbContainer.min.js',
                          modname=__name__)
container_css = twc.CSSLink(filename='static/css/mbContainer.css',
                            modname=__name__)
container_resources = twc.DirLink(filename='static/css/elements',
                                  modname=__name__)


# TODO -- this should extend from an as yet unwritten tw2 container (nb?)
# TODO -- should this extend from moksha/api/widgets/containers ?  duplication?
class MokshaContainer(twc.Widget):
    template = 'mako:moksha.widgets.container.templates.container'
    resources = [
        jquery_js,
        jquery_ui_js,
        container_js,
        container_css,
        container_resources,
    ]
コード例 #21
0
    'chosen_img', 'chosen_js', 'chosen_css', 'ChosenSingleSelectField',
    'ChosenMultipleSelectField'
]

chosen_img = twc.Link(modname=__name__, filename='static/chosen-sprite.png')
chosen_img_2x = twc.Link(modname=__name__,
                         filename='static/[email protected]')
chosen_js = twc.JSLink(modname=__name__,
                       filename='static/chosen.jquery.js',
                       resources=[twj.jquery_js],
                       location='headbottom')
chosen_js_min = twc.JSLink(modname=__name__,
                           filename='static/chosen.jquery.min.js',
                           resources=[twj.jquery_js],
                           location='headbottom')
chosen_css = twc.CSSLink(modname=__name__, filename='static/chosen.css')
chosen_css_min = twc.CSSLink(modname=__name__,
                             filename='static/chosen.min.css')


class ChosenMixin(twc.Widget):
    '''Mixin for Chosen SelectFields'''
    resources = [chosen_js, chosen_css]

    selector = twc.Variable("Escaped id.  jQuery selector.")
    opts = twc.Variable(
        'Arguments for the javascript init function. '
        'See http://harvesthq.github.io/chosen/options.html',
        default=dict())

    placeholder = twc.Param('Placeholder text, prompting user for selection',
コード例 #22
0
import tw2.core as twc
import tw2.jqplugins.ui
import testapi

from nose.tools import eq_

js = twc.JSLink(link='paj')
css = twc.CSSLink(link='joe')
csssrc = twc.CSSSource(src='.bob { font-weight: bold; }')
jssrc = twc.JSSource(src='bob')

html = "<html><head><title>a</title></head><body>hello</body></html>"


def simple_app(environ, start_response):
    req = wo.Request(environ)
    ct = 'text/html' if req.path == '/' else 'test/plain'
    resp = wo.Response(request=req, content_type="%s; charset=UTF8" % ct)
    resp.body = html
    return resp(environ, start_response)

mw = twc.make_middleware(simple_app)


def setup():
    testapi.setup()


def test_weird_case_for_zykes():
    rl = testapi.request(1, mw)
    tw2.jqplugins.ui.jquery_ui.inject()
コード例 #23
0
## You should have received a copy of the GNU Affero General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import tw2.core as twc
import tw2.jquery as twj

from sprox.widgets import SproxDataGrid

tablesorter_js = twc.JSLink(
    #filename='static/javascript/jquery.tablesorter.js',
    link='/javascript/jquery.tablesorter.js',
    resources=[twj.jquery_js],
    location='headbottom')
tablesorter_css = twc.CSSLink(
    #filename='static/style/tablesorter.css',
    link='/css/tablesorter.css')


class JSSortableDataGrid(SproxDataGrid):
    resources = [tablesorter_js, tablesorter_css]
    css_class = 'tablesorter table table-striped table-condensed'

    headers = twc.Param('', default={})
    sortList = twc.Param('', default=[])

    def prepare(self):
        super(JSSortableDataGrid, self).prepare()
        if 'id' in self.attrs:
            selector = "#" + self.attrs['id'].replace(':', '\\:')
        else:
コード例 #24
0
    Label = {
        'size': 12,
        'color': '#3e3e3e',
    }


class ForeclosureArea(JitCustomized, AreaChart):
    pass


class ForeclosurePie(JitCustomized, PieChart):
    sliceOffset = 10


custom_polymaps_css = twc.CSSLink(
    modname=__name__,
    filename='public/css/custom-polymaps.css')


class ForeclosureMap(PolyMap):
    id = 'foreclosure_map'
    data_url = '/foreclosure_map_data/'

    # Both specify the css_class AND include your own custom css file that
    # specifies what it looks like.
    css_class = 'sample-tw2-polymaps-container-1'
    resources = PolyMap.resources + [custom_polymaps_css]

    # 10.00/43.1164/-437.5940
    zoom = 10.0
    center_latlon = {'lat': 43.1164, 'lon': -437.5940}
コード例 #25
0
ファイル: widgets.py プロジェクト: pombredanne/tw2.olap
class Table(twc.Widget):

    template = "tw2.olap.templates.table"
    mdxresult = twc.Param("An IMDXResult object.")
    properties = twc.Param(
        "A list of properties to load from the result cells")
    showTrigger = twc.Param("Show or hide +/- trigger", default=False)
    showSpan = twc.Param("Show or hide spanning cells", default=False)
    showRowColumnHeaders = twc.Param("Show or hide column headers of row head",
                                     default=False)
    colHeaderMap = twc.Param(
        "Optionally substitute columns header names as by this mapping",
        default={})

    resources = [
        twc.CSSLink(modname="tw2.olap", filename="static/table.css"),
        twc.Link(id="do_collapse",
                 modname="tw2.olap",
                 filename="static/do-collapse.gif"),
        twc.Link(id="do_expand",
                 modname="tw2.olap",
                 filename="static/do-expand.gif"),
        twc.Link(id="do_nothing",
                 modname="tw2.olap",
                 filename="static/do-nothing.gif")
    ]

    css_class = "olaptable"

    def prepare(self):
        super(Table, self).prepare()
        res = self.mdxresult
        axistuple = []
        try:
            axis = 0
            while True:
                axistuple.append(res.getAxisTuple(axis))
                axis += 1
        except:
            pass

        self.slices = res.getSlice(properties=self.properties)
        self.axistuple = axistuple
        #import pdb; pdb.set_trace()
        maxhier = self.getRowColumnCount()
        if maxhier > 1 and not self.showSpan:
            self.spanning(self.axistuple[1], 0, maxhier, 0, self.getRowCount())

        maxhier = self.getColumnRowCount()
        if maxhier > 1 and not self.showSpan:
            self.spanning(self.axistuple[0], 0, maxhier, 0,
                          self.getColumnCount())

    def getContent(self):
        colgroup = []
        theadrows = self.getLeadingRows()
        tfootrows = []
        tbodyrows = []

        cr_count = self.getColumnRowCount()
        rc_count = self.getRowColumnCount()
        cc = self.getColumnCount()

        # thead
        for cr in range(cr_count):
            if self.showColumnHeaderRow(cr):
                row_attrs = {}
                ths = []
                if rc_count > 0:
                    if self.showRowColumnHeader() and cr == cr_count - 1:
                        for c in range(self.getRowColumnCount()):
                            ths.append(("th", self.getRowColumnHeaderAttrs(c),
                                        self.displayRowColumnHeader(c)))
                    else:
                        ths.append(self.getEmptyRowDesc(cr))
                for c in range(cc):
                    if self.showColumnRowCell(c, cr):
                        ths.append(("th", self.getColumnRowCellAttrs(c, cr),
                                    self.displayColumnRowCell(c, cr)))

                row = ("tr", row_attrs, ths)
                rows = self.alterHeadRow(cr, row)
                if rows:
                    theadrows.extend(rows)

        # tbody
        for r in range(self.getRowCount()):
            if self.showRow(r):
                row_attrs = {}
                tds = []
                # row header cells
                for rc in range(rc_count):
                    if self.showRowColumnCell(r, rc):
                        td_attrs = self.getRowColumnCellAttrs(r, rc)
                        div_attrs = self.getRowColumnDivAttrs(r, rc)
                        div = ("div", div_attrs,
                               self.getRowColumnCellDesc(r, rc))
                        tds.append(("th", td_attrs, div))

                # data cells
                for c in range(cc):
                    if self.showCell(r, c):
                        tds.append(("td", self.getCellAttrs(r, c),
                                    self.displayCell(r, c)))

                row = ("tr", row_attrs, tds)
                rows = self.alterBodyRow(r, row)
                if rows:
                    tbodyrows.extend(rows)

        # tfoot
        tfootrows = self.getTrailingRows()

        if tfootrows:
            tfootrows = ("tfoot", {}, tfootrows)

        if theadrows:
            theadrows = ("thead", {}, theadrows)

        if tbodyrows:
            tbodyrows = ("tbody", {}, tbodyrows)

        return colgroup, theadrows, tbodyrows, tfootrows

    def getColumnCount(self):
        return len(self.axistuple[0])

    def getColumnRowCount(self):

        tup = self.axistuple[0][0]
        if isinstance(tup, list):
            return len(tup)
        return 1

    def getRowCount(self):
        if self.slices:
            if isinstance(self.slices[0], list):
                return len(self.slices)
            return 1
        return 0

    def getRowColumnCount(self):
        try:
            tup = self.axistuple[1][0]
            if isinstance(tup, list):
                return len(tup)
            return 1
        except:
            return 0

    def showColumnHeaderRow(self, row):
        return True

    def getColumnRowCell(self, column, row):
        cell = self.axistuple[0][column]
        if isinstance(cell, list):
            cell = cell[row]
        return cell

    def showColumnRowCell(self, column, row):
        cell = self.getColumnRowCell(column, row)
        return getattr(cell, "_tw2_span", 1) > 0

    def getColumnRowCellAttrs(self, column, row):
        cell = self.getColumnRowCell(column, row)
        span = getattr(cell, "_tw2_span", 1)
        attrs = {
            "class":
            "column-heading-even" if column % 2 == 0 else "column-heading-odd"
        }
        if span > 1:
            attrs["colspan"] = span
            attrs["class"] = "column-heading-span"
        return attrs

    def displayColumnRowCell(self, column, row):
        cell = self.getColumnRowCell(column, row)
        caption = cell.Caption
        if self.colHeaderMap:
            return self.colHeaderMap.get(caption, caption)
        return caption

    def getRowColumnCell(self, row, col):
        cell = self.axistuple[1][row]
        if isinstance(cell, list):
            cell = cell[col]
        return cell

    def showRowColumnCell(self, row, col):
        cell = self.getRowColumnCell(row, col)
        return getattr(cell, "_tw2_span", 1) > 0

    def getRowColumnCellDesc(self, row, col):
        e_name = "input"
        e_attrs = self.getRowColumnInputAttrs(row, col)
        e_content = self.displayRowColumnCell(row, col)
        return e_name, e_attrs, e_content

    def getRowColumnCellAttrs(self, row, col):
        cell = self.getRowColumnCell(row, col)
        span = getattr(cell, "_tw2_span", 1)
        attrs = {
            "class": "row-heading-even" if row % 2 == 0 else "row-heading-odd"
        }
        if span > 1:
            attrs["rowspan"] = span
            attrs["class"] = "row-heading-span"
        return attrs

    def getRowColumnDivAttrs(self, row, col):
        cell = self.getRowColumnCell(row, col)
        level = getattr(cell, "LNum", "0")
        attrs = {"style": "margin-left: %sem" % level}
        return attrs

    def getRowColumnInputAttrs(self, row, col):
        cell = self.getRowColumnCell(row, col)
        di = DisplayInfo(getattr(cell, "DisplayInfo", "0"))
        #log.info(cell.Caption + " - dispinfo:" + getattr(cell, "DisplayInfo", "0") + ", dd:"+ (di.isDrilledDown and "YES" or "NO"))
        attrs = {"border": "0", "width": "9", "type": "image", "height": "9"}
        if di.countChildren and self.showTrigger:
            attrs[
                "src"] = self.resources.do_collapse.link if di.isDrilledDown else self.resources.do_expand.link
        else:
            attrs["src"] = self.resources.do_nothing.link
        return attrs

    def displayRowColumnCell(self, row, col):
        cell = self.getRowColumnCell(row, col)
        return cell.Caption

    def showCell(self, row, col):
        return True

    def getCellAttrs(self, row, col):
        attrs = {"class": "cell-even" if row % 2 == 0 else "cell-odd"}
        return attrs

    def getCell(self, row, col):
        if self.slices:
            if isinstance(self.slices[0], list):
                cell = self.slices[row][col]
            else:
                cell = self.slices[col]
            return cell
        return None

    def displayCell(self, row, col):
        cell = self.getCell(row, col)
        if isinstance(self.properties, basestring):
            return cell
        return "override displayRowColumnCell and assemble your cell display"
        return None

    def showRowColumnHeader(self):
        return self.showRowColumnHeaders

    def getRowColumnHeaderAttrs(self, col):
        return {"class": "heading-heading"}

    def displayRowColumnHeader(self, col):
        cell = self.axistuple[1][0]
        if isinstance(cell, list):
            cell = cell[col]
        #import pdb; pdb.set_trace()
        return cell._Hierarchy

    def showRow(self, row):
        """
        Do i want to display that row?
        """
        return True

    def getLeadingRows(self):
        return []

    def getTrailingRows(self):
        return []

    def alterHeadRow(self, row, rowDesc):
        return [rowDesc]

    def alterBodyRow(self, row, rowDesc):
        return [rowDesc]

    def getEmptyRowDesc(self, row):
        attrs = {"colspan": self.getRowColumnCount()}
        return attrs, None

    def spanning(self, src, hier, maxhier, start, end):
        i = start
        startcellspan = None
        if hier == maxhier:
            return
        while i < end:
            cell = src[i][hier]
            if startcellspan == None:
                startcellspan = cell
                startcellspan._tw2_span = 1
            elif startcellspan.UName == cell.UName:
                startcellspan._tw2_span += 1
                cell._tw2_span = 0
            else:
                startcellspan = cell
                startcellspan._tw2_span = 1
                self.spanning(src, hier + 1, maxhier, start, i)
                start = i

            i += 1

        self.spanning(src, hier + 1, maxhier, start, i)
コード例 #26
0
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, see <http://www.gnu.org/licenses/>
#
#
""" Resources for widgets etc """
import tw2.core as twc
from tg import lurl
""" JavaScript Resources """
jquery_js = twc.JSLink(link=lurl('/javascript/jquery.min.js'))
chart_min_js = twc.JSLink(link=lurl('/javascript/chart.min.js'))
bootstrap_table_js = twc.JSLink(
    link=lurl('/javascript/bootstrap-table.min.js'))
c3_min_js = twc.JSLink(link=lurl('/javascript/c3.min.js'))
d3_min_js = twc.JSLink(link=lurl('/javascript/d3.min.js'))
pnotify_core_js = twc.JSLink(link=lurl('/javascript/notify/pnotify.core.js'))
pnotify_buttons_js = twc.JSLink(
    link=lurl('/javascript/notify/pnotify.buttons.js'))
pnotify_nonblock_js = twc.JSLink(
    link=lurl('/javascript/notify/pnotify.nonblock.js'))
""" CSS Resources """
bootstrap_table_css = twc.CSSLink(link=lurl('/css/bootstrap-table.min.css'))
c3_min_css = twc.CSSLink(link=lurl('/css/c3.min.css'))
コード例 #27
0
        """.replace('\n', '')))


## Load our feed tree widgets.
feedtree_engine = config.get('moksha.feedtree.engine', 'live')
if feedtree_engine == 'live':  # Live widgets
    feed_tree = MokshaLiveFeedTree(id='feed_tree')
    feed_entries_tree = MokshaLiveFeedEntriesTree(id='feed_entries_tree')
elif feedtree_engine == 'ajax':  # Ajax widgets
    feed_tree = MokshaAjaxFeedTree(id='feed_tree')
    feed_entries_tree = MokshaAjaxFeedEntriesTree(id='feed_entries_tree')

splitter_js = twc.JSLink(filename='static/splitter.js', modname=__name__)

splitter_css = twc.CSSLink(filename='static/main.css',
                           media='all',
                           modname=__name__)


class MokshaFeedReaderWidget(LiveWidget):
    name = 'Moksha Feed Reader'
    params = ['topic']
    topic = 'moksha.feeds'  # will get replaced by a unique uuid at render-time
    template = 'mako:moksha.widgets.feeds.templates.feedreader'
    resources = [jquery_js, splitter_js, splitter_css]
    css_class = 'moksha-feedreader'

    # Child widgets.
    feed_tree = twc.Param(default=feed_tree)
    feed_entries_tree = twc.Param(default=feed_entries_tree)
コード例 #28
0
import os
import tw2.core as twc
import tw2.forms as twf
from markupsafe import Markup, escape_silent

__all__ = ['CodeMirrorEditor', 'CodeMirrorDisplay']

codemirror_js = twc.JSLink(
    modname=__name__,
    filename='static/lib/codemirror.js',
    fromTextArea=twc.js_function('CodeMirror.fromTextArea'),
)
codemirror_css = twc.CSSLink(
    modname=__name__,
    filename='static/lib/codemirror.css',
)

_codemirror_css = twc.CSSLink(
    modname=__name__,
    filename='static/style.css',
)

# codemirror_util_dir = twc.DirLink(
#     modname=__name__,
#     whole_dir=True,
#     filename='static/lib/util/',
# )

#TODO: Make addons programmatically usable
# codemirror_addons = dict(
#     (d, twc.DirLink(modname=__name__, filename=os.path.join('static/addon', d)))
コード例 #29
0
ファイル: widgets.py プロジェクト: decause/moksha
"""

import tw2.core as twc
from tw2.jquery import jquery_js
from tw2.jquery.base import jQuery

from moksha.lib.helpers import when_ready

modname = __name__

jquery_mbmenu_js = twc.JSLink(modname=modname, filename='static/mbMenu.js')
jquery_mbmenu_min_js = twc.JSLink(modname=modname,
                                  filename='static/mbMenu.min.js')

mbmenu_css_1 = twc.CSSLink(modname=modname,
                           filename='static/css/menu1.css',
                           media='screen')
mbmenu_css = twc.CSSLink(modname=modname,
                         filename='static/css/menu.css',
                         media='screen')
mbmenu_resources = twc.DirLink(modname=modname,
                               filename='static/images',
                               media='screen')


# TODO -- this should be broken out into tw2.jqplugins.mbmenu
class MokshaMenuBase(twc.Widget):
    template = "mako:moksha.apps.menus.templates.mbmenu"
    resources = [
        jquery_js,
        jquery_mbmenu_min_js,
コード例 #30
0
ファイル: widgets.py プロジェクト: toscawidgets/tw2.wysihtml5
import tw2.core as twc
import tw2.forms as twf

__all__ = ['Wysihtml5']

wysihtml5_js = twc.JSLink(filename='static/wysihtml5.js',
                          location='headbottom')
wysihtml5_editor_css = twc.CSSLink(filename='static/editor.css')

wysihtml5_parser_simple = twc.JSLink(filename='static/simple.js',
                                     location='headbottom')
wysihtml5_parser_advanced = twc.JSLink(filename='static/advanced.js',
                                       location='headbottom')
parsers = dict(simple=wysihtml5_parser_simple,
               advanced=wysihtml5_parser_advanced)


class Wysihtml5(twf.TextArea):
    template = "mako:tw2.wysihtml5.templates.wysihtml5"

    resources = [wysihtml5_js]

    parser = twc.Param(
        'The set of parser rules to use. '
        'The simple parser contains only basic html5 tags, while the '
        'advanced parser contains more html5 tags and preserves some '
        'css classes. If you use the simple parser, the editor css is '
        'not strictly needed.',
        default='advanced')
    toolbar_id = twc.Variable(default='wysihtml5-toolbar')