class Root(rend.Page):
    implements(ITodo)
    
    child_css = webform.defaultCSS
    
    docFactory = loaders.stan(
        t.html(render=t.directive("time"))[
            t.head[
                t.title['todo'],
                t.style(type="text/css")[".done { color: #dddddd; }"],
                t.style(type="text/css")["@import url(/css);"]
                ],
            t.body[
                webform.renderForms(),
                t.ul(data=t.directive("findAll"),
                     render=t.directive("sequence"))[
                         t.li(pattern="item",render=t.directive('todo')),
                         t.li(pattern="empty",render=t.directive('empty')),
                ],
                t.p(render=t.directive("end"))
            ]
        ]
    )
    
    def insert(self, ctx, description):
        return itodo.ITodos(ctx).add(description, 0)
    
    def delete(self, ctx, id):
        return itodo.ITodos(ctx).delete(id)

    def update(self, ctx, id, oldstate):
        newstate = [1, 0][oldstate]
        return itodo.ITodos(ctx).update(id, newstate)
        
    def data_findAll(self, ctx, data):
        return itodo.ITodos(ctx).findAll()

    def render_todo(self, ctx, data):
        deluri = "freeform_post!!delete?id="+str(data[0])
        updateuri = "freeform_post!!update?id="+str(data[0])+"&oldstate="+str(data[2])
        state = [" Done", " To Do"][int(data[2])==0]
        tag = ctx.tag
        if data[2]:
            tag = ctx.tag(_class="done")
        return tag[data[1]+" - ",
                   t.a(href=deluri)["Delete"], " / ",
                   t.a(href=updateuri)[("Mark Done", "Mark Undone")[data[2]]],
                   state]

    def render_empty(self, ctx, data):
        return ctx.tag["No Todos"]
    
    def render_time(self, ctx, data):
        ctx.remember(now(), itodo.ITimer)
        return ctx.tag
        
    def render_end(self, ctx, data):
        return ctx.tag["%.3f"%(now()-itodo.ITimer(ctx))]
Beispiel #2
0
class FormBuilder(rend.Page):
    implements(IFormBuilder)
    addSlash = True

    def __init__(self):
        rend.Page.__init__(self)
        self.clearForm()

    def configurable_formBuilder(self, ctx):
        return configurable.TypedInterfaceConfigurable(self)

    def configurable_dynamicForm(self, ctx):
        return self.builderCore

    def addElement(self, name, type):
        self.builderCore.addElement(name, type)

    def clearForm(self):
        self.builderCore = BuilderCore()

    docFactory = loaders.stan(
        T.html[T.head[T.title["Form builder!"]],
               T.style(type="text/css")[open(
                   util.resource_filename('formless', 'freeform-default.css')
               ).read()], T.body[T.h1["Welcome to form builder"],
                                 webform.renderForms('formBuilder'),
                                 T.h2["Here is your form:"],
                                 webform.renderForms('dynamicForm')]])
class ReSTPreview(rend.Page):
    def __init__(self, ctx, restWriter, key, srcId):
        self.restWriter = restWriter

        form = iformal.IForm(ctx)
        u = widgetResourceURLFromContext(
            ctx, form.name).child(key).child(srcId).child('_submit')
        self.destId = srcId + '-dest'
        formId = srcId + '-form'

        stan = T.html(
        )[T.head()[T.script(type="text/javascript")["""
                function ReSTTranslate() {
                    dest = document.getElementById('%(destId)s');
                    form = document.getElementById('%(formId)s');
                    src = parent.document.getElementById('%(srcId)s');
                    dest.value = src.value;
                    form.submit(); 
                }    

                """ %
                                                    {
                                                        'srcId': srcId,
                                                        'destId': self.destId,
                                                        'formId': formId
                                                    }]],
          T.body(
          )[T.form(id=formId, method="POST", action=u
                   )[T.input(type="hidden", name=self.destId, id=self.destId)],
            T.script(type="text/javascript")["ReSTTranslate();"], ], ]

        self.docFactory = loaders.stan(stan)

    def child__submit(self, ctx):
        args = inevow.IRequest(ctx).args
        value = args.get(self.destId, [''])[0]

        from docutils.utils import SystemMessage

        try:
            if self.restWriter:
                restValue = self._html_fragment(value, writer=self.restWriter)
            else:
                restValue = self._html_fragment(value, writer_name='html')
        except SystemMessage, e:
            restValue = str(e)

        stan = T.html()[T.head()[T.style(type="text/css")["""
                
                    .system-message {border: 1px solid red; background-color: #FFFFDD; margin: 5px; padding: 5px;}
                    .system-message-title { font-weight: bold;}
                """]],
                        T.body()[T.div()[T.xml(restValue)]], ]

        self.docFactory = loaders.stan(stan)

        return self
Beispiel #4
0
 def head(self):
     # i think this is the lesser evil.
     # alternatives being:
     #  * mangle form element names so we can put these in mantissa.css
     #    without interfering with similarly named things
     #  * put the following line of CSS into it's own file that is included
     #    by only this page
     #  * remove these styles entirely (makes the form unusable, the
     #    type="text" inputs are *tiny*)
     return tags.style(type='text/css')['''
     input[name=linktext], input[name=subject], textarea[name=blurb] { width: 40em }
     ''']
Beispiel #5
0
 def head(self):
     # i think this is the lesser evil.
     # alternatives being:
     #  * mangle form element names so we can put these in mantissa.css
     #    without interfering with similarly named things
     #  * put the following line of CSS into it's own file that is included
     #    by only this page
     #  * remove these styles entirely (makes the form unusable, the
     #    type="text" inputs are *tiny*)
     return tags.style(type='text/css')['''
     input[name=linktext], input[name=subject], textarea[name=blurb] { width: 40em }
     ''']
Beispiel #6
0
class tabbedPaneGlue:

    _css = util.resource_filename('nevow.taglibrary', "tabbedPane.css")
    _js = util.resource_filename('nevow', "js/Nevow/TagLibrary/TabbedPane.js")

    fileCSS = static.File(_css, 'text/css')
    fileJS = static.File(_js, 'text/javascript')
    fileGlue = (t.link(rel='stylesheet',
                       type='text/css',
                       href='/tabbedPane.css'),
                t.script(type='text/javascript', src='/tabbedPane.js'))

    inlineCSS = t.style(type_='text/css')[t.xml(file(_css).read())]
    inlineJS = t.inlineJS(file(_js).read())
    inlineGlue = inlineJS, inlineCSS
Beispiel #7
0
class progressBarGlue:
    
    _css = util.resource_filename('nevow.taglibrary', "progressBar.css")
    _js = util.resource_filename('nevow.taglibrary', "progressBar.js")
    
    fileCSS = static.Data(_css, 'text/css')
    fileJS = static.Data(_js, 'text/javascript')
    fileGlue = (
        t.link(rel='stylesheet', type_='text/css', href='/progressBar.css'),
        t.script(type_='text/javascript', src='/progressBar.js')
        )
    
    inlineCSS = t.style(type_='text/css')[ t.xml(file(_css).read()) ]
    inlineJS = t.inlineJS(file(_js).read())
    inlineGlue = inlineJS, inlineCSS
class tabbedPaneGlue:
    """
    Record which holds information about the Javascript & CSS requirements
    of L{TabbedPane} and L{TabbedPaneFragment}.

    @type stylesheetPath: C{str}
    @ivar stylesheetPath: Filesystem path of the tabbed pane stylesheet.

    @type javascriptPath: C{str}
    @ivar javascriptPath: Filesystem path of the tabbed pane Javascript
    module.

    @type fileCSS: L{static.File}
    @ivar fileCSS: Resource which serves L{stylesheetPath}.

    @type fileJS: L{static.File}
    @ivar fileJS: Resource which serves L{javascriptPath}.

    @type fileGlue: Stan
    @ivar fileGlue: Stan which, when placed in the <head> of an HTML document,
    will include the required CSS & Javascript.

    @type inlineCSS: L{t.style}
    @ivar inlineCSS: <style> tag containing the tabbedpane CSS inline.

    @type inlineJS: L{t.script}
    @ivar inlineJS: <script> tag containing the tabbedpane Javascript inline.

    @type inlineGlue: Stan
    @ivar inlineGlue: A tuple of L{inlineCSS} and L{inlineJS}.
    """
    stylesheetPath = util.resource_filename('nevow', 'css/Nevow/TagLibrary/TabbedPane.css')
    javascriptPath = util.resource_filename('nevow', 'js/Nevow/TagLibrary/TabbedPane.js')

    fileCSS = static.File(stylesheetPath, 'text/css')
    fileJS = static.File(javascriptPath, 'text/javascript')
    fileGlue = (
        t.link(rel='stylesheet', type='text/css', href='/tabbedPane.css'),
        t.script(type='text/javascript', src='/tabbedPane.js')
        )

    inlineCSS = t.style(type_='text/css')[ t.xml(file(stylesheetPath).read()) ]
    inlineJS = t.inlineJS(file(javascriptPath).read())
    inlineGlue = inlineJS, inlineCSS
Beispiel #9
0
class tabbedPaneGlue:
    """
    Record which holds information about the Javascript & CSS requirements
    of L{TabbedPane} and L{TabbedPaneFragment}.

    @type stylesheetPath: C{str}
    @ivar stylesheetPath: Filesystem path of the tabbed pane stylesheet.

    @type fileCSS: L{static.File}
    @ivar fileCSS: Resource which serves L{stylesheetPath}.

    @type inlineCSS: L{t.style}
    @ivar inlineCSS: <style> tag containing the tabbedpane CSS inline.
    """
    stylesheetPath = util.resource_filename('nevow', 'css/Nevow/TagLibrary/TabbedPane.css')

    fileCSS = static.File(stylesheetPath, 'text/css')

    inlineCSS = t.style(type_='text/css')[ t.xml(file(stylesheetPath).read()) ]
class ResultPage(athena.LivePage):
    addSlash = True
    source = None
    CSS = open(basedir+'/ajaxpb.css').read()
    start = CSS.find('height', CSS.find('resultOut'))
    stop = CSS.find('\n', start)
    css = CSS[:start]+'height: 30em;\n'+CSS[stop:]
    docFactory = loaders.stan(tags.html[
        tags.head(render=tags.directive('liveglue')),
        tags.style(type="text/css")[css],
        tags.body(render=tags.directive('resultElement'))])
    
    def __init__(self, source):
        athena.LivePage.__init__(self)
        self.source = source
    
    def render_resultElement(self, ctx, data):
        f = ResultElement()
        f.setFragmentParent(self)
        reactor.callLater(1, self.source.addGatherer, f)
        return ctx.tag[f]
Beispiel #11
0
            var next = childNode;
        }
    }
    if (next.className == 'collapsed') {
        img.src = '/images/outline-expanded.png';
        next.className = 'expanded';
        head.innerHTML = expandedText;
    } else {
        img.src = '/images/outline-collapsed.png';
        next.className = 'collapsed';
        head.innerHTML = collapsedText;
    }
}//""")

blocks_glue = [
    tags.style(type="text/css")[boxStyle],
    tags.script(type="text/javascript")[tags.comment[js]]
]

mozBinding = """<?xml version="1.0"?>

<bindings xmlns="http://www.mozilla.org/xbl"
          xmlns:xbl="http://www.mozilla.org/xbl"
          xmlns:html="http://www.w3.org/1999/xhtml"
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

<binding id="inlineblock">
  <content>
  <html:style type="text/css">
    .nevow-inline-table { display: inline-table; }
    .nevow-inline-table-row { display: table-row; }
Beispiel #12
0
        try:
            # Check whether it is valid to be loaded
            xml = """<!DOCTYPE html
                    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                    <div xmlns:n="http://nevow.com/ns/nevow/0.1" >""" + restValue + '</div>'

            test = loaders.xmlstr(xml, ignoreDocType=True).load() 
        except Exception, e:
            restValue = "HTML Validation Error: please check any raw HTML blocks."

        stan = T.html()[
            T.head()[
                T.style(type="text/css")["""

                    .system-message {border: 1px solid red; background-color: #FFFFDD; margin: 5px; padding: 5px;}
                    .system-message-title { font-weight: bold;}
                """
                ]
            ],
            T.body()[
                T.div()[
                    T.xml(restValue)
                ]
            ],
        ]

        self.docFactory = loaders.stan(stan)

        return self

    def _html_fragment(self, input_string, writer=None, writer_name=None):
Beispiel #13
0
import calendar
import datetime

from nevow import tags as t, url, itaglibrary, rend, static

_calendar_css = """
.calendar tbody td.today { background-color: #aaaaaa; }
"""

calendarCSS = t.style(type_="text/css")[_calendar_css]
calendarCSSFile = static.File(_calendar_css, "text/css")

class CalendarComponent(object):
    current_date = None
    def days(self, year, month):
        def _(ctx, data):
            return [[day and datetime.date(year, month, day) or None
                     for day in row]
                         for row in calendar.monthcalendar(year, month)]
        return _

    def render_calendarDay(self, ctx, data):
        options = itaglibrary.ICalendarOptions(ctx, {})
        today_class = options.get('today_class', 'today')
        if data is None:
            return ctx.tag['']
        if self.current_date.day == data.day and \
           self.current_date.month == data.month and \
           self.current_date.year == data.year:
            return ctx.tag(class_=today_class)[data.day] 
        return ctx.tag[data.day]
Beispiel #14
0
stylesheet = T.style(type="text/css")["""
@import "css";

body { margin: 0px; font-family: "gill sans" sans-serif; background-color: #f5f5f5; }
h1 { background-color: #dddddd; font-size: large; }
h2 { font-size: medium; }
h1,h2,form,table { padding: 7px; margin: 0px; }
form { background-color: #f5f5f5; }
p { margin: 5px; }
label { margin-left: 5px; cursor: pointer; }

#message {
    margin-bottom: 0.25em;
    padding: 0.25em;
    color: green;
    background-color: #efefef; }

.tab {
    background-color: #f5f5f5; }

.tab-selected {
    background-color: #ccccee;
    text-decoration: underline; }

.tab,.tab-selected {
    cursor: pointer;
    display: inline-block;
    padding: 15px;
    padding-top: 4px;
    padding-bottom: 4px; }

img { border: 0px; }

.header-line {
    white-space: nowrap;
    padding-top: 4px; }

.mode-switch { float: right; }

table { width: 100%; }
th { text-align: left; }
"""]
Beispiel #15
0
 def head(self):
     #XXX put this in its own CSS file?
     return tags.style(type='text/css')['''
     input[name=linktext], input[name=subject], textarea[name=blurb] { width: 40em }
     ''']
Beispiel #16
0
from nevow import tags as t, static, livepage as le

def _locateFile(filename):
    import os.path
    dirname = os.path.abspath(os.path.dirname(__file__))
    return os.path.join(dirname, filename)

_tp_style_fn = _locateFile("tabbedPane-style.css")
_tp_layout_fn = _locateFile("tabbedPane-layout.css")
_tp_JS = _locateFile("tabbedPane.js")

tabbedPaneStyle = t.style(type_='text/css')[
    open(_tp_style_fn).read()
    ]
tabbedPaneLayout = t.style(type_='text/css')[
    open(_tp_layout_fn).read()
    ]
tabbedPaneJS = t.inlineJS(
    open(_tp_JS).read()
    )

tabbedPaneHeadInline = t.invisible[
    tabbedPaneStyle,
    tabbedPaneLayout,
    tabbedPaneJS,
]

tabbedPaneStyleFile = static.File(_tp_style_fn, 'text/css')
tabbedPaneLayoutFile = static.File(_tp_layout_fn, 'text/css')
tabbedPaneJSFile = static.File(_tp_JS, 'text/javascript')
Beispiel #17
0
    def statusPage(self):
        title = 'sparqlhttp server status'

        prof = QueryProfileView(self)
        prof.original = self
        profStan = prof.rend(None)

        upHours = (time.time() - self.powerOnTime) / 3600
        oneLine = (self.lastQuery or '').replace('\n', ' ')

        return str(
            flat.flatten(T.html[
                T.head[T.title[title],
                       T.style(type="text/css")['''
                       span, div {
                         font-family: sans-serif;
                       }
                       div.one-line-query {
                         border: 1px solid #ccc;
                         padding: .2em;
                         background: #f8f8ff;
                       }
                       h2 {
                         color: #6e5636;
                         margin-left: -.5em;
                       }

                       table, td, th {
                          border-top: 1px solid #ddd;
                          border-collapse: collapse;
                        }
                        th, table {
                          border-top: 0px;
                        }
                        th {
                          font-size: 80%;
                          padding-left: .5em;
                          padding-right: .5em;
                        }
                        div.section {
                          padding: 3px;
                          margin-bottom: 6px;
                  
                          margin-left: 1em;
                        }
                        span, th {
                          color:#A2927E;
                          font-style:italic;
                        }
                        '''], ],
                T.body[T.h1[title],
                       T.div(class_="section")[T.h2["Stats"],
                                               T.div[T.span["Up for "],
                                                     "%.1f" % upHours,
                                                     T.span[" hours"]],
                                               T.div[self.queries,
                                                     T.span[" queries"]]],
                       T.div(
                           class_="section")[T.h2["Last error"],
                                             T.div[T.span["query: "],
                                                   T.pre[self.lastErrorQuery]],
                                             T.div[T.span["error: "],
                                                   T.pre[self.lastError]]],
                       T.div(class_="section")[
                           T.h2["Last query"],
                           T.pre[reindent(self.lastQuery)],
                           T.span["Again, as one line:"],
                           T.div(class_="one-line-query")[oneLine], ],
                       T.div(class_="section")[
                           T.h2["All query types, by total time spent"],
                           profStan], ]]))
Beispiel #18
0
 def render_stylesheet(self, context, data):
     return tags.style(type="text/css")[self.getStyleSheet()]
Beispiel #19
0
class BabyTable(rend.Page):
    addSlash = True
    docFactory = loaders.stan(T.html[T.head[
        T.title["Baby event table"],
        T.style(type="text/css")[T.raw('''
        body {
          width: 1000px;
          font-family: sans-serif;
          color: #333;
        }
        table { border-collapse: collapse; }
        td {
          white-space: nowrap;
          padding: 0 3px;
        }
        div.bar {
          position: relative;
          background: #eee;
        }
        div.bar .fill {
          position:absolute; 
        }
        div.bar .txt {
          position:absolute; 
        }
        ''')],
        T.
        meta(name="viewport",
             content=
             "width=500; initial-scale=1.0; minimum-scale: .01; user-scalable=yes"
             ), ], T.body[T.h1['Baby events'],
                          T.directive('table')]])

    def __init__(self, graph):
        self.graph = graph
        rend.Page.__init__(self)

    def render_table(self, ctx, data):
        rows = []
        for row in self.graph.queryd("""
          SELECT DISTINCT ?cmd ?t WHERE {
           {
             ?iss cl:command cmd:BabyStart .
           } UNION {
             ?iss cl:command cmd:BabyStop .
           }
           ?iss
              dcterms:created ?t ;
              cl:command ?cmd ;
              a cl:IssuedCommand .
           FILTER ( ?t > "2009-07-25T00:00:00Z"^^xs:dateTime )
          } ORDER BY ?t"""):
            t = time.mktime(parse(row['t']).timetuple())
            rows.append((t, row['cmd'], row['t']))

        label = {CMD.BabyStart: 'start', CMD.BabyStop: 'stop'}

        def cleanTime(isot):
            m = re.match(r"^(....-..-..)T(..:..:..)", isot)
            return "%s %s" % (m.group(1), m.group(2))

        def prettyElapsed(sec):
            return "%.1f min" % (sec / 60)

        trs = []

        lastStart = None
        lastStop = None
        for row in rows:
            t, cmd, isot = row
            if cmd == CMD.BabyStart:
                if lastStart is not None:
                    period = t - lastStart[0]
                    cols = [
                        T.td[cleanTime(isot)],
                        T.td[divBar("%s since prev" % prettyElapsed(period),
                                    200, period / 600, "#f88")],
                    ]
                    if lastStop is not None:
                        dur = lastStop[0] - lastStart[0]
                        cols.append(T.td[divBar(
                            "duration %s" % prettyElapsed(dur), 150, dur / 200,
                            "#8c3")])
                    trs.append(T.tr[cols])
                lastStart = row
                lastStop = None
            if cmd == CMD.BabyStop:
                lastStop = row

        return T.table[trs]
Beispiel #20
0
from nevow import tags as t, static, livepage as le


def _locateFile(filename):
    import os.path
    dirname = os.path.abspath(os.path.dirname(__file__))
    return os.path.join(dirname, filename)


_tp_style_fn = _locateFile("tabbedPane-style.css")
_tp_layout_fn = _locateFile("tabbedPane-layout.css")
_tp_JS = _locateFile("tabbedPane.js")

tabbedPaneStyle = t.style(type_='text/css')[open(_tp_style_fn).read()]
tabbedPaneLayout = t.style(type_='text/css')[open(_tp_layout_fn).read()]
tabbedPaneJS = t.inlineJS(open(_tp_JS).read())

tabbedPaneHeadInline = t.invisible[tabbedPaneStyle, tabbedPaneLayout,
                                   tabbedPaneJS, ]

tabbedPaneStyleFile = static.File(_tp_style_fn, 'text/css')
tabbedPaneLayoutFile = static.File(_tp_layout_fn, 'text/css')
tabbedPaneJSFile = static.File(_tp_JS, 'text/javascript')

tabbedPaneHeadFiles = t.invisible[
    t.link(rel='stylesheet', type='text/css', href='/tabbedPane-style.css'),
    t.link(rel='stylesheet', type='text/css', href='/tabbedPane-layout.css'),
    t.script(type='text/javascript', src='/tabbedPane.js'), ]


class TabbedPane(object):
Beispiel #21
0
    def statusPage(self):
        title = 'sparqlhttp server status'

        prof = QueryProfileView(self)
        prof.original = self
        profStan = prof.rend(None)

        upHours = (time.time() - self.powerOnTime) / 3600
        oneLine = (self.lastQuery or '').replace('\n',' ')
        
        return str(flat.flatten(T.html[
            T.head[T.title[title],
                   T.style(type="text/css")['''
                       span, div {
                         font-family: sans-serif;
                       }
                       div.one-line-query {
                         border: 1px solid #ccc;
                         padding: .2em;
                         background: #f8f8ff;
                       }
                       h2 {
                         color: #6e5636;
                         margin-left: -.5em;
                       }

                       table, td, th {
                          border-top: 1px solid #ddd;
                          border-collapse: collapse;
                        }
                        th, table {
                          border-top: 0px;
                        }
                        th {
                          font-size: 80%;
                          padding-left: .5em;
                          padding-right: .5em;
                        }
                        div.section {
                          padding: 3px;
                          margin-bottom: 6px;
                  
                          margin-left: 1em;
                        }
                        span, th {
                          color:#A2927E;
                          font-style:italic;
                        }
                        '''],
                   ],
            T.body[
              T.h1[title],

              T.div(class_="section")[T.h2["Stats"],
                                      T.div[T.span["Up for "],
                                            "%.1f" % upHours, T.span[" hours"]],
                                      T.div[self.queries, T.span[" queries"]]],
              T.div(class_="section")[T.h2["Last error"],
                                      T.div[T.span["query: "],
                                            T.pre[self.lastErrorQuery]],
                                      T.div[T.span["error: "],
                                            T.pre[self.lastError]]],
              T.div(class_="section")[T.h2["Last query"],
                                      T.pre[reindent(self.lastQuery)],
                                      T.span["Again, as one line:"],
                                      T.div(class_="one-line-query")[oneLine],
                     ],
                
              T.div(class_="section")[T.h2["All query types, by total time spent"],
                                      profStan],
              
              ]
            ]))
Beispiel #22
0
 def render_stylesheet(self, context, data):
     return tags.style(type="text/css")[self.getStyleSheet()]
Beispiel #23
0
    width: 50%;
    height: 15px;
    border-style: solid;
    border-width: 1px;
}
.progressbar div {
    height: 15px;
    background-color: #aaaaaa;
}
"""

progressGlueJS = static.File(_progress_glue, "text/javascript")
progressGlue = t.inlineJS(_progress_glue)

progressCSSFile = static.File(_progress_css, "text/css")
progressCSS = t.style(type_="text/css")[_progress_css]


class ProgressBarComponent(object):
    def progressBar(self, ctx, data):
        name = data.get("name", "progressbar")
        start_perc = data.get("start", 0)
        bar = t.div(id_=str(name), class_="progressbar")
        meter = t.div(id_="%s_meter" % str(name))
        return bar[meter(style="width:%s%%" % (start_perc))]


progressBar = ProgressBarComponent().progressBar


__all__ = ["progressGlueJS", "progressGlue", "progressBar", "progressCSS", "progressCSSFile"]
Beispiel #24
0
import calendar
import datetime

from nevow import tags as t, url, itaglibrary, rend, static

_calendar_css = """
.calendar tbody td.today { background-color: #aaaaaa; }
"""

calendarCSS = t.style(type_="text/css")[_calendar_css]
calendarCSSFile = static.File(_calendar_css, "text/css")


class CalendarComponent(object):
    current_date = None

    def days(self, year, month):
        def _(ctx, data):
            return [[
                day and datetime.date(year, month, day) or None for day in row
            ] for row in calendar.monthcalendar(year, month)]

        return _

    def render_calendarDay(self, ctx, data):
        options = itaglibrary.ICalendarOptions(ctx, {})
        today_class = options.get('today_class', 'today')
        if data is None:
            return ctx.tag['']
        if self.current_date.day == data.day and \
           self.current_date.month == data.month and \
Beispiel #25
0
def formatFailure(myFailure):
    if not isinstance(myFailure, failure.Failure):
        return t.pre[str(myFailure)]

    stackTrace = t.div(_class="stackTrace")
    failureOverview = t.p(_class="error")[str(myFailure.type), ": ",
                                          str(myFailure.value)]

    result = [
        t.style(type="text/css")[stylesheet, ],
        t.a(href="#tracebackEnd")[failureOverview], stackTrace,
        t.a(name="tracebackEnd")[failureOverview]
    ]

    first = 1
    for method, filename, lineno, localVars, globalVars in myFailure.frames:
        # It's better to have a line number than nothing at all.
        #if filename == '<string>':
        #    continue
        if first:
            frame = t.div(_class="firstFrame")
            first = 0
        else:
            frame = t.div(_class="frame")
        stackTrace[frame]

        snippet = t.div(_class="snippet")
        frame[t.div(_class="location")[filename, ", line ", lineno, " in ",
                                       t.span(_class="function")[method]],
              snippet, ]

        textSnippet = ''
        for snipLineNo in range(lineno - 2, lineno + 2):
            snipLine = linecache.getline(filename, snipLineNo)
            textSnippet += snipLine
            if snipLineNo == lineno:
                snippetClass = "snippetHighlightLine"
            else:
                snippetClass = "snippetLine"
            snippet[t.div(_class=snippetClass)[t.span(
                _class="lineno")[snipLineNo],
                                               t.pre(_class="code")[snipLine]]]

        # Instance variables
        for name, var in localVars:
            if name == 'self' and hasattr(var, '__dict__'):
                usedVars = [(key, value)
                            for (key, value) in var.__dict__.items()
                            if re.search(r'\Wself.%s\W' %
                                         (re.escape(key), ), textSnippet)]
                if usedVars:
                    frame[t.div(_class="variables")[t.strong(
                        _class="variableClass")["Self"],
                                                    varTable(usedVars)]]
                    break

        # Local and global vars
        for nm, varList in ('Locals', localVars), ('Globals', globalVars):
            usedVars = [
                (name, var) for (name, var) in varList
                if re.search(r'\W%s\W' % (re.escape(name), ), textSnippet)
            ]
            if usedVars:
                frame[t.div(_class="variables")[t.strong(
                    _class="variableClass")[nm]],
                      varTable(usedVars)]

    return result
Beispiel #26
0
    }
    node.style['width'] = val+'%';
}
"""
_progress_css = """
.progressbar {
    width: 50%;
    height: 15px;
    border-style: solid;
    border-width: 1px;
}
.progressbar div {
    height: 15px;
    background-color: #aaaaaa;
}
"""
progressGlueJS = static.File(_progress_glue, 'text/javascript')
progressGlue = t.inlineJS(_progress_glue)
progressCSSFile = static.File(_progress_css, 'text/css')
progressCSS = t.style(type_='text/css')[_progress_css]
class ProgressBarComponent(object):
    def progressBar(self, ctx, data):
        name = data.get('name', 'progressbar')
        start_perc = data.get('start', 0)
        bar = t.div(id_=str(name), class_="progressbar")
        meter = t.div(id_="%s_meter" % str(name))
        return bar[meter(style="width:%s%%" % (start_perc))]
progressBar = ProgressBarComponent().progressBar
__all__ = ["progressGlueJS", "progressGlue", "progressBar",
           "progressCSS", "progressCSSFile"]
Beispiel #27
0
def formatFailure(myFailure):
    if not isinstance(myFailure, failure.Failure):
        return t.pre[ str(myFailure) ]

    stackTrace = t.div(_class="stackTrace")
    failureOverview = t.p(_class="error")[ str(myFailure.type), ": ", str(myFailure.value) ]

    result = [
        t.style(type="text/css")[
            stylesheet,
        ],
        t.a(href="#tracebackEnd")[ failureOverview ],
        stackTrace,
        t.a(name="tracebackEnd")[ failureOverview ]
    ]

    first = 1
    for method, filename, lineno, localVars, globalVars in myFailure.frames:
        # It's better to have a line number than nothing at all.
        #if filename == '<string>':
        #    continue
        if first:
            frame = t.div(_class="firstFrame")
            first = 0
        else:
            frame = t.div(_class="frame")
        stackTrace[ frame ]

        snippet = t.div(_class="snippet")
        frame[
            t.div(_class="location")[
                filename, ", line ", lineno, " in ", t.span(_class="function")[ method ]
            ],
            snippet,
        ]

        textSnippet = ''
        for snipLineNo in range(lineno-2, lineno+2):
            snipLine = linecache.getline(filename, snipLineNo)
            textSnippet += snipLine
            if snipLineNo == lineno:
                snippetClass = "snippetHighlightLine"
            else:
                snippetClass = "snippetLine"
            snippet[
                t.div(_class=snippetClass)[
                    t.span(_class="lineno")[ snipLineNo ],
                    t.pre(_class="code")[ snipLine ]
                ]
            ]

        # Instance variables
        for name, var in localVars:
            if name == 'self' and hasattr(var, '__dict__'):
                usedVars = [ (key, value) for (key, value) in var.__dict__.items()
                             if re.search(r'\Wself.%s\W' % (re.escape(key),), textSnippet) ]
                if usedVars:
                    frame[
                        t.div(_class="variables")[
                            t.strong(_class="variableClass")[ "Self" ],
                            varTable(usedVars)
                        ]
                    ]
                    break

        # Local and global vars
        for nm, varList in ('Locals', localVars), ('Globals', globalVars):
            usedVars = [ (name, var) for (name, var) in varList
                         if re.search(r'\W%s\W' % (re.escape(name),), textSnippet) ]
            if usedVars:
                frame[
                    t.div(_class="variables")[ t.strong(_class="variableClass")[ nm ] ],
                    varTable(usedVars)
                ]

    return result
Beispiel #28
0
            var next = childNode;
        }
    }
    if (next.className == 'collapsed') {
        img.src = '/images/outline-expanded.png';
        next.className = 'expanded';
        head.innerHTML = expandedText;
    } else {
        img.src = '/images/outline-collapsed.png';
        next.className = 'collapsed';
        head.innerHTML = collapsedText;
    }
}//""")

blocks_glue = [
    tags.style(type="text/css")[ boxStyle ],
    tags.script(type="text/javascript")[ tags.comment[js] ]]


mozBinding = """<?xml version="1.0"?>

<bindings xmlns="http://www.mozilla.org/xbl"
          xmlns:xbl="http://www.mozilla.org/xbl"
          xmlns:html="http://www.w3.org/1999/xhtml"
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

<binding id="inlineblock">
  <content>
  <html:style type="text/css">
    .nevow-inline-table { display: inline-table; }
    .nevow-inline-table-row { display: table-row; }
Beispiel #29
0
    width: 50%;
    height: 15px;
    border-style: solid;
    border-width: 1px;
}
.progressbar div {
    height: 15px;
    background-color: #aaaaaa;
}
"""

progressGlueJS = static.File(_progress_glue, 'text/javascript')
progressGlue = t.inlineJS(_progress_glue)

progressCSSFile = static.File(_progress_css, 'text/css')
progressCSS = t.style(type_='text/css')[_progress_css]


class ProgressBarComponent(object):
    def progressBar(self, ctx, data):
        name = data.get('name', 'progressbar')
        start_perc = data.get('start', 0)
        bar = t.div(id_=str(name), class_="progressbar")
        meter = t.div(id_="%s_meter" % str(name))
        return bar[meter(style="width:%s%%" % (start_perc))]


progressBar = ProgressBarComponent().progressBar

__all__ = [
    "progressGlueJS", "progressGlue", "progressBar", "progressCSS",