示例#1
0
def sect_markup(txt, name):

    res = ''
    idx = 0
    links = []

    while 1:
        prev_idx = idx
        idx = txt.find("L#{", idx)
        if idx == -1:
            res += txt[prev_idx:]
            break

        beg = txt[prev_idx:idx]
        idx += 3
        i = txt.find("}", idx)
        if i == -1:
            res += txt[prev_idx:]
            break

        if i == len(txt)-1:
            url = txt[idx:]
            end = ''
        else:
            url = txt[idx:i]
            end = txt[i+1:]

        res += beg
        idx = i+1

        page_url = "%s_" % name
        page_url += url.lower()
        i = HTMLPanel.createUniqueId()

        res += "<span id='%s'></span>" % str(i)

        links.append([i, Hyperlink(url, False, page_url)])

    if not links:
        return HTML(res)

    p = HTMLPanel(res)

    for il in links:
        i = il[0]
        l = il[1]
        p.add(l, i)

    return p
示例#2
0
文件: Chapter.py 项目: Afey/pyjs
def sect_markup(txt, name):

    res = ''
    idx = 0
    links = []

    while 1:
        prev_idx = idx
        idx = txt.find("L#{", idx)
        if idx == -1:
            res += txt[prev_idx:]
            break

        beg = txt[prev_idx:idx]
        idx += 3
        i = txt.find("}", idx)
        if i == -1:
            res += txt[prev_idx:]
            break

        if i == len(txt)-1:
            url = txt[idx:]
            end = ''
        else:
            url = txt[idx:i]
            end = txt[i+1:]

        res += beg
        idx = i+1

        page_url = "%s_" % name
        page_url += url.lower()
        i = HTMLPanel.createUniqueId()

        res += "<span id='%s'></span>" % str(i)

        links.append([i, Hyperlink(url, False, page_url)])

    if not links:
        return HTML(res)

    p = HTMLPanel(res)

    for il in links:
        i = il[0]
        l = il[1]
        p.add(l, i)

    return p
示例#3
0
    def __init__(self, topPanel):
        TickeryTab.__init__(self, topPanel)
        # Get the query string and wanted tab, if any, from URL args.
        args = Window.getLocation().getSearchDict()
        query = args.get('query')
        wantedTab = args.get('tab')
        if wantedTab:
            wantedTab = wantedTab.lower()
        if query and wantedTab == self.tabName.lower():
            query = urllib.unquote_plus(query)
            self.autoActivate = True
        else:
            query = self.defaultQuery
            
        self.instructions.setHorizontalAlignment(HasAlignment.ALIGN_LEFT)
        self.instructions.setStyleName('instructions-popup')
        self.popup = InstructionBox(
            self.__class__.__name__, self.instructions)
        self.popup.setText(self.instructionsTitle)
        self.db = Button(HELP_TEXT, StyleName='help-button')
        self.db.addClickListener(self)

        huhId = HTMLPanel.createUniqueId()
        help = HTMLPanel('%s <span id="%s"></span>' %
                             (SHORT_INSTRUCTIONS[self.tabName], huhId),
                             StyleName='simple-instructions')
        help.add(self.db, huhId)
        
        self.goButton = go.GoButton(self)
        self.query = text.TextAreaFocusHighlight(Text=query,
                                                 VisibleLines=3,
                                                 StyleName='large-query-area')
        self.checkResult = HorizontalPanel(Spacing=4)
        
        mainGrid = Grid(2, 2, StyleName='tickery-tab-panel',
                        HorizontalAlignment=HasAlignment.ALIGN_LEFT)
        formatter = mainGrid.getCellFormatter()
        mainGrid.setWidget(0, 0, help)
        mainGrid.setWidget(1, 0, self.query)
        mainGrid.setWidget(1, 1, self.goButton)
        formatter.setHorizontalAlignment(0, 0, 'left')
        formatter.setHorizontalAlignment(1, 0, 'left')
        formatter.setAlignment(1, 1, 'left', 'bottom')
        self.topGrid.setWidget(0, 1, mainGrid)
        
        self.add(self.checkResult)
        self.results = userlist.UserListPanel(self, topPanel,
            HorizontalAlignment=HasAlignment.ALIGN_LEFT)
        self.add(self.results)
示例#4
0
    def __init__(self):
        SimplePanel.__init__(self)

        id1 = HTMLPanel.createUniqueId()
        id2 = HTMLPanel.createUniqueId()

        panel = HTMLPanel('<b>This is some HTML</b><br>' +
                          'First widget:<span id="' + id1 + '"></span><br>' +
                          'Second widget:<span id="' + id2 + '"></span><br>' +
                          'More <i>HTML</i>',
                          Width="150px")

        panel.add(Button("Hi there"), id1)
        panel.add(Label("This label intentionally left blank"), id2)

        self.add(panel)
示例#5
0
文件: htmlPanel.py 项目: Afey/pyjs
    def __init__(self):
        SimplePanel.__init__(self)

        id1 = HTMLPanel.createUniqueId()
        id2 = HTMLPanel.createUniqueId()

        panel = HTMLPanel('<b>This is some HTML</b><br>' +
                          'First widget:<span id="' + id1 + '"></span><br>' +
                          'Second widget:<span id="' + id2 + '"></span><br>' +
                          'More <i>HTML</i>',
                          Width="150px")

        panel.add(Button("Hi there"), id1)
        panel.add(Label("This label intentionally left blank"), id2)

        self.add(panel)
示例#6
0
文件: Showcase.py 项目: Afey/pyjs
    def showDemo(self, name):
        """ Show the demonstration with the given name.
        """
        if self._curContents is not None:
            self._rightPanel.remove(self._curContents)
            self._curContents = None

        demo = None
        for d in self._demos:
            if d['name'] == name:
                demo = d
                break

        if demo is not None:
            exampleID = HTMLPanel.createUniqueId()

            html = []
            html.append('<div style="padding:20px">')
            html.append('<b>' + demo['title'] + '</b>')
            html.append('<p/>')
            html.append(self.docToHTML(demo['doc']))
            html.append('<p/>')
            html.append('<hr/>')
            html.append('<b>Working Example</b>')
            html.append('<p/>')
            html.append('<div style="padding-left:20px">')
            html.append('<span id="' + exampleID + '"></span>')
            html.append('</div>')
            html.append('<p/>')
            html.append('<hr/>')
            html.append('<b>Source Code</b>')
            html.append('<p/>')
            html.append(self.srcToHTML(demo['src']))
            html.append('</div>')

            panel = HTMLPanel("\n".join(html))
            panel.add(demo['example'], exampleID)

            self._rightPanel.add(panel)
            self._curContents = panel
        else:
            self._rightPanel.add(self._introPanel)
            self._curContents = self._introPanel
示例#7
0
    def showDemo(self, name):
        """ Show the demonstration with the given name.
        """
        if self._curContents is not None:
            self._rightPanel.remove(self._curContents)
            self._curContents = None

        demo = None
        for d in self._demos:
            if d['name'] == name:
                demo = d
                break

        if demo is not None:
            exampleID = HTMLPanel.createUniqueId()

            html = []
            html.append('<div style="padding:20px">')
            html.append('<b>' + demo['title'] + '</b>')
            html.append('<p/>')
            html.append(self.docToHTML(demo['doc']))
            html.append('<p/>')
            html.append('<hr/>')
            html.append('<b>Working Example</b>')
            html.append('<p/>')
            html.append('<div style="padding-left:20px">')
            html.append('<span id="' + exampleID + '"></span>')
            html.append('</div>')
            html.append('<p/>')
            html.append('<hr/>')
            html.append('<b>Source Code</b>')
            html.append('<p/>')
            html.append(self.srcToHTML(demo['src']))
            html.append('</div>')

            panel = HTMLPanel("\n".join(html))
            panel.add(demo['example'], exampleID)

            self._rightPanel.add(panel)
            self._curContents = panel
        else:
            self._rightPanel.add(self._introPanel)
            self._curContents = self._introPanel
示例#8
0
    def __init__(self):
        Sink.__init__(self)

        text="""This is a <code>ScrollPanel</code> contained at 
        the center of a <code>DockPanel</code>. 
        By putting some fairly large contents 
        in the middle and setting its size explicitly, it becomes a 
        scrollable area within the page, but without requiring the use of 
        an IFRAME.
        Here's quite a bit more meaningless text that will serve primarily 
        to make this thing scroll off the bottom of its visible area.  
        Otherwise, you might have to make it really, really small in order 
        to see the nifty scroll bars!"""
        
        contents = HTML(text)
        scroller = ScrollPanel(contents, StyleName="ks-layouts-Scroller")
        
        dock = DockPanel(HorizontalAlignment=HasAlignment.ALIGN_CENTER,
                         Spacing=10)
        north0 = HTML("This is the <i>first</i> north component", True)
        east = HTML("<center>This<br>is<br>the<br>east<br>component</center>", True)
        south = HTML("This is the south component")
        west = HTML("<center>This<br>is<br>the<br>west<br>component</center>", True)
        north1 = HTML("This is the <b>second</b> north component", True)
        dock.add(north0, DockPanel.NORTH)
        dock.add(east, DockPanel.EAST)
        dock.add(south, DockPanel.SOUTH)
        dock.add(west, DockPanel.WEST)
        dock.add(north1, DockPanel.NORTH)
        dock.add(scroller, DockPanel.CENTER)
        
        #Logger.write("Layouts", "TODO: flowpanel")
        flow = FlowPanel()
        for i in range(8):
            flow.add(CheckBox("Flow %d" % i))

        horz = HorizontalPanel(VerticalAlignment=HasAlignment.ALIGN_MIDDLE)
        horz.add(Button("Button"))
        horz.add(HTML("<center>This is a<br>very<br>tall thing</center>", True))
        horz.add(Button("Button"))

        vert = VerticalPanel(HorizontalAlignment=HasAlignment.ALIGN_CENTER)
        vert.add(Button("Small"))
        vert.add(Button("--- BigBigBigBig ---"))
        vert.add(Button("tiny"))

        menu = MenuBar()
        menu0 = MenuBar(True)
        menu1 = MenuBar(True)
        menu.addItem("menu0", menu0)
        menu.addItem("menu1", menu1)
        menu0.addItem("child00")
        menu0.addItem("child01")
        menu0.addItem("child02")
        menu1.addItem("child10")
        menu1.addItem("child11")
        menu1.addItem("child12")

        #Logger.write("Layouts", "TODO: htmlpanel")
        id = HTMLPanel.createUniqueId()
        text="""This is an <code>HTMLPanel</code>.  It allows you to add 
            components inside existing HTML, like this: <span id='%s' />
            Notice how the menu just fits snugly in there?  Cute.""" % id
        html = HTMLPanel(text)
        
        DOM.setStyleAttribute(menu.getElement(), "display", "inline")
        html.add(menu, id)

        disclose = DisclosurePanel("Click to disclose")
        disclose.add(HTML("""<b>Ta-daaaaa!</b><br />Ok - it could have
                             been<br />more of a surprise."""))

        panel = VerticalPanel(Spacing=8,
                              HorizontalAlignment=HasAlignment.ALIGN_CENTER)
        
        panel.add(self.makeLabel("Dock Panel"))
        panel.add(dock)
        panel.add(self.makeLabel("Flow Panel"))
        panel.add(flow)
        panel.add(self.makeLabel("Horizontal Panel"))
        panel.add(horz)
        panel.add(self.makeLabel("Vertical Panel"))
        panel.add(vert)
        panel.add(self.makeLabel("HTML Panel"))
        panel.add(html)
        panel.add(self.makeLabel("Disclosure Panel"))
        panel.add(disclose)
        
        self.initWidget(panel)
        self.setStyleName("ks-layouts")
示例#9
0
    def __init__(self):
        Sink.__init__(self)

        text = """This is a <code>ScrollPanel</code> contained at 
        the center of a <code>DockPanel</code>. 
        By putting some fairly large contents 
        in the middle and setting its size explicitly, it becomes a 
        scrollable area within the page, but without requiring the use of 
        an IFRAME.
        Here's quite a bit more meaningless text that will serve primarily 
        to make this thing scroll off the bottom of its visible area.  
        Otherwise, you might have to make it really, really small in order 
        to see the nifty scroll bars!"""

        contents = HTML(text)
        scroller = ScrollPanel(contents, StyleName="ks-layouts-Scroller")

        dock = DockPanel(HorizontalAlignment=HasAlignment.ALIGN_CENTER,
                         Spacing=10)
        north0 = HTML("This is the <i>first</i> north component", True)
        east = HTML("<center>This<br>is<br>the<br>east<br>component</center>",
                    True)
        south = HTML("This is the south component")
        west = HTML("<center>This<br>is<br>the<br>west<br>component</center>",
                    True)
        north1 = HTML("This is the <b>second</b> north component", True)
        dock.add(north0, DockPanel.NORTH)
        dock.add(east, DockPanel.EAST)
        dock.add(south, DockPanel.SOUTH)
        dock.add(west, DockPanel.WEST)
        dock.add(north1, DockPanel.NORTH)
        dock.add(scroller, DockPanel.CENTER)

        #Logger.write("Layouts", "TODO: flowpanel")
        flow = FlowPanel()
        for i in range(8):
            flow.add(CheckBox("Flow %d" % i))

        horz = HorizontalPanel(VerticalAlignment=HasAlignment.ALIGN_MIDDLE)
        horz.add(Button("Button"))
        horz.add(HTML("<center>This is a<br>very<br>tall thing</center>",
                      True))
        horz.add(Button("Button"))

        vert = VerticalPanel(HorizontalAlignment=HasAlignment.ALIGN_CENTER)
        vert.add(Button("Small"))
        vert.add(Button("--- BigBigBigBig ---"))
        vert.add(Button("tiny"))

        menu = MenuBar()
        menu0 = MenuBar(True)
        menu1 = MenuBar(True)
        menu.addItem("menu0", menu0)
        menu.addItem("menu1", menu1)
        menu0.addItem("child00")
        menu0.addItem("child01")
        menu0.addItem("child02")
        menu1.addItem("child10")
        menu1.addItem("child11")
        menu1.addItem("child12")

        #Logger.write("Layouts", "TODO: htmlpanel")
        id = HTMLPanel.createUniqueId()
        text = """This is an <code>HTMLPanel</code>.  It allows you to add 
            components inside existing HTML, like this: <span id='%s' />
            Notice how the menu just fits snugly in there?  Cute.""" % id
        html = HTMLPanel(text)

        DOM.setStyleAttribute(menu.getElement(), "display", "inline")
        html.add(menu, id)

        disclose = DisclosurePanel("Click to disclose")
        disclose.add(
            HTML("""<b>Ta-daaaaa!</b><br />Ok - it could have
                             been<br />more of a surprise."""))

        panel = VerticalPanel(Spacing=8,
                              HorizontalAlignment=HasAlignment.ALIGN_CENTER)

        panel.add(self.makeLabel("Dock Panel"))
        panel.add(dock)
        panel.add(self.makeLabel("Flow Panel"))
        panel.add(flow)
        panel.add(self.makeLabel("Horizontal Panel"))
        panel.add(horz)
        panel.add(self.makeLabel("Vertical Panel"))
        panel.add(vert)
        panel.add(self.makeLabel("HTML Panel"))
        panel.add(html)
        panel.add(self.makeLabel("Disclosure Panel"))
        panel.add(disclose)

        self.initWidget(panel)
        self.setStyleName("ks-layouts")
示例#10
0
        Widget=HTML('Test 1: Anchor to external site using HTML widget.'),
        Href='http://pyjs.org',
        Title='Test1')
    RootPanel().add(a1)
    # EXAMPLE 2
    label = Label(text='Test 2: Click listener added to a label.')
    label.addClickListener(onClick)
    RootPanel().add(label)
    # EXAMPLE 3
    a2 = Hyperlink(text='Hyperlink', Element=DOM.createSpan())
    a2.setID('param1')
    a2.addClickListener(onClick)
    html2 = HTMLPanel(
        "Test 3: <span id ='t3'></span> added to HTMLPanel with click listener."
    )
    html2.add(a2, "t3")
    RootPanel().add(html2)
    # EXAMPLE 4
    hpanel = HorizontalPanel()
    hpanel.append(HTML('Test 4:  Anchor to external site using Image widget'))
    a3 = Anchor(Widget=Image('http://pyjs.org/assets/images/pyjs.128x128.png'),
                Href='http://pyjs.org',
                Title='Test4')
    hpanel.append(a3)
    RootPanel().add(hpanel)
    # EXAMPLE 5
    serverXml = \
"""
<html>
  <head>
    <title>Example 5</title>
示例#11
0
文件: Anchor.py 项目: Afey/pyjs
    
if __name__ == '__main__':
    pyjd.setup("public/Anchor.html")
    # EXAMPLE 1
    a1 = Anchor(Widget = HTML('Test 1: Anchor to external site using HTML widget.'), Href='http://pyjs.org', Title = 'Test1')
    RootPanel().add(a1) 
    # EXAMPLE 2
    label = Label(text = 'Test 2: Click listener added to a label.')
    label.addClickListener(onClick)
    RootPanel().add(label) 
    # EXAMPLE 3
    a2 = Hyperlink(text = 'Hyperlink', Element = DOM.createSpan())
    a2.setID('param1')
    a2.addClickListener(onClick)
    html2=HTMLPanel("Test 3: <span id ='t3'></span> added to HTMLPanel with click listener.")
    html2.add(a2, "t3")
    RootPanel().add(html2)
    # EXAMPLE 4
    hpanel = HorizontalPanel()
    hpanel.append(HTML('Test 4:  Anchor to external site using Image widget'))
    a3 = Anchor(Widget = Image('http://pyjs.org/assets/images/pyjs.128x128.png'), Href='http://pyjs.org', Title = 'Test4')
    hpanel.append(a3)
    RootPanel().add(hpanel) 
    # EXAMPLE 5
    serverXml = \
"""
<html>
  <head>
    <title>Example 5</title>
  </head>
  <body>