~ubuntu-branches/ubuntu/quantal/jokosher/quantal

« back to all changes in this revision

Viewing changes to Jokosher/ProjectTemplate.py

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna, Luca Falavigna, Piotr Ożarowski
  • Date: 2009-05-12 00:37:15 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090512003715-3hp2ycoqjlzwfnlv
Tags: 0.11.2-1
[ Luca Falavigna ]
* New upstream release (Closes: #517234).
  - Jokosher now appears under Sound & Video (Closes: #443788).
* New Maintainer (Closes: #523167).
* Add Python Applications Packaging Team to Uploaders.
* Add Vcs-* fields in source stanza.
* Adjust copyright informations:
  - Refresh upstream authors and copyright holders.
  - Link to /usr/share/common-licenses/GPL-2.
  - Adjust copyright holders for Debian packaging.
  - Replace (c) with ©.
* Apply changes from Ubuntu by Daniel Holbach (thanks!):
  - Drop scrollkeeper from Build-Depends.
  - Drop useless dependencies: python-alsaaudio, gstreamer0.10-gnomevfs,
    librsvg2-common, python-gnome2.
  - Bump gstreamer0.10-plugins-good requirement to >= 0.10.9.
  - Drop debian/jokosher.sh, useless.
  - Provide debian/watch file.
* Switch to debhelper 7.
* Install Jokosher module in private directory.
* Unpack egg files to let python-support handle them.
* Drop python-dev from Build-Depends, use python (>= 2.4) instead.
* Depend on python-gobject.
* Switch dependency from python-setuptools to python-pkg-resources
  because of package rename (Closes: #468728).
* debian/patches/10_update_mime_database.dpatch:
  - Refresh for new upstream release.
* debian/patches/20_LevelList_IOError.dpatch:
  - Fix IOError exception trying to add an audio file to a project.
* debian/patches/30_desktop_file.dpatch:
  - Adhere to Freedesktop.org standards by removing deprecated entries.
* debian/patches/50_CreateNewProject_return.dpatch:
  - Return class while creating a new project.
* Provide a simple man page for jokosher.
* Bump Standards-Version to 3.8.1:
  - Provide Homepage field in source stanza.
  - Provide debian/README.source to document dpatch usage.

[ Piotr Ożarowski ]
* Add 40_load_extensions_from_unpacked_eggs patch so that extensions in
  unzipped Eggs are recognized as well

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
#       THIS FILE IS PART OF THE JOKOSHER PROJECT AND LICENSED UNDER THE GPL. SEE
 
3
#       THE 'COPYING' FILE FOR DETAILS
 
4
#
 
5
#       ProjectTemplate.py
 
6
#       
 
7
#       This module handles the saving and loading of project templates.
 
8
#       
 
9
#
 
10
#-------------------------------------------------------------------------------
 
11
 
 
12
import os
 
13
import gobject
 
14
import Globals
 
15
import xml.dom.minidom as xml
 
16
from Utils import LoadListFromXML, StoreListToXML
 
17
 
 
18
#=========================================================================
 
19
 
 
20
class ProjectTemplate(gobject.GObject):
 
21
        """
 
22
        This class saves and loads templates and template information to disk.
 
23
        """
 
24
 
 
25
        #the extension put on the end of template files
 
26
        TEMPLATE_EXT = "template"
 
27
        
 
28
        """
 
29
        Signals:
 
30
                "template-update" -- This template has changed.
 
31
        """
 
32
        
 
33
        __gsignals__ = {
 
34
                "template-update" : ( gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, () )
 
35
        }
 
36
        
 
37
        #_____________________________________________________________________
 
38
 
 
39
        def __init__(self):
 
40
                """ 
 
41
                Creates a new instance of ProjectTemplate.
 
42
                """
 
43
                gobject.GObject.__init__(self)
 
44
 
 
45
        #_____________________________________________________________________
 
46
 
 
47
        def SaveTemplateFile(self, name, instrlist):
 
48
                """ 
 
49
                This method will write a template file to JOKOSHER_DATA_HOME/templates/.
 
50
                instrlist is a list containing type strings corresponding to each instrument.
 
51
                e.g. ["audiofile", "acousticguitar"].
 
52
        
 
53
                Parameters:
 
54
                        name -- the name of the template file.
 
55
                        instrlist -- a list containing the instrument type strings
 
56
                """
 
57
                doc = xml.Document()
 
58
                head = doc.createElement("JokosherProjectTemplate")
 
59
                doc.appendChild(head)
 
60
                
 
61
                for typeString in instrlist:
 
62
                        # create instrument tags for every instrument in the list
 
63
                        instrtag = doc.createElement("Instrument")
 
64
                        instrtag.setAttribute("type", typeString)
 
65
                        head.appendChild(instrtag)
 
66
                
 
67
                if not name.endswith("." + self.TEMPLATE_EXT):
 
68
                        name += "." + self.TEMPLATE_EXT
 
69
                namePath = os.path.join(Globals.TEMPLATES_PATH, name)
 
70
                try:
 
71
                        try:
 
72
                                filename = open(namePath, "w")
 
73
                                filename.write(doc.toprettyxml())
 
74
                        except IOError, e:
 
75
                                Globals.debug("The template %s does not exist" % namePath)
 
76
                finally:
 
77
                        filename.close()
 
78
                        
 
79
                self.emit("template-update")
 
80
 
 
81
        #_____________________________________________________________________
 
82
        
 
83
        def DeleteTemplateFile(self, name):
 
84
                """
 
85
                This method will delete a template file.
 
86
                
 
87
                Parameters:
 
88
                        name -- the name of the template file which will be deleted.
 
89
                """
 
90
                if not name.endswith("." + self.TEMPLATE_EXT):
 
91
                        name += "." + self.TEMPLATE_EXT
 
92
                namePath = os.path.join(Globals.TEMPLATES_PATH, name)
 
93
                try:
 
94
                        os.remove(namePath)
 
95
                except OSError, e:
 
96
                        Globals.debug("Cannot remove template %s" % namePath)
 
97
                        
 
98
                self.emit("template-update")
 
99
 
 
100
        #_____________________________________________________________________
 
101
        
 
102
        def __LoadInstrumentsFromTemplateFile(self, name):
 
103
                """
 
104
                This method will return a list containing a list of instruments which are in the given template filename.
 
105
                
 
106
                Parameters:
 
107
                        name -- the name of the template.
 
108
                        
 
109
                Returns:
 
110
                        instrlist -- a list containing a list of instruments, e.g. [["audiofile", "Audio File", "path_to_image"]].
 
111
                """
 
112
                if not name.endswith("." + self.TEMPLATE_EXT):
 
113
                        name += "." + self.TEMPLATE_EXT
 
114
                namePath = os.path.join(Globals.TEMPLATES_PATH, name)
 
115
                if os.path.exists(namePath):
 
116
                        file = open(namePath, "r")
 
117
                        doc = xml.parse(file)
 
118
                        instrlist = []
 
119
                        for node in doc.getElementsByTagName("Instrument"):
 
120
                                typeString = str(node.getAttribute("type"))
 
121
                                instrlist.append(typeString)
 
122
                        return instrlist
 
123
                else:
 
124
                        Globals.debug("The template %s does not exist" % namePath)
 
125
        
 
126
        #_____________________________________________________________________
 
127
        
 
128
        def __GetTemplateList(self):
 
129
                """
 
130
                This method will return a list of template files in the template directory (JOKOSHER_DATA_HOME/templates/")
 
131
                
 
132
                Returns:
 
133
                        filenames -- a list containing the names of file in the template directory.
 
134
                """
 
135
                templist = []
 
136
                for files in os.listdir(Globals.TEMPLATES_PATH):
 
137
                        filenames = files.split(".")[0]
 
138
                        templist.append(filenames)
 
139
                return templist
 
140
 
 
141
        #_____________________________________________________________________
 
142
 
 
143
        def LoadDictionaryOfInstrumentsFromTemplateFile(self):
 
144
                """
 
145
                This method will return a dictionary containing the the template file name (key) and a list
 
146
                of the associated instrument tupels.
 
147
                e.g. {"Rock" : [ ("electricguitar", "Electric Guitar", pixbufImage) ]}
 
148
                """
 
149
                instrdict = {}
 
150
                cached = Globals.getCachedInstruments()
 
151
                for filename in self.__GetTemplateList():
 
152
                        instrTuples = []
 
153
                        typeStringList = self.__LoadInstrumentsFromTemplateFile(filename)
 
154
                        for type in typeStringList:
 
155
                                tuple_ = [x for x in cached if x[1] == type]
 
156
                                if tuple_:
 
157
                                        name, type, pixbuf, path = tuple_[0]
 
158
                                        instrTuples.append( (name, type, pixbuf) )
 
159
                                        
 
160
                        instrdict[filename] = instrTuples
 
161
                
 
162
                return instrdict
 
163
        
 
164
#=========================================================================