mainwindow.py 6.06 KB
Newer Older
Edward Hervey's avatar
Edward Hervey committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
# PiTiVi , Non-linear video editor
#
#       ui/mainwindow.py
#
# Copyright (c) 2005, Edward Hervey <bilboed@bilboed.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

import os
import gobject
import gtk

from timeline import TimelineWidget
from sourcefactories import SourceFactoriesWidget
from viewer import PitiviViewer
29
from projectsettings import ProjectSettingsDialog
Edward Hervey's avatar
Edward Hervey committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

PITIVI_VERSION = "0.1.9"

class PitiviMainWindow(gtk.Window):
    """
    Pitivi's main window
    """

    def __init__(self, pitivi):
        """ initialize with the Pitivi object """
        self.pitivi = pitivi
        gtk.Window.__init__(self)
        self._set_actions()
        self._create_gui()
        self.pitivi.connect("new-project", self._new_project_cb)
        self.pitivi.connect("closing-project", self._closing_project_cb)
        self.pitivi.connect("not-project", self._not_project_cb)
        self.show_all()

    def destroy(self, widget, data=None):
        gtk.main_quit()

    def _set_actions(self):
        """ sets up the GtkActions """
        self.actions = [("NewProject", gtk.STOCK_NEW, "_New Project", None, "Create a new project", self.new_project_cb),
                        ("OpenProject", gtk.STOCK_OPEN, "_Open Project", None, "Opens an existing project", self.open_project_cb),
                        ("SaveProject", gtk.STOCK_SAVE, "_Save Project", None, "Save the current project", self.save_project_cb),
                        ("SaveProjectAs", gtk.STOCK_SAVE_AS, "Save Project As...", None, "Save the current project", self.save_project_as_cb),
58
                        ("ProjectSettings", gtk.STOCK_PROPERTIES, "Project Settings", None, "Edit the project settings", self.project_settings_cb),
Edward Hervey's avatar
Edward Hervey committed
59 60 61 62 63 64
                        ("Quit", gtk.STOCK_QUIT, "_Quit PiTiVi", None, "Quit PiTiVi", self.quit_cb),
                        ("About", gtk.STOCK_ABOUT, "About PiTiVi", None, "Information about PiTiVi", self.about_cb),
                        ("File", None, "_File"),
                        ("Help", None, "_Help")]
        self.actiongroup = gtk.ActionGroup("mainwindow")
        self.actiongroup.add_actions (self.actions)
65 66
        # deactivating non-functional actions
        for action in self.actiongroup.list_actions():
67
            if action.get_name() in ["ProjectSettings", "Quit", "File", "Help", "About"]:
68 69 70
                action.set_sensitive(True)
            else:
                action.set_sensitive(False)
Edward Hervey's avatar
Edward Hervey committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
        self.uimanager = gtk.UIManager()
        self.add_accel_group(self.uimanager.get_accel_group())
        self.uimanager.insert_action_group(self.actiongroup, 0)
        self.uimanager.add_ui_from_file(os.path.join(os.path.dirname(os.path.abspath(__file__)), "actions.xml"))

    def _create_gui(self):
        """ Create the graphical interface """
        self.set_title("PiTiVi v%s" % PITIVI_VERSION)
        self.set_geometry_hints(min_width=400, min_height=300)

        self.connect("destroy", self.destroy)

        vbox = gtk.VBox(False, 5)
        self.add(vbox)

        self.menu = self.uimanager.get_widget("/MainMenuBar")
        vbox.pack_start(self.menu, expand=False)

        self.toolbar = self.uimanager.get_widget("/MainToolBar")
        self.toolbar.set_style(gtk.TOOLBAR_ICONS)
        vbox.pack_start(self.toolbar, expand=False)
        
        vpaned = gtk.VPaned()
        vbox.pack_start(vpaned)
        
        self.timeline = TimelineWidget(self.pitivi)
        timelineframe = gtk.Frame()
        timelineframe.add(self.timeline)
        vpaned.pack2(timelineframe, resize=False, shrink=False)
        
        hpaned = gtk.HPaned()
        vpaned.pack1(hpaned, resize=True, shrink=False)

        # source-and-effects list
        self.sourcefactories = SourceFactoriesWidget(self.pitivi)

        # Viewer
        self.viewer = PitiviViewer(self.pitivi)
        viewerframe = gtk.Frame()
        viewerframe.add(self.viewer)

        hpaned.pack1(self.sourcefactories, resize=True, shrink=False)
        hpaned.pack2(viewerframe, resize=False, shrink=False)

    def new_project_cb(self, action):
        print "new project"
        self.pitivi.new_blank_project()

    def open_project_cb(self, action):
        print "open project"

    def save_project_cb(self, action):
        print "save project"

    def save_project_as_cb(self, action):
        print "save project as"

128 129 130 131 132
    def project_settings_cb(self, action):
        print "project settings"
        l = ProjectSettingsDialog(self, self.pitivi.current)
        l.show()

Edward Hervey's avatar
Edward Hervey committed
133 134 135 136 137 138
    def quit_cb(self, action):
        print "quit"
        gtk.main_quit()

    def about_cb(self, action):
        print "About..."
139 140 141 142 143 144 145 146
	abt = gtk.AboutDialog()
	abt.set_name("PiTiVi")
	abt.set_version("v%s" % PITIVI_VERSION)
	abt.set_website("http://www.pitivi.org/")
	authors = ["Edward Hervey" ]
	abt.set_authors(authors)
	abt.set_license("GNU Lesser Public License\nSee http://www.gnu.org/copyleft/lesser.html for more details")
	abt.show()
Edward Hervey's avatar
Edward Hervey committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

    def _new_project_cb(self, pitivi, project):
        print "Starting up a new project", project

    def _closing_project_cb(self, pitivi, project):
        print "Project", project, "is being closed"
        # Return True if we accept the project being close
        # if we want to save it before it being closed, we must
        #   do so

        # For the time being we always accept it being closed
        return True

    def _not_project_cb(self, pitivi, uri):
        print uri, "is not a project file !"

        
gobject.type_register(PitiviMainWindow)