class ColorPicker(YuiWidget): resources = YuiWidget.resources + [ twc.CSSLink(modname=__name__, filename="static/" + yui_version + "/colorpicker/assets/skins/sam/colorpicker.css"), twc.JSLink( modname=__name__, filename="static/" + yui_version + "/dragdrop/dragdrop-min.js"), twc.JSLink( modname=__name__, filename="static/" + yui_version + "/animation/animation-min.js"), twc.JSLink(modname=__name__, filename="static/" + yui_version + "/slider/slider-min.js"), twc.JSLink( modname=__name__, filename="static/" + yui_version + "/element/element-min.js"), twc.JSLink(modname=__name__, filename="static/" + yui_version + "/colorpicker/colorpicker-min.js"), twc.Link(id='picker_thumb', modname=__name__, filename="static/" + yui_version + "/colorpicker/assets/picker_thumb.png"), twc.Link(id='hue_thumb', modname=__name__, filename="static/" + yui_version + "/colorpicker/assets/hue_thumb.png"), ] template = "genshi:tw2.yui.templates.colorpicker" rgb = twc.Variable(default='[0xFF,0xFF,0xFF]') def prepare(self): self.safe_modify('options') if self.value and re.match('^#[0-9a-fA-F]{6}$', self.value): self.rgb = twc.encoder.encode( [int(self.value[i:i + 2], 16) for i in (1, 3, 5)]) self.options['images'] = { 'PICKER_THUMB': '/resources/tw2.yui.widgets/static/' + yui_version + '/colorpicker/assets/picker_thumb.png', 'HUE_THUMB': '/resources/tw2.yui.widgets/static/' + yui_version + '/colorpicker/assets/hue_thumb.png', } super(ColorPicker, self).prepare()
class CalendarDatePicker(twf.widgets.InputField): """ A JavaScript calendar system for picking dates. The date format can be configured on the validator. """ resources = [ twc.CSSLink(modname='tw2.dynforms', filename='static/calendar/calendar-system.css'), twc.JSLink(modname='tw2.dynforms', filename='static/calendar/calendar.js'), twc.JSLink(modname='tw2.dynforms', filename='static/calendar/calendar-setup.js'), twc.Link(id='cal', modname='tw2.dynforms', filename='static/office-calendar.png'), ] language = twc.Param('Short country code for language to use, e.g. fr, de', default='en') show_time = twc.Variable('Whether to display the time', default=False) value = twc.Param('The default value is the current date/time', default=None) validator = twc.DateValidator template = "genshi:tw2.dynforms.templates.calendar" type = 'text' def prepare(self): if not self.value: # XXX -- Doing this instead of twc.Deferred consciously. # twc.Deferred is/was nice, but the execution in post_define(...) of # cls._deferred = [k for k, v in cls.__dict__.iteritems() # if isinstance(v, pm.Deferred)] # with dir(..) instead of vars(..) is too costly. This is the only # place I'm aware of that actually uses deferred params. - threebean self.value = dt.datetime.now() super(CalendarDatePicker, self).prepare() self.safe_modify('resources') self.resources.extend([ twc.JSLink(parent=self.__class__, modname='tw2.dynforms', filename='static/calendar/lang/calendar-%s.js' % self.language), ]) self.add_call( twc.js_function('Calendar.setup')(dict( inputField=self.compound_id, ifFormat=self.validator.format, button=self.compound_id + ':trigger', showsTime=self.show_time)))
class GrowingGridLayout(twf.GridLayout): """A GridLayout that can dynamically grow on the client, with delete and undo functionality. This is useful for allowing users to enter a list of items that can vary in length. To function correctly, the widget must appear inside a CustomisedForm.""" resources = [ twc.Link(id='undo', modname=__name__, filename="static/undo.png"), twc.JSLink(modname=__name__, filename="static/dynforms.js"), ] template = 'genshi:tw2.dynforms.templates.growing_grid_layout' # TBD: support these properly & min/max repetitions = twc.Variable() extra_reps = twc.Variable(default=1) mix_reps = twc.Variable() max_reps = twc.Variable() @classmethod def post_define(cls): if hasattr(cls.child, 'children'): if not hasattr(cls.child.children, 'del'): # TBD: 'del' in ... cls.child = cls.child(children=list(cls.child.children) + [DeleteButton(id='del', label='')]) def prepare(self): if not hasattr(self, '_validated'): self.value = [None] + (self.value or []) super(GrowingGridLayout, self).prepare() # First and last rows have delete hidden (and hidingbutton) and get onchange for r in (self.children[0], self.children[self.repetitions - 1]): for c in r.children: c.safe_modify('attrs') if c.id == 'del': c.attrs['style'] = 'display:none;' + c.attrs.get( 'style', '') else: c.attrs['onchange'] = 'twd_grow_add(this);' + c.attrs.get( 'onchange', '') # First row is hidden hidden_row = self.children[0] hidden_row.safe_modify('attrs') hidden_row.attrs['style'] = 'display:none;' + hidden_row.attrs.get( 'style', '') def _validate(self, value, state=None): value = [v for v in value if not ('del.x' in v and 'del.y' in v)] return twc.RepeatingWidget._validate( self, [None] + twf.StripBlanks().to_python(value), state)[1:]
class RowLayout(BaseLayout): """ Arrange widgets in a table row. This is normally only useful as a child to GridLayout. """ resources = [ twc.Link(id='error', modname='tw2.forms', filename='static/dialog-warning.png'), ] template = "tw2.forms.templates.row_layout" def prepare(self): row_class = (self.repetition % 2 and 'even') or 'odd' if not self.css_class or row_class not in self.css_class: self.css_class = ' '.join((self.css_class or '', row_class)).strip() super(RowLayout, self).prepare()
class Slider(YuiWidget): resources = YuiWidget.resources + [ twc.CSSLink(modname=__name__, filename="static/" + yui_version + "/slider/assets/skins/sam/slider.css"), twc.JSLink( modname=__name__, filename="static/" + yui_version + "/animation/animation-min.js"), twc.JSLink( modname=__name__, filename="static/" + yui_version + "/dragdrop/dragdrop-min.js"), twc.JSLink(modname=__name__, filename="static/" + yui_version + "/slider/slider-min.js"), twc.Link( id='thumb', modname=__name__, filename='static/' + yui_version + '/slider/assets/thumb-n.gif'), ] template = "genshi:tw2.yui.templates.slider" size = twc.Param('Size in pixels of control', default=200) min = twc.Param('Minimum effective value', default=0) max = twc.Param('Maximum effective value', default=100)
import tw2.core as twc import tw2.forms as twf import tw2.jquery as twj __all__ = [ 'chosen_img', 'chosen_js', 'chosen_css', 'ChosenSingleSelectField', 'ChosenMultipleSelectField' ] chosen_img = twc.Link(modname=__name__, filename='static/chosen-sprite.png') chosen_img_2x = twc.Link(modname=__name__, filename='static/[email protected]') chosen_js = twc.JSLink(modname=__name__, filename='static/chosen.jquery.js', resources=[twj.jquery_js], location='headbottom') chosen_js_min = twc.JSLink(modname=__name__, filename='static/chosen.jquery.min.js', resources=[twj.jquery_js], location='headbottom') chosen_css = twc.CSSLink(modname=__name__, filename='static/chosen.css') chosen_css_min = twc.CSSLink(modname=__name__, filename='static/chosen.min.css') class ChosenMixin(twc.Widget): '''Mixin for Chosen SelectFields''' resources = [chosen_js, chosen_css] selector = twc.Variable("Escaped id. jQuery selector.") opts = twc.Variable(
class Table(twc.Widget): template = "tw2.olap.templates.table" mdxresult = twc.Param("An IMDXResult object.") properties = twc.Param( "A list of properties to load from the result cells") showTrigger = twc.Param("Show or hide +/- trigger", default=False) showSpan = twc.Param("Show or hide spanning cells", default=False) showRowColumnHeaders = twc.Param("Show or hide column headers of row head", default=False) colHeaderMap = twc.Param( "Optionally substitute columns header names as by this mapping", default={}) resources = [ twc.CSSLink(modname="tw2.olap", filename="static/table.css"), twc.Link(id="do_collapse", modname="tw2.olap", filename="static/do-collapse.gif"), twc.Link(id="do_expand", modname="tw2.olap", filename="static/do-expand.gif"), twc.Link(id="do_nothing", modname="tw2.olap", filename="static/do-nothing.gif") ] css_class = "olaptable" def prepare(self): super(Table, self).prepare() res = self.mdxresult axistuple = [] try: axis = 0 while True: axistuple.append(res.getAxisTuple(axis)) axis += 1 except: pass self.slices = res.getSlice(properties=self.properties) self.axistuple = axistuple #import pdb; pdb.set_trace() maxhier = self.getRowColumnCount() if maxhier > 1 and not self.showSpan: self.spanning(self.axistuple[1], 0, maxhier, 0, self.getRowCount()) maxhier = self.getColumnRowCount() if maxhier > 1 and not self.showSpan: self.spanning(self.axistuple[0], 0, maxhier, 0, self.getColumnCount()) def getContent(self): colgroup = [] theadrows = self.getLeadingRows() tfootrows = [] tbodyrows = [] cr_count = self.getColumnRowCount() rc_count = self.getRowColumnCount() cc = self.getColumnCount() # thead for cr in range(cr_count): if self.showColumnHeaderRow(cr): row_attrs = {} ths = [] if rc_count > 0: if self.showRowColumnHeader() and cr == cr_count - 1: for c in range(self.getRowColumnCount()): ths.append(("th", self.getRowColumnHeaderAttrs(c), self.displayRowColumnHeader(c))) else: ths.append(self.getEmptyRowDesc(cr)) for c in range(cc): if self.showColumnRowCell(c, cr): ths.append(("th", self.getColumnRowCellAttrs(c, cr), self.displayColumnRowCell(c, cr))) row = ("tr", row_attrs, ths) rows = self.alterHeadRow(cr, row) if rows: theadrows.extend(rows) # tbody for r in range(self.getRowCount()): if self.showRow(r): row_attrs = {} tds = [] # row header cells for rc in range(rc_count): if self.showRowColumnCell(r, rc): td_attrs = self.getRowColumnCellAttrs(r, rc) div_attrs = self.getRowColumnDivAttrs(r, rc) div = ("div", div_attrs, self.getRowColumnCellDesc(r, rc)) tds.append(("th", td_attrs, div)) # data cells for c in range(cc): if self.showCell(r, c): tds.append(("td", self.getCellAttrs(r, c), self.displayCell(r, c))) row = ("tr", row_attrs, tds) rows = self.alterBodyRow(r, row) if rows: tbodyrows.extend(rows) # tfoot tfootrows = self.getTrailingRows() if tfootrows: tfootrows = ("tfoot", {}, tfootrows) if theadrows: theadrows = ("thead", {}, theadrows) if tbodyrows: tbodyrows = ("tbody", {}, tbodyrows) return colgroup, theadrows, tbodyrows, tfootrows def getColumnCount(self): return len(self.axistuple[0]) def getColumnRowCount(self): tup = self.axistuple[0][0] if isinstance(tup, list): return len(tup) return 1 def getRowCount(self): if self.slices: if isinstance(self.slices[0], list): return len(self.slices) return 1 return 0 def getRowColumnCount(self): try: tup = self.axistuple[1][0] if isinstance(tup, list): return len(tup) return 1 except: return 0 def showColumnHeaderRow(self, row): return True def getColumnRowCell(self, column, row): cell = self.axistuple[0][column] if isinstance(cell, list): cell = cell[row] return cell def showColumnRowCell(self, column, row): cell = self.getColumnRowCell(column, row) return getattr(cell, "_tw2_span", 1) > 0 def getColumnRowCellAttrs(self, column, row): cell = self.getColumnRowCell(column, row) span = getattr(cell, "_tw2_span", 1) attrs = { "class": "column-heading-even" if column % 2 == 0 else "column-heading-odd" } if span > 1: attrs["colspan"] = span attrs["class"] = "column-heading-span" return attrs def displayColumnRowCell(self, column, row): cell = self.getColumnRowCell(column, row) caption = cell.Caption if self.colHeaderMap: return self.colHeaderMap.get(caption, caption) return caption def getRowColumnCell(self, row, col): cell = self.axistuple[1][row] if isinstance(cell, list): cell = cell[col] return cell def showRowColumnCell(self, row, col): cell = self.getRowColumnCell(row, col) return getattr(cell, "_tw2_span", 1) > 0 def getRowColumnCellDesc(self, row, col): e_name = "input" e_attrs = self.getRowColumnInputAttrs(row, col) e_content = self.displayRowColumnCell(row, col) return e_name, e_attrs, e_content def getRowColumnCellAttrs(self, row, col): cell = self.getRowColumnCell(row, col) span = getattr(cell, "_tw2_span", 1) attrs = { "class": "row-heading-even" if row % 2 == 0 else "row-heading-odd" } if span > 1: attrs["rowspan"] = span attrs["class"] = "row-heading-span" return attrs def getRowColumnDivAttrs(self, row, col): cell = self.getRowColumnCell(row, col) level = getattr(cell, "LNum", "0") attrs = {"style": "margin-left: %sem" % level} return attrs def getRowColumnInputAttrs(self, row, col): cell = self.getRowColumnCell(row, col) di = DisplayInfo(getattr(cell, "DisplayInfo", "0")) #log.info(cell.Caption + " - dispinfo:" + getattr(cell, "DisplayInfo", "0") + ", dd:"+ (di.isDrilledDown and "YES" or "NO")) attrs = {"border": "0", "width": "9", "type": "image", "height": "9"} if di.countChildren and self.showTrigger: attrs[ "src"] = self.resources.do_collapse.link if di.isDrilledDown else self.resources.do_expand.link else: attrs["src"] = self.resources.do_nothing.link return attrs def displayRowColumnCell(self, row, col): cell = self.getRowColumnCell(row, col) return cell.Caption def showCell(self, row, col): return True def getCellAttrs(self, row, col): attrs = {"class": "cell-even" if row % 2 == 0 else "cell-odd"} return attrs def getCell(self, row, col): if self.slices: if isinstance(self.slices[0], list): cell = self.slices[row][col] else: cell = self.slices[col] return cell return None def displayCell(self, row, col): cell = self.getCell(row, col) if isinstance(self.properties, basestring): return cell return "override displayRowColumnCell and assemble your cell display" return None def showRowColumnHeader(self): return self.showRowColumnHeaders def getRowColumnHeaderAttrs(self, col): return {"class": "heading-heading"} def displayRowColumnHeader(self, col): cell = self.axistuple[1][0] if isinstance(cell, list): cell = cell[col] #import pdb; pdb.set_trace() return cell._Hierarchy def showRow(self, row): """ Do i want to display that row? """ return True def getLeadingRows(self): return [] def getTrailingRows(self): return [] def alterHeadRow(self, row, rowDesc): return [rowDesc] def alterBodyRow(self, row, rowDesc): return [rowDesc] def getEmptyRowDesc(self, row): attrs = {"colspan": self.getRowColumnCount()} return attrs, None def spanning(self, src, hier, maxhier, start, end): i = start startcellspan = None if hier == maxhier: return while i < end: cell = src[i][hier] if startcellspan == None: startcellspan = cell startcellspan._tw2_span = 1 elif startcellspan.UName == cell.UName: startcellspan._tw2_span += 1 cell._tw2_span = 0 else: startcellspan = cell startcellspan._tw2_span = 1 self.spanning(src, hier + 1, maxhier, start, i) start = i i += 1 self.spanning(src, hier + 1, maxhier, start, i)
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ :mod:`moksha.api.widgets.buttons` - Fancy Button CSS ==================================================== This module contains a ToscaWidget for the mbButtons project:: http://www.open-lab.com/mb.ideas/index.html#mbButtons .. moduleauthor:: Luke Macken <*****@*****.**> """ import tw2.core as twc buttons_css = twc.CSSLink(filename='static/buttons.css', media='all', modname=__name__) buttons_dir = twc.DirLink(filename='static/images', modname=__name__) static_images = twc.Link(filename='static/images/ventitre.gif', modname=__name__)
import tw2.core as twc import tw2.forms as twf import tw2.jquery as twj __all__ = [ 'select2_spinner_img', 'select2_sprite_img', 'select2_js', 'select2_css', 'Select2SingleSelectField', 'Select2MultipleSelectField', 'Select2AjaxSingleSelectField', ] select2_spinner_img = twc.Link(modname=__name__, filename='static/select2-spinner.gif') select2_sprite_img = twc.Link(modname=__name__, filename='static/select2.png') select2_js = twc.JSLink(modname=__name__, filename='static/select2.min.js', resources=[twj.jquery_js], location='headbottom') select2_css = twc.CSSLink(modname=__name__, filename='static/select2.css') class Select2Mixin(twc.Widget): '''Mixin for Select2 SelectFields''' resources = [select2_js, select2_css] selector = twc.Variable("Escaped id. jQuery selector.") opts = twc.Variable('Arguments for the javascript init function', default=dict())