feat: refactoring terminal file
This commit is contained in:
parent
24757a6922
commit
ed54a0d683
|
@ -844,7 +844,7 @@ class Terminal(Gtk.VBox):
|
|||
|
||||
def get_window_title(self):
|
||||
"""Return the window title"""
|
||||
return(self.vte.get_window_title() or str(self.command))
|
||||
return self.vte.get_window_title() or str(self.command)
|
||||
|
||||
def on_group_button_press(self, widget, event):
|
||||
"""Handler for the group button"""
|
||||
|
@ -885,13 +885,13 @@ class Terminal(Gtk.VBox):
|
|||
return True
|
||||
else:
|
||||
dbg('on_group_button_press: unknown group button interaction')
|
||||
return(False)
|
||||
return False
|
||||
|
||||
def on_keypress(self, widget, event):
|
||||
"""Handler for keyboard events"""
|
||||
if not event:
|
||||
dbg('Terminal::on_keypress: Called on %s with no event' % widget)
|
||||
return(False)
|
||||
return False
|
||||
|
||||
# FIXME: Does keybindings really want to live in Terminator()?
|
||||
mapping = self.terminator.keybindings.lookup(event)
|
||||
|
@ -908,10 +908,10 @@ class Terminal(Gtk.VBox):
|
|||
if isinstance(child, Terminal):
|
||||
# not a Notebook instance => a single tab is used
|
||||
# .get_n_pages() can not be used
|
||||
return(False)
|
||||
return False
|
||||
|
||||
if mapping == "hide_window":
|
||||
return(False)
|
||||
return False
|
||||
|
||||
if mapping and mapping not in ['close_window',
|
||||
'full_screen']:
|
||||
|
@ -922,12 +922,12 @@ class Terminal(Gtk.VBox):
|
|||
if (mapping == "copy" and event.get_state() & Gdk.ModifierType.CONTROL_MASK):
|
||||
if self.vte.get_has_selection():
|
||||
getattr(self, "key_" + mapping)()
|
||||
return(True)
|
||||
return True
|
||||
elif not self.config['smart_copy']:
|
||||
return(True)
|
||||
return True
|
||||
else:
|
||||
getattr(self, "key_" + mapping)()
|
||||
return(True)
|
||||
return True
|
||||
|
||||
# FIXME: This is all clearly wrong. We should be doing this better
|
||||
# maybe we can emit the key event and let Terminator() care?
|
||||
|
@ -941,7 +941,7 @@ class Terminal(Gtk.VBox):
|
|||
if groupsend == groupsend_type['all']:
|
||||
self.terminator.all_emit(self, 'key-press-event', event)
|
||||
|
||||
return(False)
|
||||
return False
|
||||
|
||||
def on_buttonpress(self, widget, event):
|
||||
"""Handler for mouse events"""
|
||||
|
@ -959,11 +959,11 @@ class Terminal(Gtk.VBox):
|
|||
middle_click = [self.paste_clipboard, (True, )]
|
||||
right_click = [self.popup_menu, (widget, event)]
|
||||
|
||||
### Ctrl-click event here.
|
||||
# Ctrl-click event here.
|
||||
if event.button == self.MOUSEBUTTON_LEFT:
|
||||
# Ctrl+leftclick on a URL should open it
|
||||
if event.get_state() & Gdk.ModifierType.CONTROL_MASK == Gdk.ModifierType.CONTROL_MASK:
|
||||
## Check new OSC-8 method first
|
||||
# Check new OSC-8 method first
|
||||
url = self.vte.hyperlink_check_event(event)
|
||||
dbg('url: %s' % url)
|
||||
if url:
|
||||
|
@ -986,9 +986,8 @@ class Terminal(Gtk.VBox):
|
|||
gtk_settings.set_property('gtk-enable-primary-paste', primary_state)
|
||||
else:
|
||||
middle_click[0](*middle_click[1])
|
||||
return(True)
|
||||
return True
|
||||
return Vte.Terminal.do_button_press_event(self.vte, event)
|
||||
#return(True)
|
||||
elif event.button == self.MOUSEBUTTON_RIGHT:
|
||||
# rightclick should display a context menu if Ctrl is not pressed,
|
||||
# plus either the app is not interested in mouse events or Shift is pressed
|
||||
|
@ -998,9 +997,8 @@ class Terminal(Gtk.VBox):
|
|||
right_click[0](*right_click[1])
|
||||
else:
|
||||
right_click[0](*right_click[1])
|
||||
return(True)
|
||||
|
||||
return(False)
|
||||
return True
|
||||
return False
|
||||
|
||||
def on_mousewheel(self, widget, event):
|
||||
"""Handler for modifier + mouse wheel scroll events"""
|
||||
|
@ -1009,7 +1007,7 @@ class Terminal(Gtk.VBox):
|
|||
if event.state & Gdk.ModifierType.CONTROL_MASK == Gdk.ModifierType.CONTROL_MASK:
|
||||
# Zoom the terminal(s) in or out if not disabled in config
|
||||
if self.config["disable_mousewheel_zoom"] is True:
|
||||
return (False)
|
||||
return False
|
||||
# Choice of target terminals depends on Shift and Super modifiers
|
||||
if event.state & Gdk.ModifierType.MOD4_MASK == Gdk.ModifierType.MOD4_MASK:
|
||||
targets = self.terminator.terminals
|
||||
|
@ -1020,20 +1018,20 @@ class Terminal(Gtk.VBox):
|
|||
if event.direction == Gdk.ScrollDirection.UP or SMOOTH_SCROLL_UP:
|
||||
for target in targets:
|
||||
target.zoom_in()
|
||||
return (True)
|
||||
return True
|
||||
elif event.direction == Gdk.ScrollDirection.DOWN or SMOOTH_SCROLL_DOWN:
|
||||
for target in targets:
|
||||
target.zoom_out()
|
||||
return (True)
|
||||
return True
|
||||
if event.state & Gdk.ModifierType.SHIFT_MASK == Gdk.ModifierType.SHIFT_MASK:
|
||||
# Shift + mouse wheel up/down
|
||||
if event.direction == Gdk.ScrollDirection.UP or SMOOTH_SCROLL_UP:
|
||||
self.scroll_by_page(-1)
|
||||
return (True)
|
||||
return True
|
||||
elif event.direction == Gdk.ScrollDirection.DOWN or SMOOTH_SCROLL_DOWN:
|
||||
self.scroll_by_page(1)
|
||||
return (True)
|
||||
return(False)
|
||||
return True
|
||||
return False
|
||||
|
||||
def popup_menu(self, widget, event=None):
|
||||
"""Display the context menu"""
|
||||
|
@ -1069,12 +1067,13 @@ class Terminal(Gtk.VBox):
|
|||
_time, data):
|
||||
"""I have no idea what this does, drag and drop is a mystery. sorry."""
|
||||
selection_data.set(Gdk.atom_intern('vte', False), info,
|
||||
bytes(str(data.terminator.terminals.index(self)), 'utf-8'))
|
||||
bytes(str(data.terminator.terminals.index(self)),
|
||||
'utf-8'))
|
||||
|
||||
def on_drag_motion(self, widget, drag_context, x, y, _time, _data):
|
||||
"""*shrug*"""
|
||||
if not drag_context.list_targets() == [Gdk.atom_intern('vte', False)] and \
|
||||
(Gtk.targets_include_text(drag_context.list_targets()) or \
|
||||
(Gtk.targets_include_text(drag_context.list_targets()) or
|
||||
Gtk.targets_include_uri(drag_context.list_targets())):
|
||||
# copy text from another widget
|
||||
return
|
||||
|
@ -1101,7 +1100,7 @@ class Terminal(Gtk.VBox):
|
|||
bottommiddle = (alloc.width/2, alloc.height)
|
||||
middleleft = (0, alloc.height/2)
|
||||
middleright = (alloc.width, alloc.height/2)
|
||||
#print "%f %f %d %d" %(coef1, coef2, b1,b2)
|
||||
|
||||
coord = ()
|
||||
if pos == "right":
|
||||
coord = (topright, topmiddle, bottommiddle, bottomright)
|
||||
|
@ -1124,9 +1123,8 @@ class Terminal(Gtk.VBox):
|
|||
|
||||
def background_draw(self, widget, cr):
|
||||
if not self.config['background_type'] == 'image' or not self.background_image:
|
||||
return(False)
|
||||
#if not self.background_image:
|
||||
# return(False)
|
||||
return False
|
||||
|
||||
rect = self.vte.get_allocation()
|
||||
xratio = float(rect.width) / float(self.background_image.get_width())
|
||||
yratio = float(rect.height) / float(self.background_image.get_height())
|
||||
|
@ -1140,7 +1138,7 @@ class Terminal(Gtk.VBox):
|
|||
|
||||
def on_draw(self, widget, context):
|
||||
if not widget._draw_data:
|
||||
return(False)
|
||||
return False
|
||||
|
||||
color = widget._draw_data['color']
|
||||
coord = widget._draw_data['coord']
|
||||
|
@ -1152,13 +1150,13 @@ class Terminal(Gtk.VBox):
|
|||
context.line_to(i[0], i[1])
|
||||
|
||||
context.fill()
|
||||
return(False)
|
||||
return False
|
||||
|
||||
def on_drag_data_received(self, widget, drag_context, x, y, selection_data,
|
||||
info, _time, data):
|
||||
"""Something has been dragged into the terminal. Handle it as either a
|
||||
URL or another terminal."""
|
||||
### FIXME this code is a mess that I don't quite understand how it works.
|
||||
# FIXME this code is a mess that I don't quite understand how it works.
|
||||
dbg('drag data received of type: %s' % (selection_data.get_data_type()))
|
||||
# print(selection_data.get_urls())
|
||||
if Gtk.targets_include_text(drag_context.list_targets()) or \
|
||||
|
@ -1168,7 +1166,7 @@ class Terminal(Gtk.VBox):
|
|||
# https://bugs.launchpad.net/terminator/+bug/1518705
|
||||
if info == self.TARGET_TYPE_MOZ:
|
||||
txt = txt.decode('utf-16')
|
||||
### KDE ends it's text/x-moz-url text with CRLF, :shrug:
|
||||
# KDE ends it's text/x-moz-url text with CRLF, :shrug:
|
||||
if not txt.endswith('\r\n'):
|
||||
txt = txt.split('\n')[0]
|
||||
else:
|
||||
|
@ -1189,7 +1187,7 @@ class Terminal(Gtk.VBox):
|
|||
'\'\\\'\''))
|
||||
str += fname + ' '
|
||||
txt = str
|
||||
### Never send a CRLF to the terminal from here
|
||||
# Never send a CRLF to the terminal from here
|
||||
txt = txt.rstrip('\r\n')
|
||||
for term in self.terminator.get_target_terms(self):
|
||||
term.feed(txt.encode())
|
||||
|
@ -1327,7 +1325,7 @@ class Terminal(Gtk.VBox):
|
|||
def deferred_on_vte_size_allocate(self, widget, allocation):
|
||||
# widget & allocation are not used in on_vte_size_allocate, so we
|
||||
# can use the on_vte_size_allocate instead of duplicating the code
|
||||
if self.pending_on_vte_size_allocate == True:
|
||||
if self.pending_on_vte_size_allocate:
|
||||
return
|
||||
self.pending_on_vte_size_allocate = True
|
||||
GObject.idle_add(self.do_deferred_on_vte_size_allocate, widget, allocation)
|
||||
|
@ -1351,22 +1349,21 @@ class Terminal(Gtk.VBox):
|
|||
sloppy = self.config.get_system_focus() in ['sloppy', 'mouse']
|
||||
elif self.config['focus'] in ['sloppy', 'mouse']:
|
||||
sloppy = True
|
||||
if sloppy == True and self.titlebar.editing() == False:
|
||||
if sloppy and self.titlebar.editing() == False:
|
||||
term.grab_focus()
|
||||
return(False)
|
||||
return False
|
||||
|
||||
def get_zoom_data(self):
|
||||
"""Return a dict of information for Window"""
|
||||
data = {}
|
||||
data['old_font'] = self.vte.get_font().copy()
|
||||
data['old_char_height'] = self.vte.get_char_height()
|
||||
data['old_char_width'] = self.vte.get_char_width()
|
||||
data['old_allocation'] = self.vte.get_allocation()
|
||||
data['old_columns'] = self.vte.get_column_count()
|
||||
data['old_rows'] = self.vte.get_row_count()
|
||||
data['old_parent'] = self.get_parent()
|
||||
data = {'old_font': self.vte.get_font().copy(),
|
||||
'old_char_height': self.vte.get_char_height(),
|
||||
'old_char_width': self.vte.get_char_width(),
|
||||
'old_allocation': self.vte.get_allocation(),
|
||||
'old_columns': self.vte.get_column_count(),
|
||||
'old_rows': self.vte.get_row_count(),
|
||||
'old_parent': self.get_parent()}
|
||||
|
||||
return(data)
|
||||
return data
|
||||
|
||||
def zoom_scale(self, widget, allocation, old_data):
|
||||
"""Scale our font correctly based on how big we are not vs before"""
|
||||
|
@ -1410,7 +1407,7 @@ class Terminal(Gtk.VBox):
|
|||
except TypeError:
|
||||
prop = False
|
||||
|
||||
return(prop)
|
||||
return prop
|
||||
|
||||
def zoom(self, widget=None):
|
||||
"""Zoom ourself to fill the window"""
|
||||
|
@ -1434,11 +1431,11 @@ class Terminal(Gtk.VBox):
|
|||
shell = None
|
||||
command = None
|
||||
|
||||
if self.terminator.doing_layout == True:
|
||||
if self.terminator.doing_layout:
|
||||
dbg('still laying out, refusing to spawn a child')
|
||||
return
|
||||
|
||||
if respawn == False:
|
||||
if respawn is False:
|
||||
self.vte.grab_focus()
|
||||
|
||||
options = self.config.options_get()
|
||||
|
@ -1483,18 +1480,16 @@ class Terminal(Gtk.VBox):
|
|||
|
||||
if shell is None:
|
||||
self.vte.feed(_('Unable to find a shell'))
|
||||
return(-1)
|
||||
return -1
|
||||
|
||||
try:
|
||||
os.putenv('WINDOWID', '%s' % self.vte.get_parent_window().xid)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
envv = []
|
||||
envv.append('TERM=%s' % self.config['term'])
|
||||
envv.append('COLORTERM=%s' % self.config['colorterm'])
|
||||
envv.append('PWD=%s' % self.cwd)
|
||||
envv.append('TERMINATOR_UUID=%s' % self.uuid.urn)
|
||||
envv = ['TERM=%s' % self.config['term'],
|
||||
'COLORTERM=%s' % self.config['colorterm'], 'PWD=%s' % self.cwd,
|
||||
'TERMINATOR_UUID=%s' % self.uuid.urn]
|
||||
if self.terminator.dbus_name:
|
||||
envv.append('TERMINATOR_DBUS_NAME=%s' % self.terminator.dbus_name)
|
||||
if self.terminator.dbus_path:
|
||||
|
@ -1516,7 +1511,7 @@ class Terminal(Gtk.VBox):
|
|||
|
||||
if self.pid == -1:
|
||||
self.vte.feed(_('Unable to start shell:') + shell)
|
||||
return(-1)
|
||||
return -1
|
||||
|
||||
def prepare_url(self, urlmatch):
|
||||
"""Prepare a URL from a VTE match"""
|
||||
|
@ -1547,11 +1542,11 @@ class Terminal(Gtk.VBox):
|
|||
except Exception as ex:
|
||||
err('Exception occurred preparing URL: %s' % ex)
|
||||
|
||||
return(url)
|
||||
return url
|
||||
|
||||
def open_url(self, url, prepare=False):
|
||||
"""Open a given URL, conditionally unpacking it from a VTE match"""
|
||||
if prepare == True:
|
||||
if prepare:
|
||||
url = self.prepare_url(url)
|
||||
dbg('open_url: URL: %s (prepared: %s)' % (url, prepare))
|
||||
|
||||
|
@ -1614,7 +1609,7 @@ class Terminal(Gtk.VBox):
|
|||
|
||||
def zoom_orig(self):
|
||||
"""Restore original font size"""
|
||||
if self.config['use_system_font'] == True:
|
||||
if self.config['use_system_font']:
|
||||
font = self.config.get_system_mono_font()
|
||||
else:
|
||||
font = self.config['font']
|
||||
|
@ -1632,25 +1627,25 @@ class Terminal(Gtk.VBox):
|
|||
col, row = self.vte.get_cursor_position()
|
||||
width = self.vte.get_char_width()
|
||||
height = self.vte.get_char_height()
|
||||
return((col * width, row * height))
|
||||
return col * width, row * height
|
||||
|
||||
def get_font_size(self):
|
||||
"""Return the width/height of our font"""
|
||||
return((self.vte.get_char_width(), self.vte.get_char_height()))
|
||||
return self.vte.get_char_width(), self.vte.get_char_height()
|
||||
|
||||
def get_size(self):
|
||||
"""Return the column/rows of the terminal"""
|
||||
return((self.vte.get_column_count(), self.vte.get_row_count()))
|
||||
return self.vte.get_column_count(), self.vte.get_row_count()
|
||||
|
||||
def on_bell(self, widget):
|
||||
"""Set the urgency hint/icon/flash for our window"""
|
||||
if self.config['urgent_bell'] == True:
|
||||
if self.config['urgent_bell']:
|
||||
window = self.get_toplevel()
|
||||
if window.is_toplevel():
|
||||
window.set_urgency_hint(True)
|
||||
if self.config['icon_bell'] == True:
|
||||
if self.config['icon_bell']:
|
||||
self.titlebar.icon_bell()
|
||||
if self.config['visible_bell'] == True:
|
||||
if self.config['visible_bell']:
|
||||
# Repurposed the code used for drag and drop overlay to provide a visual terminal flash
|
||||
alloc = widget.get_allocation()
|
||||
|
||||
|
@ -1676,17 +1671,14 @@ class Terminal(Gtk.VBox):
|
|||
GObject.timeout_add(100, self.on_bell_cleanup, widget, alloc)
|
||||
|
||||
def on_bell_cleanup(self, widget, alloc):
|
||||
'''Queue a redraw to clear the visual flash overlay'''
|
||||
"""Queue a redraw to clear the visual flash overlay"""
|
||||
widget.queue_draw_area(0, 0, alloc.width, alloc.height)
|
||||
widget.get_window().process_updates(True)
|
||||
return False
|
||||
|
||||
def describe_layout(self, count, parent, global_layout, child_order):
|
||||
"""Describe our layout"""
|
||||
layout = {}
|
||||
layout['type'] = 'Terminal'
|
||||
layout['parent'] = parent
|
||||
layout['order'] = child_order
|
||||
layout = {'type': 'Terminal', 'parent': parent, 'order': child_order}
|
||||
if self.group:
|
||||
layout['group'] = self.group
|
||||
profile = self.get_profile()
|
||||
|
@ -1700,7 +1692,7 @@ class Terminal(Gtk.VBox):
|
|||
name = 'terminal%d' % count
|
||||
count = count + 1
|
||||
global_layout[name] = layout
|
||||
return(count)
|
||||
return count
|
||||
|
||||
def create_layout(self, layout):
|
||||
"""Apply our layout"""
|
||||
|
@ -1739,7 +1731,8 @@ class Terminal(Gtk.VBox):
|
|||
adjustment.set_value(min(value, bottom))
|
||||
|
||||
def get_allocation(self):
|
||||
"""Get a real allocation which includes the bloody x and y coordinates (grumble, grumble)"""
|
||||
"""Get a real allocation which includes the bloody x and y coordinates
|
||||
(grumble, grumble) """
|
||||
alloc = super(Terminal, self).get_allocation()
|
||||
rv = self.translate_coordinates(self.get_toplevel(), 0, 0)
|
||||
if rv:
|
||||
|
@ -2014,5 +2007,6 @@ class Terminal(Gtk.VBox):
|
|||
|
||||
# End key events
|
||||
|
||||
|
||||
GObject.type_register(Terminal)
|
||||
# vim: set expandtab ts=4 sw=4:
|
||||
|
|
Loading…
Reference in New Issue