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/>.
21
from classes import messagebox, profiles, project
22
from windows.SimpleGladeApp import SimpleGladeApp
24
# init the foreign language
25
from language import Language_Init
28
# This form is used to create new projects and save
30
class frmNewProject(SimpleGladeApp):
32
def __init__(self, mode="", path="NewProject.glade", root="frmNewProject", domain="OpenShot", project=None, **kwargs):
34
SimpleGladeApp.__init__(self, os.path.join(project.GLADE_DIR, path), root, domain, **kwargs)
36
# Add language support
37
_ = Language_Init.Translator(project).lang.gettext
40
self.project = project
41
self.form = project.form
43
# check the mode of the form (i.e. new project or save as screen)
46
# init the project type properties
47
self.init_properties()
49
# init the list of possible project types / profiles
50
self.profile_list = profiles.mlt_profiles(self.project).get_profile_list()
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())
58
# get the model and iterator of the project type dropdown box
59
model = self.cmbProjectType.get_model()
60
iter = model.get_iter_first()
62
# get the value of each item in the dropdown
63
value = model.get_value(iter, 0)
65
# check for the matching project type
66
if self.project.project_type == value:
68
# set the item as active
69
self.cmbProjectType.set_active_iter(iter)
71
# get the next item in the list
72
iter = model.iter_next(iter)
74
# break loop when no more dropdown items are found
79
if (self.mode == "saveas"):
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))
85
#if the video folder exists, default to this
86
#video_dir = os.path.join(os.path.expanduser("~"), "Video")
88
# self.frmAddFiles.set_current_folder(video_dir)
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"))
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)
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)
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()))
112
self.lblProgressiveValue.set_text("Yes")
114
self.lblProgressiveValue.set_text("No")
118
print "A new %s has been created" % self.__class__.__name__
121
def on_frmNewProject_close(self, widget, *args):
122
print "on_frmNewProject_close called with self.%s" % widget.get_name()
126
def on_frmNewProject_destroy(self, widget, *args):
127
print "on_frmNewProject_destroy called with self.%s" % widget.get_name()
129
# Is openshot existing?
130
if self.project.form.is_exiting:
131
self.project.form.frmMain.destroy()
134
def on_frmNewProject_response(self, widget, *args):
135
print "on_frmNewProject_response called with self.%s" % widget.get_name()
138
#def on_fileProjectFolder_selection_changed(self, widget, *args):
139
# print "on_fileProjectFolder_selection_changed called with self.%s" % widget.get_name()
142
def on_cmbProjectType_changed(self, widget, *args):
143
print "on_cmbProjectType_changed called with self.%s" % widget.get_name()
145
# init the project type properties
146
self.init_properties()
148
def on_btnCancel_clicked(self, widget, *args):
149
print "on_btnCancel_clicked called with self.%s" % widget.get_name()
152
self.frmNewProject.destroy()
154
def on_btnCreateProject_clicked(self, widget, *args):
155
print "on_btnCreateProject_clicked called with self.%s" % widget.get_name()
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())
162
# Validate the the form is valid
163
if (len(localName) == 0):
165
messagebox.show(_("Validation Error!"), _("Please enter a valid project name."))
167
elif (localType == - 1):
169
messagebox.show(_("Validation Error!"), _("Please enter a valid project type."))
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
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
189
self.project.form.MyVideo.pause()
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()
197
self.project.Save("%s/%s.osp" % (localFolder, localName))
199
# Is openshot existing?
200
if self.project.form.is_exiting:
201
self.project.form.frmMain.destroy()
203
# Update the main form
204
self.project.form.refresh()
207
self.frmNewProject.destroy()
211
frm_new_project = Frmnewproject()
212
frm_new_project.run()
214
if __name__ == "__main__":