~openshot.code/openshot/main

« back to all changes in this revision

Viewing changes to openshot/windows/NewProject.py

  • Committer: Jonathan Thomas
  • Date: 2009-09-08 04:49:08 UTC
  • Revision ID: jonathan@jonathan64-20090908044908-kzhw2m1dl251yt9y
Bumping version to 0.9.30

Here it goes.  Massive re-factoring across OpenShot.  I put
a ton of regression work into this to ensure everything still
works, but as always, I could have missed something.

The biggest changes: 
------------------------------
1) Distutils is now used to install OpenShot (setup.py install).
   Installing OpenShot this way will copy Mime Types, Register Icons,
   Add launcher to Application menu, and copy the OpenShot .py code 
   to the /site-packages/ folder.
2) Python code moved into ~/openshot/openshot/
3) New folders ~/openshot/[bin,docs,xdg]
4) Translations moved to ~/openshot/openshot/locale
5) classes/project.py contains all of the PATH variables
6) classes/info.py contains the version of OpenShot
7) after installing (using setup.py), the /openshot/bin/openshot 
   is the launcher that gets copied to the /usr/bin
8) A few bug fixes have also been added:
   A) removing marker clears timeline
   B) opening a project stopped some changes from refreshing the video
9) Arguments can be passed to OpenShot ($ openshot 'video1.avi', 'video2.avi')
------------------------------

There are now 2 ways to launch OpenShot.

$ openshot (assuming setup.py was used to install OpenShot)
$ ~/openshot/openshot/openshot.py  (I know... it looks funny)

Good luck to everyone testing this!  =)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#       OpenShot Video Editor is a program that creates, modifies, and edits video files.
 
2
#   Copyright (C) 2009  Jonathan Thomas
 
3
#
 
4
#       This file is part of OpenShot Video Editor (http://launchpad.net/openshot/).
 
5
#
 
6
#       OpenShot Video Editor is free software: you can redistribute it and/or modify
 
7
#       it under the terms of the GNU General Public License as published by
 
8
#       the Free Software Foundation, either version 3 of the License, or
 
9
#       (at your option) any later version.
 
10
#
 
11
#       OpenShot Video Editor is distributed in the hope that it will be useful,
 
12
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
#       GNU General Public License for more details.
 
15
#
 
16
#       You should have received a copy of the GNU General Public License
 
17
#       along with OpenShot Video Editor.  If not, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
import os
 
20
import gtk, gtk.glade
 
21
from classes import messagebox, profiles, project
 
22
from windows.SimpleGladeApp import SimpleGladeApp
 
23
 
 
24
# init the foreign language
 
25
from language import Language_Init
 
26
 
 
27
 
 
28
# This form is used to create new projects and save 
 
29
# existing projects
 
30
class frmNewProject(SimpleGladeApp):
 
31
        
 
32
        def __init__(self, mode="", path="NewProject.glade", root="frmNewProject", domain="OpenShot", project=None, **kwargs):
 
33
                print "init"
 
34
                SimpleGladeApp.__init__(self, os.path.join(project.GLADE_DIR, path), root, domain, **kwargs)
 
35
 
 
36
                # Add language support
 
37
                _ = Language_Init.Translator(project).lang.gettext
 
38
 
 
39
                # project instance
 
40
                self.project = project
 
41
                self.form = project.form
 
42
 
 
43
                # check the mode of the form (i.e. new project or save as screen)
 
44
                self.mode = mode
 
45
                
 
46
                # init the project type properties
 
47
                self.init_properties()
 
48
                
 
49
                # init the list of possible project types / profiles
 
50
                self.profile_list = profiles.mlt_profiles(self.project).get_profile_list()
 
51
                
 
52
                # loop through each profile, and add it to the dropdown
 
53
                for file_name, p in self.profile_list:
 
54
                        # append profile to list
 
55
                        self.cmbProjectType.append_text(p.description())
 
56
 
 
57
                
 
58
                # get the model and iterator of the project type dropdown box
 
59
                model = self.cmbProjectType.get_model()
 
60
                iter = model.get_iter_first()
 
61
                while True:
 
62
                        # get the value of each item in the dropdown
 
63
                        value = model.get_value(iter, 0)
 
64
                        
 
65
                        # check for the matching project type
 
66
                        if self.project.project_type == value:                  
 
67
                                
 
68
                                # set the item as active
 
69
                                self.cmbProjectType.set_active_iter(iter)
 
70
                
 
71
                        # get the next item in the list
 
72
                        iter = model.iter_next(iter)
 
73
                        
 
74
                        # break loop when no more dropdown items are found
 
75
                        if iter is None:
 
76
                                break
 
77
        
 
78
                        
 
79
                if (self.mode == "saveas"):
 
80
 
 
81
                        # init the values (based on the mode)
 
82
                        self.txtProjectName.set_text(self.project.name)
 
83
                        self.spinProjectLength.set_text(str(self.project.sequences[0].length / 60))
 
84
                        
 
85
                        #if the video folder exists, default to this
 
86
                        #video_dir = os.path.join(os.path.expanduser("~"), "Video")
 
87
                        #if video_dir:
 
88
                        #       self.frmAddFiles.set_current_folder(video_dir)
 
89
                        
 
90
                        if ".openshot" in self.project.folder:
 
91
                                # This is the openshot default project (set the folder to 'DESKTOP')
 
92
                                self.fileProjectFolder.set_current_folder(os.path.join(os.path.expanduser("~"), "Desktop"))
 
93
                        
 
94
                        elif len(self.project.folder) > 0:
 
95
                                # set default folder (if there is a current folder)
 
96
                                self.fileProjectFolder.set_current_folder(self.project.folder)
 
97
 
 
98
 
 
99
        def init_properties(self):
 
100
                # get the mlt profile
 
101
                localType = self.cmbProjectType.get_active_text()
 
102
                p = profiles.mlt_profiles(self.project).get_profile(localType)
 
103
 
 
104
                # populate the labels with values
 
105
                self.lblHeightValue.set_text(str(p.height()))
 
106
                self.lblWidthValue.set_text(str(p.width()))
 
107
                self.lblAspectRatioValue.set_text("%s:%s" % (p.display_aspect_num(), p.display_aspect_den()))
 
108
                self.lblFrameRateValue.set_text("%.2f" % float(p.fps()))
 
109
                self.lblPixelRatioValue.set_text("%s:%s" % (p.sample_aspect_num(), p.sample_aspect_den()))
 
110
                
 
111
                if p.progressive():
 
112
                        self.lblProgressiveValue.set_text("Yes")
 
113
                else:
 
114
                        self.lblProgressiveValue.set_text("No")
 
115
                
 
116
 
 
117
        def new(self):
 
118
                print "A new %s has been created" % self.__class__.__name__
 
119
 
 
120
 
 
121
        def on_frmNewProject_close(self, widget, *args):
 
122
                print "on_frmNewProject_close called with self.%s" % widget.get_name()
 
123
 
 
124
 
 
125
 
 
126
        def on_frmNewProject_destroy(self, widget, *args):
 
127
                print "on_frmNewProject_destroy called with self.%s" % widget.get_name()
 
128
 
 
129
                # Is openshot existing?
 
130
                if self.project.form.is_exiting:
 
131
                        self.project.form.frmMain.destroy()
 
132
                        
 
133
 
 
134
        def on_frmNewProject_response(self, widget, *args):
 
135
                print "on_frmNewProject_response called with self.%s" % widget.get_name()
 
136
 
 
137
 
 
138
        #def on_fileProjectFolder_selection_changed(self, widget, *args):
 
139
        #       print "on_fileProjectFolder_selection_changed called with self.%s" % widget.get_name()
 
140
 
 
141
 
 
142
        def on_cmbProjectType_changed(self, widget, *args):
 
143
                print "on_cmbProjectType_changed called with self.%s" % widget.get_name()
 
144
 
 
145
                # init the project type properties
 
146
                self.init_properties()
 
147
 
 
148
        def on_btnCancel_clicked(self, widget, *args):
 
149
                print "on_btnCancel_clicked called with self.%s" % widget.get_name()
 
150
 
 
151
                # close the window              
 
152
                self.frmNewProject.destroy()
 
153
 
 
154
        def on_btnCreateProject_clicked(self, widget, *args):
 
155
                print "on_btnCreateProject_clicked called with self.%s" % widget.get_name()
 
156
 
 
157
                localName = str.strip(self.txtProjectName.get_text())
 
158
                localFolder = str.strip(self.fileProjectFolder.get_filename())
 
159
                localType = self.cmbProjectType.get_active_text()
 
160
                localLength = str.strip(self.spinProjectLength.get_text())
 
161
 
 
162
                # Validate the the form is valid
 
163
                if (len(localName) == 0):
 
164
                        # Show error message
 
165
                        messagebox.show(_("Validation Error!"), _("Please enter a valid project name."))
 
166
 
 
167
                elif (localType == - 1):
 
168
                        # Show error message
 
169
                        messagebox.show(_("Validation Error!"), _("Please enter a valid project type."))
 
170
 
 
171
                else:
 
172
 
 
173
                        
 
174
                        # check if mode is 'New Project'
 
175
                        if (self.mode == "new"):
 
176
                                # Re-init / clear the current project object (to reset all exisint data)
 
177
                                self.project = project.project()
 
178
                                self.project.form = self.form
 
179
                                self.project.form.project = self.project
 
180
                        
 
181
                        # set the project properties
 
182
                        self.project.name = localName
 
183
                        self.project.project_type = localType
 
184
                        self.project.folder = localFolder
 
185
                        self.project.sequences[0].length = float(localLength) * 60  # convert to seconds
 
186
                        self.project.is_modified = True
 
187
 
 
188
                        # stop video
 
189
                        self.project.form.MyVideo.pause()
 
190
 
 
191
                        # set the profile settings in the video thread
 
192
                        self.project.form.MyVideo.set_project(self.project, self.project.form, os.path.join(self.project.USER_DIR, "westley.xml"), mode="preview")
 
193
                        self.project.form.MyVideo.set_profile(localType)
 
194
                        self.project.form.MyVideo.load_xml()
 
195
 
 
196
                        # Save the project
 
197
                        self.project.Save("%s/%s.osp" % (localFolder, localName))
 
198
 
 
199
                        # Is openshot existing?
 
200
                        if self.project.form.is_exiting:
 
201
                                self.project.form.frmMain.destroy()
 
202
 
 
203
                        # Update the main form
 
204
                        self.project.form.refresh()
 
205
 
 
206
                        # close the window
 
207
                        self.frmNewProject.destroy()
 
208
 
 
209
 
 
210
def main():
 
211
        frm_new_project = Frmnewproject()
 
212
        frm_new_project.run()
 
213
 
 
214
if __name__ == "__main__":
 
215
        main()