Пример #1
0
    def __init__(self):
        Sink.__init__(self)
        img = Image("images/num1.png")
        img.addMouseListener(TooltipListener("An image: " + img.getUrl()))

        img2 = Image("images/num2.png")
        img2.addMouseListener(TooltipListener("An image: " + img2.getUrl()))

        html = HTML("Some <i>HTML</i> text.")
        html.addMouseListener(TooltipListener("An HTML component."))

        panel_h = HorizontalPanel()
        panel_h.add(img)
        panel_h.add(img2)
        panel_h.setSpacing(8)

        panel = VerticalPanel()
        panel.add(panel_h)
        panel.add(html)

        panel.setSpacing(8)
        self.setWidget(panel)
Пример #2
0
    def __init__(self):
        Sink.__init__(self)
        img = Image("images/num1.png")
        img.addMouseListener(TooltipListener("An image: " + img.getUrl()))
        
        img2 = Image("images/num2.png")
        img2.addMouseListener(TooltipListener("An image: " + img2.getUrl()))

        html = HTML("Some <i>HTML</i> text.")
        html.addMouseListener(TooltipListener("An HTML component."))
        
        panel_h = HorizontalPanel()
        panel_h.add(img)
        panel_h.add(img2)       
        panel_h.setSpacing(8)
        
        panel = VerticalPanel()
        panel.add(panel_h)
        panel.add(html)
        
        panel.setSpacing(8)
        self.setWidget(panel)
Пример #3
0
    def __init__(self, worksheet, id):
        SimplePanel.__init__(self)
        MouseHandler.__init__(self)
        self._id = id
        self._worksheet = worksheet
        insert_new_cell = HTML("", StyleName="insert_new_cell")
        insert_new_cell.addClickListener(InsertListener(worksheet, self._id))
        input_prompt = HTML("In [%d]:" % self._id, Element=DOM.createSpan(),
                StyleName="input_prompt")
        cell_input = InputArea(worksheet, self._id, StyleName='cell_input')
        evaluate_button = HTML("evaluate", Element=DOM.createAnchor(),
                StyleName="eval_button", Visible=False)
        evaluate_button.getElement().setAttribute("href", "")
        evaluate_button.addClickListener(EvaluateListener(self))
        evaluate_button.addMouseListener(self)
        output_delimiter = HTML("", StyleName="output_delimiter")
        output_prompt = HTML("Out[%d]:" % self._id, Element=DOM.createSpan(),
                StyleName="output_prompt")
        cell_output = HTML("", Element=DOM.createSpan(),
                StyleName="cell_output")
        output_prompt.setVisible(False)
        p = FlowPanel(StyleName="cell")
        p.add(insert_new_cell)
        p.add(input_prompt)
        p.add(cell_input)
        p.add(evaluate_button)
        p.add(output_delimiter)
        p.add(output_prompt)
        p.add(cell_output)
        self.add(p)

        self._cell_input = cell_input
        self._cell_output = cell_output
        self._output_prompt = output_prompt
        self._evaluate_button = evaluate_button

        self._mouse_in = False
Пример #4
0
class PopupPagina(PopupPanel):
    def __init__(self, autoHide=None, modal=True, **kwargs):

        PopupPanel.__init__(self, autoHide, modal, **kwargs)

        datasource = None
        id = None

        if kwargs.has_key("datasrc"):
            datasource = kwargs["datasrc"]
        if kwargs.has_key("id"):
            id = kwargs["id"]

        self.setSize(Window.getClientWidth() - 50, Window.getClientHeight() - 50)
        self.setPopupPosition(20, 0)
        DOM.setAttribute(self, "align", "center")

        # self.dbProxInstrucao = DialogBox()
        # self.dbProxInstrucao.setHTML("Alow")
        # botton = Button("Ok")
        # botton.addClickListener(self.onCloseDialog)
        # self.dbProxInstrucao.setWidget(botton)

        self.caption = HTML()
        self.child = None
        self.setHTML("<b>Soma de Matrizes.</b>")

        self.dragging = False
        self.dragStartX = 0
        self.dragStartY = 0

        self.imageFechar = Image("images/fechar.gif", Size=("32px", "32px"), StyleName="gwt-ImageButton")
        self.imgbtnDesfazer = Image("images/previous-arrow.png", Size=("32px", "20px"), StyleName="gwt-ImageButton")
        self.imgbtnFazer = Image("images/next-arrow.png", Size=("32px", "20px"), StyleName="gwt-ImageButton")
        #        self.imgbtnDesfazer.addClickListener(desfazerProxOperacao)
        #        self.imgbtnFazer.addClickListener(fazerProxOperacao)

        self.btnAutomatic = Button("Automático", self.onIniciarAnimacaoAutomatica)
        self.btnInterativo = Button("Interativo")
        if id == "escalar":
            self.btnStepByStep = Button("Passo a passo", IniciarAnimacaoPassoAPasso)
        else:
            self.btnStepByStep = Button("Passo a passo", self.onIniciarAnimacaoPassoAPasso)
        self.btnFazer = Button("fazer >>", fazerProxOperacao)
        # self.btnFazer.setEnabled(False);
        self.btnDesfazer = Button("<< desfazer", desfazerProxOperacao)
        # self.btnDesfazer.setEnabled(False);
        self.btnFechar = PushButton(imageFechar, imageFechar)
        self.btnTestarResposta = Button("Testar Solução")
        self.lbVelocidade = ListBox()
        self.lbVelocidade.setID("lbseg")

        self.lbVelocidade.addItem("0.5 segundo", value=2)
        self.lbVelocidade.addItem("1 segundo", value=1)
        self.lbVelocidade.addItem("2 segundos", value=0.5)
        self.lbVelocidade.addItem("3 segundos", value=1 / 3)
        self.lbVelocidade.addItem("4 segundos", value=0.25)
        self.lbVelocidade.addItem("5 segundos", value=0.20)
        self.lbVelocidade.addItem("6 segundos", value=0.167)
        self.lbVelocidade.addItem("7 segundos", value=0.143)
        self.lbVelocidade.addItem("8 segundos", value=0.125)
        self.lbVelocidade.addItem("10 segundos", value=0.1)

        lblinha1 = ListBox()
        lblinha1.setID("lm1")
        lblinha1.addItem("1", value=1)
        lblinha1.addItem("2", value=2)
        lblinha1.addItem("3", value=3)
        lblinha1.addItem("4", value=4)
        lblinha1.addItem("5", value=5)

        lblinha2 = ListBox()
        lblinha2.setID("lm2")
        lblinha2.addItem("1", value=1)
        lblinha2.addItem("2", value=2)
        lblinha2.addItem("3", value=3)
        lblinha2.addItem("4", value=4)
        lblinha2.addItem("5", value=5)

        lbcoluna1 = ListBox()
        lbcoluna1.setID("cm1")
        lbcoluna1.addItem("1", value=1)
        lbcoluna1.addItem("2", value=2)
        lbcoluna1.addItem("3", value=3)
        lbcoluna1.addItem("4", value=4)
        lbcoluna1.addItem("5", value=5)
        lbcoluna1.addItem("6", value=6)
        lbcoluna1.addItem("7", value=7)

        lbcoluna2 = ListBox()
        lbcoluna2.setID("cm2")
        lbcoluna2.addItem("1", value=1)
        lbcoluna2.addItem("2", value=2)
        lbcoluna2.addItem("3", value=3)
        lbcoluna2.addItem("4", value=4)
        lbcoluna2.addItem("5", value=5)
        lbcoluna2.addItem("6", value=6)
        lbcoluna2.addItem("7", value=7)

        self.lblStatus = Label("Label para Status")

        # Eventos
        self.imageFechar.addClickListener(self.onFecharPopup)

        # Cabeçalho da poupPanel
        self.grid = Grid(1, 16)
        self.grid.setWidth(self.getWidth())
        self.grid.setHTML(0, 0, "<b>Matriz 1:</b> Nº Linhas:")
        self.grid.setWidget(0, 1, lblinha1)
        self.grid.setText(0, 2, "Nº Colunas:")
        self.grid.setWidget(0, 3, lbcoluna1)
        self.grid.setHTML(0, 4, "<b>Matriz 2:</b> Nº Linhas:")
        self.grid.setWidget(0, 5, lblinha2)
        self.grid.setText(0, 6, "Nº Colunas:")
        self.grid.setWidget(0, 7, lbcoluna2)
        #        self.grid.setWidget(0, 3, self.txtColunas)
        self.grid.setWidget(0, 8, self.btnStepByStep)
        self.grid.setWidget(0, 9, self.btnDesfazer)
        self.grid.setWidget(0, 10, self.btnFazer)
        self.grid.setHTML(0, 11, "<b>Velocidade:</b>")
        self.grid.setWidget(0, 12, self.lbVelocidade)
        self.grid.setWidget(0, 13, self.btnAutomatic)
        # self.grid.setWidget(0, 14, self.btnInterativo)
        self.grid.setWidget(0, 15, self.imageFechar)
        # self.grid.setWidget(0, 7, self.btnFechar)
        self.grid.getCellFormatter().setAlignment(
            0, 15, HasHorizontalAlignment.ALIGN_RIGHT, HasVerticalAlignment.ALIGN_TOP
        )

        self.panel = FlexTable(Height="100%", width="100%", BorderWidth="0", CellPadding="0", CellSpacing="0")

        self.panel.setWidget(0, 0, self.caption)
        self.panel.setWidget(1, 0, self.grid)
        self.panel.getCellFormatter().setHeight(2, 0, "100%")
        self.panel.getCellFormatter().setWidth(2, 0, "100%")
        self.panel.getCellFormatter().setAlignment(
            2, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_TOP
        )
        self.panel.setID("contetepopup")

        painelhorizontal = HorizontalPanel()
        gridinterativa = FlexTable()

        painelhorizontal.add(
            HTML(
                "<canvas id='%s' datasrc='%s' width='%s' height='%s' style='image-rendering: optimizespeed !important; '></canvas>"
                % ("soma", datasource, "1000px", "500px")
            )
        )

        ftInterativo = FlexTable(Height="100%", width="100%", BorderWidth="0", CellPadding="0", CellSpacing="0")

        gridinterativa = Grid(4, 4)
        gridinterativa.setWidget(
            0,
            0,
            HTML(
                "<b>M1(</b><input type='text' class='gwt-TextBox' id='linha1' style='width: 25px; height:20px;' maxLength='1'><b> , </b>"
            ),
        )

        gridinterativa.setWidget(
            0,
            1,
            HTML(
                "<input type='text' class='gwt-TextBox' id='coluna1' style='width: 25px;height:20px;' maxLength='1'><b>)&nbsp;+</b>"
            ),
        )

        gridinterativa.setWidget(
            0,
            2,
            HTML(
                "<b>M2(</b>&nbsp;<input type='text' class='gwt-TextBox' id='linha2' style='width: 25px; height:20px;' maxLength='1'><b> , </b>"
            ),
        )

        gridinterativa.setWidget(
            0,
            3,
            HTML(
                "<input type='text' class='gwt-TextBox' id='coluna2' style='width: 25px; height:20px;' maxLength='1'><b>)&nbsp;=</b>"
            ),
        )

        gridinterativa.setWidget(
            2,
            0,
            HTML(
                "&nbsp;&nbsp;<b>(</b><input type='text' class='gwt-TextBox' id='n1' style='width: 25px; height:20px;' maxLength='1'><b>)&nbsp;+</b>"
            ),
        )

        gridinterativa.setWidget(
            2,
            1,
            HTML(
                "<b>(</b><input type='text' class='gwt-TextBox' id='n2' style='width: 25px; height:20px;' maxLength='1'><b>)</b>"
            ),
        )

        gridinterativa.setWidget(
            2,
            2,
            HTML(
                "<b>=&nbsp;</b>&nbsp;<input type='text' class='gwt-TextBox' id='solucao' style='width: 25px; height:20px;' maxLength='1'>"
            ),
        )

        ftInterativo.setHTML(0, 0, "</br>")
        ftInterativo.setHTML(1, 0, "<b><h3>Painel Interativo<h3></b>")
        # ftInterativo.setWidget(2, 0, self.btnInterativo)
        ftInterativo.setWidget(3, 0, gridinterativa)
        ftInterativo.setWidget(4, 0, self.btnTestarResposta)
        ftInterativo.setHTML(5, 0, "</br>")
        ftInterativo.setHTML(6, 0, "Use a tecla tab para agilizar.")

        ftInterativo.getCellFormatter().setAlignment(
            4, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_TOP
        )
        ftInterativo.getCellFormatter().setAlignment(
            1, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_TOP
        )

        # painelhorizontal.add(ftInterativo)

        self.panel.setWidget(2, 0, painelhorizontal)

        self.panel.setWidget(3, 0, self.lblStatus)

        self.panel.setStyleName("dialogContent")

        PopupPanel.setWidget(self, self.panel)

        self.setStyleName("gwt-DialogBox")
        self.caption.setStyleName("Caption")
        self.caption.addMouseListener(self)

        # self.txtlm1.setFocus(True);

    def onFecharPopup(self, event):
        self.hide()
        PararAnimacao()

    def onIniciarAnimacaoPassoAPasso(self, event):
        self.btnFazer.setEnabled(True)
        self.btnDesfazer.setEnabled(True)

        if self.validarParametrosMatriz():
            IniciarAnimacaoPassoAPasso()

    def onIniciarAnimacaoAutomatica(self, event):

        if self.validarParametrosMatriz():
            IniciarAnimacaoAutomatica()

        def onTestarSolucao(self, event):
            pass
            # if self.validarParametrosMatriz():

            # def onCloseDialog(self, event):
            # self.dbProxInstrucao.hide()

            # def onOpenDialog(self, event):
            # self.dbProxInstrucao.show()

    def validarParametrosTestarSolucao():
        lm1 = DOM.getElementById("linha1")
        lm1 = lm1.value
        cm1 = DOM.getElementById("coluna1")
        cm1 = cm1.value
        lm2 = DOM.getElementById("linha2")
        lm2 = lm2.value
        cm2 = DOM.getElementById("coluna2")
        cm2 = cm2.value

    def validarParametrosMatriz():
        lm1 = DOM.getElementById("lm1")
        lm1 = lm1.value
        cm1 = DOM.getElementById("cm1")
        cm1 = cm1.value
        lm2 = DOM.getElementById("lm2")
        lm2 = lm2.value
        cm2 = DOM.getElementById("cm2")
        cm2 = cm2.value
        if not lm1 or not lm2:
            Window.alert("Informe o numero de linhas da matriz M1 e M2.")
            return False

        if lm1 != lm2:
            Window.alert("A quantidade de linhas da matriz M1 deve ser igual a da matriz M2 para operação de soma.")
            return False

        if lm1 > "5" or lm2 > "5" or len(lm1) != 1 or len(lm2) != 1:
            Window.alert("A quantidade de linhas da matriz M1 e da matriz M2, deve ser menor ou igual a 5.")
            return False

        if not cm1 or not cm2:
            Window.alert("Informe o numero de colunas da matriz M1 e M2.")
            return False

        if cm1 != cm2:
            Window.alert("A quantidade de colunas da matriz M1 deve ser igual a da matriz M2 para operação de soma.")
            return False

        if cm1 > "7" or cm2 > "7" or len(cm1) != 1 or len(cm2) != 1:
            Window.alert("A quantidade de colunas da matriz M1 e da matriz M2, deve ser menor ou igual a 7.")
            return False
        return True

    def getHTML(self):
        return self.caption.getHTML()

    def getText(self):
        return self.caption.getText()

    def onEventPreview(self, event):
        # preventDefault on mousedown events, outside of the
        # dialog, to stop text-selection on dragging
        type = DOM.eventGetType(event)
        if type == "mousedown":
            target = DOM.eventGetTarget(event)
            elem = self.caption.getElement()
            event_targets_popup = target and DOM.isOrHasChild(elem, target)
            if event_targets_popup:
                DOM.eventPreventDefault(event)
        return PopupPanel.onEventPreview(self, event)

    def onMouseDown(self, sender, x, y):
        self.dragging = True
        DOM.setCapture(self.caption.getElement())
        self.dragStartX = x
        self.dragStartY = y

    def onMouseMove(self, sender, x, y):
        if self.dragging:
            absX = x + self.getAbsoluteLeft()
            absY = y + self.getAbsoluteTop()
            self.setPopupPosition(absX - self.dragStartX, absY - self.dragStartY)

    def onMouseUp(self, sender, x, y):
        self.dragging = False
        DOM.releaseCapture(self.caption.getElement())

    def onMouseLeave(self, self, x, y):
        pass

    def onMouseEnter(self, self, x, y):
        pass

    def remove(self, widget):
        if self.child != widget:
            return False

        self.panel.remove(widget)
        self.child = None
        return True

    def setHTML(self, html):
        self.caption.setHTML(html)

    def setText(self, text):
        self.caption.setText(text)

    def doAttachChildren(self):
        PopupPanel.doAttachChildren(self)
        self.caption.onAttach()

    def doDetachChildren(self):
        PopupPanel.doDetachChildren(self)
        self.caption.onDetach()

    def setWidget(self, widget):
        if self.child is not None:
            self.panel.remove(self.child)

        if widget is not None:
            self.panel.setWidget(1, 0, widget)

        self.child = widget
Пример #5
0
class DialogBoxModal(PopupPanel):
    def __init__(self, identifier, autoHide=None, modal=False, rootpanel=None):
        PopupPanel.__init__(self, autoHide, modal, rootpanel)

        self.identifier = identifier
        self.caption = HTML()
        self.child = None
        self.showing = False
        self.dragging = False
        self.dragStartX = 0
        self.dragStartY = 0
        self.panel = FlexTable()

        self.closeButton = Image("images/cancel.png")
        self.closeButton.addClickListener(self)
        dock = DockPanel()
        dock.setSpacing(0)

        dock.add(self.closeButton, DockPanel.EAST)
        dock.add(self.caption, DockPanel.WEST)

        dock.setCellHorizontalAlignment(self.closeButton,
                                        HasAlignment.ALIGN_RIGHT)
        dock.setCellHorizontalAlignment(self.caption, HasAlignment.ALIGN_LEFT)
        dock.setCellWidth(self.caption, "100%")
        dock.setWidth("100%")

        self.panel.setWidget(0, 0, dock)
        self.panel.setHeight("100%")
        self.panel.setBorderWidth(0)
        self.panel.setCellPadding(0)
        self.panel.setCellSpacing(0)
        self.panel.getCellFormatter().setHeight(1, 0, "100%")
        self.panel.getCellFormatter().setWidth(1, 0, "100%")
        #self.panel.getCellFormatter().setAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE)
        PopupPanel.setWidget(self, self.panel)

        self.setStyleName("gwt-DialogBox")
        self.caption.setStyleName("Caption")
        self.closeButton.setStyleName("Close")
        dock.setStyleName("Header")
        self.caption.addMouseListener(self)

    def getHTML(self):
        return self.caption.getHTML()

    def getText(self):
        return self.caption.getText()

    def onMouseDown(self, sender, x, y):
        self.dragging = True
        DOM.setCapture(self.caption.getElement())
        self.dragStartX = x
        self.dragStartY = y

    def onMouseEnter(self, sender):
        pass

    def onMouseLeave(self, sender):
        pass

    def onMouseMove(self, sender, x, y):
        if self.dragging:
            absX = x + self.getAbsoluteLeft()
            absY = y + self.getAbsoluteTop()
            self.setPopupPosition(absX - self.dragStartX,
                                  absY - self.dragStartY)

    def onMouseUp(self, sender, x, y):
        self.dragging = False
        DOM.releaseCapture(self.caption.getElement())

    def remove(self, widget):
        if self.child != widget:
            return False

        self.panel.remove(widget)
        self.child = None
        return True

    def setHTML(self, html):
        self.caption.setHTML(html)

    def setText(self, text):
        self.caption.setText(text)

    def doAttachChildren(self):
        PopupPanel.doAttachChildren(self)
        self.caption.onAttach()

    def doDetachChildren(self):
        PopupPanel.doDetachChildren(self)
        self.caption.onDetach()

    def setWidget(self, widget):
        if self.child is not None:
            self.panel.remove(self.child)

        if widget is not None:
            self.panel.setWidget(1, 0, widget)

        self.child = widget

    def createElement(self):
        return DOM.createDiv()

    def setPopupPosition(self, left, top):
        if left < 0:
            left = 0
        if top < 0:
            top = 0

        element = self.getElement()
        DOM.setStyleAttribute(element, "left", "%dpx" % left)
        DOM.setStyleAttribute(element, "top", "%dpx" % top)

    def show(self):
        if self.showing:
            return

        if modal_popups.has_key(self.identifier) and \
           modal_popups[self.identifier] != self:
            return
        modal_popups[self.identifier] = self

        PopupPanel.show(self)

    def hide(self, autoClosed=False):
        if not self.showing:
            return

        if modal_popups.has_key(self.identifier):
            del modal_popups[self.identifier]

        PopupPanel.hide(self)

    def onEventPreview(self, event):
        # preventDefault on mousedown events, outside of the
        # dialog, to stop text-selection on dragging
        type = DOM.eventGetType(event)
        if type == 'mousedown':
            target = DOM.eventGetTarget(event)
            elem = self.caption.getElement()
            event_targets_popup = target and DOM.isOrHasChild(elem, target)
            if event_targets_popup:
                DOM.eventPreventDefault(event)
        return PopupPanel.onEventPreview(self, event)
Пример #6
0
class DialogBoxModal(PopupPanel):
    def __init__(self, identifier, autoHide=None, modal=False, rootpanel=None):
        PopupPanel.__init__(self, autoHide, modal, rootpanel)

        self.identifier = identifier
        self.caption = HTML()
        self.child = None
        self.showing = False
        self.dragging = False
        self.dragStartX = 0
        self.dragStartY = 0
        self.panel = FlexTable()

        self.closeButton = Image('cancel.png')
        self.closeButton.addClickListener(self)
        dock = DockPanel()
        dock.setSpacing(0)

        dock.add(self.closeButton, DockPanel.EAST)
        dock.add(self.caption, DockPanel.WEST)

        dock.setCellHorizontalAlignment(self.closeButton,
                                        HasAlignment.ALIGN_RIGHT)
        dock.setCellHorizontalAlignment(self.caption, HasAlignment.ALIGN_LEFT)
        dock.setCellWidth(self.caption, '100%')
        dock.setWidth('100%')

        self.panel.setWidget(0, 0, dock)
        self.panel.setHeight('100%')
        self.panel.setBorderWidth(0)
        self.panel.setCellPadding(0)
        self.panel.setCellSpacing(0)
        self.panel.getCellFormatter().setHeight(1, 0, '100%')
        self.panel.getCellFormatter().setWidth(1, 0, '100%')
        #self.panel.getCellFormatter().setAlignment(1, 0,
        # HasHorizontalAlignment.ALIGN_CENTER,
        # HasVerticalAlignment.ALIGN_MIDDLE)
        PopupPanel.setWidget(self, self.panel)

        self.setStyleName('gwt-DialogBox')
        self.caption.setStyleName('Caption')
        self.closeButton.setStyleName('Close')
        dock.setStyleName('Header')
        self.caption.addMouseListener(self)

    def getHTML(self):
        return self.caption.getHTML()

    def getText(self):
        return self.caption.getText()

    def onMouseDown(self, sender, x, y):
        self.dragging = True
        DOM.setCapture(self.caption.getElement())
        self.dragStartX = x
        self.dragStartY = y

    def onMouseEnter(self, sender):
        pass

    def onMouseLeave(self, sender):
        pass

    def onMouseMove(self, sender, x, y):
        if self.dragging:
            absX = x + self.getAbsoluteLeft()
            absY = y + self.getAbsoluteTop()
            self.setPopupPosition(absX - self.dragStartX,
                                  absY - self.dragStartY)

    def onMouseUp(self, sender, x, y):
        self.dragging = False
        DOM.releaseCapture(self.caption.getElement())

    def remove(self, widget):
        if self.child != widget:
            return False

        self.panel.remove(widget)
        self.child = None
        return True

    def setHTML(self, html):
        self.caption.setHTML(html)

    def setText(self, text):
        self.caption.setText(text)

    def doAttachChildren(self):
        PopupPanel.doAttachChildren(self)
        self.caption.onAttach()

    def doDetachChildren(self):
        PopupPanel.doDetachChildren(self)
        self.caption.onDetach()

    def setWidget(self, widget):
        if self.child is not None:
            self.panel.remove(self.child)

        if widget is not None:
            self.panel.setWidget(1, 0, widget)

        self.child = widget

    def createElement(self):
        return DOM.createDiv()

    def setPopupPosition(self, left, top):
        if left < 0:
            left = 0
        if top < 0:
            top = 0

        element = self.getElement()
        DOM.setStyleAttribute(element, 'left', '%dpx' % left)
        DOM.setStyleAttribute(element, 'top', '%dpx' % top)

    def show(self):
        if self.showing:
            return

        if (self.identifier in modal_popups and
            modal_popups[self.identifier] != self):
            return
        modal_popups[self.identifier] = self

        PopupPanel.show(self)

    def hide(self, autoClosed=False):
        if not self.showing:
            return

        if self.identifier in modal_popups:
            del modal_popups[self.identifier]

        PopupPanel.hide(self)

    def onEventPreview(self, event):
        # preventDefault on mousedown events, outside of the
        # dialog, to stop text-selection on dragging
        type = DOM.eventGetType(event)
        if type == 'mousedown':
            target = DOM.eventGetTarget(event)
            elem = self.caption.getElement()
            event_targets_popup = target and DOM.isOrHasChild(elem, target)
            if event_targets_popup:
                DOM.eventPreventDefault(event)
        return PopupPanel.onEventPreview(self, event)
Пример #7
0
class DialogBox(PopupPanel):
    _props = [
        ("caption", "Caption", "HTML", None),
    ]

    def __init__(self, autoHide=None, modal=True, centered=False, **kwargs):
        # Init section
        self.dragging = False
        self.dragStartX = 0
        self.dragStartY = 0
        self.child = None
        self.panel = FlexTable(
            Height="100%",
            BorderWidth="0",
            CellPadding="0",
            CellSpacing="0",
        )
        cf = self.panel.getCellFormatter()
        cf.setHeight(1, 0, "100%")
        cf.setWidth(1, 0, "100%")
        cf.setAlignment(
            1,
            0,
            HasHorizontalAlignment.ALIGN_CENTER,
            HasVerticalAlignment.ALIGN_MIDDLE,
        )

        # Arguments section
        self.modal = modal
        self.caption = HTML()
        self.panel.setWidget(0, 0, self.caption)
        self.caption.setStyleName("Caption")
        self.caption.addMouseListener(self)

        # Finalize
        kwargs['StyleName'] = kwargs.get('StyleName', "gwt-DialogBox")
        PopupPanel.__init__(self, autoHide, modal, **kwargs)
        PopupPanel.setWidget(self, self.panel)

        self.centered = centered

    def onWindowResized(self, width, height):
        super(DialogBox, self).onWindowResized(width, height)
        if self.centered:
            self.centerBox()

    def show(self):
        super(DialogBox, self).show()
        if self.centered:
            self.centerBox()

    @classmethod
    def _getProps(self):
        return PopupPanel._getProps() + self._props

    def onEventPreview(self, event):
        # preventDefault on mousedown events, outside of the
        # dialog, to stop text-selection on dragging
        type = DOM.eventGetType(event)
        if type == 'mousedown':
            target = DOM.eventGetTarget(event)
            elem = self.caption.getElement()
            event_targets_popup = target and DOM.isOrHasChild(elem, target)
            if event_targets_popup:
                DOM.eventPreventDefault(event)
        return PopupPanel.onEventPreview(self, event)

    def getHTML(self):
        return self.caption.getHTML()

    def getText(self):
        return self.caption.getText()

    def setHTML(self, html):
        self.caption.setHTML(html)

    def setText(self, text):
        self.caption.setText(text)

    def onMouseDown(self, sender, x, y):
        self.dragging = True
        GlassWidget.show(self.caption)
        self.dragStartX = x
        self.dragStartY = y

    def onMouseEnter(self, sender):
        pass

    def onMouseLeave(self, sender):
        pass

    def onMouseMove(self, sender, x, y):
        if not self.dragging:
            return
        absX = x + self.getAbsoluteLeft()
        absY = y + self.getAbsoluteTop()
        self.setPopupPosition(absX - self.dragStartX, absY - self.dragStartY)

    def onMouseUp(self, sender, x, y):
        self.endDragging()

    def onMouseGlassEnter(self, sender):
        pass

    def onMouseGlassLeave(self, sender):
        self.endDragging()

    def endDragging(self):
        if not self.dragging:
            return
        self.dragging = False
        GlassWidget.hide()

    def remove(self, widget):
        if self.child != widget:
            return False

        self.panel.remove(widget)
        self.child = None
        return True

    def doAttachChildren(self):
        PopupPanel.doAttachChildren(self)
        self.caption.onAttach()

    def doDetachChildren(self):
        PopupPanel.doDetachChildren(self)
        self.caption.onDetach()

    def setWidget(self, widget):
        if self.child is not None:
            self.panel.remove(self.child)

        if widget is not None:
            self.panel.setWidget(1, 0, widget)

        self.child = widget
Пример #8
0
class DialogBox(PopupPanel):
    _props = [
        ("caption", "Caption", "HTML", None),
    ]

    def __init__(self, autoHide=None, modal=True, **kwargs):
        # Init section
        self.dragging = False
        self.dragStartX = 0
        self.dragStartY = 0
        self.child = None
        self.panel = FlexTable(
            Height="100%",
            BorderWidth="0",
            CellPadding="0",
            CellSpacing="0",
        )
        cf = self.panel.getCellFormatter()
        cf.setHeight(1, 0, "100%")
        cf.setWidth(1, 0, "100%")
        cf.setAlignment(
            1, 0,
            HasHorizontalAlignment.ALIGN_CENTER,
            HasVerticalAlignment.ALIGN_MIDDLE,
        )

        # Arguments section
        self.modal = modal
        self.caption = HTML()
        self.panel.setWidget(0, 0, self.caption)
        self.caption.setStyleName("Caption")
        self.caption.addMouseListener(self)

        # Finalize
        kwargs['StyleName'] = kwargs.get('StyleName', "gwt-DialogBox")
        PopupPanel.__init__(self, autoHide, modal, **kwargs)
        PopupPanel.setWidget(self, self.panel)

    @classmethod
    def _getProps(self):
        return PopupPanel._getProps() + self._props

    def onEventPreview(self, event):
        # preventDefault on mousedown events, outside of the
        # dialog, to stop text-selection on dragging
        type = DOM.eventGetType(event)
        if type == 'mousedown':
            target = DOM.eventGetTarget(event)
            elem = self.caption.getElement()
            event_targets_popup = target and DOM.isOrHasChild(elem, target)
            if event_targets_popup:
                DOM.eventPreventDefault(event)
        return PopupPanel.onEventPreview(self, event)

    def getHTML(self):
        return self.caption.getHTML()

    def getText(self):
        return self.caption.getText()

    def setHTML(self, html):
        self.caption.setHTML(html)

    def setText(self, text):
        self.caption.setText(text)

    def onMouseDown(self, sender, x, y):
        self.dragging = True
        GlassWidget.show(self.caption)
        self.dragStartX = x
        self.dragStartY = y

    def onMouseEnter(self, sender):
        pass

    def onMouseLeave(self, sender):
        pass

    def onMouseMove(self, sender, x, y):
        if not self.dragging:
            return
        absX = x + self.getAbsoluteLeft()
        absY = y + self.getAbsoluteTop()
        self.setPopupPosition(absX - self.dragStartX,
                              absY - self.dragStartY)

    def onMouseUp(self, sender, x, y):
        self.endDragging()

    def onMouseGlassEnter(self, sender):
        pass

    def onMouseGlassLeave(self, sender):
        self.endDragging()

    def endDragging(self):
        if not self.dragging:
            return
        self.dragging = False
        GlassWidget.hide()

    def remove(self, widget):
        if self.child != widget:
            return False

        self.panel.remove(widget)
        self.child = None
        return True

    def doAttachChildren(self):
        PopupPanel.doAttachChildren(self)
        self.caption.onAttach()

    def doDetachChildren(self):
        PopupPanel.doDetachChildren(self)
        self.caption.onDetach()

    def setWidget(self, widget):
        if self.child is not None:
            self.panel.remove(self.child)

        if widget is not None:
            self.panel.setWidget(1, 0, widget)

        self.child = widget

    def onWindowResized(self, width, height):
        super(DialogBox, self).onWindowResized(width, height)

    def show(self):
        super(DialogBox, self).show()
Пример #9
0
class DialogBox(PopupPanel):
    _props = [
        ("caption", "Caption", "HTML", None),
    ]

    def __init__(self, autoHide=None, modal=True, centered=False,
                 **kwargs):
        # Init section
        self.dragging = False
        self.dragStartX = 0
        self.dragStartY = 0
        self.child = None
        self.panel = FlexTable(
            Height="100%",
            BorderWidth="0",
            CellPadding="0",
            CellSpacing="0",
        )

        cf = self.panel.getCellFormatter()
        rf = self.panel.getRowFormatter()

        # Arguments section
        self.modal = modal
        self.caption = HTML()
        self.caption.setStyleName("Caption")
        self.caption.addMouseListener(self)

        # Make the DialogBox a 3x3 table, like GWT does, with
        # empty elements with specific style names. These can be
        # used with CSS to, for example, create border around the
        # dialog box.
        self.generate_gwt15 = kwargs.pop('gwt15', False) and True

        if not self.generate_gwt15:
            cf.setHeight(1, 0, "100%")
            cf.setWidth(1, 0, "100%")
            cf.setAlignment(
                1, 0,
                HasHorizontalAlignment.ALIGN_CENTER,
                HasVerticalAlignment.ALIGN_MIDDLE,
            )
            self.panel.setWidget(0, 0, self.caption)
        else:
            row_labels = ['Top', 'Middle', 'Bottom']
            col_labels = ['Left', 'Center', 'Right']

            for r in range(3):
                rf.setStyleName(r, 'dialog%s' % row_labels[r])
                for c in range(3):
                    cf.setStyleName(r, c, 'dialog%s%s' % (row_labels[r],
                                                          col_labels[c]))
                    sp = SimplePanel()
                    sp.setStyleName('dialog%s%sInner' % (row_labels[r],
                                                         col_labels[c]))
                    self.panel.setWidget(r, c, sp)

            cf.setAlignment(
                1, 1,
                HasHorizontalAlignment.ALIGN_CENTER,
                HasVerticalAlignment.ALIGN_MIDDLE,
            )

            self.dialog_content = SimplePanel()
            self.dialog_content.setStyleName('dialogContent')

            self.panel.getWidget(0, 1).add(self.caption)
            self.panel.getWidget(1, 1).add(self.dialog_content)

        # Finalize
        kwargs['StyleName'] = kwargs.get('StyleName', "gwt-DialogBox")
        PopupPanel.__init__(self, autoHide, modal, **kwargs)
        PopupPanel.setWidget(self, self.panel)

        self.centered = centered

    def onWindowResized(self, width, height):
        super(DialogBox, self).onWindowResized(width, height)
        if self.centered:
            self.centerBox()

    def show(self):
        super(DialogBox, self).show()
        if self.centered:
            self.centerBox()

    @classmethod
    def _getProps(self):
        return PopupPanel._getProps() + self._props

    def onEventPreview(self, event):
        # preventDefault on mousedown events, outside of the
        # dialog, to stop text-selection on dragging
        type = DOM.eventGetType(event)
        if type == 'mousedown':
            target = DOM.eventGetTarget(event)
            elem = self.caption.getElement()
            event_targets_popup = target and DOM.isOrHasChild(elem, target)
            if event_targets_popup:
                DOM.eventPreventDefault(event)
        return PopupPanel.onEventPreview(self, event)

    def getHTML(self):
        return self.caption.getHTML()

    def getText(self):
        return self.caption.getText()

    def setHTML(self, html):
        self.caption.setHTML(html)

    def setText(self, text):
        self.caption.setText(text)

    def onMouseDown(self, sender, x, y):
        self.dragging = True
        GlassWidget.show(self.caption)
        self.dragStartX = x
        self.dragStartY = y

    def onMouseEnter(self, sender):
        pass

    def onMouseLeave(self, sender):
        pass

    def onMouseMove(self, sender, x, y):
        if not self.dragging:
            return
        absX = x + self.getAbsoluteLeft()
        absY = y + self.getAbsoluteTop()
        self.setPopupPosition(absX - self.dragStartX,
                              absY - self.dragStartY)

    def onMouseUp(self, sender, x, y):
        self.endDragging()

    def onMouseGlassEnter(self, sender):
        pass

    def onMouseGlassLeave(self, sender):
        self.endDragging()

    def endDragging(self):
        if not self.dragging:
            return
        self.dragging = False
        GlassWidget.hide()

    def remove(self, widget):
        if self.child != widget:
            return False

        self.panel.remove(widget)
        self.child = None
        return True

    def doAttachChildren(self):
        PopupPanel.doAttachChildren(self)
        self.caption.onAttach()

    def doDetachChildren(self):
        PopupPanel.doDetachChildren(self)
        self.caption.onDetach()

    def setWidget(self, widget):
        if self.child is not None:
            if not self.generate_gwt15:
                self.panel.remove(self.child)
            else:
                self.dialog_content.remove(self.child)

        if widget is not None:
            if not self.generate_gwt15:
                self.panel.setWidget(1, 0, widget)
            else:
                self.dialog_content.setWidget(widget)

        self.child = widget