lastFocus = widget.orderNo if widget.focused: # keep the focued orderNo break nextFocus = None minWidget = None for widget in self.widgets: if widget.orderNo == 0: continue if minWidget == None: minWidget = widget elif widget.orderNo < minWidget.orderNo: minWidget = widget if nextFocus == None: if widget.orderNo > lastFocus: nextFocus = widget elif widget.orderNo > lastFocus and widget.orderNo < nextFocus.orderNo: nextFocus = widget if nextFocus: self.app.setFocus(nextFocus) elif minWidget: self.app.setFocus(minWidget) registerWidget(Window, 'window')
if os.name == "nt": # TODO this is ugly windows only hack char = unicode(chr(ord(evt.unicode)), 'cp1250') else: char = evt.unicode if self.text: self.text = u'%s%c%s' % ( self.text[:self.cursorPos], char, self.text[self.cursorPos:] ) else: self.text = char self.cursorPos += 1 elif mapping.has_key(evt.key): self.text = u'%s%c%s' % ( self.text[:self.cursorPos], mapping[evt.key], self.text[self.cursorPos:] ) self.cursorPos += 1 if (self.reportValueChanged): self.processAction("onValueChanged") return Widget.processKeyDown(self, NoEvent) def onFocusGained(self): Widget.onFocusGained(self) self.cursorPos = len(self.text) def onFocusLost(self): Widget.onFocusLost(self) self.processAction(self.action) registerWidget(Entry, 'entry')
def processMB1UpMissed(self, evt): self._processingMB1 = 0 return Widget.processMB1UpMissed(self, evt) def onMouseOut(self): if self._processingMB1: self.checked = not self.checked return Widget.onMouseOut(self) def onMouseOver(self): if self._processingMB1: self.checked = not self.checked return Widget.onMouseOver(self) def onFocusLost(self): self._processingMB1 = 0 self._processingMB3 = 0 return Widget.onFocusLost(self) def processMB3Down(self, evt): self._processingMB3 = 1 return NoEvent def processMB3Up(self, evt): if self._processingMB3: self.processAction(self.rmbAction) self._processingMB3 = 0 return NoEvent registerWidget(Check, 'check')
def onMouseOver(self): if self._processingMB1: self.theme.playButtonSound(self) self.pressed = not self.pressed return Widget.onMouseOver(self) def onFocusLost(self): self._processingMB1 = 0 self._processingMB3 = 0 return Widget.onFocusLost(self) def processMB3Down(self, evt): self._processingMB3 = 1 if self.rmbAction and not self.toggle: self.pressed = not self.pressed return NoEvent def processMB3Up(self, evt): if self._processingMB3: self.processAction(self.rmbAction) if self.rmbAction and self.pressed and not self.toggle: if self.pressed: self.theme.playButtonSound(self) self.pressed = 0 self._processingMB3 = 0 return NoEvent registerWidget(Button, 'button')
# Pygame.UI is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # Lesser GNU General Public License for more details. # # You should have received a copy of the Lesser GNU General Public License # along with Pygame.UI; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # from pygame.locals import * from Const import * from Widget import Widget, registerWidget class Title(Widget): def __init__(self, parent, **kwargs): Widget.__init__(self, parent) # data self.text = None self.icons = [] # flags self.processKWArguments(kwargs) parent.registerWidget(self) def draw(self, surface): self.theme.drawTitle(surface, self) return self.rect registerWidget(Title, 'title')
# Lesser GNU General Public License for more details. # # You should have received a copy of the Lesser GNU General Public License # along with Pygame.UI; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # from pygame.locals import * from Const import * from Widget import registerWidget from Button import Button class ArrowButton(Button): def __init__(self, parent, **kwargs): Button.__init__(self, parent) # data self.direction = ALIGN_N # del del self.text del self.icons # flags self.processKWArguments(kwargs) parent.registerWidget(self) def draw(self, surface): self.theme.drawArrowButton(surface, self) return self.rect registerWidget(ArrowButton, 'arrowbutton')
self._setListIndex(item.index, item) def addItem(self, item): if item not in self.items: self.items.append(item) def delItem(self, item): self.items.remove(item) self.itemsChanged() def delItemByIndex(self, index): del self.items[index] self.itemsChanged() def setItems(self, items): self.items = items self.itemsChanged() # redirect mouse wheel events to the scollbar def processMWUp(self, evt): return self.bar.processMWUp(evt) def processMWDown(self, evt): return self.bar.processMWDown(evt) def drawMetaWidget(self, surface): return self.theme.drawListbox(surface, self) registerWidget(Listbox, 'listbox')
# Pygame.UI is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # Lesser GNU General Public License for more details. # # You should have received a copy of the Lesser GNU General Public License # along with Pygame.UI; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # import Const from Widget import Widget, registerWidget class Title(Widget): def __init__(self, parent, **kwargs): Widget.__init__(self, parent) # data self.text = None self.icons = [] # flags self.processKWArguments(kwargs) parent.registerWidget(self) def draw(self, surface): self.theme.drawTitle(surface, self) return self.rect registerWidget(Title, 'title')
elif mapping.has_key(evt.key): if self.selStart != None: self.deleteSelection() self.text[self.cursorRow] = u'%s%c%s' % ( self.text[self.cursorRow][:self.cursorColumn], mapping[evt.key], self.text[self.cursorRow][self.cursorColumn:]) self.cursorColumn += 1 return Widget.processKeyDown(self, NoEvent) def onFocusGained(self): Widget.onFocusGained(self) self.cursorRow = len(self.text) - 1 self.cursorColumn = len(self.text[self.cursorRow]) def onFocusLost(self): Widget.onFocusLost(self) self.processAction(self.action) # redirect mouse wheel events to the scollbar def processMWUp(self, evt): return self.vertScrollbar.processMWUp(evt) def processMWDown(self, evt): return self.vertScrollbar.processMWDown(evt) registerWidget(Text, 'text')
self._processingMB1 = 0 return Widget.processMB1UpMissed(self, evt) def onMouseOut(self): if self._processingMB1: self.checked = not self.checked return Widget.onMouseOut(self) def onMouseOver(self): if self._processingMB1: self.checked = not self.checked return Widget.onMouseOver(self) def onFocusLost(self): self._processingMB1 = 0 self._processingMB3 = 0 return Widget.onFocusLost(self) def processMB3Down(self, evt): self._processingMB3 = 1 return NoEvent def processMB3Up(self, evt): if self._processingMB3: self.processAction(self.rmbAction) self._processingMB3 = 0 return NoEvent registerWidget(Check, 'check')
if item.index != None: self._setListIndex(item.index, item) def addItem(self, item): if item not in self.items: self.items.append(item) def delItem(self, item): self.items.remove(item) self.itemsChanged() def delItemByIndex(self, index): del self.items[index] self.itemsChanged() def setItems(self, items): self.items = items self.itemsChanged() # redirect mouse wheel events to the scollbar def processMWUp(self, evt): return self.bar.processMWUp(evt) def processMWDown(self, evt): return self.bar.processMWDown(evt) def drawMetaWidget(self, surface): return self.theme.drawListbox(surface, self) registerWidget(Listbox, 'listbox')
# if shown is greater then max, then position is negative if self.position < self.min: self.position = self.min if self.dragging and evt.buttons[0] == 1: self.processAction(self.action) return NoEvent def processMWUp(self, evt): self.position -= 3 if self.position < self.min: self.position = self.min self.processAction(self.action) return NoEvent def processMWDown(self, evt): self.position += 3 if self.position + self.shown > self.max: self.position = self.max - self.shown # if shown is greater then max, then position is negative if self.position < self.min: self.position = self.min self.processAction(self.action) return NoEvent registerWidget(ScrollSlider, "scrollslider")
import Const from Widget import Widget, registerWidget class ColorBox(Widget): def __init__(self, parent, **kwargs): Widget.__init__(self, parent) # data self.color = None self.margins = (0, 0, 0, 0) # flags self.processKWArguments(kwargs) parent.registerWidget(self) def draw(self, surface): oldClip = surface.get_clip() surface.set_clip(self.rect.left + self.margins[0], self.rect.top + self.margins[1], self.rect.width - self.margins[2] - self.margins[0], self.rect.height - self.margins[3] - self.margins[1]) surface.fill(self.color) surface.set_clip(oldClip) return self.rect registerWidget(ColorBox, 'colorbox')
# Pygame.UI is free software; you can redistribute it and/or modify # it under the terms of the Lesser GNU General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # Pygame.UI is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # Lesser GNU General Public License for more details. # # You should have received a copy of the Lesser GNU General Public License # along with Pygame.UI; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # import Const from Widget import registerWidget from Button import Button class ActiveLabel(Button): def draw(self, surface): if self.mouseOver: self.theme.drawLabel(surface, self, 1) else: self.theme.drawLabel(surface, self, 0) return self.rect registerWidget(ActiveLabel, 'activelabel')
# Lesser GNU General Public License for more details. # # You should have received a copy of the Lesser GNU General Public License # along with Pygame.UI; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # import Const from Widget import registerWidget from Button import Button class ArrowButton(Button): def __init__(self, parent, **kwargs): Button.__init__(self, parent) # data self.direction = Const.ALIGN_N # del del self.text del self.icons # flags self.processKWArguments(kwargs) parent.registerWidget(self) def draw(self, surface): self.theme.drawArrowButton(surface, self) return self.rect registerWidget(ArrowButton, 'arrowbutton')
# it under the terms of the Lesser GNU General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # Pygame.UI is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # Lesser GNU General Public License for more details. # # You should have received a copy of the Lesser GNU General Public License # along with Pygame.UI; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # from pygame.locals import * from Const import * from Widget import registerWidget from Button import Button class ActiveLabel(Button): def draw(self, surface): if self.mouseOver: self.theme.drawLabel(surface, self, 1) else: self.theme.drawLabel(surface, self, 0) return self.rect registerWidget(ActiveLabel, "activelabel")
self.text[self.cursorRow] = u'%s%c%s' % ( self.text[self.cursorRow][:self.cursorColumn], mapping[evt.key], self.text[self.cursorRow][self.cursorColumn:] ) self.cursorColumn += 1 return Widget.processKeyDown(self, Const.NoEvent) def onFocusGained(self): Widget.onFocusGained(self) self.cursorRow = len(self.text) - 1 self.cursorColumn = len(self.text[self.cursorRow]) def onFocusLost(self): Widget.onFocusLost(self) self.processAction(self.action) # redirect mouse wheel events to the scollbar def processMWUp(self, evt): if self.vertScrollbar: return self.vertScrollbar.processMWUp(evt) def processMWDown(self, evt): if self.vertScrollbar: return self.vertScrollbar.processMWDown(evt) registerWidget(Text, 'text')
# Pygame.UI is free software; you can redistribute it and/or modify # it under the terms of the Lesser GNU General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # Pygame.UI is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # Lesser GNU General Public License for more details. # # You should have received a copy of the Lesser GNU General Public License # along with Pygame.UI; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # from pygame.locals import * from Const import * from Widget import registerWidget from Button import Button class ActiveLabel(Button): def draw(self, surface): if self.mouseOver: self.theme.drawLabel(surface, self, 1) else: self.theme.drawLabel(surface, self, 0) return self.rect registerWidget(ActiveLabel, 'activelabel')
if not button.visible: button.visible = 1 if item == self.selected: button.pressed = 1 # do not trigger auto update self.__dict__['selectedButton'] = button else: button.pressed = 0 else: break index += 1 while index < len(self.buttons): button = self.buttons[index] button.text = None button.icons = None button.data = None button.tooltip = None button.statustip = None button.pressed = 0 button.enabled = 0 button.foreground = None button.background = None if button.visible: button.visible = 0 index += 1 self.clearSelection() self.parent.redraw(self) def drawMetaWidget(self, surface): return self.theme.drawListbox(surface, self) registerWidget(ButtonArray, 'buttonarray')
elif evt.key == pygame.K_LEFT: if self.cursorPos > 0: self.cursorPos -= 1 elif evt.key == pygame.K_RIGHT: if self.cursorPos < len(self.text): self.cursorPos += 1 elif evt.key == pygame.K_TAB: pass elif hasattr(evt, 'unicode') and evt.unicode: # TODO this is ugly windows only hack needed for Win 9x and XP # char = unicode(chr(ord(evt.unicode)), 'cp1250') char = evt.unicode if self.text: self.text = u'%s%c%s' % ( self.text[:self.cursorPos], char, self.text[self.cursorPos:] ) else: self.text = char self.cursorPos += 1 if (self.reportValueChanged): self.processAction("onValueChanged") return Widget.processKeyDown(self, Const.NoEvent) def onFocusGained(self): Widget.onFocusGained(self) self.cursorPos = len(self.text) def onFocusLost(self): Widget.onFocusLost(self) self.processAction(self.action) registerWidget(Entry, 'entry')
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # Lesser GNU General Public License for more details. # # You should have received a copy of the Lesser GNU General Public License # along with Pygame.UI; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # from pygame.locals import * from Const import * from Widget import Widget, registerWidget class ProgressBar(Widget): def __init__(self, parent, **kwargs): Widget.__init__(self, parent) # data self.min = 0 self.max = 100 self.value = 0 # flags self.processKWArguments(kwargs) parent.registerWidget(self) def draw(self, surface): self.theme.drawProgressBar(surface, self) return self.rect registerWidget(ProgressBar, 'progressbar')
from pygame.locals import * from Const import * from Widget import Widget, registerWidget class ColorBox(Widget): def __init__(self, parent, **kwargs): Widget.__init__(self, parent) # data self.color = None self.margins = (0, 0, 0, 0) # flags self.processKWArguments(kwargs) parent.registerWidget(self) def draw(self, surface): oldClip = surface.get_clip() surface.set_clip(self.rect.left + self.margins[0], self.rect.top + self.margins[1], self.rect.width - self.margins[2] - self.margins[0], self.rect.height - self.margins[3] - self.margins[1]) surface.fill(self.color) surface.set_clip(oldClip) return self.rect registerWidget(ColorBox, 'colorbox')
# (at your option) any later version. # # Pygame.UI is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # Lesser GNU General Public License for more details. # # You should have received a copy of the Lesser GNU General Public License # along with Pygame.UI; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # import Const from Widget import registerWidget from Button import Button class TitleButton(Button): def __init__(self, parent, **kwargs): Button.__init__(self, parent) # data # flags self.processKWArguments(kwargs) parent.registerWidget(self) def draw(self, surface): self.theme.drawTitleButton(surface, self) registerWidget(TitleButton, 'titlebutton')
# (at your option) any later version. # # Pygame.UI is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # Lesser GNU General Public License for more details. # # You should have received a copy of the Lesser GNU General Public License # along with Pygame.UI; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # from pygame.locals import * from Const import * from Widget import registerWidget from Button import Button class TitleButton(Button): def __init__(self, parent, **kwargs): Button.__init__(self, parent) # data # flags self.processKWArguments(kwargs) parent.registerWidget(self) def draw(self, surface): self.theme.drawTitleButton(surface, self) registerWidget(TitleButton, 'titlebutton')
return self.theme.drawScrollbar(surface, self) def onButton1(self, widget, actionName, data): s = self.slider s.position -= s.shown if s.position < s.min: s.position = s.min self.processAction(self.action) def onButton2(self, widget, actionName, data): s = self.slider s.position += s.shown if s.position + s.shown > s.max: s.position = s.max - s.shown # if shown is greater then max, then position is negative if s.position < s.min: s.position = s.min self.processAction(self.action) def onSlider(self, widget, actionName, data): self.processAction(self.action) # redirect mouse wheel events to the slider def processMWUp(self, evt): return self.slider.processMWUp(evt) def processMWDown(self, evt): return self.slider.processMWDown(evt) registerWidget(Scrollbar, 'scrollbar')
# Pygame.UI is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # Lesser GNU General Public License for more details. # # You should have received a copy of the Lesser GNU General Public License # along with Pygame.UI; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # import Const from Widget import Widget, registerWidget class ProgressBar(Widget): def __init__(self, parent, **kwargs): Widget.__init__(self, parent) # data self.min = 0 self.max = 100 self.value = 0 # flags self.processKWArguments(kwargs) parent.registerWidget(self) def draw(self, surface): self.theme.drawProgressBar(surface, self) return self.rect registerWidget(ProgressBar, 'progressbar')
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # Lesser GNU General Public License for more details. # # You should have received a copy of the Lesser GNU General Public License # along with Pygame.UI; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # from pygame.locals import * from Const import * from Widget import Widget, registerWidget class Label(Widget): def __init__(self, parent, **kwargs): Widget.__init__(self, parent) # data self.text = None self.icons = [] # flags self.processKWArguments(kwargs) parent.registerWidget(self) def draw(self, surface): self.theme.drawLabel(surface, self) return self.rect registerWidget(Label, 'label')
# # Pygame.UI is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # Lesser GNU General Public License for more details. # # You should have received a copy of the Lesser GNU General Public License # along with Pygame.UI; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # import Const from Widget import Widget, registerWidget class Label(Widget): def __init__(self, parent, **kwargs): Widget.__init__(self, parent) # data self.text = None self.icons = [] # flags self.processKWArguments(kwargs) parent.registerWidget(self) def draw(self, surface): self.theme.drawLabel(surface, self) return self.rect registerWidget(Label, 'label')
self.position = self.max - self.shown # if shown is greater then max, then position is negative if self.position < self.min: self.position = self.min if self.dragging and evt.buttons[0] == 1: self.processAction(self.action) return NoEvent def processMWUp(self, evt): self.position -= 1 if self.position < self.min: self.position = self.min self.processAction(self.action) return NoEvent def processMWDown(self, evt): self.position += 1 if self.position + self.shown > self.max: self.position = self.max - self.shown # if shown is greater then max, then position is negative if self.position < self.min: self.position = self.min self.processAction(self.action) return NoEvent registerWidget(ScrollSlider, 'scrollslider')
def onButton1(self, widget, actionName, data): s = self.slider s.position -= s.shown if s.position < s.min: s.position = s.min self.processAction(self.action) def onButton2(self, widget, actionName, data): s = self.slider s.position += s.shown if s.position + s.shown > s.max: s.position = s.max - s.shown # if shown is greater then max, then position is negative if s.position < s.min: s.position = s.min self.processAction(self.action) def onSlider(self, widget, actionName, data): self.processAction(self.action) # redirect mouse wheel events to the slider def processMWUp(self, evt): return self.slider.processMWUp(evt) def processMWDown(self, evt): return self.slider.processMWDown(evt) registerWidget(Scrollbar, 'scrollbar')