Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArtActivity.py
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2013-07-25 21:35:13 (GMT)
committer Walter Bender <walter@sugarlabs.org>2013-07-25 21:35:13 (GMT)
commitfd64feabf05ba37c4888626cf2f7a9ac57d4733a (patch)
tree208a61a4c3824b0f08f3e545cba8a8e96c1c9517 /TurtleArtActivity.py
parent3d6de0867d1b09c3460e6fd5576373652ae0064f (diff)
add iconview for sample projects
Diffstat (limited to 'TurtleArtActivity.py')
-rw-r--r--TurtleArtActivity.py94
1 files changed, 93 insertions, 1 deletions
diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py
index 3274dfc..8b5fb36 100644
--- a/TurtleArtActivity.py
+++ b/TurtleArtActivity.py
@@ -47,6 +47,7 @@ from sugar.datastore import datastore
from sugar import profile
import os
+import glob
import tarfile
import subprocess
import ConfigParser
@@ -130,6 +131,10 @@ class TurtleArtActivity(activity.Activity):
self.client = gconf.client_get_default()
if self.client.get_int(self._HOVER_HELP) == 1:
self._do_hover_help_toggle(None)
+
+ self._selected_sample = None
+ self._sample_window = None
+
self.init_complete = True
def check_buttons_for_fit(self):
@@ -394,7 +399,8 @@ class TurtleArtActivity(activity.Activity):
if hasattr(self.get_window(), 'get_cursor'):
self._old_cursor = self.get_window().get_cursor()
self.get_window().set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
- self.tw.load_file_from_chooser(True)
+ self._create_store()
+ # self.tw.load_file_from_chooser(True)
# Now that the file is loaded, restore the cursor
_logger.debug('restoring cursor')
self.restore_cursor()
@@ -1584,3 +1590,89 @@ in order to use the plugin.'))
def restore_state(self):
''' Anything that needs restoring after a clear screen can go here '''
pass
+
+ def _hide_store(self, widget=None):
+ if self._sample_window is not None:
+ self._sample_box.hide()
+
+ def _create_store(self, widget=None):
+ if self._sample_window is None:
+ self._sample_box = gtk.EventBox()
+ self._sample_window = gtk.ScrolledWindow()
+ self._sample_window.set_policy(gtk.POLICY_NEVER,
+ gtk.POLICY_AUTOMATIC)
+ width = gtk.gdk.screen_width() / 2
+ height = gtk.gdk.screen_height() / 2
+ self._sample_window.set_size_request(width, height)
+ self._sample_window.show()
+
+ store = gtk.ListStore(gtk.gdk.Pixbuf, str)
+
+ icon_view = gtk.IconView()
+ icon_view.set_model(store)
+ icon_view.set_selection_mode(gtk.SELECTION_SINGLE)
+ icon_view.connect('selection-changed', self._sample_selected,
+ store)
+ icon_view.set_pixbuf_column(0)
+ icon_view.grab_focus()
+ self._sample_window.add_with_viewport(icon_view)
+ icon_view.show()
+ self._fill_samples_list(store)
+
+ width = gtk.gdk.screen_width() / 4
+ height = gtk.gdk.screen_height() / 4
+
+ self._sample_box.add(self._sample_window)
+ self.fixed.put(self._sample_box, width, height)
+
+ self._sample_window.show()
+ self._sample_box.show()
+
+ def _get_selected_path(self, widget, store):
+ try:
+ iter_ = store.get_iter(widget.get_selected_items()[0])
+ image_path = store.get(iter_, 1)[0]
+
+ return image_path, iter_
+ except:
+ return None
+
+ def _sample_selected(self, widget, store):
+ selected = self._get_selected_path(widget, store)
+
+ if selected is None:
+ self._selected_sample = None
+ self._sample_window.hide()
+ return
+
+ image_path, _iter = selected
+ iter_ = store.get_iter(widget.get_selected_items()[0])
+ image_path = store.get(iter_, 1)[0]
+
+ self._selected_sample = image_path
+ self._sample_window.hide()
+
+ # Convert from thumbnail path to sample path
+ basename = os.path.basename(self._selected_sample)[:-4]
+ for suffix in ['.ta', '.tb']:
+ file_path = os.path.join(activity.get_bundle_path(),
+ 'samples', basename + suffix)
+ if os.path.exists(file_path):
+ self.tw.load_files(file_path)
+ break
+
+ def _fill_samples_list(self, store):
+ '''
+ Append images from the artwork_paths to the store.
+ '''
+ for filepath in self._scan_for_samples():
+ pixbuf = None
+ pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
+ filepath, 100, 100)
+ store.append([pixbuf, filepath])
+
+ def _scan_for_samples(self):
+ samples = glob.glob(os.path.join(activity.get_bundle_path(),
+ 'samples', 'thumbnails', '*.png'))
+ samples.sort()
+ return samples