1 # -*- coding: utf-8 -*-
3 # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
4 #Copyright (c) 2005-2006 The PIDA Project
6 #Permission is hereby granted, free of charge, to any person obtaining a copy
7 #of this software and associated documentation files (the "Software"), to deal
8 #in the Software without restriction, including without limitation the rights
9 #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 #copies of the Software, and to permit persons to whom the Software is
11 #furnished to do so, subject to the following conditions:
13 #The above copyright notice and this permission notice shall be included in
14 #all copies or substantial portions of the Software.
16 #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 ''' A library to embed vim in a gtk socket '''
35 class vim_embed(object):
37 HAS_CONTROL_BOX
= False
41 def init(self
, command
='gvim', args
=[]):
42 self
.__servername
= self
.__generate
_servername
()
45 self
.r_cb_plugged
= None
46 self
.r_cb_unplugged
= None
52 self
.widget
.pack_start(eb
)
53 eb
.add_events(gtk
.gdk
.KEY_PRESS_MASK
)
57 return socket
.get_id()
59 def __generate_servername(self
):
60 return 'PIDA_EMBEDDED_%s' % time
.time()
62 def get_servername(self
):
63 return self
.__servername
64 servername
= property(get_servername
)
66 def should_remove(self
):
67 self
.service
.remove_attempt()
70 def run(self
, command
):
71 self
.command
= command
73 args
= self
.args
[:] # a copy
74 args
.extend(['--socketid', '%s' % xid
])
78 popen
= subprocess
.Popen([self
.command
, '--servername',
79 self
.servername
, '--cmd',
80 'let PIDA_EMBEDDED=1'] + args
,
85 def grab_input_focus(self
):
86 self
.__eb
.child_focus(gtk
.DIR_TAB_FORWARD
)
88 class VimEmbedWidget(gtk
.EventBox
):
90 def __init__(self
, command
, script_path
, args
=[]):
91 gtk
.EventBox
.__init
__(self
)
92 self
._servername
= self
._generate
_servername
()
93 self
._command
= command
94 self
._init
_script
= script_path
97 self
.r_cb_plugged
= None
98 self
.r_cb_unplugged
= None
101 def _create_ui(self
):
102 socket
= gtk
.Socket()
103 self
.add_events(gtk
.gdk
.KEY_PRESS_MASK
)
106 return socket
.get_id()
108 def _generate_servername(self
):
109 return 'PIDA_EMBEDDED_%s' % time
.time()
111 def get_server_name(self
):
112 return self
._servername
114 def should_remove(self
):
115 self
.service
.remove_attempt()
119 xid
= self
._create
_ui
()
120 args
= self
.args
[:] # a copy
121 args
.extend(['--socketid', '%s' % xid
])
126 popen
= subprocess
.Popen(
128 '--servername', self
.get_server_name(),
129 '--cmd', 'let PIDA_EMBEDDED=1',
130 '-c', 'so %s' % self
._init
_script
140 def grab_input_focus(self
):
141 self
.child_focus(gtk
.DIR_TAB_FORWARD
)