Skip to content

Commit

Permalink
Adds a new CTK.List class().
Browse files Browse the repository at this point in the history
git-svn-id: svn://cherokee-project.com/CTK/trunk@4704 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information
alobbs committed Apr 3, 2010
1 parent 701a614 commit bf02ff4
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
78 changes: 78 additions & 0 deletions CTK/List.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-
#
# CTK: Cherokee Toolkit
#
# Authors:
# Alvaro Lopez Ortega <alvaro@alobbs.com>
#
# Copyright (C) 2010 Alvaro Lopez Ortega
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program 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
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#

from Widget import Widget
from Container import Container
from util import props_to_str

ENTRY_HTML = '<%(tag)s id="%(id)s" %(props)s>%(content)s</%(tag)s>'

class ListEntry (Container):
def __init__ (self, _props={}, tag='li'):
Container.__init__ (self)
self.tag = tag
self.props = _props.copy()

def Render (self):
render = Container.Render (self)

props = {'id': self.id,
'tag': self.tag,
'props': props_to_str(self.props),
'content': render.html}

render.html = ENTRY_HTML %(props)
return render


class List (Container):
def __init__ (self, _props={}, tag='ul'):
Container.__init__ (self)
self.tag = tag
self.props = _props.copy()

def Add (self, list_entry):
assert isinstance (list_entry, ListEntry)
Container.__iadd__ (self, list_entry)

def __iadd__ (self, widget):
assert isinstance (widget, Widget) or widget is None

entry = ListEntry()
if widget:
entry += widget

self.Add (entry)
return self

def Render (self):
render = Container.Render (self)

props = {'id': self.id,
'tag': self.tag,
'props': props_to_str(self.props),
'content': render.html}

render.html = ENTRY_HTML %(props)
return render
1 change: 1 addition & 0 deletions CTK/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
from TextArea import TextArea
from ToggleButton import ToggleButtonImages, ToggleButtonOnOff
from Druid import Druid, DruidButtonsPanel, DruidButton, DruidButton_Goto, DruidButtonsPanel_Next, DruidButtonsPanel_PrevNext, DruidButtonsPanel_PrevCreate
from List import List, ListEntry

# Comodity
from cgi import escape as escape_html

0 comments on commit bf02ff4

Please sign in to comment.