Merge branch 'master' of git+ssh://dev.laptop.org/git/sugar
This commit is contained in:
commit
ef369e97de
@ -36,23 +36,26 @@ def _get_display_number():
|
||||
log.info( "Attempting to find free port for X11 (Xephyr)" )
|
||||
retries = 20
|
||||
display_number = 1
|
||||
display_is_free = False
|
||||
display_is_free = False
|
||||
|
||||
while not display_is_free and retries > 0:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
try:
|
||||
s.connect(('127.0.0.1', 6000 + display_number))
|
||||
s.close()
|
||||
lockstr = "/tmp/.X%d-lock" % display_number
|
||||
if not os.path.exists(lockstr):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
try:
|
||||
s.connect(('127.0.0.1', 6000 + display_number))
|
||||
s.close()
|
||||
except:
|
||||
display_is_free = True
|
||||
break
|
||||
|
||||
display_number += 1
|
||||
retries -= 1
|
||||
except:
|
||||
display_is_free = True
|
||||
display_number += 1
|
||||
retries -= 1
|
||||
|
||||
if display_is_free:
|
||||
log.info(
|
||||
' Found free port: #%s (%s)',
|
||||
display_number, display_number+6000
|
||||
log.info(
|
||||
' Found free port: #%s (%s)',
|
||||
display_number, display_number+6000
|
||||
)
|
||||
return display_number
|
||||
else:
|
||||
|
@ -44,7 +44,6 @@ class Palette(gtk.Window):
|
||||
_WIN_BORDER = 5
|
||||
|
||||
def __init__(self):
|
||||
|
||||
gobject.GObject.__init__(self, type=gtk.WINDOW_POPUP)
|
||||
gtk.Window.__init__(self)
|
||||
|
||||
@ -75,25 +74,14 @@ class Palette(gtk.Window):
|
||||
vbox.show()
|
||||
|
||||
# Widget events
|
||||
self.connect('motion-notify-event', self._mouse_over_widget)
|
||||
self.connect('leave-notify-event', self._mouse_out_widget)
|
||||
self.connect('button-press-event', self._close_palette)
|
||||
self.connect('key-press-event', self._on_key_press_event)
|
||||
self.connect('motion-notify-event', self._mouse_over_widget_cb)
|
||||
self.connect('leave-notify-event', self._mouse_out_widget_cb)
|
||||
self.connect('button-press-event', self._close_palette_cb)
|
||||
self.connect('key-press-event', self._on_key_press_event_cb)
|
||||
|
||||
self.set_border_width(self._WIN_BORDER)
|
||||
self.add(vbox)
|
||||
|
||||
def _is_mouse_out(self, window, event):
|
||||
# If we're clicking outside of the Palette
|
||||
# return True
|
||||
if (event.window != self.window or
|
||||
(tuple(self.allocation.intersect(
|
||||
gdk.Rectangle(x=int(event.x), y=int(event.y),
|
||||
width=1, height=1)))) == (0, 0, 0, 0)):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def do_set_property(self, pspec, value):
|
||||
|
||||
if pspec.name == 'parent':
|
||||
@ -145,10 +133,6 @@ class Palette(gtk.Window):
|
||||
|
||||
self.move(move_x, move_y)
|
||||
|
||||
def _close_palette(self, widget=None, event=None):
|
||||
gtk.gdk.pointer_ungrab()
|
||||
self.hide()
|
||||
|
||||
def set_primary_state(self, label, accel_path=None):
|
||||
if accel_path != None:
|
||||
item = gtk.MenuItem(label)
|
||||
@ -168,15 +152,27 @@ class Palette(gtk.Window):
|
||||
widget.show()
|
||||
|
||||
def append_button(self, button):
|
||||
button.connect('released', self._close_palette)
|
||||
button.connect('released', self._close_palette_cb)
|
||||
self._button_bar.pack_start(button, True, True, self._PADDING)
|
||||
button.show()
|
||||
|
||||
def display(self, button):
|
||||
def popup(self):
|
||||
self.show()
|
||||
self.set_position()
|
||||
self._pointer_grab()
|
||||
|
||||
# PRIVATE METHODS
|
||||
|
||||
def _is_mouse_out(self, window, event):
|
||||
# If we're clicking outside of the Palette
|
||||
# return True
|
||||
event_rect = gdk.Rectangle(event.x, event.y, 1, 1)
|
||||
|
||||
if (event.window != self.window or self.allocation.intersect(event_rect).width==0):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def _pointer_grab(self):
|
||||
gtk.gdk.pointer_grab(self.window, owner_events=False,
|
||||
event_mask=gtk.gdk.BUTTON_PRESS_MASK |
|
||||
@ -187,15 +183,24 @@ class Palette(gtk.Window):
|
||||
|
||||
gdk.keyboard_grab(self.window, False)
|
||||
|
||||
def _mouse_out_widget(self, widget, event):
|
||||
# SIGNAL HANDLERS
|
||||
|
||||
# Release the GDK pointer and hide the palette
|
||||
def _close_palette_cb(self, widget=None, event=None):
|
||||
gtk.gdk.pointer_ungrab()
|
||||
self.hide()
|
||||
|
||||
# Mouse is out of the widget
|
||||
def _mouse_out_widget_cb(self, widget, event):
|
||||
if (widget == self) and self._is_mouse_out(widget, event):
|
||||
self._pointer_grab()
|
||||
|
||||
def _mouse_over_widget(self, widget, event):
|
||||
# Mouse inside the widget
|
||||
def _mouse_over_widget_cb(self, widget, event):
|
||||
gtk.gdk.pointer_ungrab()
|
||||
|
||||
def _on_key_press_event(self, window, event):
|
||||
|
||||
# Some key is pressed
|
||||
def _on_key_press_event_cb(self, window, event):
|
||||
# Escape or Alt+Up: Close
|
||||
# Enter, Return or Space: Select
|
||||
|
||||
@ -204,6 +209,6 @@ class Palette(gtk.Window):
|
||||
if (keyval == keysyms.Escape or
|
||||
((keyval == keysyms.Up or keyval == keysyms.KP_Up) and
|
||||
state == gdk.MOD1_MASK)):
|
||||
self._close_palette()
|
||||
self._close_palette_cb()
|
||||
elif keyval == keysyms.Tab:
|
||||
self._close_palette()
|
||||
|
@ -31,10 +31,14 @@ class ToolButton(gtk.ToolButton):
|
||||
icon.show()
|
||||
|
||||
def set_palette(self, palette):
|
||||
self.connect('clicked', palette.display)
|
||||
palette.props.parent = self
|
||||
palette.props.alignment = ALIGNMENT_BOTTOM_LEFT
|
||||
|
||||
self._palette = palette
|
||||
self._palette.props.parent = self
|
||||
self._palette.props.alignment = ALIGNMENT_BOTTOM_LEFT
|
||||
self.connect('clicked', self._display_palette_cb)
|
||||
|
||||
def set_tooltip(self, text):
|
||||
tp = gtk.Tooltips()
|
||||
self.set_tooltip(tp, text, text)
|
||||
|
||||
def _display_palette_cb(self, widget):
|
||||
self._palette.popup()
|
||||
|
Loading…
Reference in New Issue
Block a user