~openshot.code/openshot/main

« back to all changes in this revision

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