22
22
pygtk.require('2.0')
25
import clicompanionlib.config as cc_config
27
from clicompanionlib.utils import get_user_shell
27
from clicompanionlib.utils import get_user_shell, dbg
28
28
import clicompanionlib.controller
29
import clicompanionlib.utils as utils
31
CONFIGFILE = os.path.expanduser("~/.config/clicompanion/config")
34
#definition gcp - how many pages is visible
37
#definition nop - (no of pages) reflects no of terminal tabs left (some may be closed by the user)
40
33
class Tabs(object):
42
35
add a new terminal in a tab above the current terminal
44
def add_tab(self,widget, notebook):
38
#definition nop - (no of pages) reflects no of terminal tabs left (some may be closed by the user)
40
#definition gcp - how many pages is visible
43
def add_tab(self, notebook):
44
dbg('Adding a new tab')
45
45
_vte = vte.Terminal()
46
46
if view.NETBOOKMODE == 1:
47
47
_vte.set_size_request(700, 120)
49
49
_vte.set_size_request(700, 220)
51
_vte.connect ("child-exited", lambda term: gtk.main_quit())
51
_vte.connect("child-exited", lambda term: gtk.main_quit())
52
52
_vte.fork_command(get_user_shell()) # Get the user's default shell
54
54
self.update_term_config(_vte)
58
58
#notebook.set_show_tabs(True)
59
59
#notebook.set_show_border(True)
65
pagenum = ('Tab %d') % gcp
63
pagenum = ('Tab %d') % self.gcp
65
dbg('More than one tab, showing them.')
67
66
view.MainWindow.notebook.set_show_tabs(True)
69
68
label = gtk.Label(pagenum)
70
69
box.pack_start(label, True, True)
75
72
## x image for tab close button
76
73
close_image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
87
84
view.MainWindow.notebook.prepend_page(vte_tab, box) # add tab
88
85
view.MainWindow.notebook.set_scrollable(True)
89
86
actions = clicompanionlib.controller.Actions()
90
_vte.connect ("button_press_event", actions.copy_paste, None)
87
_vte.connect("button_press_event", actions.copy_paste, None)
91
88
vte_tab.grab_focus()
92
89
# signal handler for tab
93
closebtn.connect("clicked", self.close_tab, vte_tab, notebook)
90
closebtn.connect("clicked", lambda *x: self.close_tab(vte_tab, notebook))
100
97
## Remove a page from the notebook
101
def close_tab(self, sender, widget, notebook):
98
def close_tab(self, vte_tab, notebook):
102
99
## get the page number of the tab we wanted to close
103
pagenum = view.MainWindow.notebook.page_num(widget)
100
pagenum = view.MainWindow.notebook.page_num(vte_tab)
105
102
view.MainWindow.notebook.remove_page(pagenum)
109
105
view.MainWindow.notebook.set_show_tabs(False)
111
107
# check if the focus does not go to the last page (ie with only a + sign)
112
if view.MainWindow.notebook.get_current_page() == nop:
108
if view.MainWindow.notebook.get_current_page() == self.nop:
113
109
view.MainWindow.notebook.prev_page()
117
def update_term_config(self, _vte):
119
config = ConfigParser.RawConfigParser()
120
config.read(CONFIGFILE)
111
def update_all_term_config(self, config=None):
112
for pagenum in range(view.MainWindow.notebook.get_n_pages()):
113
page = view.MainWindow.notebook.get_nth_page(pagenum)
115
if isinstance(page, gtk.ScrolledWindow):
116
for grandson in page.get_children():
118
if isinstance(grandson,vte.Terminal):
119
self.update_term_config(grandson, config)
121
def update_term_config(self, _vte, config=None):
122
122
##set terminal preferences from conig file data
123
config_scrollback = config.getint('terminal', 'scrollb')
124
config = cc_config.get_config()
126
config_scrollback = config.getint('terminal', 'scrollb')
128
print _("WARNING: Invalid value for property 'terminal', int expected:"
129
" got '%s', using default '%s'")%(
130
config.get('terminal', 'scrollb'),
131
config.get('DEFAULT', 'scrollb'))
132
config.set('terminal','scrollb',config.get('DEFAULT', 'scrollb'))
133
config_scrollback = config.getint('DEFAULT', 'scrollb')
124
134
_vte.set_scrollback_lines(config_scrollback)
126
136
color = '#2e3436:#cc0000:#4e9a06:#c4a000:#3465a4:#75507b:#06989a:#d3d7cf:#555753:#ef2929:#8ae234:#fce94f:#729fcf:#ad7fa8:#34e2e2:#eeeeec'
131
141
palette.append(gtk.gdk.color_parse(color))
133
config_color_fore = gtk.gdk.color_parse(config.get('terminal', 'colorf'))
134
#_vte.set_color_foreground(config_color_fore)
136
config_color_back = gtk.gdk.color_parse(config.get('terminal', 'colorb'))
137
#_vte.set_color_background( config_color_back)
144
config_color_fore = gtk.gdk.color_parse(config.get('terminal', 'colorf'))
145
except ValueError, e:
146
print _("WARNING: Invalid value for property '%s':"
147
" got '%s', using default '%s'.")%(
149
config.get('terminal', 'colorf'),
150
config.get('DEFAULT', 'colorf'))
151
config.set('terminal','colorf',config.get('DEFAULT', 'colorf'))
152
config_color_fore = gtk.gdk.color_parse(config.get('DEFAULT', 'colorf'))
155
config_color_back = gtk.gdk.color_parse(config.get('terminal', 'colorb'))
156
except ValueError, e:
157
print _("WARNING: Invalid value for property '%s':"
158
" got '%s', using default '%s'.")%(
160
config.get('terminal', 'colorb'),
161
config.get('DEFAULT', 'colorb'))
162
config.set('terminal','colorb',config.get('DEFAULT', 'colorb'))
163
config_color_back = gtk.gdk.color_parse(config.get('DEFAULT', 'colorb'))
139
164
_vte.set_colors(config_color_fore, config_color_back, palette)
141
166
config_encoding = config.get('terminal', 'encoding')
167
if config_encoding.upper() not in [ enc.upper() for enc, desc in utils.encodings]:
168
print _("WARNING: Invalid value for property '%s':"
169
" got '%s', using default '%s'")%(
172
config.get('DEFAULT', 'encoding'))
173
config.set('terminal','encoding',config.get('DEFAULT', 'encoding'))
174
config_encoding = config.get('DEFAULT', 'encoding')
142
175
_vte.set_encoding(config_encoding)