moksha.wsgi.widgets.all

A module that imports all known widgets.

This is currently used by the archive_tw_resources setuptools command, which archives all of the resources used by all ToscaWidgets.

MokshaContainer
Moksha Container
    class MokshaContainer(twc.Widget):
        template = 'mako:moksha.wsgi.widgets.container.templates.container'
        resources = [container_js, container_css]
        options = ['draggable', 'resizable']
        button_options = ['iconize', 'minimize', 'close']
        params = ['buttons', 'skin', 'height', 'width', 'left', 'top', 'id',
                  'title', 'icon', 'content', 'widget_name', 'view_source', 'dock',
                  'onResize', 'onClose', 'onCollapse', 'onIconize', 'onDrag',
                  'onRestore'] + options[:]
        draggable = droppable = True
        resizable = False
        iconize = minimize = close = True
        hidden = True  # hide from the moksha menu
        content = ''  # either text, or a Widget instance
        widget_name = ''
        title = 'Moksha Container'
        skin = 'default'  # default, black, white, stiky, alert
        view_source = True
        dock = 'moksha_dock'
        icon = 'gears.png'
        # Pixel tweaking
        width = 450
        height = 500
        left = 170
        top = 125
        # Javascript callbacks
        onResize = "function(o){}"
        onClose = "function(o){}"
        onCollapse = "function(o){}"
        onIconize = "function(o){}"
        onDrag = "function(o){}"
        onRestore = "function(o){}"
        def prepare(self):
            super(MokshaContainer, self).prepare()
            if self.content and not isinstance(self.content,
                                               tw2.core.widgets.WidgetMeta):
                # This does not have to be cause for ultra-alarm.  We could take
                # care to render tw1 widgets inside tw2 widgets, but I'm throwing
                # hard errors here so I don't mess up jquery dependencies.
                raise ValueError("non-tw2 widget found inside tw2 container")
            # If we weren't passed a widget_name explicitly, then take a guess.
            if not getattr(self, 'widget_name') and hasattr(self.content, 'id'):
                self.widget_name = self.content.id
            content_args = getattr(self, 'content_args', {})
            if isinstance(self.content, (LiveWidget, LiveWidgetMeta)):
                topics = self.content.get_topics()
                # FIXME: also unregister the moksha callback functions.  Handle
                # cases where multiple widgets are listening to the same topics
                obj = self.content.req()
                if not isinstance(unsubscribe_topics(obj, topics), basestring):
                    raise ValueError('wtf')
                self.onClose = "function(o){%s $(o).remove();}" % \
                    unsubscribe_topics(obj, topics)
                self.onIconize = self.onCollapse = "function(o){%s}" % \
                    unsubscribe_topics(obj, topics)
                self.onRestore = "function(o){%s}" % \
                    subscribe_topics(obj, topics)
            if self.content:
                self.content = self.content.display(**content_args)
            for option in self.options:
                setattr(self, option, getattr(self, option, True) and option or '')
            self.buttons = ''
            for button in self.button_options:
                if getattr(self, button, True):
                    self.buttons += '%s,' % button[:1]
            self.buttons = self.buttons[:-1]
            self.id = str(uuid.uuid4())
            self.elementsPath = '/tw2/resources/moksha.wsgi.widgets.container.container/static/css/elements/'
    
    <%namespace name="tw" module="tw2.core.mako_util"/>
    <div id="${tw._('id')}" class="containerPlus ${tw._('draggable')} ${tw._('resizable')}" style="top:${str(tw._('top'))}px;left:${str(tw._('left'))}px" buttons="${tw._('buttons')}" skin="${tw._('skin')}" icon="${tw._('icon')}" width="${str(tw._('width'))}" height="${str(tw._('height'))}" dock="${tw._('dock')}">
        <div class="no">
            <div class="ne">
                <div class="n">${tw._('title')}</div>
            </div>
            <div class="o">
                <div class="e">
                    <div class="c">
                        <div class="content">
                          ${tw._('content')}
                        % if tw._('view_source'):
                          <a href="#" onclick="$.ajax({
                                  url: moksha.url('/widgets/code_widget?chrome=True&source=${tw._('widget_name')}'),
                                  success: function(r, s) {
                                      $('body').append(moksha.filter_resources(r));
                                  }
                              });
                              return false;">View Source</a>
                          % endif
                        </div>
                    </div>
                </div>
            </div>
            <div>
                <div class="so">
                    <div class="se">
                        <div class="s"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
    	$('#${tw._("id")}').buildContainers({
    		'elementsPath': "${tw._('elementsPath')|n}",
    		'onClose': ${tw._('onClose')|n},
    		'onResize': ${tw._('onResize')|n},
    		'onCollapse': ${tw._('onCollapse')|n},
    		'onIconize': ${tw._('onIconize')|n},
    		'onDrag': ${tw._('onDrag')|n},
    		'onRestore': ${tw._('onRestore')|n},
    	});
    });
    </script>