Permalink
Browse files

more abstract panel api with more consitent behavior

  • Loading branch information...
1 parent 9d90a2a commit c0728c297d245bf8ff035b4f4ebeb01182c5d951 @baverman committed Nov 13, 2011
Showing with 59 additions and 40 deletions.
  1. +3 −15 snaked/core/console.py
  2. +50 −8 snaked/core/window.py
  3. +4 −8 snaked/plugins/python/__init__.py
  4. +2 −9 snaked/plugins/python/pytest_runner.py
@@ -31,8 +31,8 @@ def get_console_widget(editor):
w.view.modify_font(pango.FontDescription(editor.conf['CONSOLE_FONT']))
console_widget.append(w)
-
- editor.window.append_panel(w, on_console_popup)
+ editor.window.append_panel(w)\
+ .on_activate(lambda w: w.view.grab_focus())
return w
def create_console_widget():
@@ -50,19 +50,7 @@ def create_console_widget():
def toggle_console(editor):
console = get_console_widget(editor)
-
- if console.props.visible:
- console.hide()
- editor.view.grab_focus()
- else:
- editor.window.popup_panel(console, editor)
-
-def hide(widget, editor):
- widget.hide()
- editor.view.grab_focus()
-
-def on_console_popup(widget, editor):
- editor.window.push_escape(Escapable(hide, widget, editor))
+ editor.window.popup_panel(console)
def unblock_fd(fd):
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
View
@@ -47,6 +47,29 @@ def init(injector):
ctx.bind_accel('toggle-tabs-visibility', 'Window/Toggle ta_bs', '<Alt>F11', Window.toggle_tabs)
+class PanelHandler(object):
+ def __init__(self, widget):
+ self.widget = widget
+ self.activate_handler = None
+ self.popup_handler = None
+
+ def on_activate(self, cb):
+ self.activate_handler = cb
+ return self
+
+ def on_popup(self, cb):
+ self.popup_handler = cb
+ return self
+
+ def activate(self, *args):
+ if self.activate_handler:
+ self.activate_handler(*((self.widget,) + args))
+
+ def popup(self, *args):
+ if self.popup_handler:
+ self.popup_handler(*((self.widget,) + args))
+
+
class Window(gtk.Window):
def __init__(self, manager, window_conf):
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
@@ -282,10 +305,11 @@ def toggle_tabs(self):
self.note.set_show_tabs(not self.note.get_show_tabs())
self.window_conf['show-tabs'] = self.note.get_show_tabs()
- def append_panel(self, widget, on_popup):
- self.panels[widget] = on_popup
+ def append_panel(self, widget):
+ v = self.panels[widget] = PanelHandler(widget)
+ return v
- def popup_panel(self, widget, *args):
+ def popup_panel(self, widget, activate=False, *args):
if widget in self.panels:
for w in self.panels:
if w is not widget and w is self.main_pane.get_child2():
@@ -296,11 +320,16 @@ def popup_panel(self, widget, *args):
_, _, _, wh, _ = self.window.get_geometry()
self.main_pane.set_position(wh - self.window_conf.get('panel-height', 200))
- self.main_pane.add2(widget)
- widget.show()
+ if not widget.get_visible():
+ if self.main_pane.get_child2() is not widget:
+ self.main_pane.add2(widget)
+ widget.show()
+ self.panels[widget].popup(*args)
+ else:
+ activate = True
- if self.panels[widget]:
- self.panels[widget](widget, *args)
+ if activate:
+ self.panels[widget].activate(*args)
def on_page_reordered(self, note, child, num):
for i, e in enumerate(self.editors):
@@ -359,4 +388,17 @@ def push_escape(self, obj):
return self.escape_manager.push(obj)
def process_escape(self):
- self.escape_manager.process()
+ if not self.escape_manager.process():
+ widget = self.main_pane.get_child2()
+ if widget:
+ if widget.get_visible():
+ if widget.get_focus_child():
+ e = self.active_editor
+ if e:
+ e.view.grab_focus()
+ else:
+ widget.hide()
+
+ return True
+
+ return False
@@ -221,18 +221,14 @@ def get_pytest_runner(editor):
from pytest_runner import TestRunner
test_runner.append(TestRunner())
- editor.window.append_panel(test_runner[0].panel, test_runner[0].on_popup)
+ editor.window.append_panel(test_runner[0].panel)\
+ .on_activate(test_runner[0].on_activate)
+
return test_runner[0]
def toggle_test_panel(editor):
runner = get_pytest_runner(editor)
- if runner.panel.get_focus_child():
- runner.hide()
- editor.view.grab_focus()
- else:
- runner.editor_ref = weakref.ref(editor)
- editor.window.popup_panel(runner.panel)
- runner.tests_view.grab_focus()
+ editor.window.popup_panel(runner.panel)
def pytest_available(editor):
try:
@@ -1,4 +1,3 @@
-import sys
import os.path
import weakref
@@ -10,7 +9,6 @@
from uxie.utils import join_to_file_dir
from uxie.misc import BuilderAware
-from uxie.escape import Escapable
from . import pytest_launcher
from .utils import get_executable
@@ -91,11 +89,6 @@ def run(self, editor, project_root, matches='', files=[]):
def show(self):
self.editor_ref().window.popup_panel(self.panel)
- def hide(self, editor=None, *args):
- self.panel.hide()
- if editor:
- editor.view.grab_focus()
-
def find_common_parent(self, nodes):
if not nodes:
return ''
@@ -266,8 +259,8 @@ def on_tests_view_cursor_changed(self, view):
self.buffer.set_text('')
self.buffer.node = None
- def on_popup(self, widget):
- self.editor_ref().window.push_escape(Escapable(self.hide))
+ def on_activate(self, widget):
+ self.tests_view.grab_focus()
def on_tests_view_row_activated(self, view, path, *args):
iter = self.tests.get_iter(path)

0 comments on commit c0728c2

Please sign in to comment.