paulb@354 | 1 | #!/usr/bin/env python |
paulb@354 | 2 | |
paulb@354 | 3 | """ |
paulb@354 | 4 | PyQt-compatible resources for use with WebStack. |
paulb@354 | 5 | |
paulb@354 | 6 | Copyright (C) 2005 Paul Boddie <paul@boddie.org.uk> |
paulb@354 | 7 | |
paulb@354 | 8 | This library is free software; you can redistribute it and/or |
paulb@354 | 9 | modify it under the terms of the GNU Lesser General Public |
paulb@354 | 10 | License as published by the Free Software Foundation; either |
paulb@354 | 11 | version 2.1 of the License, or (at your option) any later version. |
paulb@354 | 12 | |
paulb@354 | 13 | This library is distributed in the hope that it will be useful, |
paulb@354 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
paulb@354 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
paulb@354 | 16 | Lesser General Public License for more details. |
paulb@354 | 17 | |
paulb@354 | 18 | You should have received a copy of the GNU Lesser General Public |
paulb@354 | 19 | License along with this library; if not, write to the Free Software |
paulb@354 | 20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
paulb@354 | 21 | """ |
paulb@354 | 22 | |
paulb@354 | 23 | import XSLForms.Prepare |
paulb@354 | 24 | import XSLForms.Resources.Common |
paulb@354 | 25 | import XSLForms.Resources.WebResources |
paulb@354 | 26 | import os |
paulb@354 | 27 | import libxml2dom |
paulb@354 | 28 | |
paulb@354 | 29 | class XSLFormsResource(XSLForms.Resources.WebResources.XSLFormsResource): |
paulb@354 | 30 | |
paulb@354 | 31 | """ |
paulb@354 | 32 | An XSLForms resource supporting PyQt-compatible Web applications for use |
paulb@354 | 33 | with WebStack. |
paulb@354 | 34 | """ |
paulb@354 | 35 | |
paulb@354 | 36 | widget_resources = {} |
paulb@354 | 37 | |
paulb@354 | 38 | def get_document(self, document_identifier): |
paulb@354 | 39 | return libxml2dom.parse(self.prepare_document(document_identifier)) |
paulb@354 | 40 | |
paulb@354 | 41 | def prepare_widget(self, design_identifier, widget_identifier, parent=None): |
paulb@354 | 42 | design_path = self.prepare_design(design_identifier) |
paulb@354 | 43 | fragment_name, widget_name = self.widget_resources[widget_identifier] |
paulb@354 | 44 | fragment_path = os.path.abspath(os.path.join(self.resource_dir, fragment_name)) |
paulb@354 | 45 | XSLForms.Prepare.ensure_qt_fragment(design_path, fragment_path, widget_name) |
paulb@354 | 46 | # NOTE: Implement the equivalent here! |
paulb@354 | 47 | return qtui.QWidgetFactory.create(fragment_path, None, parent) |
paulb@354 | 48 | |
paulb@354 | 49 | def populate_list(self, field, elements): |
paulb@354 | 50 | # NOTE: Support this! |
paulb@354 | 51 | current_text = field.currentText() |
paulb@354 | 52 | while field.count() > 0: |
paulb@354 | 53 | field.removeItem(0) |
paulb@354 | 54 | item = 0 |
paulb@354 | 55 | set = 0 |
paulb@354 | 56 | for element in elements: |
paulb@354 | 57 | text = element.getAttribute("value") |
paulb@354 | 58 | field.insertItem(text) |
paulb@354 | 59 | if text == current_text: |
paulb@354 | 60 | field.setCurrentItem(item) |
paulb@354 | 61 | set = 1 |
paulb@354 | 62 | item += 1 |
paulb@354 | 63 | if not set: |
paulb@354 | 64 | field.setCurrentItem(0) |
paulb@354 | 65 | |
paulb@354 | 66 | def reset_collection(self, field): |
paulb@354 | 67 | # NOTE: Support this! |
paulb@354 | 68 | layout = field.layout() |
paulb@354 | 69 | for child in field.children(): |
paulb@354 | 70 | if child is not layout: |
paulb@354 | 71 | layout.remove(child) |
paulb@354 | 72 | child.deleteLater() |
paulb@354 | 73 | |
paulb@354 | 74 | class Factory: |
paulb@354 | 75 | |
paulb@354 | 76 | "A widget factory helper class." |
paulb@354 | 77 | |
paulb@354 | 78 | def __init__(self, ui_filename): |
paulb@354 | 79 | self.ui_filename = ui_filename |
paulb@354 | 80 | self.ui_doc = libxml2dom.parse(ui_filename) |
paulb@354 | 81 | |
paulb@354 | 82 | def connect(self, widget, obj): |
paulb@354 | 83 | pass |
paulb@354 | 84 | |
paulb@354 | 85 | def find_widgets(self, widget, name): |
paulb@354 | 86 | # NOTE: Support this! |
paulb@354 | 87 | widgets = [] |
paulb@354 | 88 | found = widget.child(name) |
paulb@354 | 89 | if found: |
paulb@354 | 90 | widgets.append(found) |
paulb@354 | 91 | for child in widget.children(): |
paulb@354 | 92 | widgets += self.find_widgets(child, name) |
paulb@354 | 93 | return widgets |
paulb@354 | 94 | |
paulb@354 | 95 | # vim: tabstop=4 expandtab shiftwidth=4 |