paulb@354 | 1 | #!/usr/bin/env python |
paulb@354 | 2 | |
paulb@354 | 3 | """ |
paulb@354 | 4 | Common resource class functionality. |
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 os |
paulb@354 | 24 | |
paulb@354 | 25 | class CommonResource: |
paulb@354 | 26 | |
paulb@354 | 27 | "Common resource methods." |
paulb@354 | 28 | |
paulb@354 | 29 | document_resources = {} |
paulb@354 | 30 | resource_dir = None |
paulb@354 | 31 | |
paulb@354 | 32 | def prepare_document(self, document_identifier): |
paulb@354 | 33 | |
paulb@354 | 34 | """ |
paulb@354 | 35 | Prepare a document using the given 'document_identifier'. |
paulb@354 | 36 | |
paulb@354 | 37 | Return the full path of the document for use either as the source |
paulb@354 | 38 | document or as a reference with 'send_output' or 'get_result'. |
paulb@354 | 39 | """ |
paulb@354 | 40 | |
paulb@354 | 41 | filename = self.document_resources[document_identifier] |
paulb@354 | 42 | return os.path.abspath(os.path.join(self.resource_dir, filename)) |
paulb@354 | 43 | |
paulb@354 | 44 | class PyQtCommonResource(CommonResource): |
paulb@354 | 45 | |
paulb@354 | 46 | "Common PyQt-compatible resource methods." |
paulb@354 | 47 | |
paulb@354 | 48 | design_resources = {} |
paulb@354 | 49 | |
paulb@354 | 50 | def get_document(self, document_identifier): |
paulb@354 | 51 | raise NotImplementedError, "get_document" |
paulb@354 | 52 | |
paulb@354 | 53 | def get_elements(self, document_identifier): |
paulb@354 | 54 | doc = self.get_document(document_identifier) |
paulb@354 | 55 | return doc.getElementsByTagName(document_identifier + "-enum") |
paulb@354 | 56 | |
paulb@354 | 57 | def prepare_design(self, design_identifier): |
paulb@354 | 58 | filename = self.design_resources[design_identifier] |
paulb@354 | 59 | return os.path.abspath(os.path.join(self.resource_dir, filename)) |
paulb@354 | 60 | |
paulb@354 | 61 | # vim: tabstop=4 expandtab shiftwidth=4 |