403 lines
10 KiB
Python
403 lines
10 KiB
Python
# -*- coding: iso-8859-15 -*-
|
|
|
|
|
|
# Glasnost
|
|
# By: Odile Bénassy <obenassy@entrouvert.com>
|
|
# Romain Chantereau <rchantereau@entrouvert.com>
|
|
# Nicolas Clapiès <nclapies@easter-eggs.org>
|
|
# Pierre-Antoine Dejace <padejace@entrouvert.be>
|
|
# Thierry Dulieu <tdulieu@easter-eggs.com>
|
|
# Florent Monnier <monnier@codelutin.com>
|
|
# Cédric Musso <cmusso@easter-eggs.org>
|
|
# Frédéric Péters <fpeters@entrouvert.be>
|
|
# Benjamin Poussin <poussin@codelutin.com>
|
|
# Emmanuel Raviart <eraviart@entrouvert.com>
|
|
# Sébastien Régnier <regnier@codelutin.com>
|
|
# Emmanuel Saracco <esaracco@easter-eggs.com>
|
|
#
|
|
# Copyright (C) 2000, 2001 Easter-eggs & Emmanuel Raviart
|
|
# Copyright (C) 2002 Odile Bénassy, Code Lutin, Thierry Dulieu, Easter-eggs,
|
|
# Entr'ouvert, Frédéric Péters, Benjamin Poussin, Emmanuel Raviart,
|
|
# Emmanuel Saracco & Théridion
|
|
# Copyright (C) 2003 Odile Bénassy, Romain Chantereau, Nicolas Clapiès,
|
|
# Code Lutin, Pierre-Antoine Dejace, Thierry Dulieu, Easter-eggs,
|
|
# Entr'ouvert, Florent Monnier, Cédric Musso, Ouvaton, Frédéric Péters,
|
|
# Benjamin Poussin, Rodolphe Quiédeville, Emmanuel Raviart, Sébastien
|
|
# Régnier, Emmanuel Saracco, Théridion & Vecam
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation; either version 2
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
__doc__ = """Glasnost Common Widgets"""
|
|
|
|
__version__ = '$Revision$'[11:-2]
|
|
|
|
|
|
import context
|
|
import properties
|
|
import things
|
|
from tools import *
|
|
|
|
|
|
register = things.register
|
|
|
|
|
|
class BaseWidget(things.BaseThing):
|
|
apply = 0
|
|
apply_kindName = 'Boolean'
|
|
|
|
colSpan = None
|
|
colSpan_kindName = 'Integer'
|
|
|
|
fieldLabel = None
|
|
fieldLabel_kind_label = N_('Label')
|
|
fieldLabel_kindName = 'String'
|
|
|
|
## helpAlias = None
|
|
## helpAlias_kind_label = N_('Help Alias')
|
|
## helpAlias_kindName = 'Alias'
|
|
|
|
hideLabel = 0
|
|
hideLabel_kindName = 'Boolean'
|
|
|
|
inForm = 0
|
|
inForm_kind_importExport = 'private'
|
|
inForm_kindName = 'Boolean'
|
|
|
|
name = None
|
|
name_kind_importExport = 'private'
|
|
name_kind_label = N_('Name')
|
|
name_kindName = 'String'
|
|
|
|
readOnly = 0
|
|
readOnly_kind_importExport = 'private'
|
|
readOnly_kindName = 'Boolean'
|
|
|
|
thingCategory = 'widget'
|
|
|
|
def __init__(self, **attributes):
|
|
things.BaseThing.__init__(self)
|
|
for name, value in attributes.items():
|
|
# Ensure that each argument has been declared as an attribute.
|
|
if not hasattr(self.__class__, name):
|
|
raise Exception('Undeclared attribute %s for %s' % (
|
|
name, self.__class__.__name__))
|
|
if getattr(self, name) == value:
|
|
continue
|
|
setattr(self, name, value)
|
|
|
|
def __str__(self):
|
|
return self.getName()
|
|
|
|
def buildOptions(self, options):
|
|
for name, value in options.items():
|
|
# Ensure that each option has been declared as an attribute.
|
|
nameBase = name.split('_')[0]
|
|
if not hasattr(self.__class__, nameBase):
|
|
raise Exception('Undeclared attribute %s for %s' % (
|
|
name, self.__class__.__name__))
|
|
if hasattr(self, name) and getattr(self, name) == value:
|
|
continue
|
|
setattr(self, name, value)
|
|
|
|
## def getHelpAlias(self, slot, fields):
|
|
## if self.helpAlias:
|
|
## return self.helpAlias
|
|
## return slot.getKind().getHelpAlias(slot, fields)
|
|
|
|
def getModelLabel(self, slot):
|
|
if self.fieldLabel:
|
|
return self.fieldLabel
|
|
return slot.getKind().getModelLabel(slot)
|
|
|
|
def getName(cls):
|
|
if type(cls) == types.InstanceType:
|
|
cls = cls.__class__
|
|
if cls.name:
|
|
name = cls.name
|
|
else:
|
|
name = cls.getThingName.im_func(cls)
|
|
return name
|
|
def isInForm(self):
|
|
return self.inForm
|
|
|
|
def isReadOnly(self, slot):
|
|
if self.readOnly:
|
|
return 1
|
|
layoutMode = context.getVar('layoutMode')
|
|
if layoutMode == 'edit':
|
|
return slot.getKind().stateInEditMode == 'read-only'
|
|
elif layoutMode == 'use':
|
|
return slot.getKind().stateInUseMode == 'read-only'
|
|
else:
|
|
return slot.getKind().stateInViewMode == 'read-only'
|
|
|
|
def labelIsHidden(self, slot):
|
|
return self.hideLabel or slot.getKind().hideLabel
|
|
|
|
def setInForm(self, value = 1):
|
|
self.inForm = value
|
|
|
|
def setReadOnly(self, value = 1):
|
|
self.readOnly = value
|
|
register(BaseWidget)
|
|
|
|
|
|
class Amount(BaseWidget):
|
|
sideLabels = None
|
|
sideLabels_kind_keyKind_valueName = 'String'
|
|
sideLabels_kind_valueKind_valueName = 'String'
|
|
sideLabels_kindName = 'Mapping'
|
|
register(Amount)
|
|
|
|
|
|
class InputText(BaseWidget):
|
|
maxLength = None
|
|
maxLength_kindName = 'Integer'
|
|
|
|
size = None
|
|
size_kindName = 'Integer'
|
|
register(InputText)
|
|
|
|
|
|
class Time(InputText):
|
|
pass
|
|
register(Time)
|
|
|
|
|
|
class Date(Time):
|
|
reverseYearOrder = None
|
|
reverseYearOrder_kind_balloonHelp = N_(
|
|
'Reverse display order for year options in select')
|
|
reverseYearOrder_kind_label = N_('Reverse Year Order?')
|
|
reverseYearOrder_kindName = 'Boolean'
|
|
|
|
yearMinRel = None
|
|
yearMinRel_kind_balloonHelp = N_('Minimum Year Value Difference to Now')
|
|
yearMinRel_kind_defaultValue = -1
|
|
yearMinRel_kind_label = N_('Year Minimum Value')
|
|
yearMinRel_kindName = 'Integer'
|
|
|
|
yearMaxRel = None
|
|
yearMaxRel_kind_balloonHelp = N_('Maximum Year Value Difference to Now')
|
|
yearMinRel_kind_defaultValue = 3
|
|
yearMaxRel_kind_label = N_('Year Maximum Value')
|
|
yearMaxRel_kindName = 'Integer'
|
|
register(Date)
|
|
|
|
|
|
class Duration(BaseWidget):
|
|
pass
|
|
register(Duration)
|
|
|
|
|
|
class Email(BaseWidget):
|
|
maxLength = None
|
|
maxLength_kindName = 'Integer'
|
|
|
|
size = None
|
|
size_kindName = 'Integer'
|
|
register(Email)
|
|
|
|
|
|
class InputCheckBox(BaseWidget):
|
|
labels = None
|
|
labels_kind_keyKind_valueName = 'String'
|
|
labels_kind_valueKind_valueName = 'String'
|
|
labels_kindName = 'Mapping'
|
|
|
|
labelsGetterName = None
|
|
labelsGetterName_kindName = 'PythonIdentifier'
|
|
|
|
titles = None
|
|
titles_kind_keyKind_valueName = 'String'
|
|
titles_kind_valueKind_valueName = 'String'
|
|
titles_kindName = 'Mapping'
|
|
|
|
def getLabels(self, slot, fields):
|
|
if self.labels:
|
|
return self.labels
|
|
return slot.getKind().getLabels(slot, fields)
|
|
register(InputCheckBox)
|
|
|
|
|
|
class InputPassword(BaseWidget):
|
|
maxLength = None
|
|
maxLength_kindName = 'Integer'
|
|
|
|
size = None
|
|
size_kindName = 'Integer'
|
|
register(InputPassword)
|
|
|
|
|
|
class Link(BaseWidget):
|
|
pass
|
|
register(Link)
|
|
|
|
|
|
class Mapping(BaseWidget):
|
|
fieldLabelPlural = None
|
|
fieldLabelPlural_kindName = 'String'
|
|
register(Mapping)
|
|
|
|
|
|
class Multi(BaseWidget):
|
|
fieldLabelPlural = None
|
|
fieldLabelPlural_kindName = 'String'
|
|
|
|
inline = 0
|
|
inline_kindName = 'Boolean'
|
|
register(Multi)
|
|
|
|
|
|
class MultiCheck(BaseWidget):
|
|
pass
|
|
register(MultiCheck)
|
|
|
|
|
|
class Path(BaseWidget):
|
|
pass
|
|
register(Path)
|
|
|
|
|
|
class PushButton(BaseWidget):
|
|
hideLabel = 1
|
|
|
|
location = 'default'
|
|
location_kind_label = N_('Location')
|
|
location_kind_labels = {
|
|
'action': N_('Action Buttons Bar'),
|
|
'default': N_('Default'),
|
|
'navigation': N_('Navigation Buttons Bar'),
|
|
'other-action': N_('Custom Buttons Bar'),
|
|
}
|
|
location_kind_values = [
|
|
'default',
|
|
'navigation',
|
|
'action',
|
|
'other-action',
|
|
]
|
|
location_kindName = 'Choice'
|
|
|
|
def getOrderedLayoutSlotNames(self, parentSlot = None):
|
|
slotNames = BaseWidget.getOrderedLayoutSlotNames(
|
|
self, parentSlot = parentSlot)
|
|
slotNames += ['location']
|
|
return slotNames
|
|
register(PushButton)
|
|
|
|
|
|
class Select(BaseWidget):
|
|
allLabel = N_('All')
|
|
allLabel_kindName = 'String'
|
|
|
|
labels = None
|
|
labels_kind_keyKind_valueName = 'String'
|
|
labels_kind_valueKind_valueName = 'String'
|
|
labels_kindName = 'Mapping'
|
|
|
|
noneLabel = N_('None')
|
|
noneLabel_kindName = 'String'
|
|
|
|
titles = None
|
|
titles_kind_keyKind_valueName = 'String'
|
|
titles_kind_valueKind_valueName = 'String'
|
|
titles_kindName = 'Mapping'
|
|
|
|
def getLabels(self, slot, fields):
|
|
if self.labels:
|
|
return self.labels
|
|
return slot.getKind().getLabels(slot, fields)
|
|
register(Select)
|
|
|
|
|
|
class SelectId(BaseWidget):
|
|
noneLabel = N_('None')
|
|
noneLabel_kindName = 'String'
|
|
register(SelectId)
|
|
|
|
|
|
class TextArea(BaseWidget):
|
|
buttonAddImage = 0
|
|
buttonAddImage_kindName = 'Boolean'
|
|
|
|
preview = 0
|
|
preview_kindName = 'Boolean'
|
|
|
|
cols = 80
|
|
cols_kindName = 'Integer'
|
|
|
|
format = 'spip'
|
|
format_kind_isRequired = 1
|
|
format_kind_values = [
|
|
'docbook',
|
|
'html',
|
|
'spip',
|
|
'text',
|
|
]
|
|
format_kindName = 'Choice'
|
|
|
|
rows = 25
|
|
rows_kindName = 'Integer'
|
|
|
|
viewInTextArea = 0
|
|
viewInTextArea_kindName = 'Boolean'
|
|
|
|
## def getHelpAlias(self, slot, fields):
|
|
## if self.format == 'spip':
|
|
## return 'help-spip-syntax'
|
|
## else:
|
|
## return BaseWidget.getHelpAlias(self, slot, fields)
|
|
register(TextArea)
|
|
|
|
|
|
class Thing(BaseWidget):
|
|
pass
|
|
register(Thing)
|
|
|
|
|
|
class Token(BaseWidget):
|
|
pass
|
|
register(Token)
|
|
|
|
|
|
class UploadFile(BaseWidget):
|
|
fileName = None
|
|
fileName_kindName = 'String'
|
|
register(UploadFile)
|
|
|
|
|
|
class Url(BaseWidget):
|
|
maxLength = None
|
|
maxLength_kindName = 'Integer'
|
|
|
|
size = None
|
|
size_kindName = 'Integer'
|
|
register(Url)
|
|
|
|
|
|
class XSelect(Select):
|
|
maxLength = None
|
|
maxLength_kindName = 'Integer'
|
|
|
|
otherFieldLabel = None
|
|
otherFieldLabel_kindName = 'String'
|
|
|
|
size = None
|
|
size_kindName = 'Integer'
|
|
register(XSelect)
|
|
|
|
|