Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/createcardpanel.py
blob: fa8ecd673ed8d542f2b5a14517107c4009d5128a (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
#! /usr/bin/env python
#
#	Copyright (C) 2006, 2007, One Laptop Per Child
#
#	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., 675 Mass Ave, Cambridge, MA 02139, USA.
#

import gtk
import svgcard
import logging
import gobject

_logger = logging.getLogger('memorize-activity')

class CreateCardPanel(gtk.EventBox):
	
	__gsignals__ = {
		'add-pair': (gobject.SIGNAL_RUN_FIRST, None, [gobject.TYPE_PYOBJECT]), 
		'update-pair': (gobject.SIGNAL_RUN_FIRST, None, [gobject.TYPE_PYOBJECT]), 
	}
	
	def __init__(self):
		gtk.EventBox.__init__(self)
		
		table = gtk.Table()
		table.set_col_spacings(10)
		table.set_row_spacings(10)
		table.set_border_width(200)
		
		addbutton = gtk.Button('Add as new pair')
		addbutton.connect('button-press-event',self.emit_add_pair)
		
		updatebutton = gtk.Button('Update selected pair')
		updatebutton.connect('button-press-event',self.emit_update_pair)
		
		self.cardeditor = CardEditor()
		table.attach(self.cardeditor, 0, 2, 0, 1)
		table.attach(addbutton, 0, 1, 1, 2)
		table.attach(updatebutton, 1, 2, 1, 2)
		
		self.add(table)
		self.show_all()
		
	def emit_add_pair(self, widget, event):
		self.emit('add-pair',self.cardeditor.get_text())

	def emit_update_pair(self, widget, event):
		self.emit('update-pair',self.cardeditor.get_text())
		
	def load_pair(self, widget, newtext):
		self.cardeditor.set_text(newtext)

class CardEditor(gtk.EventBox):
	
	def __init__(self):
		gtk.EventBox.__init__(self)
		self.set_size_request(400, 400)

		table = gtk.Table()
		self.previewlabel = gtk.Label('Preview:')
		self.previewlabel.set_alignment(1, 0.5)
		self.textlabel = gtk.Label('Text:')
		self.textlabel.set_alignment(1, 0.5)
		self.picturelabel = gtk.Label('Picture:')
		self.picturelabel.set_alignment(1, 0.5)
		self.soundlabel = gtk.Label('Sound:')
		self.soundlabel.set_alignment(1, 0.5)
		
		self.browsepicture = gtk.Button('Browse')
		self.capturepicture = gtk.Button('Capture')
		self.browsesound = gtk.Button('Browse')
		self.recordsound = gtk.Button('Record')
		self.textentry = gtk.Entry()
		self.textentry.connect('changed', self.update_text)
				
		table.set_col_spacings(10)
		table.set_row_spacings(10)
		table.set_border_width(20)
		self.card = svgcard.SvgCard(-1, {'front_text':{'card_text':'', 'text_color':'#ffffff'}, 'front_border':{'fill_color':'#4c4d4f', 'stroke_color':'#ffffff', 'opacity':'1'}}, {}, None, 184, 1, '#c0c0c0')
		self.card.flip()
		
		table.attach(self.previewlabel, 0, 1, 1, 2)
		table.attach(self.card, 1, 3, 1, 2)
		#Text label and entry
		table.attach(self.textlabel, 0, 1, 2, 3)
		table.attach(self.textentry, 1, 3, 2, 3)
		#Picture label and entry
		table.attach(self.picturelabel, 0, 1, 3, 4)
		table.attach(self.browsepicture, 1, 2, 3, 4)
		table.attach(self.capturepicture, 2, 3, 3, 4)
		#Sound label and entry
		table.attach(self.soundlabel, 0, 1, 4, 5)
		table.attach(self.browsesound, 1, 2, 4, 5)
		table.attach(self.recordsound, 2, 3, 4, 5)
		
		self.add(table)
		
	def update_text(self, entry):
		self.card.change_text(entry.get_text())
		
	def get_text(self):
		return self.textentry.get_text()

	def set_text(self, newtext):
		self.textentry.set_text(newtext)