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