Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README3
-rw-r--r--activity/activity.info6
-rw-r--r--activity/terminal.svg75
-rw-r--r--setup.py22
-rw-r--r--terminal.py258
5 files changed, 364 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..8304f35
--- /dev/null
+++ b/README
@@ -0,0 +1,3 @@
+Terminal-Activity
+-----------------
+
diff --git a/activity/activity.info b/activity/activity.info
new file mode 100644
index 0000000..bb4e3b2
--- /dev/null
+++ b/activity/activity.info
@@ -0,0 +1,6 @@
+[Activity]
+name = Terminal
+activity_version = 1
+service_name = org.laptop.Terminal
+icon = terminal
+class = terminal.TerminalActivity
diff --git a/activity/terminal.svg b/activity/terminal.svg
new file mode 100644
index 0000000..60011a2
--- /dev/null
+++ b/activity/terminal.svg
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Generator: Adobe Illustrator 12.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 51448) -->
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://web.resource.org/cc/"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ version="1.1"
+ id="Icon"
+ width="43.307"
+ height="43.305"
+ viewBox="0 0 43.307 43.305"
+ overflow="visible"
+ enable-background="new 0 0 43.307 43.305"
+ xml:space="preserve"
+ sodipodi:version="0.32"
+ inkscape:version="0.45.1"
+ sodipodi:docname="activity-test.svg"
+ inkscape:output_extension="org.inkscape.output.svg.inkscape"
+ sodipodi:docbase="/home/edsiper/coding/sugar_activities/terminal-activity/activity"><metadata
+ id="metadata20"><rdf:RDF><cc:Work
+ rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
+ id="defs18" /><sodipodi:namedview
+ inkscape:window-height="627"
+ inkscape:window-width="910"
+ inkscape:pageshadow="2"
+ inkscape:pageopacity="0.0"
+ guidetolerance="10.0"
+ gridtolerance="10.0"
+ objecttolerance="10.0"
+ borderopacity="1.0"
+ bordercolor="#666666"
+ pagecolor="#ffffff"
+ id="base"
+ inkscape:zoom="9.3984528"
+ inkscape:cx="21.6535"
+ inkscape:cy="24.783565"
+ inkscape:window-x="12"
+ inkscape:window-y="71"
+ inkscape:current-layer="Icon" />
+<circle
+ id="Globe"
+ fill="#AAAAAA"
+ stroke="#000000"
+ stroke-width="3.5"
+ cx="21.652"
+ cy="21.653"
+ r="19.903"
+ style="fill:#f3bd70;fill-opacity:1" />
+<g
+ id="Lines">
+
+
+ <line
+ x1="9.2688932"
+ y1="12.167065"
+ x2="34.462708"
+ y2="12.073284"
+ id="line9"
+ style="fill:#aaaaaa;stroke:#000000;stroke-width:2.99707246" />
+
+
+
+<line
+ x1="21.838366"
+ y1="10.852942"
+ x2="21.998638"
+ y2="36.046421"
+ id="line2160"
+ style="fill:#aaaaaa;stroke:#000000;stroke-width:2.99707246" /></g>
+</svg> \ No newline at end of file
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..876cd3f
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,22 @@
+#!/usr/bin/python
+
+# Copyright (C) 2006, Red Hat, Inc.
+#
+# 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
+
+from sugar.activity import bundlebuilder
+
+bundlebuilder.start()
+
diff --git a/terminal.py b/terminal.py
new file mode 100644
index 0000000..8c0e243
--- /dev/null
+++ b/terminal.py
@@ -0,0 +1,258 @@
+# Copyright (C) 2007, Eduardo Silva <edsiper@gmail.com>.
+#
+# 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 os
+import logging
+from gettext import gettext as _
+
+import gtk
+import dbus
+
+from sugar.activity import activity
+from sugar import env
+
+import ConfigParser
+import os.path
+
+import vte
+import pango
+
+class TerminalActivity(activity.Activity):
+
+ def __init__(self, handle):
+
+ activity.Activity.__init__(self, handle)
+ logging.debug('Starting the Terminal activity')
+ self.set_title(_('Terminal Activity'))
+
+ # CANVAS
+ terminal = Multiple()
+
+ self.set_canvas(terminal)
+
+ # TOOLBAR
+ toolbox = activity.ActivityToolbox(self)
+ self.set_toolbox(toolbox)
+ self.show_all()
+
+class Terminal(gtk.HBox):
+ def __init__(self):
+ gtk.HBox.__init__(self, False, 4)
+
+ self._vte = vte.Terminal()
+ self._configure_vte()
+ self._vte.set_size(100, 5)
+ self._vte.set_size_request(200, 450)
+ self._vte.show()
+ self.pack_start(self._vte)
+
+ self._scrollbar = gtk.VScrollbar(self._vte.get_adjustment())
+ self._scrollbar.show()
+ self.pack_start(self._scrollbar, False, False, 0)
+
+ self._vte.connect("child-exited", lambda term: term.fork_command())
+
+ self._vte.fork_command()
+
+ def _configure_vte(self):
+ conf = ConfigParser.ConfigParser()
+
+ conf_file = os.path.join(env.get_profile_path(), 'terminalrc')
+
+ if os.path.isfile(conf_file):
+ f = open(conf_file, 'r')
+ conf.readfp(f)
+ f.close()
+ else:
+ conf.add_section('terminal')
+
+ if conf.has_option('terminal', 'font'):
+ font = conf.get('terminal', 'font')
+ else:
+ font = 'Monospace 10'
+ conf.set('terminal', 'font', font)
+ self._vte.set_font(pango.FontDescription(font))
+
+ if conf.has_option('terminal', 'fg_color'):
+ fg_color = conf.get('terminal', 'fg_color')
+ else:
+ fg_color = '#000000'
+ conf.set('terminal', 'fg_color', fg_color)
+ if conf.has_option('terminal', 'bg_color'):
+ bg_color = conf.get('terminal', 'bg_color')
+ else:
+ bg_color = '#FFFFFF'
+ conf.set('terminal', 'bg_color', bg_color)
+ self._vte.set_colors(gtk.gdk.color_parse (fg_color),
+ gtk.gdk.color_parse (bg_color),
+ [])
+
+ if conf.has_option('terminal', 'cursor_blink'):
+ blink = conf.getboolean('terminal', 'cursor_blink')
+ else:
+ blink = False
+ conf.set('terminal', 'cursor_blink', blink)
+
+ self._vte.set_cursor_blinks(blink)
+
+ if conf.has_option('terminal', 'bell'):
+ bell = conf.getboolean('terminal', 'bell')
+ else:
+ bell = False
+ conf.set('terminal', 'bell', bell)
+ self._vte.set_audible_bell(bell)
+
+ if conf.has_option('terminal', 'scrollback_lines'):
+ scrollback_lines = conf.getint('terminal', 'scrollback_lines')
+ else:
+ scrollback_lines = 1000
+ conf.set('terminal', 'scrollback_lines', scrollback_lines)
+
+ self._vte.set_scrollback_lines(scrollback_lines)
+
+ self._vte.set_allow_bold(True)
+
+ if conf.has_option('terminal', 'scroll_on_keystroke'):
+ scroll_key = conf.getboolean('terminal', 'scroll_on_keystroke')
+ else:
+ scroll_key = False
+ conf.set('terminal', 'scroll_on_keystroke', scroll_key)
+ self._vte.set_scroll_on_keystroke(scroll_key)
+
+ if conf.has_option('terminal', 'scroll_on_output'):
+ scroll_output = conf.getboolean('terminal', 'scroll_on_output')
+ else:
+ scroll_output = False
+ conf.set('terminal', 'scroll_on_output', scroll_output)
+ self._vte.set_scroll_on_output(scroll_output)
+
+ if conf.has_option('terminal', 'emulation'):
+ emulation = conf.get('terminal', 'emulation')
+ else:
+ emulation = 'xterm'
+ conf.set('terminal', 'emulation', emulation)
+ self._vte.set_emulation(emulation)
+
+ if conf.has_option('terminal', 'visible_bell'):
+ visible_bell = conf.getboolean('terminal', 'visible_bell')
+ else:
+ visible_bell = False
+ conf.set('terminal', 'visible_bell', visible_bell)
+ self._vte.set_visible_bell(visible_bell)
+
+ conf.write(open(conf_file, 'w'))
+
+ def on_gconf_notification(self, client, cnxn_id, entry, what):
+ self.reconfigure_vte()
+
+ def on_vte_button_press(self, term, event):
+ if event.button == 3:
+ self.do_popup(event)
+ return True
+
+ def on_vte_popup_menu(self, term):
+ pass
+
+class Multiple(gtk.VBox):
+ def __init__(self):
+ gtk.VBox.__init__(self, False, 3)
+
+ self._page_number = 0
+ self.notebook = gtk.Notebook()
+ t_width = gtk.gdk.screen_width()
+ t_height = gtk.gdk.screen_height() * 83 / 100
+ self.notebook.set_size_request(t_width, t_height)
+
+ self.add_new_terminal()
+
+ open_terminal = gtk.Button('Open a new terminal')
+ open_terminal.connect("clicked", self.add_new_terminal)
+ open_terminal.show()
+
+ self.notebook.show()
+
+ self.pack_start(open_terminal, True, True, 2)
+ self.pack_start(self.notebook, True, True, 2)
+ self.show_all()
+
+ # Remove a page from the notebook
+ def close_terminal(self, button, child):
+ page = self.notebook.page_num(child)
+
+ if page != -1:
+ self.notebook.remove_page(page)
+
+
+ pages = self.notebook.get_n_pages()
+ if pages <= 0:
+ self._page_number = 0
+ self.add_new_terminal()
+
+ # Need to refresh the widget --
+ # This forces the widget to redraw itself.
+ self.notebook.queue_draw_area(0, 0, -1, -1)
+
+ def add_icon_to_button(self, button):
+ iconBox = gtk.HBox(False, 0)
+ image = gtk.Image()
+ image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
+ gtk.Button.set_relief(button, gtk.RELIEF_NONE)
+
+ settings = gtk.Widget.get_settings (button)
+ (w,h) = gtk.icon_size_lookup_for_settings (settings, gtk.ICON_SIZE_MENU)
+ gtk.Widget.set_size_request (button, w + 4, h + 4)
+ image.show()
+ iconBox.pack_start(image, True, False, 0)
+ button.add(iconBox)
+ iconBox.show()
+
+ def add_new_terminal(self, *arguments, **keywords):
+ self._page_number += 1
+
+ terminal = Terminal()
+ terminal.show()
+
+ eventBox = self.create_custom_tab("Term %d" % self._page_number, terminal)
+ self.notebook.append_page(terminal, eventBox)
+
+ # Set the new page
+ pages = gtk.Notebook.get_n_pages(self.notebook)
+ self.notebook.set_current_page(pages - 1)
+ return True
+
+ def create_custom_tab(self, text, child):
+ eventBox = gtk.EventBox()
+ tabBox = gtk.HBox(False, 2)
+ tabLabel = gtk.Label(text)
+
+ tabButton = gtk.Button()
+ tabButton.connect('clicked', self.close_terminal, child)
+
+ # Add a picture on a button
+ self.add_icon_to_button(tabButton)
+ iconBox = gtk.HBox(False, 0)
+
+ eventBox.show()
+ tabButton.show()
+ tabLabel.show()
+
+ tabBox.pack_start(tabLabel, False)
+ tabBox.pack_start(tabButton, False)
+
+ tabBox.show_all()
+ eventBox.add(tabBox)
+
+ return eventBox