root/branch/UmitPlugins/source-plugins/terminal-pad/sources/main.py @ 3009

Revision 3009, 3.1 kB (checked in by nopper, 5 years ago)

Adding a terminal plugin and implementing some apis

Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (C) 2008 Adriano Monteiro Marques
4#
5# Author: Francesco Piccinno <stack.box@gmail.com>
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21import gtk
22import vte
23import gobject
24
25from higwidgets.higtooltips import *
26from higwidgets.hignotebooks import HIGAnimatedTabLabel
27from umitPlugin.Engine import Plugin
28
29class TerminalPage(gtk.Bin):
30    def __init__(self):
31        super(TerminalPage, self).__init__()
32       
33        self.term = vte.Terminal()
34        self.term.fork_command()
35
36        self.__termbox = gtk.HBox()
37        self.__scroll = gtk.VScrollbar(self.term.get_adjustment())
38        border = gtk.Frame()
39        border.set_shadow_type(gtk.SHADOW_ETCHED_IN)
40        border.add(self.term)
41        self.__termbox.pack_start(border)
42        self.__termbox.pack_start(self.__scroll, False)
43        self.add(self.__termbox)
44
45    def do_size_request(self, req):
46        (w,h) = self.__termbox.size_request()
47        req.width = w
48        req.height = h
49
50    def do_size_allocate(self, alloc):
51        self.allocation = alloc
52        wid_req = self.__termbox.size_allocate(alloc)
53
54gobject.type_register(TerminalPage)
55
56class TerminalPlugin(Plugin):
57    __type__ = "usual"
58   
59    def start(self, core, reader):
60        self.core = core
61        self.reader = reader
62
63        # Create a ToolItem
64        self.item = gtk.ToolButton(None, "Terminal")
65
66        image = gtk.image_new_from_stock(gtk.STOCK_ABOUT, \
67                                         gtk.ICON_SIZE_LARGE_TOOLBAR)
68        image.show()
69        self.item.set_icon_widget(image)
70
71        # Append our item
72        self.core.get_main_toolbar().insert(self.item, -1)
73        self.item.connect('clicked', self.__on_create_page)
74        self.item.show_all()
75
76        # Create a page
77        widget = gtk.Label("Miao")
78        widget.show()
79
80    def stop(self, core):
81        self.core.get_main_toolbar().remove(self.item)
82
83    def __on_create_page(self, widget):
84        nb = self.core.get_main_scan_notebook()
85
86        widget = TerminalPage()
87        widget.show_all()
88
89        label = HIGAnimatedTabLabel("Terminal")
90        label.connect('close-clicked', self.__on_close_page, widget)
91
92        gtk.Notebook.append_page(nb, widget, label)
93
94    def __on_close_page(self, widget, page):
95        nb = self.core.get_main_scan_notebook()
96        idx = gtk.Notebook.page_num(nb, page)
97
98        if idx > 0:
99            page.hide()
100            gtk.Notebook.remove_page(nb, idx)
101
102__plugins__ = [TerminalPlugin]
Note: See TracBrowser for help on using the browser.