Esempio n. 1
0
    def __init__(self):
        Composite.__init__(self)

        self.m_isInText = False
        self.m_lastText = ""
        self.trigger = False
        self.m_lastRange = None

        # Timer for trying real time selection change stuff
        self.m_timerRange = None
        self.m_selTimer = Timer()

        self.m_mainPanel = DockPanel()
        self.m_toolbarPanel = HorizontalPanel()
        self.m_toolbarPanel.setWidth("100%")
        self.m_toolbarPanel.setHeight("25px")
        self.m_toolbarPanel.setBorderWidth(1)
        self.m_toolbarPanel.addStyleName("timeline-RichTextToolbar")

        self.m_textW = RichTextArea()
        self.m_textW.addClickListener(self)
        self.m_textW.addKeyboardListener(self)
        self.m_textW.addFocusListener(self)
        self.m_textW.addMouseListener(self)
        # According to gwt doc, these do need to be set because this is a frame
        self.m_textW.setHeight("100%")
        self.m_textW.setWidth("100%")

        # Add buttons
        self.m_formatter = self.getFormatter()

        self.m_boldW = self.addToggleButton(self.m_toolbarPanel,
                                            Icons.bold_icon, "Bold")
        self.m_italicW = self.addToggleButton(self.m_toolbarPanel,
                                              Icons.italics_icon, "Italic")
        self.m_underlineW = self.addToggleButton(self.m_toolbarPanel,
                                                 Icons.underline_icon,
                                                 "Underline")
        self.m_subscriptW = self.addToggleButton(self.m_toolbarPanel,
                                                 Icons.subscript_icon,
                                                 "Subscript")
        self.m_superscriptW = self.addToggleButton(self.m_toolbarPanel,
                                                   Icons.superscript_icon,
                                                   "Superscript")
        self.m_strikethroughW = self.addToggleButton(self.m_toolbarPanel,
                                                     Icons.strikethrough_icon,
                                                     "Strikethrough")

        self.m_indentW = self.addPushButton(self.m_toolbarPanel,
                                            Icons.indentmore_icon,
                                            "Indent Right")
        self.m_outdentW = self.addPushButton(self.m_toolbarPanel,
                                             Icons.indentless_icon,
                                             "Indent Left")
        self.m_justifyLeftW = self.addPushButton(self.m_toolbarPanel,
                                                 Icons.justifyleft_icon,
                                                 "Justify Left")
        self.m_justifyCenterW = self.addPushButton(self.m_toolbarPanel,
                                                   Icons.justifycenter_icon,
                                                   "Justify Center")
        self.m_justifyRightW = self.addPushButton(self.m_toolbarPanel,
                                                  Icons.justifyright_icon,
                                                  "Justify Right")
        self.m_hrW = self.addPushButton(self.m_toolbarPanel,
                                        Icons.horizontalrule_icon,
                                        "Horizontal Rule")
        self.m_olW = self.addPushButton(self.m_toolbarPanel,
                                        Icons.numberedlist_icon,
                                        "Numbered List")
        self.m_ulW = self.addPushButton(self.m_toolbarPanel, Icons.list_icon,
                                        "List")
        self.m_newLinkW = self.addPushButton(self.m_toolbarPanel,
                                             Icons.link_icon, "Link Document")
        self.m_removeFormatW = self.addPushButton(self.m_toolbarPanel,
                                                  Icons.noformat_icon,
                                                  "No Format")

        self.m_mainPanel.add(self.m_toolbarPanel, DockPanel.NORTH)
        self.m_mainPanel.add(self.m_textW, DockPanel.CENTER)

        self.initWidget(self.m_mainPanel)
        self.sinkEvents(Event.ONCLICK)
Esempio n. 2
0
    def onModuleLoad(self):
        dlp = DockPanel(Width="100%", Height="100%")

        self.m_rte = RichTextArea(Width="500px", Height="400px")
        self.m_tb = RichTextToolbar(self.m_rte, self)

        buts = FlowPanel()
        self.m_getCurr = Button("Refresh v", self)
        self.m_setHtml = Button("Set html ^", self)
        self.m_setHtml.setTitle("Set html from the lower left text area")
        self.m_toSCursor = Button("< To Cursor", self)
        self.m_toSCursor.setTitle(
            "Set the selection to be a cursor at the beginning of the current selection"
        )
        self.m_toECursor = Button("To Cursor >", self)
        self.m_toECursor.setTitle(
            "Set the selection to be a cursor at the end of the current selection"
        )
        self.m_surround1 = Button("Surround1", self)
        self.m_surround2 = Button("Surround2", self)
        self.m_font1 = Button("Times New Roman", self)
        self.m_font2 = Button("Arial", self)

        grid = Grid(2, 2)
        self.m_startNode = self.createTextBox(1)
        self.m_startOffset = self.createTextBox(3)
        self.m_endNode = self.createTextBox(4)
        self.m_endOffset = self.createTextBox(5)
        self.m_select = Button("`>Select", self)
        self.m_select.setTitle("Select the texts/offsets in the boxes above")
        self.m_cursor = Button("`>Cursor", self)
        self.m_cursor.setTitle(
            "Set cursor to text/offset of top 2 boxes above")
        grid.setWidget(0, 0, self.m_startNode)
        grid.setWidget(0, 1, self.m_startOffset)
        grid.setWidget(1, 0, self.m_endNode)
        grid.setWidget(1, 1, self.m_endOffset)

        self.m_deleteSel = Button("Delete", self)
        self.m_reset = Button("Reset", self)

        buts.add(self.m_getCurr)
        buts.add(self.m_setHtml)
        buts.add(self.m_toSCursor)
        buts.add(self.m_toECursor)
        buts.add(self.m_font1)
        buts.add(self.m_font2)
        buts.add(self.m_surround1)
        buts.add(self.m_surround2)
        buts.add(grid)
        buts.add(self.m_select)
        buts.add(self.m_cursor)

        buts.add(self.m_deleteSel)
        buts.add(self.m_reset)

        dlp.add(buts, DockPanel.WEST)

        textPanels = DockPanel()

        self.m_html = TextArea()
        self.m_html.setSize("100%", "100%")
        self.m_sel = TextArea()
        self.m_sel.setSize("100%", "100%")

        textPanels.add(self.m_sel, DockPanel.EAST)
        textPanels.add(self.m_html, DockPanel.WEST)

        dlp.add(textPanels, DockPanel.SOUTH)
        dlp.add(self.m_tb, DockPanel.NORTH)
        dlp.add(self.m_rte, DockPanel.CENTER)

        rp = RootPanel.get()
        rp.add(dlp)

        DeferredCommand.add(getattr(self, "set_html_focus"))

        self.reset()