예제 #1
0
	def move_play_head (self, new_time):
		"""this method allows the play head to be moved to a specific spot on the timeline.  It accepts
		a parameter for the # of seconds to move the playhead to."""
		
		# move play_head to the top layer
		if self.play_head and new_time != self.play_head_position:

			self.play_head.raise_(None)
			self.play_head_line.raise_(None)
			
			# get the pixels per second from the parent sequence
			pixels_per_second = self.get_pixels_per_second()
			
			# get width of playhead
			playhead_width = self.play_head.get_bounds().x2 - self.play_head.get_bounds().x1
			min_x = (playhead_width / 2) * -1
	
			# don't allow the clip to slide past the beginning of the canvas
			total_x_diff = (new_time * pixels_per_second) - (self.play_head.get_bounds().x2 + min_x)
	
			# move clip				
			self.play_head.translate (total_x_diff, 0)
			self.play_head_line.translate (total_x_diff, 0)
			
			# print time of playhead
			milliseconds = ((self.play_head.get_bounds().x1 + (playhead_width / 2)) / pixels_per_second) * 1000
			time = timeline.timeline().get_friendly_time(milliseconds)
			frame = round((time[5] / 1000.0) * self.project.fps()) + 1
			self.ruler_time.set_property("text", "%02d:%02d:%02d:%02d" % (time[2], time[3], time[4], frame))
			#self.ruler_time.set_property("text", "%s" % (self.project.form.MyVideo.p.position()))
			
			# update playhead position
			self.play_head_position = (self.play_head.get_bounds().x1 + (playhead_width / 2)) / pixels_per_second
예제 #2
0
    def refresh(self):
        # clear the tree
        self.OSTreeFiles.store.clear()

        # Init the project files tree (with selected files)
        for item in self.selected_files:

            if isinstance(item, files.LibreShotFile):
                #format the file length field
                milliseconds = item.length * 1000
                time = timeline.timeline().get_friendly_time(milliseconds)
                time_str = "%02d:%02d:%02d" % (time[2], time[3], time[4])

                # get the thumbnail (or load default)
                pbThumb = item.get_thumbnail(51, 38)

                #find parent (if any)
                match_iter = None

                # get file name
                (dirName, fileName) = os.path.split(item.name)

                # Add row to tree
                self.OSTreeFiles.store.append(
                    match_iter,
                    [pbThumb, fileName, time_str, item.label, item.unique_id])
예제 #3
0
	def __init__(self, file, path="FileProperties.glade", root="frmFileProperties", domain="OpenShot", form=None, project=None, **kwargs):
		SimpleGladeApp.__init__(self, os.path.join(project.GLADE_DIR, path), root, domain, **kwargs)

		# Add language support
		_ = Language_Init.Translator(project).lang.gettext
		
		self.form = form
		self.project = project
		self.file = file
		
		#set the thumbnail - use the preview thumbnail
		#for video & image files
		if file.file_type != "audio":
			if file.thumb_location != "":
				pixbuf = gtk.gdk.pixbuf_new_from_file(file.thumb_location)
				pixbuf = pixbuf.scale_simple(112,83,gtk.gdk.INTERP_BILINEAR)
				self.imgPreview.set_from_pixbuf(pixbuf)
		else:
			#use the generic OpenShot audio thumbnail
			pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.join(IMAGE_DIR, "AudioThumbnail.png"))
			pixbuf = pixbuf.scale_simple(112,83,gtk.gdk.INTERP_BILINEAR)
			self.imgPreview.set_from_pixbuf(pixbuf)
		
		#set the file type	
		self.lblMimeType.set_label(file.file_type)
		
		#if the file name is too long to fit the space, add ellipses and a tooltip.
		self.lblLocation1.set_text(file.name)
		#self.lblLocation1.set_tooltip_text(file.name)
		#self.lblLocation1.set_ellipsize(pango.ELLIPSIZE_END)
		#format the file length
		milliseconds = file.length * 1000
		time = timeline.timeline().get_friendly_time(milliseconds)
	
		hours = time[2]
		mins = time[3]
		secs = time[4]
		milli = time[5]
	
		time_str =  "%02d:%02d:%02d" % (time[2], time[3], time[4])
		self.lblLengthValue.set_label(time_str)
		#project label
		self.txtLabel.set_text(file.label)
		
		if file.file_type.startswith("video"):
		#video specific properties
			self.lblRateValue.set_label(str(file.videorate[0]) + "/" + str(file.videorate[1]))
			self.lblSizeValue.set_label(str(file.width) + " x " + str(file.height))
			
		else:
			self.lblRate.set_sensitive(False)
			self.lblSize.set_sensitive(False)
		
		#show the form
		self.frmFileProperties.show_all()
예제 #4
0
    def __init__(self,
                 file,
                 path="FileProperties.ui",
                 root="frmFileProperties",
                 domain="LibreShot",
                 form=None,
                 project=None,
                 **kwargs):
        SimpleGtkBuilderApp.__init__(self, os.path.join(project.UI_DIR, path),
                                     root, domain, **kwargs)

        # Add language support
        _ = Language_Init.Translator(project).lang.gettext

        self.form = form
        self.project = project
        self.file = file

        #set the thumbnail - use the preview thumbnail
        #for video & image files
        pixbuf = file.get_thumbnail(112, 83)
        self.imgPreview.set_from_pixbuf(pixbuf)

        #set the file type
        self.lblMimeType.set_label(str(file.file_type).title())

        #if the file name is too long to fit the space, add ellipses and a tooltip.
        self.lblLocation1.set_text(file.name)
        #self.lblLocation1.set_tooltip_text(file.name)
        #self.lblLocation1.set_ellipsize(pango.ELLIPSIZE_END)
        #format the file length
        milliseconds = file.length * 1000
        time = timeline.timeline().get_friendly_time(milliseconds)

        hours = time[2]
        mins = time[3]
        secs = time[4]
        milli = time[5]

        time_str = "%02d:%02d:%02d:%03d" % (hours, mins, secs, milli)
        self.lblLengthValue.set_label(time_str)
        #project label
        self.txtLabel.set_text(file.label)

        if file.file_type in ["video", "image", "image sequence"]:
            self.lblSizeValue.set_label(
                str(file.width) + " x " + str(file.height))
        else:
            self.lblSize.set_sensitive(False)

        #show the form
        self.frmFileProperties.show_all()
예제 #5
0
    def move_play_head(self, new_time):
        """this method allows the play head to be moved to a specific spot on the timeline.  It accepts
		a parameter for the # of seconds to move the playhead to."""

        # move play_head to the top layer
        if self.play_head and new_time != self.play_head_position:

            # keep track of the current play-head position
            self.play_head_position = float(new_time)

            self.play_head.raise_(None)
            self.play_head_line.raise_(None)

            # get the pixels per second from the parent sequence
            pixels_per_second = self.get_pixels_per_second()

            # get width of playhead
            playhead_width = self.play_head.get_bounds(
            ).x2 - self.play_head.get_bounds().x1
            min_x = (playhead_width / 2) * -1

            # don't allow the clip to slide past the beginning of the canvas
            total_x_diff = (new_time * pixels_per_second) - (
                self.play_head.get_bounds().x2 + min_x)

            # animate clip (if needed)
            if self.enable_animated_playhead == True:
                self.play_head.animate(total_x_diff, 0, 1.0, 0.0, False, 100,
                                       4, goocanvas.ANIMATE_FREEZE)
                self.play_head_line.animate(total_x_diff, 0, 1.0, 0.0, False,
                                            100, 4, goocanvas.ANIMATE_FREEZE)

            # move clip
            self.play_head.translate(total_x_diff, 0)
            self.play_head_line.translate(total_x_diff, 0)

            # Get theme settings
            theme_settings = self.project.theme_settings.settings

            # print time of playhead
            milliseconds = ((self.play_head.get_bounds().x1 +
                             (playhead_width / 2)) / pixels_per_second) * 1000
            time = timeline.timeline().get_friendly_time(milliseconds)
            frame = round((time[5] / 1000.0) * self.project.fps())
            self.ruler_time.set_property(
                "text", theme_settings["timeline"]["playhead_text"]["font"] %
                (time[2], time[3], time[4], frame))
예제 #6
0
	def __init__(self, file, path="FileProperties.ui", root="frmFileProperties", domain="OpenShot", form=None, project=None, **kwargs):
		SimpleGtkBuilderApp.__init__(self, os.path.join(project.UI_DIR, path), root, domain, **kwargs)

		# Add language support
		_ = Language_Init.Translator(project).lang.gettext
		
		self.form = form
		self.project = project
		self.file = file
		
		#set the thumbnail - use the preview thumbnail
		#for video & image files
		pixbuf = file.get_thumbnail(112, 83)
		self.imgPreview.set_from_pixbuf(pixbuf)
		
		#set the file type	
		self.lblMimeType.set_label(str(file.file_type).title())
		
		#if the file name is too long to fit the space, add ellipses and a tooltip.
		self.lblLocation1.set_text(file.name)
		#self.lblLocation1.set_tooltip_text(file.name)
		#self.lblLocation1.set_ellipsize(pango.ELLIPSIZE_END)
		#format the file length
		milliseconds = file.length * 1000
		time = timeline.timeline().get_friendly_time(milliseconds)
	
		hours = time[2]
		mins = time[3]
		secs = time[4]
		milli = time[5]
		
		time_str =  "%02d:%02d:%02d:%03d" % (hours, mins, secs, milli)
		self.lblLengthValue.set_label(time_str)
		#project label
		self.txtLabel.set_text(file.label)
		
		if file.file_type in ["video", "image", "image sequence"]:
			self.lblSizeValue.set_label(str(file.width) + " x " + str(file.height))
		else:
			self.lblSize.set_sensitive(False)
		
		#show the form
		self.frmFileProperties.show_all()
예제 #7
0
	def move_play_head (self, new_time):
		"""this method allows the play head to be moved to a specific spot on the timeline.  It accepts
		a parameter for the # of seconds to move the playhead to."""

		# move play_head to the top layer
		if self.play_head and new_time != self.play_head_position:

			# keep track of the current play-head position
			self.play_head_position = float(new_time)

			self.play_head.raise_(None)
			self.play_head_line.raise_(None)

			# get the pixels per second from the parent sequence
			pixels_per_second = self.get_pixels_per_second()

			# get width of playhead
			playhead_width = self.play_head.get_bounds().x2 - self.play_head.get_bounds().x1
			min_x = (playhead_width / 2) * -1

			# don't allow the clip to slide past the beginning of the canvas
			total_x_diff = (new_time * pixels_per_second) - (self.play_head.get_bounds().x2 + min_x)

			# animate clip (if needed)
			if self.enable_animated_playhead == True:
				self.play_head.animate(total_x_diff, 0, 1.0, 0.0, False, 100, 4, goocanvas.ANIMATE_FREEZE)
				self.play_head_line.animate(total_x_diff, 0, 1.0, 0.0, False, 100, 4, goocanvas.ANIMATE_FREEZE)

			# move clip
			self.play_head.translate (total_x_diff, 0)
			self.play_head_line.translate (total_x_diff, 0)

			# Get theme settings
			theme_settings = self.project.theme_settings.settings

			# print time of playhead
			milliseconds = ((self.play_head.get_bounds().x1 + (playhead_width / 2)) / pixels_per_second) * 1000
			time = timeline.timeline().get_friendly_time(milliseconds)
			frame = round((time[5] / 1000.0) * self.project.fps())
			self.ruler_time.set_property("text", theme_settings["timeline"]["playhead_text"]["font"] % (time[2], time[3], time[4], frame))
예제 #8
0
	def refresh(self):
		# clear the tree
		self.OSTreeFiles.store.clear()
		
		# Init the project files tree (with selected files)
		for item in self.selected_files:
			
			if isinstance(item, files.OpenShotFile):
				#format the file length field
				milliseconds = item.length * 1000
				time = timeline.timeline().get_friendly_time(milliseconds)
				time_str =  "%02d:%02d:%02d" % (time[2], time[3], time[4])
	
				# get the thumbnail (or load default)
				pbThumb = item.get_thumbnail(51, 38)
				
				#find parent (if any)
				match_iter = None

				# get file name
				(dirName, fileName) = os.path.split(item.name)
				
				# Add row to tree
				self.OSTreeFiles.store.append(match_iter, [pbThumb, fileName, time_str, item.label, item.unique_id])
예제 #9
0
	def RenderRuler(self):
		"""This adds a track to the canvas with 3 images: a left, middle, and right"""
		
		# get the pixels per second from the parent sequence
		pixels_per_second = self.get_pixels_per_second()
		
		# determine position of playhead
		time = timeline.timeline().get_friendly_time(self.play_head_position * 1000) 
		
		# set the top coordinate of this track to the bottom coordinate of the last track
		x = 10	  
		y_top = 12
		
		# get a reference to the 2 main canvas objects & theme
		theme = self.project.theme
		canvas_timeline = self.project.form.MyCanvas
		canvas_left = self.project.form.TimelineCanvas_Left
		canvas_right = self.project.form.TimelineCanvas_Right
		
		# Add an item to the goocanvas
		root_left = canvas_left.get_root_item ()
		root_right = canvas_right.get_root_item ()

		# Load all 3 images
		imgTrack_Left = gtk.image_new_from_file("%s/openshot/themes/%s/ruler_left.png" % (self.project.form.openshot_path, theme))
		imgTrack_Middle = gtk.image_new_from_file("%s/openshot/themes/%s/ruler_middle.png" % (self.project.form.openshot_path, theme))
		imgTrack_Right = gtk.image_new_from_file("%s/openshot/themes/%s/ruler_right.png" % (self.project.form.openshot_path, theme))	   
		imgTrack_Tick = gtk.image_new_from_file("%s/openshot/themes/%s/ruler_tick.png" % (self.project.form.openshot_path, theme))	   

		# Get Height and Width of Images 
		imgTrack_Left_Height = imgTrack_Left.get_pixbuf().get_height()
		imgTrack_Left_Width = imgTrack_Left.get_pixbuf().get_width()
		imgTrack_Right_Width = imgTrack_Right.get_pixbuf().get_width()		

		# Get Size of Window (to determine how wide the middle image should be streched)
		Size_Of_Middle = int(pixels_per_second * self.length)
		
		# resize the canvas height and width
		canvas_right.set_bounds (0, 0, Size_Of_Middle + 200, 80)
		canvas_timeline.set_bounds (0, 0, Size_Of_Middle + 185, 5000)
		self.project.form.hscrollbar2.set_range(0, Size_Of_Middle + 200)
		self.project.form.on_hscrollbar2_value_changed(self.project.form.hscrollbar2)

		# Resize Middle pixbuf
		middlePixBuf = imgTrack_Middle.get_pixbuf()
		pixbuf_list = self.split_images(middlePixBuf, imgTrack_Left_Height, Size_Of_Middle)
		
		# Create Group (for the track)
		GroupTrack = goocanvas.Group (parent = root_right)

		# Add Left Image to Group
		image1 = goocanvas.Image (parent = root_left,
								  pixbuf = imgTrack_Left.get_pixbuf(),
								  x = x,
								  y = y_top)

		# Add Middle Image to Group (this can be multiple image tiled together
		pixbuf_x = 0
		for pixbuf in pixbuf_list:
			# get width of this pixbuf
			pixbuf_width = pixbuf.get_width()
			
			image2 = goocanvas.Image (parent = GroupTrack,
									  pixbuf = pixbuf,
									  x = pixbuf_x,
									  y = y_top)  
			
			# increment the x
			pixbuf_x = pixbuf_x + pixbuf_width


		# Add Middle Image to Group
		image3 = goocanvas.Image (parent = GroupTrack,
								  pixbuf = imgTrack_Right.get_pixbuf(),
								  x = Size_Of_Middle - 1,
								  y = y_top)

		# Add Text to the Track
		self.ruler_time = goocanvas.Text (parent = root_left,
								text = "%02d:%02d:%02d:%03d" % (time[2], time[3], time[4], time[5]),
								font = "Sans 12",
								antialias = True,
								x = x + 27,
								y = y_top + 8)
			  
		# Resize tick marks for ruler
		tickPixBuf = imgTrack_Tick.get_pixbuf()
		big_tickPixBuf = tickPixBuf.scale_simple(1, 24, gtk.gdk.INTERP_NEAREST)
		medium_tickPixBuf = tickPixBuf.scale_simple(1, 16, gtk.gdk.INTERP_NEAREST)
		small_tickPixBuf = tickPixBuf.scale_simple(1, 10, gtk.gdk.INTERP_NEAREST)

		# loop through each tick mark
		number_of_ticks = int(self.length / self.scale)
		ruler_pixels = ((float(self.length) / float(self.scale)) * self.tick_pixels)
		tick = 0
		end_of_timeline = False
		
		while end_of_timeline == False:
			
			# increment tick
			tick = tick + 1

			# get the formatted time code
			milliseconds = (tick * self.scale) * 1000
			time = timeline.timeline().get_friendly_time(milliseconds)
			
			if (tick * self.tick_pixels + 16) < ruler_pixels:

				# Add Text to the Track
				text1 = goocanvas.Text (parent = GroupTrack,
										text = "<span face='Sans' foreground='#2A5799' size='7000'>%02d:%02d:%02d:%03d</span>" % (time[2], time[3], time[4], time[5]),
										
										antialias = True,
										use_markup = True,
										x = (tick * self.tick_pixels) - 31,
										y = y_top + 3)				

				# Add BIG TICK Image to Group
				image5 = goocanvas.Image (parent = GroupTrack,
										  pixbuf = big_tickPixBuf,
										  x = (tick * self.tick_pixels),
										  y = y_top + 15)
	
			
			# determine # of minor ticks.  The longer the timeline, the less
			# ticks can be added do to performance reasons.
			number_of_minor_ticks = 6
			if (number_of_ticks * 10) > 1500:
				number_of_minor_ticks = 2
				
			# Add Minor ticks
			big_tick_x = ((tick - 1) * self.tick_pixels)
			minor_tick_increment = self.tick_pixels / number_of_minor_ticks
 
			# loop through minor ticks, and add them to the canvas
			for minor_tick in range(1, number_of_minor_ticks):

				# Resize minor tick pixbuf
				tickPixBuf = None
				minor_y_adjustment = 29
				if minor_tick == int(number_of_minor_ticks / 2):
					minor_y_adjustment = 23
					tickPixBuf = medium_tickPixBuf
				else:
					tickPixBuf = small_tickPixBuf
				
				# don't extend past the ruler
				if (big_tick_x + int(minor_tick_increment * minor_tick)) < ruler_pixels:

					# Add minor tick Image to Group
					image5 = goocanvas.Image (parent = GroupTrack,
											  pixbuf = tickPixBuf,
											  x = big_tick_x + int(minor_tick_increment * minor_tick),
											  y = y_top + minor_y_adjustment)
				else:
					end_of_timeline = True
					break

		# Connect signals to ruler to allow drag and drop
		GroupTrack.connect ("button_press_event", self.on_ruler_press)
		GroupTrack.connect ("motion_notify_event", self.on_ruler_motion)
예제 #10
0
	def RenderRuler(self):
		"""This adds a track to the canvas with 3 images: a left, middle, and right"""

		# get the pixels per second from the parent sequence
		pixels_per_second = self.get_pixels_per_second()

		# determine position of playhead
		time = timeline.timeline().get_friendly_time(self.play_head_position * 1000) 

		# Get theme settings
		theme = self.project.theme
		theme_settings = self.project.theme_settings.settings

		# set the top coordinate of this track to the bottom coordinate of the last track
		x = theme_settings["timeline"]["ruler"]["x"]	  
		y_top = theme_settings["timeline"]["ruler"]["y"]

		# determine the height of the timeline
		imgTrack_Track = gtk.image_new_from_file("%s/openshot/themes/%s/Track_Middle.png" % (self.project.form.openshot_path, theme))
		imgTrack_Track_Height = imgTrack_Track.get_pixbuf().get_height()
		timeline_heigth = len(self.tracks) * imgTrack_Track_Height + (len(self.tracks) * theme_settings["track"]["padding"]) + 10

		# get a reference to the 2 main canvas objects & theme
		theme = self.project.theme
		canvas_timeline = self.project.form.MyCanvas
		canvas_timeline_left = self.project.form.MyCanvas_Left
		canvas_left = self.project.form.TimelineCanvas_Left
		canvas_right = self.project.form.TimelineCanvas_Right

		# Add an item to the goocanvas
		root_left = canvas_left.get_root_item ()
		root_right = canvas_right.get_root_item ()

		# Load all 3 images
		imgTrack_Left = gtk.image_new_from_file("%s/openshot/themes/%s/ruler_left.png" % (self.project.form.openshot_path, theme))
		imgTrack_Middle = gtk.image_new_from_file("%s/openshot/themes/%s/ruler_middle.png" % (self.project.form.openshot_path, theme))
		imgTrack_Right = gtk.image_new_from_file("%s/openshot/themes/%s/ruler_right.png" % (self.project.form.openshot_path, theme))	   
		imgTrack_Tick = gtk.image_new_from_file("%s/openshot/themes/%s/ruler_tick.png" % (self.project.form.openshot_path, theme))	   

		# Get Height and Width of Images 
		imgTrack_Left_Height = imgTrack_Left.get_pixbuf().get_height()
		imgTrack_Left_Width = imgTrack_Left.get_pixbuf().get_width()
		imgTrack_Right_Width = imgTrack_Right.get_pixbuf().get_width()		

		# Get Size of Window (to determine how wide the middle image should be streched)
		Size_Of_Middle = int(pixels_per_second * self.length)

		# resize the canvas height and width
		new_size_of_middle = Size_Of_Middle + 200
		
		canvas_timeline.set_bounds (0, 0, new_size_of_middle, timeline_heigth)
		#1.02 is a fudge factor to make up for rounding errors
		#without this, the scrollbar range will be just a little smaller than the
		#size of the canvas_timeline and you wouldn't be able to scroll all the way to the end		
		#I don't know why this changed from 1.4.3 to 1.4.4 - in 1.4.3 I didn't need to do this.
		#My best guess is that the length is calculated differently than in 1.4.3
		self.project.form.hscrollbar2.set_range(0, new_size_of_middle*1.02)
		self.project.form.vscrollbar2.set_range(0, timeline_heigth)
		self.project.form.on_hscrollbar2_value_changed(self.project.form.hscrollbar2)

		# Get the height of the RULER
		ruler_height = theme_settings["timeline"]["ruler"]["height"]
		left_canvas_width = theme_settings["track"]["track_name_text"]["w"]

		# Resize the LEFT RULER
		canvas_timeline_left.set_bounds (0, 0, left_canvas_width, timeline_heigth)
		canvas_left.set_bounds (0, 0, left_canvas_width, ruler_height)
		canvas_left.set_size_request (0, ruler_height)
		self.project.form.timelineWindowLeft.set_size_request (left_canvas_width, ruler_height)
		self.project.form.scrolledwindow_Left.set_size_request (left_canvas_width, 0)

		# Resize the RIGHT RULER
		canvas_right.set_bounds (0, 0, new_size_of_middle + 16, ruler_height)
		canvas_right.set_size_request (0, ruler_height)
		self.project.form.timelinewindowRight.set_size_request (0, ruler_height)

		# Resize RULER Hbox (which holds both the LEFT and RIGHT windows)
		self.project.form.hbox5.set_size_request (0, ruler_height)

		# Resize Middle pixbuf
		middlePixBuf = imgTrack_Middle.get_pixbuf()
		pixbuf_list = self.split_images(middlePixBuf, imgTrack_Left_Height, Size_Of_Middle)

		# Create Group (for the track)
		GroupTrack = goocanvas.Group (parent = root_right)

		# Add Left Image to Group
		image1 = goocanvas.Image (parent = root_left,
				                  pixbuf = imgTrack_Left.get_pixbuf(),
				                  x = x,
				                  y = y_top)

		# Add Middle Image to Group (this can be multiple image tiled together
		pixbuf_x = 0
		for pixbuf in pixbuf_list:
			# get width of this pixbuf
			pixbuf_width = pixbuf.get_width()

			image2 = goocanvas.Image (parent = GroupTrack,
						              pixbuf = pixbuf,
						              x = pixbuf_x,
						              y = y_top)  

			# increment the x
			pixbuf_x = pixbuf_x + pixbuf_width


		# Add Middle Image to Group
		image3 = goocanvas.Image (parent = GroupTrack,
				                  pixbuf = imgTrack_Right.get_pixbuf(),
				                  x = Size_Of_Middle - 1,
				                  y = y_top)

		# Add Playhead position text
		self.ruler_time = goocanvas.Text (parent = root_left,
				                          text = theme_settings["timeline"]["playhead_text"]["font"] % (time[2], time[3], time[4], time[5]),
				                          antialias = True,
				                          use_markup = True,
				                          x = x + theme_settings["timeline"]["playhead_text"]["x"],
				                          y = y_top + theme_settings["timeline"]["playhead_text"]["y"])

		# Resize tick marks for ruler
		tickPixBuf = imgTrack_Tick.get_pixbuf()
		big_tickPixBuf = tickPixBuf.scale_simple(1, theme_settings["timeline"]["ruler"]["large_tick"]["h"], gtk.gdk.INTERP_NEAREST)
		medium_tickPixBuf = tickPixBuf.scale_simple(1, theme_settings["timeline"]["ruler"]["medium_tick"]["h"], gtk.gdk.INTERP_NEAREST)
		small_tickPixBuf = tickPixBuf.scale_simple(1, theme_settings["timeline"]["ruler"]["small_tick"]["h"], gtk.gdk.INTERP_NEAREST)

		# loop through each tick mark
		number_of_ticks = int(self.length / self.scale)
		ruler_pixels = ((float(self.length) / float(self.scale)) * self.tick_pixels)
		
		tick = 0
		end_of_timeline = False

		while end_of_timeline == False:

			# increment tick
			tick = tick + 1

			# get the formatted time code
			milliseconds = (tick * self.scale) * 1000
			time = timeline.timeline().get_friendly_time(milliseconds)

			if (tick * self.tick_pixels + 16) < ruler_pixels:

				# Add Text to the Track
				text1 = goocanvas.Text (parent = GroupTrack,
								        text = theme_settings["timeline"]["ruler"]["time_text"]["font"] % (time[2], time[3], time[4], time[5]),
								        antialias = True,
								        use_markup = True,
								        x = (tick * self.tick_pixels) - theme_settings["timeline"]["ruler"]["time_text"]["x"],
								        y = y_top + theme_settings["timeline"]["ruler"]["time_text"]["y"])				

				# Add BIG TICK Image to Group
				image5 = goocanvas.Image (parent = GroupTrack,
								          pixbuf = big_tickPixBuf,
								          x = (tick * self.tick_pixels),
								          y = y_top + theme_settings["timeline"]["ruler"]["large_tick"]["y"])


			# determine # of minor ticks.  The longer the timeline, the less
			# ticks can be added do to performance reasons.
			number_of_minor_ticks = 6
			if (number_of_ticks * 10) > 1500:
				number_of_minor_ticks = 2

			# Add Minor ticks
			big_tick_x = ((tick - 1) * self.tick_pixels)
			minor_tick_increment = self.tick_pixels / number_of_minor_ticks

			# loop through minor ticks, and add them to the canvas
			for minor_tick in range(1, number_of_minor_ticks):

				# Resize minor tick pixbuf
				tickPixBuf = None
				minor_y_adjustment = theme_settings["timeline"]["ruler"]["small_tick"]["y"]
				if minor_tick == int(number_of_minor_ticks / 2):
					minor_y_adjustment = theme_settings["timeline"]["ruler"]["medium_tick"]["y"]
					tickPixBuf = medium_tickPixBuf
				else:
					tickPixBuf = small_tickPixBuf

				# don't extend past the ruler
				if (big_tick_x + int(minor_tick_increment * minor_tick)) < ruler_pixels:

					# Add minor tick Image to Group
					image5 = goocanvas.Image (parent = GroupTrack,
										      pixbuf = tickPixBuf,
										      x = big_tick_x + int(minor_tick_increment * minor_tick),
										      y = y_top + minor_y_adjustment)
				else:
					end_of_timeline = True
					break

		# Connect signals to ruler to allow drag and drop
		GroupTrack.connect ("button_press_event", self.on_ruler_press)
		GroupTrack.connect ("motion_notify_event", self.on_ruler_motion)
		GroupTrack.connect ("button_release_event", self.on_ruler_release)
예제 #11
0
    def RenderRuler(self):
        """This adds a track to the canvas with 3 images: a left, middle, and right"""

        # get the pixels per second from the parent sequence
        pixels_per_second = self.get_pixels_per_second()

        # determine position of playhead
        time = timeline.timeline().get_friendly_time(self.play_head_position *
                                                     1000)

        # Get theme settings
        theme = self.project.theme
        theme_settings = self.project.theme_settings.settings

        # set the top coordinate of this track to the bottom coordinate of the last track
        x = theme_settings["timeline"]["ruler"]["x"]
        y_top = theme_settings["timeline"]["ruler"]["y"]

        # determine the height of the timeline
        imgTrack_Track = gtk.image_new_from_file(
            "%s/libreshot/themes/%s/Track_Middle.png" %
            (self.project.form.libreshot_path, theme))
        imgTrack_Track_Height = imgTrack_Track.get_pixbuf().get_height()
        timeline_heigth = len(self.tracks) * imgTrack_Track_Height + (
            len(self.tracks) * theme_settings["track"]["padding"]) + 10

        # get a reference to the 2 main canvas objects & theme
        theme = self.project.theme
        canvas_timeline = self.project.form.MyCanvas
        canvas_timeline_left = self.project.form.MyCanvas_Left
        canvas_left = self.project.form.TimelineCanvas_Left
        canvas_right = self.project.form.TimelineCanvas_Right

        # Add an item to the goocanvas
        root_left = canvas_left.get_root_item()
        root_right = canvas_right.get_root_item()

        # Load all 3 images
        imgTrack_Left = gtk.image_new_from_file(
            "%s/libreshot/themes/%s/ruler_left.png" %
            (self.project.form.libreshot_path, theme))
        imgTrack_Middle = gtk.image_new_from_file(
            "%s/libreshot/themes/%s/ruler_middle.png" %
            (self.project.form.libreshot_path, theme))
        imgTrack_Right = gtk.image_new_from_file(
            "%s/libreshot/themes/%s/ruler_right.png" %
            (self.project.form.libreshot_path, theme))
        imgTrack_Tick = gtk.image_new_from_file(
            "%s/libreshot/themes/%s/ruler_tick.png" %
            (self.project.form.libreshot_path, theme))

        # Get Height and Width of Images
        imgTrack_Left_Height = imgTrack_Left.get_pixbuf().get_height()
        imgTrack_Left_Width = imgTrack_Left.get_pixbuf().get_width()
        imgTrack_Right_Width = imgTrack_Right.get_pixbuf().get_width()

        # Get Size of Window (to determine how wide the middle image should be streched)
        Size_Of_Middle = int(pixels_per_second * self.length)

        # resize the canvas height and width
        new_size_of_middle = Size_Of_Middle + 200

        canvas_timeline.set_bounds(0, 0, new_size_of_middle, timeline_heigth)
        #1.02 is a fudge factor to make up for rounding errors
        #without this, the scrollbar range will be just a little smaller than the
        #size of the canvas_timeline and you wouldn't be able to scroll all the way to the end
        #I don't know why this changed from 1.4.3 to 1.4.4 - in 1.4.3 I didn't need to do this.
        #My best guess is that the length is calculated differently than in 1.4.3
        self.project.form.hscrollbar2.set_range(0, new_size_of_middle * 1.02)
        self.project.form.vscrollbar2.set_range(0, timeline_heigth)
        self.project.form.on_hscrollbar2_value_changed(
            self.project.form.hscrollbar2)

        # Get the height of the RULER
        ruler_height = theme_settings["timeline"]["ruler"]["height"]
        left_canvas_width = theme_settings["track"]["track_name_text"]["w"]

        # Resize the LEFT RULER
        canvas_timeline_left.set_bounds(0, 0, left_canvas_width,
                                        timeline_heigth)
        canvas_left.set_bounds(0, 0, left_canvas_width, ruler_height)
        canvas_left.set_size_request(0, ruler_height)
        self.project.form.timelineWindowLeft.set_size_request(
            left_canvas_width, ruler_height)
        self.project.form.scrolledwindow_Left.set_size_request(
            left_canvas_width, 0)

        # Resize the RIGHT RULER
        canvas_right.set_bounds(0, 0, new_size_of_middle + 16, ruler_height)
        canvas_right.set_size_request(0, ruler_height)
        self.project.form.timelinewindowRight.set_size_request(0, ruler_height)

        # Resize RULER Hbox (which holds both the LEFT and RIGHT windows)
        self.project.form.hbox5.set_size_request(0, ruler_height)

        # Resize Middle pixbuf
        middlePixBuf = imgTrack_Middle.get_pixbuf()
        pixbuf_list = self.split_images(middlePixBuf, imgTrack_Left_Height,
                                        Size_Of_Middle)

        # Create Group (for the track)
        GroupTrack = goocanvas.Group(parent=root_right)

        # Add Left Image to Group
        image1 = goocanvas.Image(parent=root_left,
                                 pixbuf=imgTrack_Left.get_pixbuf(),
                                 x=x,
                                 y=y_top)

        # Add Middle Image to Group (this can be multiple image tiled together
        pixbuf_x = 0
        for pixbuf in pixbuf_list:
            # get width of this pixbuf
            pixbuf_width = pixbuf.get_width()

            image2 = goocanvas.Image(parent=GroupTrack,
                                     pixbuf=pixbuf,
                                     x=pixbuf_x,
                                     y=y_top)

            # increment the x
            pixbuf_x = pixbuf_x + pixbuf_width

        # Add Middle Image to Group
        image3 = goocanvas.Image(parent=GroupTrack,
                                 pixbuf=imgTrack_Right.get_pixbuf(),
                                 x=Size_Of_Middle - 1,
                                 y=y_top)

        # Add Playhead position text
        self.ruler_time = goocanvas.Text(
            parent=root_left,
            text=theme_settings["timeline"]["playhead_text"]["font"] %
            (time[2], time[3], time[4], time[5]),
            antialias=True,
            use_markup=True,
            x=x + theme_settings["timeline"]["playhead_text"]["x"],
            y=y_top + theme_settings["timeline"]["playhead_text"]["y"])

        # Resize tick marks for ruler
        tickPixBuf = imgTrack_Tick.get_pixbuf()
        big_tickPixBuf = tickPixBuf.scale_simple(
            1, theme_settings["timeline"]["ruler"]["large_tick"]["h"],
            gtk.gdk.INTERP_NEAREST)
        medium_tickPixBuf = tickPixBuf.scale_simple(
            1, theme_settings["timeline"]["ruler"]["medium_tick"]["h"],
            gtk.gdk.INTERP_NEAREST)
        small_tickPixBuf = tickPixBuf.scale_simple(
            1, theme_settings["timeline"]["ruler"]["small_tick"]["h"],
            gtk.gdk.INTERP_NEAREST)

        # loop through each tick mark
        number_of_ticks = int(self.length / self.scale)
        ruler_pixels = ((float(self.length) / float(self.scale)) *
                        self.tick_pixels)

        tick = 0
        end_of_timeline = False

        while end_of_timeline == False:

            # increment tick
            tick = tick + 1

            # get the formatted time code
            milliseconds = (tick * self.scale) * 1000
            time = timeline.timeline().get_friendly_time(milliseconds)

            if (tick * self.tick_pixels + 16) < ruler_pixels:

                # Add Text to the Track
                text1 = goocanvas.Text(
                    parent=GroupTrack,
                    text=theme_settings["timeline"]["ruler"]["time_text"]
                    ["font"] % (time[2], time[3], time[4], time[5]),
                    antialias=True,
                    use_markup=True,
                    x=(tick * self.tick_pixels) -
                    theme_settings["timeline"]["ruler"]["time_text"]["x"],
                    y=y_top +
                    theme_settings["timeline"]["ruler"]["time_text"]["y"])

                # Add BIG TICK Image to Group
                image5 = goocanvas.Image(
                    parent=GroupTrack,
                    pixbuf=big_tickPixBuf,
                    x=(tick * self.tick_pixels),
                    y=y_top +
                    theme_settings["timeline"]["ruler"]["large_tick"]["y"])

            # determine # of minor ticks.  The longer the timeline, the less
            # ticks can be added do to performance reasons.
            number_of_minor_ticks = 6
            if (number_of_ticks * 10) > 1500:
                number_of_minor_ticks = 2

            # Add Minor ticks
            big_tick_x = ((tick - 1) * self.tick_pixels)
            minor_tick_increment = self.tick_pixels / number_of_minor_ticks

            # loop through minor ticks, and add them to the canvas
            for minor_tick in range(1, number_of_minor_ticks):

                # Resize minor tick pixbuf
                tickPixBuf = None
                minor_y_adjustment = theme_settings["timeline"]["ruler"][
                    "small_tick"]["y"]
                if minor_tick == int(number_of_minor_ticks / 2):
                    minor_y_adjustment = theme_settings["timeline"]["ruler"][
                        "medium_tick"]["y"]
                    tickPixBuf = medium_tickPixBuf
                else:
                    tickPixBuf = small_tickPixBuf

                # don't extend past the ruler
                if (big_tick_x +
                        int(minor_tick_increment * minor_tick)) < ruler_pixels:

                    # Add minor tick Image to Group
                    image5 = goocanvas.Image(
                        parent=GroupTrack,
                        pixbuf=tickPixBuf,
                        x=big_tick_x + int(minor_tick_increment * minor_tick),
                        y=y_top + minor_y_adjustment)
                else:
                    end_of_timeline = True
                    break

        # Connect signals to ruler to allow drag and drop
        GroupTrack.connect("button_press_event", self.on_ruler_press)
        GroupTrack.connect("motion_notify_event", self.on_ruler_motion)
        GroupTrack.connect("button_release_event", self.on_ruler_release)