Beispiel #1
0
    def __init__(self,pos, size, steps=10,\
                 transparent=False, backcol=GREY, barfcol=DEEPSKYBLUE4, barbcol=BLACK):
        """pos is the postion to place this widget
        size is a tuple with the width and height of the widget
        steps is the amount of steps that should be taken to fill the bar, defaults to 10
        The update call returns the number of steps taken, when the bar is full it will return False
        """
        Widget.__init__(self)
        self.end = size[0]
        self.step = self.end / steps
        self.steps = steps
        self.backcol = backcol
        self.barfcol = barfcol
        self.barbcol = barbcol

        self.image = pygame.Surface((size[0], size[1]))
        self.image.fill(backcol)
        self.rect = self.image.get_rect()
        pygame.draw.rect(self.image, barbcol, self.rect.inflate(-8, -8), 0)

        self.barsurf = pygame.Surface((size[0] - 8, size[1] - 8))
        self.barsurf.fill(barfcol)
        self.barrect = self.barsurf.get_rect()
        self.barend = self.step
        self._initbar()
        self.moveto(pos)
Beispiel #2
0
 def __init__(self, txt, pos=(0, 0), fsize=18, padding=4, name='', fbold=True, **kwargs):
     """Button which shows a text
     txt - string to display
     pos - position to display the box
     fsize - Font size
     padding - space in pixels around the text
     name - string to indicate this object
     kwargs - bgcol, fgcol
     """
     Widget.__init__(self)
     if kwargs.has_key('fgcol'):
         fgcol = kwargs['fgcol']
     else:
         fgcol = self.THEME['button_fg_color']
     self.kwargs = kwargs
     self.ImSelected = False
     if type(txt) in (types.StringType, types.UnicodeType):
         s = utils.char2surf(txt, fcol=fgcol, fsize=fsize, ttf=TTF, bold=fbold)
         r = s.get_rect()
         r.w += padding*2
         r.h += padding*2
     else:
         s = txt
         r = s.get_rect()
         r.w += padding*2
         r.h += padding*2
     if kwargs.has_key('maxlength') and r.w > kwargs['maxlength']:
         r.w = kwargs['maxlength']
     self.pos = pos
     self.padding = padding
     self.name = name
     self.r = r
     self._setup(s)
Beispiel #3
0
 def __init__(self, rect, fsize, bgcol=None, fgcol=None, padding=8, border=2, lines=1):
     """Starts empty, use set_text to fill it.
     rect - Rect indicating the size of the box and position. 
     fsize - Font size
     fgcol - text color (R,G,B), if None the theme color will be used.
     bgcol - background color (R,G,B), if None the theme color will be used.
             If bgcol is set to 'trans' the background will be transparent.
     padding - space in pixels around the text
     border - border in pixels, None means no border.
     lines - how many previous lines of text should be visible (cheap scroll effect)
             """
     if not fgcol: 
         fgcol = self.THEME['textview_fg_color']
     if not bgcol:
         bgcol = self.THEME['textview_bg_color']
     self.fgcol = fgcol
     self.bgcol = bgcol
     self.padding = padding
     self.fsize = fsize
     self.image = pygame.Surface(rect.size)
     self.image.fill(self.bgcol)
     self.rect = self.image.get_rect()
     if border:
         pygame.draw.rect(self.image, BLACK, self.rect, border)
     self.org_image = self.image.copy()
     Widget.__init__(self, self.image)
     self.rect.move_ip(rect.topleft)
     self.prevlines = []
     self.lines = lines
 def __init__(self, place, **kwds):
     wx.MenuBar.__init__(self)
     self.frame = place[0]
     Widget.__init__(self, place, **kwds)
     self.frame.Bind(wx.EVT_MENU, self.on_menu)
     self.menus = {}
     self.items = {}
Beispiel #5
0
    def _setup(self):
        # get all the surfaces
        title = utils.char2surf(self.title,
                                24,
                                ttf=TTF,
                                fcol=self.THEME['dialog_title_fg_color'],
                                bold=True)

        if type(self.txt) == types.ListType or type(
                self.txt) in types.StringTypes:
            tv = TextView(self.txt, (0, 0), pygame.Rect(0, 0, self.dialogwidth, 400),\
                           bgcol='trans',fsize=self.fsize ,\
                          fgcol=self.THEME['dialog_fg_color'], autofit=True, bold=self.fbold)
        else:  # we assume a SPWidget.Widget object
            tv = self.txt
        b = self.buttons_list[0]
        # start building dialog
        if self.dialogwidth and self.dialogheight:
            r = pygame.Rect(0, 0, self.dialogwidth, self.dialogheight)
        else:
            r = pygame.Rect(0, 0, max(self.butspace,(tv.rect.w + (self.padding * 2)),100), \
                        title.get_rect().h + 8 + b.rect.h + tv.rect.h + (self.padding*3))
        if r.w > 750:
            r.w = 750
        if r.h > 530:
            r.h = 530
        dlgsurf, dlgsizes = make_dialog_bg_dynamic(r.w + 50, r.h + 70,
                                                   self.THEME)

        r = dlgsurf.get_rect()
        if not self.pos:
            y = max(10, (600 - r.h) / 2)
            x = (800 - r.w) / 2
            self.pos = (x, y)

        y = 10
        x = 20
        dlgsurf.blit(title, (x, y))
        dlgsurf.blit(tv.image, (x, dlgsizes['title_area'].h))

        Widget.__init__(self, dlgsurf)

        self.image = dlgsurf

        self.rect.move_ip(self.pos)
        for k, v in dlgsizes.items():
            dlgsizes[k].move_ip(self.pos)
        x = self.rect.left + (
            (self.rect.w - (self.butspace + 16 * len(self.buttons_list))) / 2)
        y = self.rect.bottom - self.buttons_list[0].rect.h * 2
        if len(self.buttons_list) == 2:
            x = self.rect.left + 16
            self.buttons_list[0].moveto((x, y), True)
            x = self.rect.right - (self.buttons_list[1].rect.w + 16)
            self.buttons_list[1].moveto((x, y), True)
        else:
            for b in self.buttons_list:
                b.moveto((x, y), True)
                x += b.rect.w + 16
        self.dlgsizes = dlgsizes
Beispiel #6
0
    def __init__(self, place, **args):
        wx.glcanvas.GLCanvas.__init__(self,
                                      place[0],
                                      -1,
                                      style=wx.glcanvas.WX_GL_DOUBLEBUFFER)
        #        , attribList =[wx.glcanvas.WX_GL_DOUBLEBUFFER])
        Widget.__init__(self, place, **args)

        self.init = False

        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
        self.Bind(wx.EVT_SIZE, self.OnSize)
        self.Bind(wx.EVT_PAINT, self.OnPaint)

        for event in (wx.EVT_LEFT_DOWN, wx.EVT_MIDDLE_DOWN, wx.EVT_RIGHT_DOWN):
            self.Bind(event, self.OnMouseDown)
        for event in (wx.EVT_LEFT_UP, wx.EVT_MIDDLE_UP, wx.EVT_RIGHT_UP):
            self.Bind(event, self.OnMouseUp)
        for event in (wx.EVT_LEFT_DCLICK, wx.EVT_MIDDLE_DCLICK,
                      wx.EVT_RIGHT_DCLICK):
            self.Bind(event, self.OnMouseDoubleClicked)
        self.Bind(wx.EVT_MOTION, self.OnMouseMotion)
        self._lastsize = (-1, -1)

        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
Beispiel #7
0
 def __init__(self, pos, volume=None, voice_unmute=True, defval=50):
     """defval - value between 0, silent, and 100, maximum, volume level."""
     Widget.__init__(self)
     self.logger = logging.getLogger("childsplay.SPWidgets.VolumeAdjust")
     self.logger.debug("VolumeAdjust called with volume level %s" % volume)
     self.soundcheck = utils.load_sound(os.path.join(ACTIVITYDATADIR, 'CPData','volumecheck.wav'))
     self.theme = self.THEME['theme']
     if volume or int(volume) == 0:
         #print "we have volume"
         self.volume = int(volume)
     elif self.WEHAVEAUMIX:
         #print "we have aumix"
         self.volume = int(self.WEHAVEAUMIX)
     else:
         #print "else defval"
         self.volume = int(defval)
     self.logger.debug("setting volume string to %s" % self.volume)
     self.volstr = '%02d' % self.volume + "%"
     # TODO: set fgcol and bgcol kwargs ?
     self.logger.debug("setting voice unmute to %s" % voice_unmute)
     imgup = os.path.join(THEMESPATH, self.theme,'core_volup_button.png')
     imgup_ro = os.path.join(THEMESPATH, self.theme,'core_volup_button_ro.png')
     imgdown = os.path.join(THEMESPATH, self.theme,'core_voldown_button.png')
     imgdown_ro = os.path.join(THEMESPATH, self.theme,'core_voldown_button_ro.png')
     px, py = pos
     
     prev = os.path.join(THEMESPATH, self.theme, 'core_volume_button.png')
     prev_ro = os.path.join(THEMESPATH, self.theme, 'core_volume_button_ro.png')
     next = os.path.join(THEMESPATH, self.theme, 'core_volmute_button.png')
     next_ro = os.path.join(THEMESPATH, self.theme, 'core_volmute_button_ro.png')
     
     self.lbl0 = Label(_("Quiz voice"), pos, fsize=18, padding=4, minh=48)
     px += self.lbl0.rect.w + 10
     self.voicetoggle = TransPrevNextButton((px, py), self._cbf_toggle_voice, \
                               prev, prev_ro,\
                               next, next_ro, states=[True,False])
     py += self.voicetoggle.rect.h + 20
     px = pos[0]
     self.lbl1 = Label(self.volstr, pos, fsize=18, padding=4, border=1, minh=48)
     self.volumetoggle = TransPrevNextButton((px, py), self._cbf_toggle_volume, \
                               prev, prev_ro,\
                               next, next_ro)
     px += self.volumetoggle.rect.w + 20
     self.voldownbut = TransImgButton(imgdown, imgdown_ro, (px, py))
     self.voldownbut.mouse_hover_leave_action = True
     self.voldownbut.connect_callback(self._cbf, MOUSEBUTTONUP, -5)
     
     px += self.voldownbut.rect.w
     self.lbl1.moveto((px , py+4))
     px += self.lbl1.rect.w
     
     self.volupbut = TransImgButton(imgup, imgup_ro, (px, py))
     self.volupbut.mouse_hover_leave_action = True
     self.volupbut.connect_callback(self._cbf, MOUSEBUTTONUP, 5)
     if self.volume == 0:
         self.volumetoggle.toggle()
         self.volumetoggle.display_sprite()
     if not voice_unmute:
         self.voicetoggle.toggle()
         self.voicetoggle.display_sprite()
Beispiel #8
0
 def __init__(self,pos, size, steps=10,\
              transparent=False, backcol=GREY, barfcol=DEEPSKYBLUE4, barbcol=BLACK):
     """pos is the postion to place this widget
     size is a tuple with the width and height of the widget
     steps is the amount of steps that should be taken to fill the bar, defaults to 10
     The update call returns the number of steps taken, when the bar is full it will return False
     """
     Widget.__init__(self)
     self.end = size[0]
     self.step = self.end / steps
     self.steps = steps
     self.backcol = backcol
     self.barfcol = barfcol
     self.barbcol = barbcol
     
     self.image = pygame.Surface((size[0],size[1]))
     self.image.fill(backcol)
     self.rect = self.image.get_rect()
     pygame.draw.rect(self.image, barbcol, self.rect.inflate(-8,-8),0)
             
     self.barsurf = pygame.Surface((size[0]-8,size[1]-8))
     self.barsurf.fill(barfcol)
     self.barrect =  self.barsurf.get_rect()
     self.barend = self.step        
     self._initbar()
     self.moveto(pos)
 def __init__(self, place, orientation='horizontal', **kwds):
     orient = { 'horizontal': wx.TB_HORIZONTAL, 'vertical': wx.TB_VERTICAL } [orientation]
     wx.ToolBar.__init__(self, place[0],
                         style=wx.SUNKEN_BORDER|wx.TB_FLAT|wx.TB_TEXT|orient)
     Widget.__init__(self, place, **kwds)
     self.Bind(wx.EVT_TOOL, self.on_tool)
     self.tools = {}
Beispiel #10
0
 def __init__(self, pos, total, fsize=10, text=''):
     """The width of the widget is determined by the width of the headertext
     with a minimal width of four spaces and a maximum of fourteen characters.
     total - the total number of exercises.
     fsize - Fontsize for the text
     text - Headertext defaults to 'Exercises' (localized)
     """
     self.logger = logging.getLogger("childsplay.SPocwWidgets.ExeCounter")
     Widget.__init__(self)
     self.total = total
     self.done = 0
     if not text:
         text = _("Exercises")
     if len(text) > 14:#prevent to large label when localized
         text = text[:14]
     fgcol=self.THEME['execounter_fg_color']
     bgcol = self.THEME['execounter_bg_color']
     s0 = utils.char2surf(text, fsize=fsize, fcol=fgcol)
     txt = "%s/%s" % (self.done, self.total)
     
     self.lbl = Label(txt, (pos[0]+2, pos[1]+s0.get_height()), fsize=12, padding=4, border=0, fgcol=fgcol, bgcol=bgcol)
     
     r = pygame.Rect(0, 0,s0.get_rect().w+4, s0.get_rect().h +\
                                            self.lbl.rect.h+4)
     box, spam = get_boxes(bgcol, BLACK, r)
     
     box.blit(s0, (2, 2))
     self.image = box       
     Widget.__init__(self, box)
     self.rect.move_ip(pos)
     self.display_sprite()
     self.lbl.display_sprite()
Beispiel #11
0
    def __init__(self, parent=None, num_tiles=128, num_frames=64, *args, **kwargs):
        Widget.__init__(self)
        Frame.__init__(self, parent, *args, **kwargs)

        self.num_frames = num_frames
        self.num_tiles = num_tiles
        self.frames = {}
    def __init__(self, place, data=None, columns=None, headers=False, editable=False, 
                 connect={}, **kwds):
        flags = wx.LC_REPORT|wx.LC_VIRTUAL|wx.BORDER_SUNKEN
        if not headers:
            flags |= wx.LC_NO_HEADER
        if editable:
            flags |= wx.LC_EDIT_LABELS

        _xListCtrl.__init__(self, self, place[0], -1, style=flags)
        Widget.__init__(self, place, connect, **kwds)

        if data is None:
            data = ListData()

        if columns is None:
            columns = [None]

        self.selection = []

        self._columns = columns
        self._data = data
        if hasattr(self._data, 'connect'):
            self._data.connect('modified', self.update)

        self.update()

        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_item_activated)
        for event in (wx.EVT_LIST_ITEM_SELECTED, wx.EVT_LIST_ITEM_DESELECTED, wx.EVT_LIST_ITEM_FOCUSED):
            self.Bind(event, self.on_update_selection)

        self.can_drop = False
        self.drop_formats = []

        self.Bind(wx.EVT_RIGHT_DOWN, self.on_right_click)
Beispiel #13
0
 def __init__(self, parent=None, statusbar=False, connect={}, **kwds):
     wx.Frame.__init__(self, parent, -1)
     Widget.__init__(self, None, connect, **kwds)
     Container.__init__(self)
     if statusbar:
         self.CreateStatusBar()
     self.parent = parent
Beispiel #14
0
 def __init__(self, place, **kwds):
     wx.MenuBar.__init__(self)
     self.frame = place[0]
     Widget.__init__(self, place, **kwds)
     self.frame.Bind(wx.EVT_MENU, self.on_menu)
     self.menus = {}
     self.items = {}
Beispiel #15
0
 def __init__(self, parent=None, statusbar=False, connect={}, **kwds):
     wx.Frame.__init__(self, parent, -1)
     Widget.__init__(self, None, connect, **kwds)
     Container.__init__(self)
     if statusbar:
         self.CreateStatusBar()
     self.parent = parent
Beispiel #16
0
    def __init__(self, parent, **place):
        self._widget = PythonSTC(parent._widget, -1)
        Widget.__init__(self, parent, **place)

        self._widget.Bind(wx.EVT_SET_FOCUS, self.evt_set_focus)
        self._widget.Bind(wx.EVT_KILL_FOCUS, self.evt_kill_focus)
        self._widget.Bind(wx.EVT_CHAR, self.evt_char)
        self._widget.Bind(wx.EVT_TEXT_ENTER, self.evt_enter)
Beispiel #17
0
 def __init__(self, place, multiline=False, connect={}, **kwds):
     style = 0
     if multiline:
         style |= wx.TE_MULTILINE
     else:
         style |= wx.TE_PROCESS_ENTER
     wx.TextCtrl.__init__(self, place[0], -1, style=style)
     Widget.__init__(self, place, connect, **kwds)
Beispiel #18
0
    def __init__(self, parent, **place):
        self._widget = PythonSTC(parent._widget, -1)
        Widget.__init__(self, parent, **place)

        self._widget.Bind(wx.EVT_SET_FOCUS, self.evt_set_focus)
        self._widget.Bind(wx.EVT_KILL_FOCUS, self.evt_kill_focus)
        self._widget.Bind(wx.EVT_CHAR, self.evt_char)
        self._widget.Bind(wx.EVT_TEXT_ENTER, self.evt_enter)
Beispiel #19
0
 def __init__(self, place, multiline=False, connect={}, **kwds):
     style = 0
     if multiline:
         style |= wx.TE_MULTILINE
     else:
         style |= wx.TE_PROCESS_ENTER
     wx.TextCtrl.__init__(self, place[0], -1, style=style)
     Widget.__init__(self, place, connect, **kwds)
Beispiel #20
0
 def __init__(self, txt, pos, rect=None, fsize=12, padding=4, \
              autofit=False, border=False, name='', \
              bgcol=None, fgcol=None, shade=0, bold=False, **kwargs):
     """Box which displays a text, wrapped if needed. 
     txt - string to display. When txt is a list of strings the lines are
         blitted on a surface big enough to hold the longest line.
         rect is not used in this case.
     pos - position to display the box
     rect - Rect indicating the size of the box. 
             Only used in conjunction with txt if it's a string.
     fsize - Font size
     padding - space in pixels around the text
     fgcol - text color (R,G,B), if None the theme color will be used.
     bgcol - background color (R,G,B), if None the theme color will be used.
             If bgcol is set to 'trans' the background will be transparent.
     autofit - Discard the empty space around the text.
     name - string to indicate this object
     shade - The amount of "3D shade" the text should have, 0 means no shade.
             Beware that shading takes time.
     """
     if not fgcol: 
         fgcol = self.self.THEME['textview_fg_color']
     if not bgcol:
         bgcol = self.self.THEME['textview_bg_color']
     if type(txt) in types.StringTypes and rect != None:
         self.image = render_textrect(txt, fsize, TTF, rect, fgcol, \
                           bgcol, justification=0, bold=bold, \
                           autofit=autofit, border=border)
     elif type(txt) is types.ListType:
         ll = []
         w = 0
         for line in txt:
             if not line.strip('\n'):
                 line = ' '
             if shade:
                 s = utils.shadefade(line, fsize, amount=shade, bold=bold, fcol=fgcol, shadecol=DARKGREY)
                 ll.append(s)
             else:
                 s = utils.char2surf(line, fsize, fgcol, bold=bold)
                 ll.append(s)
             if s.get_rect().w > w:
                 w = s.get_rect().w
             
         h = s.get_rect().h   
         if bgcol == 'trans':
             self.image = pygame.Surface((w, h * len(ll)), SRCALPHA)
             self.image.fill((0, 0, 0, 0))
         else:
             self.image = pygame.Surface((w, h * len(ll)))
             self.image.fill(bgcol)
         x, y = 0, 0
         for s in ll:
             self.image.blit(s, (x, y))
             y += h
         
     self.rect  = self.image.get_rect()
     Widget.__init__(self, self.image)
     self.rect.move_ip(pos)       
    def __init__(self, place, **args):
        ScrolledPanel.__init__(self, place[0], -1)#, style=wx.SUNKEN_BORDER)
        Widget.__init__(self, place, **args)
        Container.__init__(self)

        self.layout = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(self.layout)
        self.SetAutoLayout(True)
        self.SetupScrolling()
    def __init__(self, place, **args):
        ScrolledPanel.__init__(self, place[0], -1)  #, style=wx.SUNKEN_BORDER)
        Widget.__init__(self, place, **args)
        Container.__init__(self)

        self.layout = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(self.layout)
        self.SetAutoLayout(True)
        self.SetupScrolling()
 def __init__(self, place, orientation, **kwds):
     self.orientation = orientation
     MultiSplitterWindow.__init__(self, place[0], style=wx.SP_LIVE_UPDATE)
     Widget.__init__(self, place, **kwds)
     Container.__init__(self)
     self.SetOrientation({
         'horizontal': wx.HORIZONTAL,
         'vertical': wx.VERTICAL
     }[orientation])
Beispiel #24
0
 def __init__(self, pos, actives, cbf, usebutton=True):
     Widget.__init__(self)
     self.logger = logging.getLogger("childsplay.SPSpriteGui.DiceButtons")
     self.actives = actives
     self.theme = self.THEME['theme']
     self.minimallevel = 1
     self.maxlevels = 6
     self._isenabled = True
     self._setup(self.theme, pos, actives, cbf, usebutton=True)
     self.showme = True
Beispiel #25
0
    def __init__(self, place, **kwds):
        PythonSTC.__init__(self, place[0], -1)
        Widget.__init__(self, place, **kwds)

        self.Bind(wx.EVT_SET_FOCUS, self.evt_set_focus)
        self.Bind(wx.EVT_KILL_FOCUS, self.evt_kill_focus)
        self.Bind(wx.EVT_CHAR, self.evt_char)
        self.Bind(wx.EVT_TEXT_ENTER, self.evt_enter)

        self._destroyed = False
    def __init__(self, place, connect={}, **kwds):
        wx.Notebook.__init__(self, place[0], -1)
        Widget.__init__(self, place, connect, **kwds)

        # item images
        self.imagelist = wx.ImageList(16, 16)
        self.SetImageList(self.imagelist)
        self.pixmaps = {}

        self.pages = []
    def __init__(self, place, rows=2, columns=2, **args):
        wx.Panel.__init__(self, place[0], -1)
        Widget.__init__(self, place, **args)
        Container.__init__(self)

        self.layout = wx.GridBagSizer(rows, columns)
        self.layout.SetEmptyCellSize((0,0))
        self.SetSizer(self.layout)
#        self.layout.SetSizeHints(self)
        self.SetAutoLayout(True)
    def __init__(self, place, rows=2, columns=2, **args):
        wx.Panel.__init__(self, place[0], -1)
        Widget.__init__(self, place, **args)
        Container.__init__(self)

        self.layout = wx.GridBagSizer(rows, columns)
        self.layout.SetEmptyCellSize((0, 0))
        self.SetSizer(self.layout)
        #        self.layout.SetSizeHints(self)
        self.SetAutoLayout(True)
Beispiel #29
0
 def __init__(self,
              txt,
              pos,
              fsize=18,
              padding=4,
              border=None,
              maxlen=0,
              name='',
              bold=False,
              transparent=False,
              **kwargs):
     """Label which displays a line of text
     txt - string to display
     pos - position to display the box
     rect - Rect indicating the size of the box
     fsize - Font size
     padding - space in pixels around the text
     border - Integer. Draw a border around the label.
     name - string to indicate this object
     bold - set font to bold.
     
     Theres also a number of keyword arguments understood by this widget;
     fgcol - foreground color (other than the theme color)
     bgcol - Background color.
     minh - Minimal height of the widget.
     transparent - No background.
     """
     Widget.__init__(self)
     self.fsize = fsize
     self.bold = bold
     self.transparent = transparent
     fgcol = self.THEME['label_fg_color']
     bgcol = self.THEME['label_bg_color']
     if kwargs.has_key('fgcol'):
         fgcol = kwargs['fgcol']
     if kwargs.has_key('bgcol'):
         bgcol = kwargs['bgcol']
     if kwargs.has_key('minh'):
         self.minh = kwargs['minh']
     else:
         self.minh = None
     if kwargs.has_key('ttf'):
         self.ttf = kwargs['ttf']
     else:
         self.ttf = TTF
     if padding < 2:
         padding = 2
     self.padding = padding
     self.fgcol = fgcol
     self.bgcol = bgcol
     self.border = border
     self.settext(txt)
     self.rect = self.image.get_rect()
     SPSprite.__init__(self, self.image)
     self.rect.move_ip(pos)
Beispiel #30
0
 def __init__(self, pos, length=200, maxlen=0, message='', fsize = 28, border=None, \
              bold=None, ttf='arial', fgcol=None, bgcol=None, password_mode=False, \
              validationlist=[], validation_values_list=[]):
     """Box which displays a text input. The height of the box is determined
     by the fontsize used.
     message - input prompt
     pos - position to display the box
     maxlen - is the maximum number of input characters.
     length - length of the display in pixels.
     fsize - font size
     border - One pixel border around the box
     ttf - family of fonts
     fgcol - foreground color (defaults to theme)
     bgcol - background color (defaults to theme)
     password_mode - displays input in stars
     validitionlist - A list with characters that are allowed
     validation_values_list - A list with values that are allowed
     """
     Widget.__init__(self)
     self.logger = logging.getLogger("childsplay.SPWidgets_lgpl.TextEntry")
     self.length = length
     self.maxlen = maxlen
     self.fsize = fsize
     self.message = message
     self.border = border
     self.ttf = ttf
     self.fgcol = fgcol
     if not self.fgcol:
         self.fgcol = self.THEME['textentry_fg_color']
     self.bgcol = bgcol
     if not self.bgcol:
         self.bgcol = self.THEME['textentry_bg_color']
     self.bold = bold
     self.password_mode = password_mode
     self.validationlist = validationlist
     self.validation_values_list = validation_values_list
     if NoGtk:
         font = pygame.font.Font(filename=None, size=fsize)
     else:
         font = pangofont.PangoFont(family=ttf, size=fsize, bold=bold)
     w, h = font.size(message)
     self.image = pygame.Surface((self.length, h))
     self.rect = self.image.get_rect()
     self.image.fill(self.bgcol)
     if self.border:
         pygame.draw.rect(self.image, BLACK, self.image.get_rect(),
                          self.border)
     self.orgimage = self.image.convert()
     self._CanHaveInputFocus = True
     self.connect_callback(self._cbf, [KEYDOWN, MOUSEBUTTONDOWN])
     self.moveto(pos)
     self.xpadding = 6
     self.ypadding = 0
     if self.message:
         self._remove_prompt()
 def __init__(self, place, orientation='vertical', **kwds):
     wx.Panel.__init__(self, place[0], -1)
     Widget.__init__(self, place, **kwds)
     if orientation == 'horizontal':
         self.layout = wx.BoxSizer(wx.HORIZONTAL)
     elif orientation == 'vertical':
         self.layout = wx.BoxSizer(wx.VERTICAL)
     else:
         raise NameError
     self.SetAutoLayout(True)
     self.SetSizer(self.layout)
Beispiel #32
0
 def __init__(self, pos, length=200, maxlen=0, message='', fsize = 28, border=None, \
              bold=None, ttf='arial', fgcol=None, bgcol=None, password_mode=False, \
              validationlist=[], validation_values_list=[]):
     """Box which displays a text input. The height of the box is determined
     by the fontsize used.
     message - input prompt
     pos - position to display the box
     maxlen - is the maximum number of input characters.
     length - length of the display in pixels.
     fsize - font size
     border - One pixel border around the box
     ttf - family of fonts
     fgcol - foreground color (defaults to theme)
     bgcol - background color (defaults to theme)
     password_mode - displays input in stars
     validitionlist - A list with characters that are allowed
     validation_values_list - A list with values that are allowed
     """
     Widget.__init__(self)
     self.logger = logging.getLogger("childsplay.SPWidgets_lgpl.TextEntry")
     self.length = length
     self.maxlen = maxlen
     self.fsize = fsize
     self.message = message
     self.border = border
     self.ttf = ttf
     self.fgcol = fgcol
     if not self.fgcol:
         self.fgcol = self.THEME['textentry_fg_color']
     self.bgcol = bgcol
     if not self.bgcol:
         self.bgcol = self.THEME['textentry_bg_color']
     self.bold = bold
     self.password_mode = password_mode
     self.validationlist = validationlist
     self.validation_values_list = validation_values_list
     if NoGtk:
         font = pygame.font.Font(filename=None, size=fsize)
     else:
         font = pangofont.PangoFont(family=ttf, size=fsize, bold=bold)
     w, h = font.size(message)
     self.image = pygame.Surface((self.length, h))
     self.rect = self.image.get_rect()
     self.image.fill(self.bgcol)
     if self.border:
         pygame.draw.rect(self.image, BLACK, self.image.get_rect(), self.border)
     self.orgimage = self.image.convert()
     self._CanHaveInputFocus = True
     self.connect_callback(self._cbf, [KEYDOWN, MOUSEBUTTONDOWN])
     self.moveto(pos)
     self.xpadding = 6
     self.ypadding = 0
     if self.message:
         self._remove_prompt()
Beispiel #33
0
    def __init__(self, txt, pos, rect=None, fsize=12, padding=4, \
                 autofit=False, border=False, name='', \
                 bgcol=None, fgcol=None, shade=0, bold=False, **kwargs):
        """Box which displays a text, wrapped if needed. 
        txt - string to display. When txt is a list of strings the lines are
            blitted on a surface big enough to hold the longest line.
            rect is not used in this case.
        pos - position to display the box
        rect - Rect indicating the size of the box. 
                Only used in conjunction with txt if it's a string.
        fsize - Font size
        padding - space in pixels around the text
        fgcol - text color (R,G,B), if None the theme color will be used.
        bgcol - background color (R,G,B), if None the theme color will be used.
                If bgcol is set to 'trans' the background will be transparent.
        autofit - Discard the empty space around the text.
        name - string to indicate this object
        shade - The amount of "3D shade" the text should have, 0 means no shade.
                Beware that shading takes time.
        """
        if not fgcol:
            fgcol = self.self.THEME['textview_fg_color']
        if not bgcol:
            bgcol = self.self.THEME['textview_bg_color']
        if type(txt) in types.StringTypes and rect != None:
            self.image = render_textrect(txt, fsize, TTF, rect, fgcol, \
                              bgcol, justification=0, bold=bold, \
                              autofit=autofit, border=border)
        elif txt and type(txt) is types.ListType:
            ll = []
            w = 0
            for line in txt:
                if not line.strip('\n'):
                    line = ' '
                s = utils.char2surf(line, fsize, fgcol, bold=bold)
                ll.append(s)
                if s.get_rect().w > w:
                    w = s.get_rect().w

            h = s.get_rect().h
            if bgcol == 'trans':
                self.image = pygame.Surface((w, h * len(ll)), SRCALPHA)
                self.image.fill((0, 0, 0, 0))
            else:
                self.image = pygame.Surface((w, h * len(ll)))
                self.image.fill(bgcol)
            x, y = 0, 0
            for s in ll:
                self.image.blit(s, (x, y))
                y += h

        self.rect = self.image.get_rect()
        Widget.__init__(self, self.image)
        self.rect.move_ip(pos)
Beispiel #34
0
    def _setup(self):
        # get all the surfaces
        title = utils.char2surf(self.title, 24, ttf=TTF, fcol=self.THEME['dialog_title_fg_color'], bold=True)
        
        if type(self.txt) == types.ListType or type(self.txt) in types.StringTypes:
            tv = TextView(self.txt, (0, 0), pygame.Rect(0, 0, self.dialogwidth, 400),\
                           bgcol='trans',fsize=self.fsize ,\
                          fgcol=self.THEME['dialog_fg_color'], autofit=True, bold=self.fbold)
        else: # we assume a SPWidget.Widget object
            tv = self.txt
        b = self.buttons_list[0]
        # start building dialog
        if self.dialogwidth and self.dialogheight:
            r = pygame.Rect(0, 0, self.dialogwidth, self.dialogheight)
        else:
            r = pygame.Rect(0, 0, max(self.butspace,(tv.rect.w + (self.padding * 2)),100), \
                        title.get_rect().h + 8 + b.rect.h + tv.rect.h + (self.padding*3))
        if r.w > 750:
            r.w = 750
        if r.h > 530:
            r.h = 530
        dlgsurf, dlgsizes = make_dialog_bg_dynamic(r.w+50, r.h+70, self.THEME)
        
        r = dlgsurf.get_rect()
        if not self.pos:
            y = max(10, (600 - r.h) / 2)
            x = (800 - r.w) / 2
            self.pos = (x, y)

        y = 10
        x = 20
        dlgsurf.blit(title, (x,y))
        dlgsurf.blit(tv.image, (x, dlgsizes['title_area'].h))
        
        Widget.__init__(self, dlgsurf)
        
        self.image = dlgsurf

        self.rect.move_ip(self.pos)
        for k, v in dlgsizes.items():
            dlgsizes[k].move_ip(self.pos)
        x = self.rect.left + ((self.rect.w - (self.butspace + 16 * len(self.buttons_list))) / 2)
        y = self.rect.bottom - self.buttons_list[0].rect.h *2
        if len(self.buttons_list) == 2:
            x = self.rect.left + 16
            self.buttons_list[0].moveto((x, y), True)
            x = self.rect.right - (self.buttons_list[1].rect.w + 16)
            self.buttons_list[1].moveto((x, y), True)
        else:
            for b in self.buttons_list:
                b.moveto((x, y), True)
                x += b.rect.w + 16
        self.dlgsizes = dlgsizes
Beispiel #35
0
 def __init__(self, place, orientation='horizontal', **kwds):
     orient = {
         'horizontal': wx.TB_HORIZONTAL,
         'vertical': wx.TB_VERTICAL
     }[orientation]
     wx.ToolBar.__init__(self,
                         place[0],
                         style=wx.SUNKEN_BORDER | wx.TB_FLAT | wx.TB_TEXT
                         | orient)
     Widget.__init__(self, place, **kwds)
     self.Bind(wx.EVT_TOOL, self.on_tool)
     self.tools = {}
Beispiel #36
0
    def __init__(self, parent=None, max_val=180, *args, **kwargs):
        Widget.__init__(self)
        Canvas.__init__(self, parent, borderwidth=0, *args, **kwargs)

        self.line = None
        self.label = None
        self.max_val = max_val
        self.color = 'black'
        self.text_margin_bottom = 20

        self.size = min(int(self.cget('width')), int(self.cget('height')))
        self.create_arc(0, 0, self.size, self.size * 2, extent=180, fill='white')
Beispiel #37
0
    def __init__(self, place, **kwds):
        self.locals = {}
        wx.py.shell.Shell.__init__(self, place[0], -1, locals=self.locals)
        Widget.__init__(self, place, **kwds)

        self.SetMarginType(1, 0)
        self.SetMarginWidth(1, 0)

        self.setLocalShell()
        self.zoom(-1)
        self.Bind(wx.EVT_KEY_DOWN, self.on_key_down)
        self.clear()
        self.prompt()
Beispiel #38
0
    def __init__(self, parent=None, max_val=180, *args, **kwargs):
        Widget.__init__(self)
        Canvas.__init__(self, parent, borderwidth=0, *args, **kwargs)

        self.line = None
        self.label = None
        self.max_val = max_val
        self.color = 'black'
        self.text_margin_bottom = 20

        self.size = min(int(self.cget('width')), int(self.cget('height')))
        self.create_arc(0,
                        0,
                        self.size,
                        self.size * 2,
                        extent=180,
                        fill='white')
Beispiel #39
0
 def __init__(self, txt, pos=None, fsize=12, butfsize=20, buttons=['OK'], title='', \
              dialogwidth=0, dialogheight=0, name='', fbold=True):
     """screen - current pygame screen surface
     txt - can be a string or a list of strings or a SPSprite object.
     pos - is a tuple with x,y grid numbers. If not set the dialog is centered.
     fsize -  the fontsize (integer)
     buttons - a list with strings for the buttons (max two)
     dialog width and hight - 0 means dynamic.
     name - to identify this object (optional) 
     """
     Widget.__init__(self)
     self.scrclip = self.screen.get_clip()
     self.screen.set_clip((0, 0, 800, 600))
     self.dim = utils.Dimmer()
     self.dim.dim(darken_factor=140, color_filter=CORNFLOWERBLUE)
     self.orgscreen = self.screen.convert()
     self.orgbackgr = self.backgr.convert()
     self.txt = txt
     self.pos = pos
     self.fsize = fsize
     self.buttons = buttons
     self.title = title
     self.dialogwidth = dialogwidth
     self.dialogheight = dialogheight
     self.name = name
     self.fbold = fbold
     self.result = None
     self.runloop = True
     self.buttons_list = []
     self.butspace = 0
     self.padding = 8
     self.actives = SPGroup(self.screen, self.backgr)
     self.actives.set_onematch(True)
     for buttxt in self.buttons:
         b = ButtonDynamic(buttxt, (380,250), butfsize, padding=8, name=buttxt,\
                            fgcol=BLACK, colorname='green')
         b.set_use_current_background(True)
         b.connect_callback(self.cbf, MOUSEBUTTONUP, buttxt)
         self.actives.add(b)
         self.buttons_list.append(
             b)  # keep the users order for showing (see below)
         self.butspace += b.rect.w + 8
     if not self.dialogwidth:
         self.dialogwidth = self.butspace
     self.ImShowed = False
     self._setup()
Beispiel #40
0
 def __init__(self, txt, pos=None, fsize=12, butfsize=20, buttons=['OK'], title='', \
              dialogwidth=0, dialogheight=0, name='', fbold=True):
     """screen - current pygame screen surface
     txt - can be a string or a list of strings or a SPSprite object.
     pos - is a tuple with x,y grid numbers. If not set the dialog is centered.
     fsize -  the fontsize (integer)
     buttons - a list with strings for the buttons (max two)
     dialog width and hight - 0 means dynamic.
     name - to identify this object (optional) 
     """
     Widget.__init__(self)
     self.scrclip = self.screen.get_clip()
     self.screen.set_clip((0, 0, 800, 600))   
     self.dim = utils.Dimmer()
     self.dim.dim(darken_factor=140, color_filter=CORNFLOWERBLUE)
     self.orgscreen = self.screen.convert()
     self.orgbackgr = self.backgr.convert()
     self.txt = txt 
     self.pos = pos
     self.fsize = fsize
     self.buttons = buttons
     self.title = title
     self.dialogwidth = dialogwidth
     self.dialogheight = dialogheight
     self.name = name
     self.fbold = fbold
     self.result = None
     self.runloop = True
     self.buttons_list = []
     self.butspace = 0
     self.padding = 8
     self.actives = SPGroup(self.screen, self.backgr)
     self.actives.set_onematch(True)
     for buttxt in self.buttons:
         b = ButtonDynamic(buttxt, (380,250), butfsize, padding=8, name=buttxt,\
                            fgcol=BLACK, colorname='green')
         b.set_use_current_background(True)
         b.connect_callback(self.cbf, MOUSEBUTTONUP, buttxt)
         self.actives.add(b)
         self.buttons_list.append(b)# keep the users order for showing (see below)
         self.butspace += b.rect.w + 8
     if not self.dialogwidth:
         self.dialogwidth = self.butspace
     self.ImShowed = False
     self._setup()
Beispiel #41
0
 def __init__(self, txt, pos, fsize=18, padding=4, border=None, maxlen=0, name='', bold=False, transparent=False, ** kwargs):
     """Label which displays a line of text
     txt - string to display
     pos - position to display the box
     rect - Rect indicating the size of the box
     fsize - Font size
     padding - space in pixels around the text
     border - Integer. Draw a border around the label.
     name - string to indicate this object
     bold - set font to bold.
     
     Theres also a number of keyword arguments understood by this widget;
     fgcol - foreground color (other than the theme color)
     bgcol - Background color.
     minh - Minimal height of the widget.
     transparent - No background.
     """ 
     Widget.__init__(self)
     self.fsize = fsize
     self.bold=bold
     self.transparent = transparent
     fgcol = self.THEME['label_fg_color']
     bgcol = self.THEME['label_bg_color']
     if kwargs.has_key('fgcol'):
         fgcol = kwargs['fgcol']
     if kwargs.has_key('bgcol'):
         bgcol = kwargs['bgcol']
     if kwargs.has_key('minh'):
         self.minh = kwargs['minh']
     else:
         self.minh = None
     if kwargs.has_key('ttf'):
         self.ttf = kwargs['ttf']
     else:
         self.ttf = TTF
     if padding < 2:
         padding = 2
     self.padding = padding
     self.fgcol = fgcol
     self.bgcol = bgcol
     self.border = border
     self.settext(txt)
     self.rect  = self.image.get_rect()
     SPSprite.__init__(self, self.image)
     self.rect.move_ip(pos)
Beispiel #42
0
    def __init__(self, pos, maxlen=0, length=300, height=2, message='', fsize = 14, border=True, \
                 ttf='arial', fgcol=None, bgcol=None, bold=False, password_mode=False):
        """Text input box with multiple lines. The height of the box is determined
        by the fontsize used times the height. You can get the actual height in pixels by calling
        the "get_height" method.
        message - input prompt
        pos - position to display the box
        maxlen - is the maximum number of input characters.
        length - length of the display in pixels.
        height - height in characters lines, 2 means two lines of text.
        fsize - font size
        border - One pixel border around the box
        ttf - family of fonts
        """
        self.height = height
        self.TEs = utils.OrderedDict()
        self.currentline = 0
        self.maxline = height - 1
        sizey = 0
        tepos = (pos[0] + 1, pos[1] + 1)
        for line in range(height):
            te = TEB_TextEntry(pos=tepos, maxlen=maxlen, \
                            length=length, message=message,\
                            fsize = fsize, border=False, ttf='arial',\
                            fgcol=fgcol, bgcol=fgcol, bold=bold, \
                            password_mode=False)
            te.disconnect_callback()
            te.connect_callback(self._cbf, [KEYDOWN, MOUSEBUTTONDOWN])
            sizey += te.get_sprite_height()
            tepos = (tepos[0], tepos[1] + te.get_sprite_height())
            te.line = line
            self.TEs[line] = te
        sizex = te.get_sprite_width()  # length stays the same for all lines
        self.image = pygame.Surface((sizex + 2, sizey + 2))
        Widget.__init__(self, self.image)
        self.image.fill(self.THEME['textentry_bg_color'])

        y = 0
        for te in self.TEs.values():
            self.image.blit(te.get_surface(), (0, y))
            y += te.get_sprite_height()
        if border:
            pygame.draw.rect(self.image, BLACK, self.rect, 1)
        self.moveto(pos)
Beispiel #43
0
 def __init__(self, pos, maxlen=0, length=300, height=2, message='', fsize = 14, border=True, \
              ttf='arial', fgcol=None, bgcol=None, bold=False, password_mode=False):
     """Text input box with multiple lines. The height of the box is determined
     by the fontsize used times the height. You can get the actual height in pixels by calling
     the "get_height" method.
     message - input prompt
     pos - position to display the box
     maxlen - is the maximum number of input characters.
     length - length of the display in pixels.
     height - height in characters lines, 2 means two lines of text.
     fsize - font size
     border - One pixel border around the box
     ttf - family of fonts
     """
     self.height = height
     self.TEs = utils.OrderedDict()
     self.currentline = 0
     self.maxline = height - 1
     sizey = 0
     tepos = (pos[0]+1, pos[1]+1)
     for line in range(height):
         te = TEB_TextEntry(pos=tepos, maxlen=maxlen, \
                         length=length, message=message,\
                         fsize = fsize, border=False, ttf='arial',\
                         fgcol=fgcol, bgcol=fgcol, bold=bold, \
                         password_mode=False)
         te.disconnect_callback()
         te.connect_callback(self._cbf, [KEYDOWN, MOUSEBUTTONDOWN])
         sizey += te.get_sprite_height()
         tepos = (tepos[0], tepos[1] + te.get_sprite_height())
         te.line = line
         self.TEs[line] = te
     sizex = te.get_sprite_width()# length stays the same for all lines
     self.image = pygame.Surface((sizex + 2, sizey + 2))
     Widget.__init__(self, self.image)
     self.image.fill(self.THEME['textentry_bg_color'])
     
     y = 0
     for te in self.TEs.values():
         self.image.blit(te.get_surface(), (0, y))
         y += te.get_sprite_height()
     if border:
         pygame.draw.rect(self.image, BLACK, self.rect, 1)
     self.moveto(pos)
Beispiel #44
0
    def __init__(self, place, **kwds):
        _xTreeCtrl.__init__(self, self, place[0])
        Widget.__init__(self, place, **kwds)
        self.roots = []
        self.items = []

        self.SetIndent(10)

        self.imagelist = wx.ImageList(16, 16)
        self.SetImageList(self.imagelist)
        self.pixmaps = {}

        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.on_sel_changed)
        self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.on_label_edit)

        self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.on_expand)
        self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.on_collapse)

        self.tree = self
        self.selection = None
Beispiel #45
0
    def __init__(self,
                 place,
                 data=None,
                 columns=None,
                 headers=False,
                 editable=False,
                 connect={},
                 **kwds):
        flags = wx.LC_REPORT | wx.LC_VIRTUAL | wx.BORDER_SUNKEN
        if not headers:
            flags |= wx.LC_NO_HEADER
        if editable:
            flags |= wx.LC_EDIT_LABELS

        _xListCtrl.__init__(self, self, place[0], -1, style=flags)
        Widget.__init__(self, place, connect, **kwds)

        if data is None:
            data = ListData()

        if columns is None:
            columns = [None]

        self.selection = []

        self._columns = columns
        self._data = data
        if hasattr(self._data, 'connect'):
            self._data.connect('modified', self.update)

        self.update()

        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_item_activated)
        for event in (wx.EVT_LIST_ITEM_SELECTED, wx.EVT_LIST_ITEM_DESELECTED,
                      wx.EVT_LIST_ITEM_FOCUSED):
            self.Bind(event, self.on_update_selection)

        self.can_drop = False
        self.drop_formats = []

        self.Bind(wx.EVT_RIGHT_DOWN, self.on_right_click)
Beispiel #46
0
    def __init__(self, place):
        wx.glcanvas.GLCanvas.__init__(self, place[0], -1, style=wx.glcanvas.WX_GL_DOUBLEBUFFER)
#        , attribList =[wx.glcanvas.WX_GL_DOUBLEBUFFER])
        Widget.__init__(self, place)

        self.init = False

        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
        self.Bind(wx.EVT_SIZE, self.OnSize)
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        
        for event in (wx.EVT_LEFT_DOWN, wx.EVT_MIDDLE_DOWN, wx.EVT_RIGHT_DOWN):
            self.Bind(event, self.OnMouseDown)
        for event in (wx.EVT_LEFT_UP, wx.EVT_MIDDLE_UP, wx.EVT_RIGHT_UP):
            self.Bind(event, self.OnMouseUp)
        for event in (wx.EVT_LEFT_DCLICK, wx.EVT_MIDDLE_DCLICK, wx.EVT_RIGHT_DCLICK):
            self.Bind(event, self.OnMouseDoubleClicked)
        self.Bind(wx.EVT_MOTION, self.OnMouseMotion)
        self._lastsize = (-1, -1)

        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)    
Beispiel #47
0
    def __init__(self, place, data=None, **kwds):
        _xTreeCtrl.__init__(self, self, place[0])
        Widget.__init__(self, place, **kwds)

        self.data = data

        self.root = None
        self.items = TwoWayDict()
        self.selection = None

        self.SetIndent(10)

        self.imagelist = wx.ImageList(16, 16)
        self.SetImageList(self.imagelist)
        self.pixmaps = {}

        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.on_sel_changed)
        self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.on_label_edit)

        #        self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.on_expand)
        #        self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.on_collapse)

        self._skip_event = False
Beispiel #48
0
    def __init__(self, place, data=None, **kwds):
        _xTreeCtrl.__init__(self, self, place[0])
        Widget.__init__(self, place,  **kwds)

        self.data = data
        
        self.root = None
        self.items = TwoWayDict()
        self.selection = None

        self.SetIndent(10)

        self.imagelist = wx.ImageList(16, 16)
        self.SetImageList(self.imagelist)
        self.pixmaps = {}

        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.on_sel_changed)
        self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.on_label_edit)

#        self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.on_expand)
#        self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.on_collapse)

        self._skip_event = False
Beispiel #49
0
 def __init__(self, maxlevels, start_level):
     Widget.__init__(self)
     self.theme = self.THEME['theme']
     self.runloop = True
     self.maxlevels = maxlevels
     self.start_level = start_level
     self.starlist =[]
     self.imgstar0 = utils.load_image(os.path.join(THEMESPATH, self.theme,'star0_b.png'))
     self.imgstar1 = utils.load_image(os.path.join(THEMESPATH, self.theme,'star1_b.png'))
     self.actives = SPGroup(self.screen, self.backgr)
     self.actives.set_onematch(True)
     self.scrclip = self.screen.get_clip()
     self.screen.set_clip((0, 0, 800, 600))    
     self.dim = utils.Dimmer()
     self.dim.dim(darken_factor=self.THEME['starbuttonsdialog_darkenfactor'], color_filter=self.THEME['starbuttonsdialog_dim_color'])
     x = 40
     y = 200
     for i in range(self.maxlevels):
         b = SPSprite(self.imgstar0)
         b.moveto((x, y), hide=True)
         b.connect_callback(self.cbf, MOUSEBUTTONUP, i+1)
         self.starlist.append(b)
         x += self.imgstar0.get_width()
     # set first star to active
     self.starlist[0].image = self.imgstar1
     self.actives.add(self.starlist)
     
     self.buttons_list = []
     x = 100
     y = 400
     
     for buttxt in [_("Cancel"), _("OK")]:
         b = Button(buttxt, (x, y), fsize=self.THEME['starbuttonsdialog_fsize'], name=buttxt)
         b.connect_callback(self.but_cbf, MOUSEBUTTONUP, buttxt)
         self.actives.add(b)
         self.buttons_list.append(b)# keep the users order for showing (see below)
         x += 300
Beispiel #50
0
    def __init__(self, pos, total, fsize=10, text=''):
        """The width of the widget is determined by the width of the headertext
        with a minimal width of four spaces and a maximum of fourteen characters.
        total - the total number of exercises.
        fsize - Fontsize for the text
        text - Headertext defaults to 'Exercises' (localized)
        """
        self.logger = logging.getLogger("childsplay.SPocwWidgets.ExeCounter")
        Widget.__init__(self)
        self.total = total
        self.done = 0
        if not text:
            text = _("Exercises")
        if len(text) > 14:  #prevent to large label when localized
            text = text[:14]
        fgcol = self.THEME['execounter_fg_color']
        bgcol = self.THEME['execounter_bg_color']
        s0 = utils.char2surf(text, fsize=fsize, fcol=fgcol)
        txt = "%s/%s" % (self.done, self.total)

        self.lbl = Label(txt, (pos[0] + 2, pos[1] + s0.get_height()),
                         fsize=12,
                         padding=4,
                         border=0,
                         fgcol=fgcol,
                         bgcol=bgcol)

        r = pygame.Rect(0, 0,s0.get_rect().w+4, s0.get_rect().h +\
                                               self.lbl.rect.h+4)
        box, spam = get_boxes(bgcol, BLACK, r)

        box.blit(s0, (2, 2))
        self.image = box
        Widget.__init__(self, box)
        self.rect.move_ip(pos)
        self.display_sprite()
        self.lbl.display_sprite()
Beispiel #51
0
 def __init__(self,
              rect,
              fsize,
              bgcol=None,
              fgcol=None,
              padding=8,
              border=2,
              lines=1):
     """Starts empty, use set_text to fill it.
     rect - Rect indicating the size of the box and position. 
     fsize - Font size
     fgcol - text color (R,G,B), if None the theme color will be used.
     bgcol - background color (R,G,B), if None the theme color will be used.
             If bgcol is set to 'trans' the background will be transparent.
     padding - space in pixels around the text
     border - border in pixels, None means no border.
     lines - how many previous lines of text should be visible (cheap scroll effect)
             """
     if not fgcol:
         fgcol = self.THEME['textview_fg_color']
     if not bgcol:
         bgcol = self.THEME['textview_bg_color']
     self.fgcol = fgcol
     self.bgcol = bgcol
     self.padding = padding
     self.fsize = fsize
     self.image = pygame.Surface(rect.size)
     self.image.fill(self.bgcol)
     self.rect = self.image.get_rect()
     if border:
         pygame.draw.rect(self.image, BLACK, self.rect, border)
     self.org_image = self.image.copy()
     Widget.__init__(self, self.image)
     self.rect.move_ip(rect.topleft)
     self.prevlines = []
     self.lines = lines
Beispiel #52
0
 def __init__(self, group, text, pos, fsize=18, padding=8, name='', **kwargs):
     """Radiobutton with a optional text label.
     group - the widget to which this button belongs. (must be None or another radiobutton)
     text - string to display
     pos - position to display the box
     fsize - Font size
     padding - space in pixels around the text
     name - string to indicate this object
     kwargs - bgcol, fgcol
     """
     self.box_pos = pos
     self.image_pos = (pos[0]+1, pos[1]+1)
     self.name = name
     
     if not group:
         self._rb_group = [self]
     else:
         self._rb_group = group._rb_group + [self]
         for rb in self._rb_group:
             rb._rb_group = self._rb_group
     self._rb_selected = False
     box = pygame.Surface((18, 18))
     box.fill(WHITE)
     rect = box.get_rect()
     lbl = Label(text, (pos[0] + 10 + rect.width, pos[1]), fsize=18, transparent=True, \
                         fgcol=WHITE, bold=True)
     lbl.display_sprite()
     pygame.draw.line(box, GREY30, (0, 0), (18, 0), 1)
     pygame.draw.line(box, GREY30, (0, 0), (0, 18), 1)
     pygame.draw.line(box, GREY30, (17, 0), (17, 17), 1)
     pygame.draw.line(box, GREY30, (1, 17), (17, 17), 1)
     self.box = box.convert()
     Widget.__init__(self, box, name=name)
     self.selected_image = utils.load_image(os.path.join(self.THEME['defaultpath'], 'radiobut_selected.png'))
     self.moveto(self.box_pos)
     self.connect_callback(self._cbf_on_select, MOUSEBUTTONUP)
Beispiel #53
0
 def __init__(self, place, data=None, **kwds):
     _xGrid.__init__(self, place[0], data, self)
     Widget.__init__(self, place, **kwds)