Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sidebar.py
blob: 8fb739a2047ae2a1b0fd0e635c239b24c0461153 (plain)
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
29
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
58
59
60
61
62
63
64
65
66
67
68
69
70
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# -*- mode:python; tab-width:4; indent-tabs-mode:t;  -*-

# sidebar.py
#
# Class to handle thumbnail views of the slide on the side of the main viewer
# 
# W.Burnside <wburnsid@u.washington.edu>
# B. Mayton <bmayton@cs.washington.edu>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import pygtk
import gtk
import slideshow
import slideviewer
import os
import logging
import gobject

from sugar.graphics import style

class SideBar(gtk.Notebook):
	
	def __init__(self, deck, renderer):
		gtk.Notebook.__init__(self)
		self.__logger = logging.getLogger('SideBar')
		self.__deck = deck
		self.__renderer = renderer	
		self.__is_instr = True	
		
		self.set_show_border(False)
		self.set_show_tabs(True)
		#self.show_tabs = True
		#self.show_border = True

        self.slide_context_menu = gtk.Menu()    # Don't need to show menus

        # Create the menu items
        move_item = gtk.ImageMenuItem('Move')
        img = gtk.Image()
        img.set_from_file('icons/Icon-move.svg')
        move_item.set_image(img)
        move_item.connect("activate", self.moveslide)

        remove_item = gtk.ImageMenuItem('remove')
        img = gtk.Image()
        img.set_from_file('icons/Icon-remove.svg')
        remove_item.set_image(img)
        remove_item.connect("activate", self.removeslide)

        # Add them to the menu
        self.slide_context_menu.append(move_item)
        self.slide_context_menu.append(remove_item)

        # We do need to show menu items
        move_item.show()
        remove_item.show()

		# Create scrolled window for viewing thumbs or subs
		# Scrollbar: horizontal if necessary; vertical always
		self.__viewing_box = gtk.ScrolledWindow()
		self.__viewing_box.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
		slide_label = gtk.Label("Slides")
		event_box = gtk.EventBox()
		event_box.add(self.__viewing_box)
		
		self.append_page(event_box, slide_label)
		#self.append_page(self.__viewing_box, sub_label)
				
		self.__sublist_store = gtk.ListStore(str, int)
		self.__sub_col = gtk.TreeViewColumn("Versions of this slide:")
		self.__sublist = gtk.TreeView(self.__sublist_store)
		self.__sublist.append_column(self.__sub_col)
		self.__sublist_cell = gtk.CellRendererText()
		self.__sub_col.pack_start(self.__sublist_cell, True)
		self.__sub_col.add_attribute(self.__sublist_cell, 'text', 0)
		
		sub_label = gtk.Label("Submissions")
		self.append_page(self.__sublist, sub_label)
		
		#self.__sublist_store.append(["My Ink", -1])
		
		self.load_thumbs()
		
		# show widgets
		self.show_all()
		
		self.__deck.connect('deck-changed', self.load_thumbs)
		self.__deck.connect('update-submissions', self.load_subs)
		self.__sublist.get_selection().connect('changed', self.sub_sel_changed)
		
	def load_subs(self, widget=None, def_sub=-1):
		self.__logger.debug("Loading submission list")
		self.__sublist_store.clear()
		sublist = self.__deck.getSubmissionList()
		self.__sublist_store.append(["My Ink", -1])
		i = 0
		for submission in sublist:
			self.__sublist_store.append([str(submission) + "'s Ink", i])
			i = i + 1
		self.__sublist.get_selection().select_path(def_sub+1)
		
	def sub_sel_changed(self, widget=None):
		(model, itera) = widget.get_selected()
		if itera:
			newindex = model.get_value(itera, 1)
			self.__logger.debug("Submission selection changed to "+ str(newindex))
			self.__deck.setActiveSubmission(newindex)

	# Method to load slides into Scrolling side window
	# The method uses a table to organize the slides
	def load_thumbs(self, widget=None):
		for c in self.__viewing_box.get_children():
			self.__viewing_box.remove(c)

		# create image table for thumbnails
		self.image_table = gtk.Table(self.__deck.getSlideCount(), 1, False)

		# Loop to show slides
		for i in range(self.__deck.getSlideCount()):		
			# Create event box for table entry
			event_box = gtk.EventBox()
			event_box.set_size_request(209, 160)

			# Add navigation to event boxes
			event_box.set_above_child(True)
			event_box.connect('button_press_event', self.change_slide, i)

			# Create viewer for slide and add to box
			slide = slideviewer.ThumbViewer(self.__deck, self.__renderer, i)
			event_box.add(slide)

			# Put box in table and show 
			self.image_table.attach(event_box, 0, 1, i, i+1)
			event_box.show()			

			# Show each slide
			slide.show()

		# show images
		self.__viewing_box.add_with_viewport(self.image_table)
		self.image_table.show()
        self.movemode=False


	def change_slide(self, widget, event, n):
        if event.button == 3:
            self.selected_slide = n
	        self.slide_context_menu.popup( None, None, None, event.button, event.time)
        elif self.movemode:
            self.movemode=False
            self.__deck.moveSlide(self.moved_slide, n)
            self.__deck.save()
            self.__deck.reload()
        else:
		    self.__deck.goToIndex(n, is_local=True)

    def moveslide(self, params):
            self.movemode=True
            self.moved_slide = self.selected_slide

    def removeslide(self, params):
            self.__deck.removeSlide(self.selected_slide)
            self.__deck.save()
            self.__deck.reload()