Esempio n. 1
0
class PopupPanelDemo(SimplePanel):
    def __init__(self):
        SimplePanel.__init__(self)

        vPanel = VerticalPanel(Spacing=4)

        self._btn = Button("Click Me", getattr(self, "showPopup"))

        vPanel.add(HTML("Click on the button below to display the popup."))
        vPanel.add(self._btn)

        self.add(vPanel)


    def showPopup(self, event):
        contents = HTML("Hello, World!")
        contents.addClickListener(getattr(self, "onClick"))

        self._popup = PopupPanel(autoHide=True)
        self._popup.add(contents)
        self._popup.setStyleName("showcase-popup")

        left = self._btn.getAbsoluteLeft() + 10
        top  = self._btn.getAbsoluteTop() + 10
        self._popup.setPopupPosition(left, top)
        self._popup.show()


    def onClick(self, sender=None):
        self._popup.hide()
Esempio n. 2
0
class PopupPanelDemo(SimplePanel):
    def __init__(self):
        SimplePanel.__init__(self)

        vPanel = VerticalPanel()
        vPanel.setSpacing(4)

        self._btn = Button("Click Me", getattr(self, "showPopup"))

        vPanel.add(HTML("Click on the button below to display the popup."))
        vPanel.add(self._btn)

        self.add(vPanel)

    def showPopup(self, event):
        contents = HTML("Hello, World!")
        contents.addClickListener(getattr(self, "onClick"))

        self._popup = PopupPanel(autoHide=True)
        self._popup.add(contents)
        self._popup.setStyleName("showcase-popup")

        left = self._btn.getAbsoluteLeft() + 10
        top = self._btn.getAbsoluteTop() + 10
        self._popup.setPopupPosition(left, top)
        self._popup.show()

    def onClick(self, sender=None):
        self._popup.hide()
Esempio n. 3
0
    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)
Esempio n. 4
0
    def hide(self, autoClosed=False):
        if not self.showing:
            return

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

        PopupPanel.hide(self)
class OperationElement(Element, ClickHandler):
                     
    def __init__(self, text, group, groupLabel, block):
        Element.__init__(self, Element=DOM.createElement('code'), StyleName='group_operation')
        ClickHandler.__init__(self)
        self.addClickListener(self)
        self.text = text
        self.group = group
        self.groupLabel = groupLabel
        self.block = block
        self.draw()
        
    def changeTexts(self):
        if self.text != '':
            DOM.setInnerHTML(self.title.getElement(), _(self.text))

    def draw(self):
        self.title = Element(Element=DOM.createSpan(), StyleName='title')
        DOM.setInnerHTML(self.title.getElement(), self.text)
        self.add(self.title)
        self.tip = PopupPanel(Element=DOM.createElement('code'), autoHide=True, modal=False, rootpanel=self)
        div = Element(Element=DOM.createElement('div'), StyleName='joyride-tip-guide')
        div.add(Widget(Element=DOM.createSpan(), StyleName='joyride-nub left'))
        self.tipItens = Element(Element=DOM.createElement('div'), StyleName='tip-itens')
        div.add(self.tipItens)
        self.tip.add(div)
        
    def onClick(self, sender):
        if self.tip.showing: self.tip.hide()
        else:
            if self.groupLabel is None: self.addValues(self.group)
            else: self.addValues(self.groupLabel)         
            self.tip.show()
    
    def addValues(self, values):
        self.tipItens.removeAll()
        if len(values)==2: self.tip.getWidget().addStyleName('two_itens')
        else: self.tip.getWidget().removeStyleName('two_itens')
        if len(values)==3: self.tip.getWidget().addStyleName('tree_itens')
        else: self.tip.getWidget().removeStyleName('tree_itens')
        for value in values.keys():
            self.tipItens.append(MenuItenListener(self.itemClick, value, StyleName='tip-item'))
    
    def itemClick(self, value):
        if self.block.original: return
        oldValue = self.block.name
        if self.groupLabel is None:
            DOM.setInnerHTML(self.title.getElement(), _(value))
            self.block.name = self.group[value]
        else:
            DOM.setInnerHTML(self.title.getElement(), _(self.groupLabel[value]))
            self.block.name = self.group[self.groupLabel[value]]
        if oldValue != value:
            from edu.uca.util.Serializable import stateChange
            stateChange()
            
Esempio n. 6
0
class AutoCompleteByURLTextBox(AutoCompleteTextBox):
	def __init__(self, url):
		self.choicesPopup = PopupPanel(True)
		self.choices = ListBox()
		self.items = AutoCompleteURL(url)
		self.popupAdded = False
		self.visible = False
		
		TextBox.__init__(self)
		self.addKeyboardListener(self)
		self.choices.addChangeListener(self)
		self.setStyleName("AutoCompleteTextBox")
		
		self.choicesPopup.add(self.choices)
		self.choicesPopup.addStyleName("AutoCompleteChoices")
		
		self.choices.setStyleName("list")
		self.url = url
	
	"""
	def setCompletionItems(self, items):
		if not items.getCompletionItems:
			items = AutoCompletionURL(self.url)
		
		self.items = items

	def getCompletionItems(self):
		return self.items
	"""
	
	def onKeyUp(self, arg0, arg1, arg2):
		if arg1 == KeyboardListener.KEY_DOWN:
			selectedIndex = self.choices.getSelectedIndex()
			selectedIndex += 1
			if selectedIndex > self.choices.getItemCount():
				selectedIndex = 0
		
			self.choices.setSelectedIndex(selectedIndex)		   
			return

		if arg1 == KeyboardListener.KEY_UP:
			selectedIndex = self.choices.getSelectedIndex()
			selectedIndex -= 1
			if selectedIndex < 0:
				selectedIndex = self.choices.getItemCount()
			self.choices.setSelectedIndex(selectedIndex)
			return

		if arg1 == KeyboardListener.KEY_ENTER:
			if self.visible:
				self.complete()	  
			return

		if arg1 == KeyboardListener.KEY_ESCAPE:
			self.choices.clear()
			self.choicesPopup.hide()
			self.visible = False
			return

		text = self.getText()
		matches = []
		if len(text) > 0:
			matches = self.items.getCompletionItems(text)

		if len(matches) > 0:
			self.choices.clear()

			for i in range(len(matches)):
				self.choices.addItem(matches[i])
				
			if len(matches) == 1 and matches[0] == text:
				self.choicesPopup.hide()
			else:
				self.choices.setSelectedIndex(0)
				self.choices.setVisibleItemCount(len(matches) + 1)
					
				if not self.popupAdded:
					RootPanel().add(self.choicesPopup)
					self.popupAdded = True

				self.choicesPopup.show()
				self.visible = True
				self.choicesPopup.setPopupPosition(self.getAbsoluteLeft(), self.getAbsoluteTop() + self.getOffsetHeight())
				self.choices.setWidth(self.getOffsetWidth() + "px")
		else:
			self.visible = False
			self.choicesPopup.hide()
Esempio n. 7
0
class MenuCmd:
    def __init__(self, menu, command):
        self.menu = menu
        self.command = command

    def execute(self):
        if self.command in ('Beginner', 'Intermediate', 'Expert', 'Custom'):
            body = doc().getElementsByTagName('body').item(0)
            body.setAttribute('id', self.command)

        modes = {
            'New': [(0, 0), 0],
            'Beginner': [(8, 8), 1],
            'Intermediate': [(16, 16), 2],
            'Expert': [(16, 32), 3]
        }
        level = modes.get(self.command)
        if level:
            if level[1]:
                self.menu.game.level = level[1]
            self.menu.game.next_game(level[0])
        elif self.command == 'Custom':
            self.menu.game.level = 4
            self.show_custom()
        elif self.command == 'Instructions':
            pass
        elif self.command == 'About':
            self.show_about()

    def show_custom(self):
        self.dialog = DialogBox(StyleName='custom-dialog')
        self.dialog.setHTML('Custom Settings')

        contents = VerticalPanel(StyleName='contents')
        self.dialog.setWidget(contents)

        # contents of contents
        rows = HorizontalPanel()
        columns = HorizontalPanel()
        bombs = HorizontalPanel()
        buttons = HorizontalPanel()

        for each in (rows, columns, bombs, buttons):
            contents.add(each)

        rows.add(Label('Rows:'))
        self.row = TextBox()
        rows.add(self.row)

        columns.add(Label('Columns:'))
        self.column = TextBox()
        columns.add(self.column)

        bombs.add(Label('Bombs:'))
        self.bomb = TextBox()
        bombs.add(self.bomb)

        buttons.add(Button("OK", getattr(self, 'new_game')))
        buttons.add(Button("Cancel", getattr(self, 'close_dialog')))

        left = (Window.getClientWidth() - 201) / 2
        top = (Window.getClientHeight() - 190) / 2
        self.dialog.setPopupPosition(left, top)

        self.dialog.show()

    def new_game(self, event):
        try:
            row = int(self.row.getText())
        except:
            Window.alert('Invalid number in rows')
            return
        try:
            column = int(self.column.getText())
        except:
            Window.alert('Invalid number in columns')
            return
        try:
            bomb = int(self.bomb.getText())
        except:
            bomb = 0
        if bomb >= (row * column):
            Window.alert("Number of bombs should not be greater than " \
                         "rows x columns.")
        else:
            self.menu.game.next_game((row, column), bomb)
            self.close_dialog()

    def close_dialog(self, event):
        self.dialog.hide()

    def show_about(self):
        self.dialog = PopupPanel(StyleName='about', autoHide=True)

        contents = HTMLPanel('', StyleName='contents')
        self.dialog.setWidget(contents)

        html = '<p class="pyjamas">MineSweeper written in Python with ' \
                    '<a href="http://pyjs.org" target="_blank">Pyjamas</a><p>' \
               '<p class="comments">Send comments to ' \
                    '<a href="mailto:[email protected]">' \
                        '[email protected]</a>.<p>'
        contents.setHTML(html)

        left = (Window.getClientWidth() - 294) / 2
        top = (Window.getClientHeight() - 112) / 2
        self.dialog.setPopupPosition(left, top)
        self.dialog.show()
Esempio n. 8
0
 def hide(self, autoClosed=False):
     self.tooltip_show_timer.cancel()
     PopupPanel.hide(self, autoClosed)
Esempio n. 9
0
class AutoCompleteTextBox(TextBox):
    def __init__(self, **kwargs):
        self.choicesPopup = PopupPanel(True, False)
        self.choices = ListBox()
        self.items = SimpleAutoCompletionItems()
        self.popupAdded = False
        self.visible = False

        self.choices.addClickListener(self)
        self.choices.addChangeListener(self)

        self.choicesPopup.add(self.choices)
        self.choicesPopup.addStyleName("AutoCompleteChoices")
            
        self.choices.setStyleName("list")

        if not kwargs.has_key('StyleName'): kwargs['StyleName']="gwt-AutoCompleteTextBox"

        TextBox.__init__(self, **kwargs)
        self.addKeyboardListener(self)

    def setCompletionItems(self, items):
        if not hasattr(items, 'getCompletionItems'):
            items = SimpleAutoCompletionItems(items)
        
        self.items = items

    def getCompletionItems(self):
        return self.items

    def onKeyDown(self, arg0, arg1, arg2):
        pass

    def onKeyPress(self, arg0, arg1, arg2):
        pass

    def onKeyUp(self, arg0, arg1, arg2):
        if arg1 == KeyboardListener.KEY_DOWN:
            selectedIndex = self.choices.getSelectedIndex()
            selectedIndex += 1
            if selectedIndex >= self.choices.getItemCount():
                selectedIndex = 0
            self.choices.setSelectedIndex(selectedIndex)           
            return

        if arg1 == KeyboardListener.KEY_UP:
            selectedIndex = self.choices.getSelectedIndex()
            selectedIndex -= 1
            if selectedIndex < 0:
                selectedIndex = self.choices.getItemCount() - 1
            self.choices.setSelectedIndex(selectedIndex)
            return

        if arg1 == KeyboardListener.KEY_ENTER:
            if self.visible:
                self.complete()      
            return

        if arg1 == KeyboardListener.KEY_ESCAPE:
            self.choices.clear()
            self.choicesPopup.hide()
            self.visible = False
            return

        text = self.getText()
        matches = []
        if len(text) > 0:
            matches = self.items.getCompletionItems(text)

        if len(matches) > 0:
            self.choices.clear()

            for i in range(len(matches)):
                self.choices.addItem(matches[i])
                
            if len(matches) == 1 and matches[0] == text:
                self.choicesPopup.hide()
            else:
                self.choices.setSelectedIndex(0)
                self.choices.setVisibleItemCount(len(matches) + 1)
                    
                if not self.popupAdded:
                    RootPanel().add(self.choicesPopup)
                    self.popupAdded = True

                self.choicesPopup.show()
                self.visible = True
                self.choicesPopup.setPopupPosition(self.getAbsoluteLeft(), self.getAbsoluteTop() + self.getOffsetHeight())
                self.choices.setWidth("%dpx" % self.getOffsetWidth())
        else:
            self.visible = False
            self.choicesPopup.hide()

    def onChange(self, arg0):
        self.complete()

    def onClick(self, arg0):
        self.complete()

    def complete(self):
        if self.choices.getItemCount() > 0:
            self.setText(self.choices.getItemText(self.choices.getSelectedIndex()))
            
        self.choices.clear()
        self.choicesPopup.hide()
        self.setFocus(True)
        self.visible = False
Esempio n. 10
0
class MenuCmd:
    def __init__(self, menu, command):
        self.menu = menu
        self.command = command
    
    def execute(self):
        if self.command in ('Beginner', 'Intermediate', 'Expert', 'Custom'):
            body = doc().getElementsByTagName('body').item(0)
            body.setAttribute('id', self.command)
        
        modes = {'New': [(0, 0), 0],
                 'Beginner': [(8, 8), 1],
                 'Intermediate': [(16, 16), 2],
                 'Expert': [(16, 32), 3]}
        level = modes.get(self.command)
        if level:
            if level[1]:
                self.menu.game.level = level[1]
            self.menu.game.next_game(level[0])
        elif self.command == 'Custom':
            self.menu.game.level = 4
            self.show_custom()
        elif self.command == 'Instructions':
            pass
        elif self.command == 'About':
            self.show_about()
    
    def show_custom(self):
        self.dialog = DialogBox(StyleName='custom-dialog')
        self.dialog.setHTML('Custom Settings')
        
        contents = VerticalPanel(StyleName='contents')
        self.dialog.setWidget(contents)
        
        # contents of contents
        rows = HorizontalPanel()
        columns = HorizontalPanel()
        bombs = HorizontalPanel()
        buttons = HorizontalPanel()
        
        for each in (rows, columns, bombs, buttons):
            contents.add(each)
        
        rows.add(Label('Rows:'))
        self.row = TextBox()
        rows.add(self.row)
        
        columns.add(Label('Columns:'))
        self.column = TextBox()
        columns.add(self.column)
        
        bombs.add(Label('Bombs:'))
        self.bomb = TextBox()
        bombs.add(self.bomb)
        
        buttons.add(Button("OK", getattr(self, 'new_game')))
        buttons.add(Button("Cancel", getattr(self, 'close_dialog')))
        
        left = (Window.getClientWidth() - 201) / 2
        top = (Window.getClientHeight() - 190) / 2
        self.dialog.setPopupPosition(left, top)
        
        self.dialog.show()
    
    def new_game(self, event):
        try:
            row = int(self.row.getText())
        except:
            Window.alert('Invalid number in rows')
            return
        try:
            column = int(self.column.getText())
        except:
            Window.alert('Invalid number in columns')
            return
        try:
            bomb = int(self.bomb.getText())
        except:
            bomb = 0
        if bomb >= (row * column):
            Window.alert("Number of bombs should not be greater than " \
                         "rows x columns.")
        else:
            self.menu.game.next_game((row, column), bomb)
            self.close_dialog()
    
    def close_dialog(self, event):
        self.dialog.hide()
    
    def show_about(self):
        self.dialog = PopupPanel(StyleName='about', autoHide=True)
        
        contents = HTMLPanel('', StyleName='contents')
        self.dialog.setWidget(contents)
        
        html = '<p class="pyjamas">MineSweeper written in Python with ' \
                    '<a href="http://pyjs.org" target="_blank">Pyjamas</a><p>' \
               '<p class="comments">Send comments to ' \
                    '<a href="mailto:[email protected]">' \
                        '[email protected]</a>.<p>'
        contents.setHTML(html)
        
        left = (Window.getClientWidth() - 294) / 2
        top = (Window.getClientHeight() - 112) / 2
        self.dialog.setPopupPosition(left, top)
        self.dialog.show()
Esempio n. 11
0
class AutoCompleteTextBox(TextBox):
    def __init__(self, **kwargs):
        self.choicesPopup = PopupPanel(True, False)
        self.choices = ListBox()
        self.items = SimpleAutoCompletionItems()
        self.popupAdded = False
        self.visible = False

        self.choices.addClickListener(self)
        self.choices.addChangeListener(self)

        self.choicesPopup.add(self.choices)
        self.choicesPopup.addStyleName("AutoCompleteChoices")

        self.choices.setStyleName("list")

        if not kwargs.has_key('StyleName'):
            kwargs['StyleName'] = "gwt-AutoCompleteTextBox"

        TextBox.__init__(self, **kwargs)
        self.addKeyboardListener(self)

    def setCompletionItems(self, items):
        if not hasattr(items, 'getCompletionItems'):
            items = SimpleAutoCompletionItems(items)

        self.items = items

    def getCompletionItems(self):
        return self.items

    def onKeyDown(self, arg0, arg1, arg2):
        pass

    def onKeyPress(self, arg0, arg1, arg2):
        pass

    def onKeyUp(self, arg0, arg1, arg2):
        if arg1 == KeyboardListener.KEY_DOWN:
            selectedIndex = self.choices.getSelectedIndex()
            selectedIndex += 1
            if selectedIndex >= self.choices.getItemCount():
                selectedIndex = 0
            self.choices.setSelectedIndex(selectedIndex)
            return

        if arg1 == KeyboardListener.KEY_UP:
            selectedIndex = self.choices.getSelectedIndex()
            selectedIndex -= 1
            if selectedIndex < 0:
                selectedIndex = self.choices.getItemCount() - 1
            self.choices.setSelectedIndex(selectedIndex)
            return

        if arg1 == KeyboardListener.KEY_ENTER:
            if self.visible:
                self.complete()
            return

        if arg1 == KeyboardListener.KEY_ESCAPE:
            self.choices.clear()
            self.choicesPopup.hide()
            self.visible = False
            return

        text = self.getText()
        matches = []
        if len(text) > 0:
            matches = self.items.getCompletionItems(text)

        if len(matches) > 0:
            self.choices.clear()

            for i in range(len(matches)):
                self.choices.addItem(matches[i])

            if len(matches) == 1 and matches[0] == text:
                self.choicesPopup.hide()
            else:
                self.choices.setSelectedIndex(0)
                self.choices.setVisibleItemCount(len(matches) + 1)

                if not self.popupAdded:
                    RootPanel().add(self.choicesPopup)
                    self.popupAdded = True

                self.choicesPopup.show()
                self.visible = True
                self.choicesPopup.setPopupPosition(
                    self.getAbsoluteLeft(),
                    self.getAbsoluteTop() + self.getOffsetHeight())
                self.choices.setWidth("%dpx" % self.getOffsetWidth())
        else:
            self.visible = False
            self.choicesPopup.hide()

    def onChange(self, arg0):
        self.complete()

    def onClick(self, arg0):
        self.complete()

    def complete(self):
        if self.choices.getItemCount() > 0:
            self.setText(
                self.choices.getItemText(self.choices.getSelectedIndex()))

        self.choices.clear()
        self.choicesPopup.hide()
        self.setFocus(True)
        self.visible = False
Esempio n. 12
0
class MenuCmd:
    def __init__(self, menu, command):
        self.menu = menu
        self.command = command

    def execute(self):
        if self.command == 'New':
            self.menu.game.restart()
        if self.command in ('Beginner', 'Intermediate', 'Expert', 'Custom'):
            body = doc().getElementsByTagName('body').item(0)
            body.setAttribute('id', self.command)

            levels = {'Beginner':     [1, ( 8,  8)],
                      'Intermediate': [2, (16, 16)],
                      'Expert':       [3, (16, 32)],
                      'Custom':       [4]}
            level_rc = levels[self.command]
            self.menu.game.level = level_rc[0]
            if level_rc[0] == 4:
                self.show_custom()
            else:
                self.menu.game.next_game(*level_rc[1])
        elif self.command == 'Instructions':
            pass
        elif self.command == 'About':
            self.show_about()

    def show_custom(self):
        self.dialog = DialogBox(StyleName='custom-dialog')
        self.dialog.setHTML('Custom Settings')

        contents = VerticalPanel(StyleName='contents')
        self.dialog.setWidget(contents)

        # contents of contents
        rows = HorizontalPanel()
        columns = HorizontalPanel()
        bombs = HorizontalPanel()
        buttons = HorizontalPanel()

        ADD(contents, rows, columns, bombs, buttons)

        self.row = TextBox()
        ADD(rows, Label('Rows:'), self.row)

        self.column = TextBox()
        ADD(columns, Label('Columns:'), self.column)

        self.bomb = TextBox()
        ADD(bombs, Label('Bombs:'), self.bomb)

        ADD(buttons, Button("OK", getattr(self, 'new_game')), \
                     Button("Cancel", getattr(self, 'close_dialog')))

        left = (Window.getClientWidth() - 201) / 2
        top = (Window.getClientHeight() - 190) / 2
        self.dialog.setPopupPosition(left, top)

        self.dialog.show()

    def new_game(self, sender):
        try:
            row = int(self.row.getText())
            column = int(self.column.getText())
            if not (2 <= row <= 50 and 2 <= column <= 50):
                raise
        except:
            Window.alert('Valid numbers in row and column field are 2 - 50.')
            return
        bomb = self.bomb.getText()
        if bomb:
            try:
                bomb = int(bomb)
                if not (1 <= bomb <= row*column-2):
                    raise
            except:
                Window.alert('Valid numbers in bomb field are 1 to row*column-2.')
                return
        else:
            bomb = self.menu.game.calculate_no_of_bomb(row, column)
        self.menu.game.next_game(row, column, bomb)
        self.close_dialog(sender)

    def close_dialog(self, sender):
        self.dialog.hide()

    def show_about(self):
        self.dialog = PopupPanel(StyleName='about', autoHide=True)

        contents = HTMLPanel('', StyleName='contents')
        self.dialog.setWidget(contents)

        html = '<p class="pyjamas">MineSweeper written in Python with ' \
                    '<a href="http://pyjs.org" target="_blank">Pyjamas</a><p>' \
               '<p class="comments">Send comments to ' \
                    '<a href="mailto:[email protected]">' \
                        '[email protected]</a>.<p>'
        contents.setHTML(html)

        left = (Window.getClientWidth() - 294) / 2
        top = (Window.getClientHeight() - 112) / 2
        self.dialog.setPopupPosition(left, top)
        self.dialog.show()