| 2390 | # the __select dictionary containing the SELECT HTML-attributes. |
| 2391 | |
| 2392 | def __init__(self, type, name, attrs, select_default=False, index=None): |
| 2393 | # fish out the SELECT HTML attributes from the OPTION HTML attributes |
| 2394 | # dictionary |
| 2395 | self.attrs = attrs["__select"].copy() |
| 2396 | self.__dict__["_label"] = _get_label(self.attrs) |
| 2397 | self.__dict__["id"] = self.attrs.get("id") |
| 2398 | self.__dict__["multiple"] = "multiple" in self.attrs |
| 2399 | # the majority of the contents, label, and value dance already happened |
| 2400 | contents = attrs.get("contents") |
| 2401 | attrs = attrs.copy() |
| 2402 | del attrs["__select"] |
| 2403 | |
| 2404 | ListControl.__init__(self, type, name, self.attrs, select_default, |
| 2405 | called_as_base_class=True, index=index) |
| 2406 | self.disabled = "disabled" in self.attrs |
| 2407 | self.readonly = "readonly" in self.attrs |
| 2408 | if "value" in attrs: |
| 2409 | # otherwise it is a marker 'select started' token |
| 2410 | o = Item(self, attrs, index) |
| 2411 | o.__dict__["_selected"] = "selected" in attrs |
| 2412 | # add 'label' label and contents label, if different. If both are |
| 2413 | # provided, the 'label' label is used for display in HTML |
| 2414 | # 4.0-compliant browsers (and any lower spec? not sure) while the |
| 2415 | # contents are used for display in older or less-compliant |
| 2416 | # browsers. We make label objects for both, if the values are |
| 2417 | # different. |
| 2418 | label = attrs.get("label") |
| 2419 | if label: |
| 2420 | o._labels.append(Label({"__text": label})) |
| 2421 | if contents and contents != label: |
| 2422 | o._labels.append(Label({"__text": contents})) |
| 2423 | elif contents: |
| 2424 | o._labels.append(Label({"__text": contents})) |
| 2425 | |
| 2426 | def fixup(self): |
| 2427 | ListControl.fixup(self) |