help please to create the widget is an analogue of Tabber()

5 views
Skip to first unread message

pythonwin

unread,
Sep 12, 2006, 1:28:20 AM9/12/06
to TurboGears
All hello!

help please to create the widget is an analogue of Tabber()

code:

#---------------------------------------------------------------------------------------
class TabControl(Widget):
"""This widget includes the tabber js and css into your rendered
page so you can create tabbed divs by assigning them the 'tabber'
and 'tabbertab' classes.
"""
css = [CSSSource("""
.tabControl{

}
.tabHeader{

}
.tabPage{
border-right:1px solid #B0BEC7;
border-left:1px solid #B0BEC7;
border-top:1px solid #B0BEC7;
border-bottom:1px solid #B0BEC7;
font: normal 12px arial;
cursor:pointer;
padding-left:10px;

background-color:#D8E3EA;
padding-right:10px;
border-collapse:collapse;
}

.tabPageSelected{
background-color: #F2F5F8;
cursor:pointer;
font: normal 12px arial;
border-right:1px solid #B0BEC7;
border-left:1px solid #B0BEC7;
border-top:1px solid #B0BEC7;
border-bottom:0px solid #B0BEC7;
padding-left:10px;
padding-right:10px;
border-collapse:collapse;
}
.tabHeaderLine{
border-bottom:1px solid #B0BEC7;
}
.tabControlBody tbody tr td{
display:none;
border-collapse:collapse;
font: normal 12px arial;
vertical-align: top;
}

.tabControlBody{
background-color: #FBFCFD;
border-right:1px solid #B0BEC7;
border-left:1px solid #B0BEC7;
border-bottom:1px solid #B0BEC7;
}""")]
javascript = [JSSource("""
function changeTab(sel){
//header
/*
* created by Tjomi4 05.09.2006
*/

i=sel.cellIndex;
num=sel.id.indexOf('_');
ID=sel.id.substring(0,num);

sel.className="tabPageSelected"
tabbs=sel.parentNode;
for (j=0;j<tabbs.cells.length;j++){
if(i!=j && j!=tabbs.cells.length-1)
tabbs.cells[j].className="tabPage";
}
//body
tab_body=document.getElementById(ID);
tab_body.cells[i].style.display="block";

for(j=0;j<tab_body.cells.length;j++){
if(i!=j)
tab_body.cells[j].style.display="none";
}
}

function selectDefaultTab(ID){
obj=document.getElementById(ID);
changeTab(obj);

}""")]

class TabControlDesc(CoreWD):
name = "TabControl"
for_widget = TabControl()
template = """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://purl.org/kid/ns#"
py:extends="'master.kid'">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type"
py:replace="''"/>
<title>123</title>
<div py:content="for_widget.display()"/>
</head>
<body>
<table border="0" class="tabControl" cellspacing="0"
cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<table border="0" cellspacing="0"
cellpadding="0" class="tabHeader">
<tbody>
<tr>
<td onclick="changeTab(this);"
id="s3475394dfbgf_1" class="tabPage">
<img src="static/images/Start
Favorites.gif" align="absmiddle" border="0" height="50" width="50"
title="img.gif" alt='img.gif'/>
</td>
<td onclick="changeTab(this);"
id="s3475394dfbgf_2" class="tabPage">
Tab2
</td>
<td onclick="changeTab(this);"
id="s3475394dfbgf_3" class="tabPage" width="28">
Tab3
</td>
<td onclick="changeTab(this);"
id="s3475394dfbgf_4" class="tabPage" width="28">
Tab4
</td>
<td width="100%"
class="tabHeaderLine"><img src="spacer" width="1" height="1"/></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td height="400px" valign="top">
<table width="100%" class="tabControlBody"
cellpadding="0" cellspacing="0" style="height:100%" border="0">
<tbody>
<tr id="s3475394dfbgf">
<td>
1 asdfasd ;fdng;fdng;dfg
fgdfgfd gkfg fdg dfgd gdfgfg df gfgfdgdf g fdg <br/>
dsfdfsdf
</td>
<td>
2 dsfsdfd
</td>
<td>
3 xzcxcxcxzcxzcxc xzczxc
</td>
<td>
Tab #4
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<script
type="text/javascript">document.onload=selectDefaultTab('s3475394dfbgf_1');</script>
</body>
</html>
"""
-------------------------------------------------------------------------------------

there is an error at the start of project:

Traceback (most recent call last):
File "C:\pr\start-test2.py", line 26, in ?
from pr.controllers import Root
File "C:\pr\test2\controllers.py", line 20, in ?
from MyWidgets import *
File "C:\pr\test2\MyWidgets.py", line 733, in ?
class TabControlDesc(CoreWD):
File
"c:\python24\lib\site-packages\TurboGears-0.9a6-py2.4.egg\turbogears\widgets\base.py",
line 600, in __init__
super(MetaDescription, cls).__init__(name, bases, dct)
File
"c:\python24\lib\site-packages\TurboGears-0.9a6-py2.4.egg\turbogears\widgets\meta.py",
line 75, in __init__
(cls.template_c,
File
"c:\python24\lib\site-packages\TurboGears-0.9a6-py2.4.egg\turbogears\widgets\meta.py",
line 197, in load_kid_temp
late
return (kid.load_template(t, name=modname).Template, t)
File
"c:\python24\lib\site-packages\kid-0.9.1-py2.4.egg\kid\__init__.py",
line 125, in load_template
mod = importer._create_module(code, name, filename, store=cache)
File
"c:\python24\lib\site-packages\kid-0.9.1-py2.4.egg\kid\importer.py",
line 88, in _create_module
exec code in mod.__dict__
File "<string>", line 17, in ?
File
"c:\python24\lib\site-packages\kid-0.9.1-py2.4.egg\kid\template_util.py",
line 43, in get_base_class
cls = kid.load_template(path).Template
File
"c:\python24\lib\site-packages\kid-0.9.1-py2.4.egg\kid\__init__.py",
line 120, in load_template
code = compiler.compile(fo, filename, encoding)
File
"c:\python24\lib\site-packages\kid-0.9.1-py2.4.egg\kid\compiler.py",
line 48, in compile
py = kid.parser.parse(source, encoding, filename=filename)
File
"c:\python24\lib\site-packages\kid-0.9.1-py2.4.egg\kid\parser.py", line
45, in parse
parser = KidParser(document(source, encoding=encoding,
filename=filename), encoding)
File "c:\python24\lib\site-packages\kid-0.9.1-py2.4.egg\kid\pull.py",
line 54, in document
file = open_resource(file, 'rb')
File "c:\python24\lib\site-packages\kid-0.9.1-py2.4.egg\kid\util.py",
line 25, in open_resource
(scheme, rest) = splittype(uri)
File "C:\Python24\lib\urllib.py", line 927, in splittype
match = _typeprog.match(url)
TypeError: Error when calling the metaclass bases
expected string or buffer


a project is not started and farther.

------------------------------------------------------------------------------

inserted in TabControl.kid:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://purl.org/kid/ns#"
py:extends="'master.kid'">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type"
py:replace="''"/>
<title>123</title>
<div py:content="TabControl.display()"/>
</head>
<body>
<table border="0" class="tabControl" cellspacing="0"
cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<table border="0" cellspacing="0"
cellpadding="0" class="tabHeader">
<tbody>
<tr>
<td onclick="changeTab(this);"
id="s3475394dfbgf_1" class="tabPage">
<img src="static/images/Start
Favorites.gif" align="absmiddle" border="0" height="50" width="50"
title="img.gif" alt='img.gif'/>
</td>
<td onclick="changeTab(this);"
id="s3475394dfbgf_2" class="tabPage">
Tab2
</td>
<td onclick="changeTab(this);"
id="s3475394dfbgf_3" class="tabPage" width="28">
Tab3
</td>
<td onclick="changeTab(this);"
id="s3475394dfbgf_4" class="tabPage" width="28">
Tab4
</td>
<td width="100%"
class="tabHeaderLine"><img src="spacer" width="1" height="1"/></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td height="400px" valign="top">
<table width="100%" class="tabControlBody"
cellpadding="0" cellspacing="0" style="height:100%" border="0">
<tbody>
<tr id="s3475394dfbgf">
<td>
1 asdfasd ;fdng;fdng;dfg
fgdfgfd gkfg fdg dfgd gdfgfg df gfgfdgdf g fdg <br/>
dsfdfsdf
</td>
<td>
2 dsfsdfd
</td>
<td>
3 xzcxcxcxzcxzcxc xzczxc
</td>
<td>
Tab #4
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<script
type="text/javascript">document.onload=selectDefaultTab('s3475394dfbgf_1');</script>
</body>
</html>


code of method of class of Root:

@turbogears.expose(template=".templates.TabControl")
def TabControl(self, *args, **kw):
return dict(TabControl=TabControl())


And for me all began to work.

I can not understand in what problem

Jorge Godoy

unread,
Sep 12, 2006, 4:19:37 AM9/12/06
to turbo...@googlegroups.com
"pythonwin" <pyt...@rbcmail.ru> writes:

> code of method of class of Root:
>
> @turbogears.expose(template=".templates.TabControl")
> def TabControl(self, *args, **kw):
> return dict(TabControl=TabControl())
>
>
> And for me all began to work.

It works or not? How it was before when it didn't work?

> I can not understand in what problem

Me neither. But to find out I'd first change the name of the method above to
be more PEP 8 compliant. Then I'd change the name of the template to be all
lowercase (I see that you use Windows, but there are other OSs that are case
sensitive for filenames).

Also, you have a widget named TabControl, a template names TabControl, a
method named TabControl and the variable inside the template is also
TabControl. Too many things with the same name to track. Applying PEP 8 will
help differentiating classes (the widget) from methods from variables. Using
the lowercase convention for the filename will help with the last confusing
case. So, *I* would have named them:

- TabControl --- widget
- tabControl --- method
- tab_control --- variable
- tabcontrol --- template

In fact, I'd use different names to avoid confusion. These are too easy to
confuse when reading or writing when you're tired...

After that, I'd insert log.debug() statements at strategic points and see what
is happening there. If debug doesn't do it, I'd use "print" until the widget
runs. I would also Insert log() statements at javascript code.

Those actions would make it easier to debug and find the problem.

--
Jorge Godoy <jgo...@gmail.com>

pythonwin

unread,
Sep 12, 2006, 1:17:19 AM9/12/06
to TurboGears
All hello!

code:

}
.tabHeader{

function selectDefaultTab(ID){
obj=document.getElementById(ID);
changeTab(obj);

}""")]

------------------------------------------------------------------------------

inserted in TabControl.kid:

code of method of class of Root:

@turbogears.expose(template=".templates.TabControl")
def TabControl(self, *args, **kw):
return dict(TabControl=TabControl())


And for me all began to work.

I can not understand in what problem

pythonwin

unread,
Sep 12, 2006, 5:12:18 AM9/12/06
to TurboGears
Thank you, did, you had said.

but wigtet TabControlDesc does not work:
-----------------------------------------------------------------------------------


class TabControlDesc(CoreWD):
name = "TabControl"
for_widget = TabControl()
template = """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://purl.org/kid/ns#"
py:extends="'master.kid'">

<!-- <html> -->

swears on the method of "template"

Reply all
Reply to author
Forward
0 new messages