1
# OpenShot Video Editor is a program that creates, modifies, and edits video files.
2
# Copyright (C) 2009 Jonathan Thomas
4
# This file is part of OpenShot Video Editor (http://launchpad.net/openshot/).
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.
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.
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/>.
19
import classes.project as project
20
import classes.messagebox as messagebox
21
import classes.profiles as profiles
23
from SimpleGladeApp import SimpleGladeApp
26
from windows.MainGTK import *
28
# init the foriegn language
29
import language.Language_Init as Language_Init
31
# This form is used to create new projects and save
33
class frmNewProject(SimpleGladeApp):
35
def __init__(self, mode="", path="NewProject.glade", root="frmNewProject", domain="OpenShot", project=None, **kwargs):
37
SimpleGladeApp.__init__(self, os.path.join("windows/glade", path), root, domain, **kwargs)
39
# Add language support
40
_ = Language_Init.Translator().lang.gettext
43
self.project = project
44
self.form = project.form
46
# check the mode of the form (i.e. new project or save as screen)
49
# init the project type properties
50
self.init_properties()
52
# init the list of possible project types / profiles
53
self.profile_list = profiles.mlt_profiles().get_profile_list()
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())
61
# get the model and iterator of the project type dropdown box
62
model = self.cmbProjectType.get_model()
63
iter = model.get_iter_first()
65
# get the value of each item in the dropdown
66
value = model.get_value(iter, 0)
68
# check for the matching project type
69
if self.project.project_type == value:
71
# set the item as active
72
self.cmbProjectType.set_active_iter(iter)
74
# get the next item in the list
75
iter = model.iter_next(iter)
77
# break loop when no more dropdown items are found
82
if (self.mode == "saveas"):
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))
88
#if the video folder exists, default to this
89
#video_dir = os.path.join(os.path.expanduser("~"), "Video")
91
# self.frmAddFiles.set_current_folder(video_dir)
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"))
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)
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)
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()))
115
self.lblProgressiveValue.set_text("Yes")
117
self.lblProgressiveValue.set_text("No")
121
print "A new %s has been created" % self.__class__.__name__
124
def on_frmNewProject_close(self, widget, *args):
125
print "on_frmNewProject_close called with self.%s" % widget.get_name()
129
def on_frmNewProject_destroy(self, widget, *args):
130
print "on_frmNewProject_destroy called with self.%s" % widget.get_name()
132
# Is openshot existing?
133
if self.project.form.is_exiting:
134
self.project.form.frmMain.destroy()
137
def on_frmNewProject_response(self, widget, *args):
138
print "on_frmNewProject_response called with self.%s" % widget.get_name()
141
#def on_fileProjectFolder_selection_changed(self, widget, *args):
142
# print "on_fileProjectFolder_selection_changed called with self.%s" % widget.get_name()
145
def on_cmbProjectType_changed(self, widget, *args):
146
print "on_cmbProjectType_changed called with self.%s" % widget.get_name()
148
# init the project type properties
149
self.init_properties()
151
def on_btnCancel_clicked(self, widget, *args):
152
print "on_btnCancel_clicked called with self.%s" % widget.get_name()
155
self.frmNewProject.destroy()
157
def on_btnCreateProject_clicked(self, widget, *args):
158
print "on_btnCreateProject_clicked called with self.%s" % widget.get_name()
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())
165
# Validate the the form is valid
166
if (len(localName) == 0):
168
messagebox.show(_("Validation Error!"), _("Please enter a valid project name."))
170
elif (localType == - 1):
172
messagebox.show(_("Validation Error!"), _("Please enter a valid project type."))
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
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
192
self.project.form.MyVideo.pause()
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()
200
self.project.Save("%s/%s.osp" % (localFolder, localName))
202
# Is openshot existing?
203
if self.project.form.is_exiting:
204
self.project.form.frmMain.destroy()
206
# Update the main form
207
self.project.form.refresh()
210
self.frmNewProject.destroy()
214
frm_new_project = Frmnewproject()
215
frm_new_project.run()
217
if __name__ == "__main__":