예제 #1
0
class PopupNewVar(Popup):
    def __init__(self, okClick, cancelClick):
        Popup.__init__(self, '<b>Nova Vari&aacute;vel</b>', okClick,
                       cancelClick, CONFIRM_CANCEL)

    def draw(self):
        Popup.draw(self)

        namePanel = HorizontalPanel()
        namePanel.add(Label(_('Name') + ':'))
        self.textBox = TextBox()
        self.textBox.setMaxLength(15)
        self.textBox.setStyleAttribute('marginLeft', 10)
        namePanel.add(self.textBox)
        self.center.add(namePanel)

        self.choose = ChooseTypeVarPanel()
        self.center.add(self.choose)

        self.textBox.addInputListener(self)

        self.message = Element(Element=DOM.createDiv())
        self.message.add(Widget(Element=DOM.createDiv(),
                                StyleName='not_image'))
        self.message.add(
            Label(text=_('Name already used'),
                  wordWrap=False,
                  StyleName='not_message'))

        self.onInput()

    def onInput(self, sender):
        if self.textBox.getText().count(' ') == len(self.textBox.getText()):
            self.okButton.addStyleName('disabled')
            self.south.remove(self.message)
        elif self.textBox.getText() in vars or self.textBox.getText(
        ) in createdBlocks:
            self.okButton.addStyleName('disabled')
            self.south.add(self.message)
        else:
            self.okButton.removeStyleName('disabled')
            self.south.remove(self.message)

    def myOkClick(self):
        if 'disabled' not in self.okButton.getStyleName():
            Popup.myOkClick(self)
            self.okClick(self.textBox.getText(), self.choose.selectedType)

    def myCancelClick(self):
        Popup.myCancelClick(self)
        if self.cancelClick is not None: self.cancelClick()

    def show(self):
        Popup.show(self)
        self.textBox.setFocus(True)
예제 #2
0
class BooleanArgument(Argument):
    def __init__(self):
        Argument.__init__(self, [Block.BOOLEAN_BLOCK])
        self.height = 20
        self.width = 15
        drawBooleanArgument(self)
        self.addInput()
        self.resize()

    def addInput(self):
        self.input = TextBox()
        self.input.setWidth(20)
        self.input.addInputListener(self)
        self.append(self.input)
        DOM.setBooleanAttribute(self.input.getElement(), "readOnly", True)
        self.input.addChangeListener(self)

    def onChange(self, sender):
        from edu.uca.util.Serializable import stateChange
        stateChange()

    def onInput(self, sender):
        if len(self.input.getText()) == 0:
            self.input.setWidth(
                20)  # nao esta usando pois nao pode digitar no input bool
        else:
            self.input.setWidth(20 + ((len(self.input.getText()) - 1) * 7))
        self.width = self.input.getWidth()
        self.resize()

    def resize(self):
        c = math.ceil(self.height / 2 + 1)
        self.tr.setStyleAttribute({
            'right': -c - 2,
            'width': c + 3,
            'height': c
        })
        self.br.setStyleAttribute({
            'right': -c - 2,
            'width': c + 3,
            'height': c
        })
        self.tl.setStyleAttribute({
            'left': -c - 2,
            'width': c + 3,
            'height': c
        })
        self.bl.setStyleAttribute({
            'left': -c - 2,
            'width': c + 3,
            'height': c
        })
        self.setStyleAttribute({'width': self.width})
        self.t.setWidth(self.width)
        self.b.setWidth(self.width)
예제 #3
0
class PopupOpenState(Popup):
        
    def __init__(self, okClick, cancelClick, title='Abrir', options=CONFIRM_CANCEL):
        Popup.__init__(self, title, okClick, cancelClick, options)
        
    def draw(self):
        Popup.draw(self)
        
        namePanel = HorizontalPanel()
        #namePanel.add(Label('Crie um arquivo'))     
        if self.title == 'Abrir':
            self.enableOkButton(False)
            namePanel.add(HTML("""<div class=""gwt-Label"" style=""white-space: normal;"">
            Abra o arquivo salvo, copie<br>e cole aqui o conteudo:</div>"""))  
            
            self.field = FileUpload()
            self.field.setName('file')
            self.field.setID('files')
            self.center.add(self.field)        
            element = self.field.getElement()   
            
            JS("""function handleFileSelect(evt) {@{{self}}.enableOkButton(evt.target.files[0]!=null);} 
            @{{element}}.addEventListener('change', handleFileSelect, false);""")
            
            
            #http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml
        else:
            namePanel.add(HTML("""<div class=""gwt-Label"" style=""white-space: normal;"">
            Crie um arquivo txt e copie<br>e cole o conteudo a seguir:</div>"""))   
                     
            self.textBox = TextBox()
            self.textBox.setStyleAttribute('marginLeft', 10)
            namePanel.add(self.textBox)
            self.center.add(namePanel)
            
            self.textBox.addInputListener(self)    
            self.onInput()
            
    def enableOkButton(self, enable):
        if enable: self.okButton.removeStyleName('disabled')
        else: self.okButton.addStyleName('disabled')
        
    def onInput(self, sender):
        self.enableOkButton(self.textBox.getText().count(' ') != len(self.textBox.getText()))
        
    def myOkClick(self):
        if 'disabled' not in self.okButton.getStyleName():
            Popup.myOkClick(self)
            if self.okClick is not None:
                if self.title == 'Abrir':
                    files = getattr(self.field.getElement(), 'files')  
                    file = JS("@{{files}}[0]")
                    if  file:              
                        JS("""var reader = new FileReader();
                        reader.onload = function(e) {@{{self}}.okClick(e.target.result);}
                        reader.readAsBinaryString(@{{file}});""")                                 
                        #self.okClick(str)                        
                else:
                    self.okClick(self.textBox.getText())
                    
    def myCancelClick(self):
        Popup.myCancelClick(self)
        if self.cancelClick is not None: self.cancelClick()
            
    def show(self):
        Popup.show(self)
        if self.title != 'Abrir': self.textBox.setFocus(True)
        else:
            pass
예제 #4
0
class DateField(Composite, DateSelectedHandler):

    img_base = None
    icon_img = None

    icon_style = "calendar-img"
    today_text = "Today"
    today_style = "calendar-today-link"

    def __init__(self, format='%d-%m-%Y'):
        DateSelectedHandler.__init__(self)
        if self.img_base is None:
            self.img_base = pygwt.getImageBaseURL(True)
        if self.icon_img is None:
            self.icon_img = self.img_base + 'icon_calendar.gif'
        self.format = format
        self.tbox = TextBox()
        self.tbox.setVisibleLength(10)
        # assume valid sep is - / . or nothing
        if format.find('-') >= 0:
            self.sep = '-'
        elif format.find('/') >= 0:
            self.sep = '/'
        elif format.find('.') >= 0:
            self.sep = '.'
        else:
            self.sep = ''
        # self.sep = format[2] # is this too presumptious?
        self.calendar = Calendar()
        self.img = Image(self.icon_img)
        self.img.addStyleName(self.icon_style)
        self.calendarLink = HyperlinkImage(self.img)
        self.todayLink = Hyperlink(self.today_text)
        self.todayLink.addStyleName(self.today_style)
        #
        # lay it out
        #
        hp = HorizontalPanel()
        hp.setSpacing(2)
        vp = VerticalPanel()
        hp.add(self.tbox)
        vp.add(self.calendarLink)
        vp.add(self.todayLink)
        #vp.add(self.calendar)
        hp.add(vp)

        Composite.__init__(self)
        self.initWidget(hp)
        #
        # done with layout, so now set up some listeners
        #
        self.tbox.addFocusListener(self) # hook to onLostFocus
        self.calendar.addSelectedDateListener(getattr(self, "onDateSelected"))
        self.todayLink.addClickListener(getattr(self, "onTodayClicked"))
        self.calendarLink.addClickListener(getattr(self, "onShowCalendar"))

        self.tbox.addChangeListener(getattr(self, "onFieldChanged"))
        self.tbox.addInputListener(getattr(self, "onFieldChanged"))

        self._last_date = None

    def emitSelectedDate(self):
        _d = self.getDate()
        if _d == self._last_date:
            return
        self._last_date = _d
        self.fireDateSelectedEvent(_d)

    def onFieldChanged(self, event):
        self.emitSelectedDate()

    def getTextBox(self):
        return self.tbox

    def getCalendar(self):
        return self.calendar

    def getDate(self):
        """ returns datetime.date object or None if empty/unparsable by current format"""
        _sdate = self.tbox.getText()
        try:
            return datetime.strptime(_sdate, self.format).date()
        except ValueError:
            return None

    def setID(self, id):
        self.tbox.setID(id)

    def onDateSelected(self, yyyy, mm, dd):
        secs = time.mktime((int(yyyy), int(mm), int(dd), 0, 0, 0, 0, 0, -1))
        d = time.strftime(self.format, time.localtime(secs))
        self.tbox.setText(d)
        self.emitSelectedDate()

    def onLostFocus(self, sender):
        #
        text = self.tbox.getText().strip()
        # if blank - leave it alone
        if text and len(text) == 8:
            # ok what format do we have? assume ddmmyyyy --> dd-mm-yyyy
            txt = text[0:2] + self.sep + text[2:4] + self.sep + text[4:8]
            self.tbox.setText(txt)
        self.emitSelectedDate()

    def onFocus(self, sender):
        pass

    def onTodayClicked(self, event):
        today = time.strftime(self.format)
        self.tbox.setText(today)
        self.emitSelectedDate()

    def onShowCalendar(self, sender):
        txt = self.tbox.getText().strip()
        try:
            if txt:
                _d = datetime.strptime(txt, self.format).date()
                self.calendar.setDate(_d)
        except ValueError: pass

        p = CalendarPopup(self.calendar)
        x = self.tbox.getAbsoluteLeft() + 10
        y = self.tbox.getAbsoluteTop() + 10
        p.setPopupPosition(x, y)
        p.show()
예제 #5
0
class SongFrequency:

    def __init__(self):
        self.artist =''
        self.start_date = ''
        self.end_date = ''
        self.period_search =''
        self.search_option = 1
        #declare the general interface widgets
        self.panel = DockPanel(StyleName = 'background')
        self.ret_area = TextArea()
        self.ret_area.setWidth("350px")
        self.ret_area.setHeight("90px")
        self.options = ListBox()

        self.search_button = Button("Search", getattr(self, "get_result"), StyleName = 'button')

        #set up the date search panel; it has different text boxes for
        #to and from search dates
        self.date_search_panel = VerticalPanel()
        self.date_search_start = TextBox()
        self.date_search_start.addInputListener(self)
        self.date_search_end = TextBox()
        self.date_search_end.addInputListener(self)
        
        self.date_search_panel.add(HTML("Enter as month/day/year", True, StyleName = 'text'))
        self.date_search_panel.add(HTML("From:", True, StyleName = 'text'))
        self.date_search_panel.add(self.date_search_start)
        self.date_search_panel.add(HTML("To:", True, StyleName = 'text'))
        self.date_search_panel.add(self.date_search_end)
        #set up the artist search panel
        self.artist_search = TextBox()
        self.artist_search.addInputListener(self)
        self.artist_search_panel = VerticalPanel()
        self.artist_search_panel.add(HTML("Enter artist's name:",True,
                                          StyleName = 'text'))
        self.artist_search_panel.add(self.artist_search)

        #Put together the list timespan search options
        self.period_search_panel = VerticalPanel()
        self.period_search_panel.add(HTML("Select a seach period:",True,
                                          StyleName = 'text'))
        self.period_search = ListBox()
        self.period_search.setVisibleItemCount(1)
        self.period_search.addItem("last week")
        self.period_search.addItem("last month")
        self.period_search.addItem("last year")
        self.period_search.addItem("all time")
        self.period_search_panel.add(self.period_search)
        #add the listeners to the appropriate widgets
        self.options.addChangeListener(self)
        self.period_search.addChangeListener(self)
        self.ret_area_scroll = ScrollPanel()
        self.search_panel = HorizontalPanel()
        self.options_panel = VerticalPanel()

    # A change listener for the boxes
    def onChange(self, sender):
        #switch the list box options
        if sender == self.options:
            self.search_panel.remove(self.period_search_panel)
            self.search_panel.remove(self.date_search_panel)
            self.search_panel.remove(self.artist_search_panel)

            index = self.options.getSelectedIndex()

            if index == 0:
                self.search_panel.add(self.artist_search_panel)
                self.search_option = 1
            elif index == 1:
                self.search_panel.add(self.date_search_panel)
                self.search_option = 2
            elif index == 2:
                self.search_panel.add(self.period_search_panel)
                self.search_option = 3

        elif sender == self.period_search:
            index = self.period_search.getSelectedIndex()
            if index == 0:
                self.period_search = "last week"
            elif index == 1:
                self.period_search = "last month"
            elif index == 2:
                self.period_search = "last year"
            elif index == 3:
                self.period_search = "all time"

    #A listener for the text boxes            
    def onInput(self, sender):
        if sender == self.artist_search:
            self.artist = sender.getText()
        elif sender == self.date_search_end:
            self.end_date = sender.getText()
        elif sender == self.date_search_start:
            self.start_date = sender.getText()

    #A listener for the buttons that, when the button is clicked, looks up the results and outputs them
    def get_result(self):
        return_str = " "
        if self.search_option == 1:
            return_str = self.artist
        elif self.search_option == 2:
            return_str = self.start_date
        elif self.search_option ==3:
            return_str = self.period_search
        else:
            return_str = "Find the most played artist, album, or song for a time period, or the number of songs played by a certain artist"
        self.ret_area.setText(return_str)

   
    def onModuleLoad(self):
        #Put together the list of options
        self.options.addItem("Artist")
        self.options.addItem("Date")
        self.options.addItem("Time Span")
        self.options.setVisibleItemCount(3)

        #put the text area together
        self.ret_area_scroll.add(self.ret_area)
        self.ret_area.setText("Find the most played artist, album, or song for a time period, or the number of songs played by a certain artist")
        #put the search items together
        self.search_panel.add(self.artist_search_panel)
        #Put together the options panel
        self.options_panel.add(HTML("Search By:", True, StyleName = 'text'))
        self.options_panel.add(self.options)
        #Add everything to the main panel
        self.panel.add(HTML("WQHS Song Search",True, StyleName = 'header'),
                       DockPanel.NORTH)

        self.panel.add(self.options_panel, DockPanel.WEST)
        
        self.panel.add(self.ret_area_scroll, DockPanel.SOUTH)
        self.panel.setCellHeight(self.ret_area_scroll, "100px")
        self.panel.setCellWidth(self.ret_area_scroll, "300px")

        self.panel.add(self.search_button, DockPanel.EAST)
        
        self.panel.add(self.search_panel, DockPanel.CENTER)
    
        #Associate panel with the HTML host page
        RootPanel().add(self.panel)
예제 #6
0
class Spinner(HorizontalPanel):
    CHAR_WIDTH = 15
    def __init__(self, minvalue=0, maxvalue=100, startvalue=10, interval=1, buttonStyleName=None, decrText='<',
                 incrText='>', **kwargs):
        HorizontalPanel.__init__(self, **kwargs)
        self.minvalue = minvalue
        self.maxvalue = maxvalue
        self.interval = interval
        self.changeListeners = []

        self.lessButton = Button(decrText, listener=self._onArrowClick, StyleName=buttonStyleName)
        self.add(self.lessButton)
        self.textbox = TextBox()
        self.textbox.addInputListener(self._onTextboxInput)
        self.add(self.textbox)

        self.moreButton = Button(incrText, listener=self._onArrowClick, StyleName=buttonStyleName)
        self.add(self.moreButton)

        self.value = startvalue + 1
        self.setValue(startvalue)
        return
    def _resizeTextbox(self):
        width = max(2, len(self.textbox.getText())) * self.CHAR_WIDTH
        if self.textbox.getWidth() != width:
            self.textbox.setWidth(width)
    def _onArrowClick(self, sender):
        if sender == self.lessButton:
            incr = -1 * self.interval
        elif sender == self.moreButton:
            incr = self.interval
        else:
            raise NotImplementedError()
        val = self.getValue() + incr
        self.setValue(val)
    def _onTextboxInput(self, sender):
        text = sender.getText()
        try:
            val = int(text)
        except Exception:
            return
        self.setValue(val)
        return
    def addOnChangeListener(self, listener):
        self.changeListeners.append(listener)
    def removeOnChangeListener(self, listener):
        self.changeListeners.remove(listener)
    def getValue(self):
        return self.value
    def setValue(self, value):
        fixedval = min(self.maxvalue, value)
        fixedval = max(self.minvalue, fixedval)
        if fixedval == self.value:
            return
        self.value = fixedval
        self.textbox.setText(str(self.value))
        self._resizeTextbox()
        self.raiseOnChanged()
    def raiseOnChanged(self):
        for c in self.changeListeners:
            c(self.value)