Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2009-01-21 17:32:44 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2009-01-21 17:32:44 (GMT)
commit718427207218a4666eb3820b4e535eade3de854a (patch)
tree302ccfcd0797a963a90fc8a7b8730007319ed7f2
parent75b12ca76bc15e43d07d40a5da6b1a2f3a35a964 (diff)
#6617 make "Create" tab screen-resolution independent
-rw-r--r--activity.py4
-rw-r--r--cardlist.py19
-rw-r--r--createcardpanel.py62
-rw-r--r--svgcard.py5
-rw-r--r--theme.py21
5 files changed, 69 insertions, 42 deletions
diff --git a/activity.py b/activity.py
index 5fdfa2a..66f3bbe 100644
--- a/activity.py
+++ b/activity.py
@@ -180,8 +180,8 @@ class MemorizeActivity(Activity):
self.hbox.remove(self.scoreboard)
self.hbox.remove(self.table)
- self.hbox.pack_start(self.createcardpanel)
- self.hbox.pack_start(self.cardlist, False, False)
+ self.hbox.pack_start(self.createcardpanel, False)
+ self.hbox.pack_start(self.cardlist)
self.play_mode = False
else:
diff --git a/cardlist.py b/cardlist.py
index 7a179f4..fef27e3 100644
--- a/cardlist.py
+++ b/cardlist.py
@@ -32,6 +32,8 @@ from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT
from sugar import profile
from sugar.datastore import datastore
+import theme
+
_logger = logging.getLogger('memorize-activity')
class CardList(gtk.EventBox):
@@ -48,7 +50,6 @@ class CardList(gtk.EventBox):
self.pairs = []
self.current_pair = None
- self.set_size_request(450, 150)
self.vbox = gtk.VBox(False)
fill_box = gtk.Label()
@@ -252,8 +253,20 @@ class Pair(gtk.EventBox):
table.connect('button-press-event', self.emit_selected)
table.set_col_spacings(0)
table.set_border_width(10)
- self.bcard1 = svgcard.SvgCard(-1, {'front_text':{'card_text':text1, 'text_color':'#ffffff'}, 'front':{'fill_color':'#4c4d4f', 'stroke_color':'#ffffff', 'opacity':'1'}}, None, 184, 1, self.bg_color)
- self.bcard2 = svgcard.SvgCard(-1, {'front_text':{'card_text':text2, 'text_color':'#ffffff'}, 'front':{'fill_color':'#4c4d4f', 'stroke_color':'#ffffff', 'opacity':'1'}}, None, 184, 1, self.bg_color)
+ self.bcard1 = svgcard.SvgCard(-1,
+ { 'front_text' : { 'card_text' : text1,
+ 'text_color' : '#ffffff' },
+ 'front' : { 'fill_color' : '#4c4d4f',
+ 'stroke_color' : '#ffffff',
+ 'opacity' : '1' } },
+ None, theme.CARD_SIZE, 1, self.bg_color)
+ self.bcard2 = svgcard.SvgCard(-1,
+ { 'front_text' : { 'card_text' : text2,
+ 'text_color' : '#ffffff' },
+ 'front' : { 'fill_color' : '#4c4d4f',
+ 'stroke_color' : '#ffffff',
+ 'opacity' : '1' } },
+ None, theme.CARD_SIZE, 1, self.bg_color)
self.bcard1.flip()
self.bcard2.flip()
diff --git a/createcardpanel.py b/createcardpanel.py
index 3532987..620d888 100644
--- a/createcardpanel.py
+++ b/createcardpanel.py
@@ -28,6 +28,8 @@ from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT
from xml.dom.minidom import parse
from sugar.graphics.objectchooser import ObjectChooser
+import theme
+
_logger = logging.getLogger('memorize-activity')
class CreateCardPanel(gtk.EventBox):
@@ -39,7 +41,6 @@ class CreateCardPanel(gtk.EventBox):
def __init__(self):
gtk.EventBox.__init__(self)
- self.set_size_request(650, 320)
self.equal_pairs = False
@@ -74,10 +75,10 @@ class CreateCardPanel(gtk.EventBox):
self.table.set_col_spacings(10)
self.table.set_row_spacings(10)
self.table.set_border_width(10)
- self.table.attach(self.cardeditor1, 0, 2, 0, 1, gtk.SHRINK|gtk.FILL, gtk.SHRINK, 10, 30)
- self.table.attach(self.cardeditor2, 2, 4, 0, 1, gtk.SHRINK|gtk.FILL, gtk.SHRINK, 10, 30)
- self.table.attach(self._addbutton, 1, 2, 1, 2, gtk.SHRINK|gtk.FILL, gtk.SHRINK)
- self.table.attach(self._updatebutton, 2, 3, 1, 2, gtk.SHRINK|gtk.FILL, gtk.SHRINK)
+ self.table.attach(self.cardeditor1, 0, 1, 0, 1, yoptions=gtk.SHRINK)
+ self.table.attach(self.cardeditor2, 1, 2, 0, 1, yoptions=gtk.SHRINK)
+ self.table.attach(self._addbutton, 0, 1, 1, 2, yoptions=gtk.SHRINK)
+ self.table.attach(self._updatebutton, 1, 2, 1, 2, yoptions=gtk.SHRINK)
self.add(self.table)
self.show_all()
@@ -169,16 +170,15 @@ class CardEditor(gtk.EventBox):
def __init__(self):
gtk.EventBox.__init__(self)
- self.set_size_request(310, 320)
tmp_root = join(environ['SUGAR_ACTIVITY_ROOT'], 'instance')
self.temp_folder = tempfile.mkdtemp(dir=tmp_root)
table = gtk.Table()
self.previewlabel = gtk.Label(_('Preview:'))
- self.previewlabel.set_alignment(1, 0.5)
+ self.previewlabel.set_alignment(0, 1)
self.textlabel = gtk.Label(_('Text:'))
- self.textlabel.set_alignment(1, 0.5)
+ self.textlabel.set_alignment(0, 1)
picture_icon = join(dirname(__file__), 'images', 'import_picture.svg')
picture_image = gtk.Image()
@@ -201,18 +201,25 @@ class CardEditor(gtk.EventBox):
table.set_col_spacings(10)
table.set_row_spacings(10)
table.set_border_width(10)
- 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 = svgcard.SvgCard(-1,
+ { 'front_text' : { 'card_text' : '',
+ 'text_color' : '#ffffff' },
+ 'front_border': { 'fill_color' : '#4c4d4f',
+ 'stroke_color' : '#ffffff',
+ 'opacity' : '1' } },
+ None, theme.CARD_SIZE, 1, '#c0c0c0')
self.card.flip()
- table.attach(self.previewlabel, 0, 1, 1, 2, gtk.EXPAND, gtk.EXPAND)
- table.attach(self.card, 1, 3, 1, 2, gtk.EXPAND, gtk.EXPAND, 10)
+ table.attach(self.previewlabel, 0, 2, 0, 1, yoptions=gtk.SHRINK)
+ table.attach(self.card, 0, 2, 1, 2, gtk.SHRINK, gtk.SHRINK, 10)
#Text label and entry
- table.attach(self.textlabel, 0, 1, 2, 3, gtk.EXPAND|gtk.FILL, gtk.EXPAND)
- table.attach(self.textentry, 1, 3, 2, 3, gtk.EXPAND|gtk.FILL, gtk.EXPAND)
+ table.attach(self.textlabel, 0, 1, 2, 3, yoptions=gtk.SHRINK)
+ table.attach(self.textentry, 0, 2, 3, 4, yoptions=gtk.SHRINK)
+ self.textentry.set_size_request(0, -1)
#Picture label and entry
- table.attach(self.browsepicture, 1, 2, 3, 4, gtk.EXPAND|gtk.FILL, gtk.EXPAND)
+ table.attach(self.browsepicture, 0, 1, 4, 5, yoptions=gtk.SHRINK)
#Sound label and entry
- table.attach(self.browsesound, 2, 3, 3, 4, gtk.EXPAND|gtk.FILL, gtk.EXPAND)
+ table.attach(self.browsesound, 1, 2, 4, 5, yoptions=gtk.SHRINK)
self.add(table)
@@ -251,8 +258,10 @@ class CardEditor(gtk.EventBox):
del chooser
def _load_image(self, index):
- pixbuf_t = gtk.gdk.pixbuf_new_from_file(index)
- self.card.set_pixbuf(self.to_card_pixbuf(pixbuf_t))
+ pixbuf_t = gtk.gdk.pixbuf_new_from_file_at_size(index,
+ theme.CARD_SIZE - theme.CARD_PAD*2,
+ theme.CARD_SIZE - theme.CARD_PAD*2)
+ self.card.set_pixbuf(pixbuf_t)
_logger.error('Picture Loaded: '+index)
self.emit('has-picture', True)
del pixbuf_t
@@ -292,22 +301,3 @@ class CardEditor(gtk.EventBox):
self.snd = None
self.emit('has-text', False)
self.emit('has-picture', False)
-
- def to_card_pixbuf(self, pixbuf):
- if pixbuf.get_width() == pixbuf.get_height():
- new = pixbuf_t.scale_simple(162, 162, gtk.gdk.INTERP_BILINEAR)
- elif pixbuf.get_width() > pixbuf.get_height():
- new = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 162, 162)
- aspect = float(pixbuf.get_width()) / float(pixbuf.get_height())
- pixbuf_t = pixbuf.scale_simple(int(float(162)*aspect) , 162, gtk.gdk.INTERP_BILINEAR)
- diff = pixbuf_t.get_width() - pixbuf_t.get_height()
- pixbuf_t.scale(new, 0, 0, 162, 162, -(diff/2), 0, 1, 1, gtk.gdk.INTERP_BILINEAR)
- del pixbuf_t
- elif pixbuf.get_width() < pixbuf.get_height():
- new = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 162, 162)
- aspect = float(pixbuf.get_height()) / float(pixbuf.get_width())
- pixbuf_t = pixbuf.scale_simple(162 , int(float(162)*aspect), gtk.gdk.INTERP_BILINEAR)
- diff = pixbuf_t.get_height() - pixbuf_t.get_width()
- pixbuf_t.scale(new, 0, 0, 162, 162, 0, -(diff/2), 1, 1, gtk.gdk.INTERP_BILINEAR)
- del pixbuf_t
- return new
diff --git a/svgcard.py b/svgcard.py
index 5ba0e8d..d0ac594 100644
--- a/svgcard.py
+++ b/svgcard.py
@@ -25,6 +25,8 @@ import gtk
import pango
import logging
+import theme
+
_logger = logging.getLogger('memorize-activity')
class SvgCard(gtk.DrawingArea):
@@ -85,7 +87,8 @@ class SvgCard(gtk.DrawingArea):
pixbuf = self._read_icon_data(self.current_face)
self.window.draw_pixbuf(None, pixbuf, 0, 0, 0, 0)
if self.show_jpeg:
- self.window.draw_pixbuf(None, self.jpeg, 0, 0, 11, 11)
+ self.window.draw_pixbuf(None, self.jpeg, 0, 0,
+ theme.CARD_PAD, theme.CARD_PAD)
if self.show_text:
widget.window.draw_layout(gc, x=6, y=self.current_layout_position, layout=self.current_layout, foreground=gtk.gdk.color_parse(self.current_text_color))
return False
diff --git a/theme.py b/theme.py
new file mode 100644
index 0000000..d786c90
--- /dev/null
+++ b/theme.py
@@ -0,0 +1,21 @@
+# Copyright (C) 2006, 2007, 2008 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
+
+CARD_SIZE = gtk.gdk.screen_width() / 5
+CARD_PAD = 11