More cleanups
This commit is contained in:
parent
6d8b196abe
commit
400cbc29e5
@ -82,9 +82,6 @@ class Palette(gtk.Window):
|
|||||||
|
|
||||||
self.set_border_width(self._WIN_BORDER)
|
self.set_border_width(self._WIN_BORDER)
|
||||||
|
|
||||||
self._scr_width = gtk.gdk.screen_width()
|
|
||||||
self._scr_height = gtk.gdk.screen_height()
|
|
||||||
|
|
||||||
def do_set_property(self, pspec, value):
|
def do_set_property(self, pspec, value):
|
||||||
if pspec.name == 'invoker':
|
if pspec.name == 'invoker':
|
||||||
self._invoker = value
|
self._invoker = value
|
||||||
@ -93,7 +90,7 @@ class Palette(gtk.Window):
|
|||||||
else:
|
else:
|
||||||
raise AssertionError
|
raise AssertionError
|
||||||
|
|
||||||
def set_position(self):
|
def place(self):
|
||||||
# Automatic Alignment
|
# Automatic Alignment
|
||||||
if self._alignment == ALIGNMENT_AUTOMATIC:
|
if self._alignment == ALIGNMENT_AUTOMATIC:
|
||||||
# Trying Different types of ALIGNMENTS,
|
# Trying Different types of ALIGNMENTS,
|
||||||
@ -120,6 +117,8 @@ class Palette(gtk.Window):
|
|||||||
self.move(move_x, move_y)
|
self.move(move_x, move_y)
|
||||||
|
|
||||||
def _try_position(self, alignment):
|
def _try_position(self, alignment):
|
||||||
|
screen_width = gtk.gdk.screen_width()
|
||||||
|
screen_height = gtk.gdk.screen_height()
|
||||||
move_x, move_y = self._calc_position(alignment)
|
move_x, move_y = self._calc_position(alignment)
|
||||||
self._width, self._height = self.size_request()
|
self._width, self._height = self.size_request()
|
||||||
|
|
||||||
@ -135,8 +134,8 @@ class Palette(gtk.Window):
|
|||||||
else:
|
else:
|
||||||
plt_y -= (plt_y - move_y)
|
plt_y -= (plt_y - move_y)
|
||||||
|
|
||||||
if (plt_x < 0 or plt_x + self._width > self._scr_width) or \
|
if (plt_x < 0 or plt_x + self._width > screen_width) or \
|
||||||
(plt_y < 0 or plt_y + self._height > self._scr_height):
|
(plt_y < 0 or plt_y + self._height > screen_height):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
self.move(move_x, move_y)
|
self.move(move_x, move_y)
|
||||||
@ -193,26 +192,27 @@ class Palette(gtk.Window):
|
|||||||
|
|
||||||
def append_menu_item(self, item):
|
def append_menu_item(self, item):
|
||||||
self._separator.show()
|
self._separator.show()
|
||||||
self._menu_bar.append(item)
|
|
||||||
self._menu_bar.show()
|
self._menu_bar.show()
|
||||||
|
self._menu_bar.append(item)
|
||||||
|
item.show()
|
||||||
|
|
||||||
def set_content(self, widget):
|
def set_content(self, widget):
|
||||||
self._separator.show()
|
self._separator.show()
|
||||||
self._content.pack_start(widget, True, True, self._PADDING)
|
self._content.pack_start(widget, True, True, self._PADDING)
|
||||||
|
widget.show()
|
||||||
|
|
||||||
def append_button(self, button):
|
def append_button(self, button):
|
||||||
self._separator.show()
|
|
||||||
button.connect('released', self._close_palette_cb)
|
button.connect('released', self._close_palette_cb)
|
||||||
self._button_bar.pack_start(button, True, True, self._PADDING)
|
self._button_bar.pack_start(button, True, True, self._PADDING)
|
||||||
|
button.show()
|
||||||
|
|
||||||
# Display the palette and set the position on the screen
|
# Display the palette and set the position on the screen
|
||||||
def popup(self):
|
def popup(self):
|
||||||
self.realize()
|
self.realize()
|
||||||
self.set_position()
|
self.place()
|
||||||
self._pointer_ungrab()
|
|
||||||
|
|
||||||
def popdown(self):
|
def popdown(self):
|
||||||
self._pointer_ungrab()
|
gdk.keyboard_ungrab()
|
||||||
self.hide()
|
self.hide()
|
||||||
|
|
||||||
# PRIVATE METHODS
|
# PRIVATE METHODS
|
||||||
@ -227,12 +227,6 @@ class Palette(gtk.Window):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _pointer_ungrab(self):
|
|
||||||
gdk.keyboard_ungrab()
|
|
||||||
|
|
||||||
def _pointer_grab(self):
|
|
||||||
gdk.keyboard_grab(self.window, False)
|
|
||||||
|
|
||||||
# SIGNAL HANDLERS
|
# SIGNAL HANDLERS
|
||||||
|
|
||||||
# Release the GDK pointer and hide the palette
|
# Release the GDK pointer and hide the palette
|
||||||
@ -245,11 +239,11 @@ class Palette(gtk.Window):
|
|||||||
self._close_palette_cb()
|
self._close_palette_cb()
|
||||||
return
|
return
|
||||||
|
|
||||||
self._pointer_grab()
|
gdk.keyboard_grab(self.window, False)
|
||||||
|
|
||||||
# Mouse inside the widget
|
# Mouse inside the widget
|
||||||
def _mouse_over_widget_cb(self, widget, event):
|
def _mouse_over_widget_cb(self, widget, event):
|
||||||
self._pointer_ungrab()
|
gdk.keyboard_ungrab()
|
||||||
|
|
||||||
# Some key is pressed
|
# Some key is pressed
|
||||||
def _on_key_press_event_cb(self, window, event):
|
def _on_key_press_event_cb(self, window, event):
|
||||||
|
Loading…
Reference in New Issue
Block a user