Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pippy_app.py
diff options
context:
space:
mode:
authoranishmangal2002 <anishmangal2002@gmail.com>2010-05-20 16:35:54 (GMT)
committer anishmangal2002 <anishmangal2002@gmail.com>2010-05-20 16:35:54 (GMT)
commit15cc3eb1beb726a2af26b5552c7f7a5016157644 (patch)
treecf35d2b9ad9c3af8f5674826e0c1d656598a0c1b /pippy_app.py
parent51535088b0e9deb0abd30fe30660e25165f58fb6 (diff)
Fixes for Pippy layout after integrating groupthink: #1927
Changes ------- [1] The pippy layout now scales according to screen size. [2] Replaced [h,v]boxes by [h,v]panes to make them adjustable. [3] Moved the [stop, run, clear] buttons to the activity toolbar. [4] Added new icons for [stop, run, clear] toolbar buttons. [5] When the toolbar [stop, run, clear] buttons are clicked, they flash color.
Diffstat (limited to 'pippy_app.py')
-rw-r--r--pippy_app.py136
1 files changed, 87 insertions, 49 deletions
diff --git a/pippy_app.py b/pippy_app.py
index abf0449..8edad4e 100644
--- a/pippy_app.py
+++ b/pippy_app.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-# Copyright 2007 Chris Ball, based on Collabora's "hellomesh" demo.
+# Copyright (C) 2007,2008,2009 Chris Ball, based on Collabora's "hellomesh" demo.
#
# 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
@@ -34,6 +34,7 @@ from activity import ViewSourceActivity, TARGET_TYPE_TEXT
from sugar.activity.activity import ActivityToolbox, \
get_bundle_path, get_bundle_name
from sugar.graphics import style
+from sugar.graphics.toolbutton import ToolButton
import groupthink.sugar_tools
import groupthink.gtk_tools
@@ -44,6 +45,10 @@ PYTHON_PREFIX="""#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
+# get screen sizes
+SIZE_X = gtk.gdk.screen_width()
+SIZE_Y = gtk.gdk.screen_height()
+
groupthink_mimetype = 'pickle/groupthink-pippy'
class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
@@ -58,6 +63,7 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
# Top toolbar with share and close buttons:
toolbox = ActivityToolbox(self)
+ activity_toolbar = toolbox.get_activity_toolbar()
# add 'make bundle' entry to 'keep' palette.
palette = toolbox.get_activity_toolbar().keep.get_palette()
# XXX: should clear out old palette entries?
@@ -73,13 +79,62 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
menu_item.connect('activate', self.makebutton_cb)
palette.menu.append(menu_item)
menu_item.show()
+
+ # The "go" button
+ goicon_bw = gtk.Image()
+ goicon_bw.set_from_file("%s/icons/run_bw.svg" % os.getcwd())
+ goicon_color = gtk.Image()
+ goicon_color.set_from_file("%s/icons/run_color.svg" % os.getcwd())
+ gobutton = ToolButton(label=_("_Run!"))
+ gobutton.props.accelerator = _('<alt>r')
+ gobutton.set_icon_widget(goicon_bw)
+ gobutton.set_tooltip("Run")
+ gobutton.connect('clicked', self.flash_cb, dict({'bw':goicon_bw,
+ 'color':goicon_color}))
+ gobutton.connect('clicked', self.gobutton_cb)
+ activity_toolbar.insert(gobutton, 2)
+
+ # The "stop" button
+ stopicon_bw = gtk.Image()
+ stopicon_bw.set_from_file("%s/icons/stopit_bw.svg" % os.getcwd())
+ stopicon_color = gtk.Image()
+ stopicon_color.set_from_file("%s/icons/stopit_color.svg" % os.getcwd())
+ stopbutton = ToolButton(label=_("_Stop"))
+ stopbutton.props.accelerator = _('<alt>s')
+ stopbutton.set_icon_widget(stopicon_bw)
+ stopbutton.connect('clicked', self.flash_cb, dict({'bw':stopicon_bw,
+ 'color':stopicon_color}))
+ stopbutton.connect('clicked', self.stopbutton_cb)
+ stopbutton.set_tooltip("Stop Running")
+ activity_toolbar.insert(stopbutton, 3)
+
+ # The "clear" button
+ clearicon_bw = gtk.Image()
+ clearicon_bw.set_from_file("%s/icons/eraser_bw.svg" % os.getcwd())
+ clearicon_color = gtk.Image()
+ clearicon_color.set_from_file("%s/icons/eraser_color.svg" % os.getcwd())
+ clearbutton = ToolButton(label=_("_Clear"))
+ clearbutton.props.accelerator = _('<alt>c')
+ clearbutton.set_icon_widget(clearicon_bw)
+ clearbutton.connect('clicked', self.clearbutton_cb)
+ clearbutton.connect('clicked', self.flash_cb, dict({'bw':clearicon_bw,
+ 'color':clearicon_color}))
+ clearbutton.set_tooltip("Clear")
+ activity_toolbar.insert(clearbutton, 4)
+
+ # A vertical toolbar separator
+ separator = gtk.SeparatorToolItem()
+ separator.set_draw(True)
+ activity_toolbar.insert(separator, 5)
+ activity_toolbar.show_all()
+
self.set_toolbox(toolbox)
toolbox.show()
# Main layout.
- self.hbox = gtk.HBox()
- vbox = gtk.VBox()
-
+ self.hpane = gtk.HPaned()
+ self.vpane = gtk.VPaned()
+
# The sidebar.
self.sidebar = gtk.VBox()
self.model = gtk.TreeStore(gobject.TYPE_PYOBJECT, gobject.TYPE_STRING)
@@ -88,13 +143,13 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
treecolumn = gtk.TreeViewColumn(_("Examples"), cellrenderer, text=1)
treeview.get_selection().connect("changed", self.selection_cb)
treeview.append_column(treecolumn)
- treeview.set_size_request(220, 900)
+ treeview.set_size_request(int(SIZE_X * 0.3), SIZE_Y)
# Create scrollbars around the view.
scrolled = gtk.ScrolledWindow()
scrolled.add(treeview)
self.sidebar.pack_start(scrolled)
- self.hbox.pack_start(self.sidebar)
+ self.hpane.add1(self.sidebar)
root = os.path.join(get_bundle_path(), 'data')
for d in sorted(os.listdir(root)):
@@ -104,7 +159,7 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
olditer = self.model.insert_before(None, None)
self.model.set_value(olditer, 0, direntry)
self.model.set_value(olditer, 1, direntry["name"])
-
+
for _file in sorted(os.listdir(os.path.join(root, d))):
if _file.endswith('~'): continue # skip emacs backups
entry = { "name": _(_file.capitalize()),
@@ -136,7 +191,7 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
# The GTK source view window
self.text_view = gtksourceview2.View(text_buffer)
- self.text_view.set_size_request(900, 350)
+ self.text_view.set_size_request(0, int(SIZE_Y * 0.5))
self.text_view.set_editable(True)
self.text_view.set_cursor_visible(True)
self.text_view.set_show_line_numbers(True)
@@ -144,7 +199,7 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
self.text_view.set_insert_spaces_instead_of_tabs(True)
self.text_view.set_tab_width(2)
self.text_view.set_auto_indent(True)
- self.text_view.modify_font(pango.FontDescription("Monospace " +
+ self.text_view.modify_font(pango.FontDescription("Monospace " +
str(font_zoom(style.FONT_SIZE))))
# We could change the color theme here, if we want to.
@@ -156,42 +211,15 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
codesw.set_policy(gtk.POLICY_AUTOMATIC,
gtk.POLICY_AUTOMATIC)
codesw.add(self.text_view)
- vbox.pack_start(codesw)
-
- # An hbox for the buttons
- buttonhbox = gtk.HBox()
-
- # The "go" button
- goicon = gtk.Image()
- goicon.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_BUTTON)
- gobutton = gtk.Button(label=_("_Run!"))
- gobutton.set_image(goicon)
- gobutton.connect('clicked', self.gobutton_cb)
- gobutton.set_size_request(650, 2)
- buttonhbox.pack_start(gobutton)
-
- # The "stop" button
- stopbutton = gtk.Button(stock=gtk.STOCK_STOP)
- stopbutton.connect('clicked', self.stopbutton_cb)
- stopbutton.set_size_request(200, 2)
- buttonhbox.pack_start(stopbutton)
-
- # The "clear" button
- clearbutton = gtk.Button(stock=gtk.STOCK_CLEAR)
- clearbutton.connect('clicked', self.clearbutton_cb)
- clearbutton.set_size_request(150, 2)
- buttonhbox.pack_end(clearbutton)
-
- vbox.pack_start(buttonhbox)
+ self.vpane.add1(codesw)
# An hbox to hold the vte window and its scrollbar.
outbox = gtk.HBox()
-
+
# The vte python window
self._vte = vte.Terminal()
self._vte.set_encoding('utf-8')
self._vte.set_size(30, 5)
- self._vte.set_size_request(200, 300)
font = 'Monospace ' + str(font_zoom(style.FONT_SIZE))
self._vte.set_font(pango.FontDescription(font))
self._vte.set_colors(gtk.gdk.color_parse ('#000000'),
@@ -204,16 +232,16 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
gtk.gdk.ACTION_COPY)
self._vte.connect('drag_data_received', self.vte_drop_cb)
outbox.pack_start(self._vte)
-
+
outsb = gtk.VScrollbar(self._vte.get_adjustment())
outsb.show()
outbox.pack_start(outsb, False, False, 0)
- vbox.pack_end(outbox)
- self.hbox.pack_end(vbox)
- return self.hbox
-
+ self.vpane.add2(outbox)
+ self.hpane.add2(self.vpane)
+ return self.hpane
+
def when_shared(self):
- self.hbox.remove(self.sidebar)
+ self.hpane.remove(self.hpane.get_child1())
global text_buffer
self.cloud.sharefield = groupthink.gtk_tools.TextBufferSharePoint(text_buffer)
@@ -233,7 +261,17 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
self.stopbutton_cb(None)
self._reset_vte()
self.text_view.grab_focus()
-
+
+ def timer_cb(self, button, icons):
+ button.set_icon_widget(icons['bw'])
+ button.show_all()
+ return False
+
+ def flash_cb(self, button, icons):
+ button.set_icon_widget(icons['color'])
+ button.show_all()
+ gobject.timeout_add(400, self.timer_cb, button, icons)
+
def clearbutton_cb(self, button):
self.save()
global text_buffer
@@ -263,10 +301,10 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
from shutil import copy2
self.stopbutton_cb(button) # try stopping old code first.
self._reset_vte()
-
+
# FIXME: We're losing an odd race here
# gtk.main_iteration(block=False)
-
+
pippy_app_name = '%s/tmp/pippy_app.py' % self.get_activity_root()
self._write_text_buffer(pippy_app_name)
# write activity.py here too, to support pippy-based activities.
@@ -387,7 +425,7 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
else:
self.metadata['mime_type'] = groupthink_mimetype
_file.write(cloudstring)
-
+
def load_from_journal(self, file_path):
if self.metadata['mime_type'] == 'text/x-python':
text = open(file_path).read()
@@ -397,7 +435,7 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
text_buffer.set_text(text)
elif self.metadata['mime_type'] == groupthink_mimetype:
return open(file_path).read()
-
+
############# TEMPLATES AND INLINE FILES ##############
ACTIVITY_INFO_TEMPLATE = """
[Activity]