summaryrefslogtreecommitdiff
path: root/caribou/ui/window.py
diff options
context:
space:
mode:
Diffstat (limited to 'caribou/ui/window.py')
-rw-r--r--caribou/ui/window.py115
1 files changed, 69 insertions, 46 deletions
diff --git a/caribou/ui/window.py b/caribou/ui/window.py
index 0ed5c90..78b2c61 100644
--- a/caribou/ui/window.py
+++ b/caribou/ui/window.py
@@ -22,34 +22,35 @@
import animation
from caribou import data_path
-import gconf
-import gtk
-import gtk.gdk as gdk
+from gi.repository import GConf
+from gi.repository import Gtk
+from gi.repository import Gdk
import opacity
import os
import sys
+import gobject
CARIBOU_GCONF_LAYOUT_KEY = '/apps/caribou/osk/layout'
CARIBOU_LAYOUT_DIR = 'keyboards'
-class CaribouWindow(gtk.Window):
+class CaribouWindow(Gtk.Window):
__gtype_name__ = "CaribouWindow"
-
def __init__(self, text_entry_mech, default_placement=None,
min_alpha=1.0, max_alpha=1.0, max_distance=100):
- super(CaribouWindow, self).__init__(gtk.WINDOW_POPUP)
+ gobject.GObject.__init__(self, type=Gtk.WindowType.POPUP)
+
self.set_name("CaribouWindow")
- self._vbox = gtk.VBox()
+ self._vbox = Gtk.VBox()
self.add(self._vbox)
self.keyboard = text_entry_mech
- self._vbox.pack_start(text_entry_mech)
+ self._vbox.pack_start(text_entry_mech, True, True, 0)
self.connect("size-allocate", lambda w, a: self._update_position())
- self._gconf_client = gconf.client_get_default()
+ self._gconf_client = GConf.Client.get_default()
- self._cursor_location = gdk.Rectangle()
- self._entry_location = gdk.Rectangle()
+ self._cursor_location = Rectangle()
+ self._entry_location = Rectangle()
self._default_placement = default_placement or \
CaribouWindowPlacement()
@@ -61,7 +62,7 @@ class CaribouWindow(gtk.Window):
def destroy(self):
self.keyboard.destroy()
- super(gtk.Window, self).destroy()
+ super(Gtk.Window, self).destroy()
def set_cursor_location(self, cursor_location):
@@ -77,12 +78,12 @@ class CaribouWindow(gtk.Window):
self._update_position()
def _get_root_bbox(self):
- root_window = gdk.get_default_root_window()
- args = root_window.get_position() + root_window.get_size()
+ root_window = Gdk.get_default_root_window()
+ args = root_window.get_geometry()
- root_bbox = gdk.Rectangle(*args)
+ root_bbox = Rectangle(*args)
- current_screen = gtk.gdk.screen_get_default().get_number()
+ current_screen = Gdk.Screen.get_default().get_number()
for panel in self._gconf_client.all_dirs('/apps/panel/toplevels'):
orientation = self._gconf_client.get_string(panel+'/orientation')
size = self._gconf_client.get_int(panel+'/size')
@@ -114,9 +115,9 @@ class CaribouWindow(gtk.Window):
def _update_position(self):
x, y = self._calculate_position()
root_bbox = self._get_root_bbox()
- proposed_position = \
- gdk.Rectangle(x, y, self.allocation.width, self.allocation.height)
-
+ proposed_position = Rectangle(x, y, self.get_allocated_width(),
+ self.get_allocated_height())
+
x += self._default_placement.x.adjust_to_bounds(root_bbox, proposed_position)
y += self._default_placement.y.adjust_to_bounds(root_bbox, proposed_position)
self.move(x, y)
@@ -129,17 +130,21 @@ class CaribouWindow(gtk.Window):
elif axis_placement.stickto == CaribouWindowPlacement.ENTRY:
bbox = self._entry_location
- offset = axis_placement.get_offset(bbox)
+ offset = axis_placement.get_offset(bbox.x, bbox.y)
if axis_placement.align == CaribouWindowPlacement.END:
- offset += axis_placement.get_length(bbox)
+ offset += axis_placement.get_length(bbox.width, bbox.height)
if axis_placement.gravitate == CaribouWindowPlacement.INSIDE:
- offset -= axis_placement.get_length(self.allocation)
+ offset -= axis_placement.get_length(
+ self.get_allocated_width(),
+ self.get_allocated_height())
elif axis_placement.align == CaribouWindowPlacement.START:
if axis_placement.gravitate == CaribouWindowPlacement.OUTSIDE:
- offset -= axis_placement.get_length(self.allocation)
+ offset -= axis_placement.get_length(
+ self.get_allocated_width(),
+ self.get_allocated_height())
elif axis_placement.align == CaribouWindowPlacement.CENTER:
- offset += axis_placement.get_length(bbox)/2
+ offset += axis_placement.get_length(bbox.width, bbox.height)/2
return offset
@@ -163,18 +168,18 @@ class CaribouWindow(gtk.Window):
def show_all(self):
- gtk.Window.show_all(self)
+ Gtk.Window.show_all(self)
self.keyboard.show_all()
- def hide_all(self):
- self.keyboard.hide_all()
- gtk.Window.hide_all(self)
+ def hide(self):
+ self.keyboard.hide()
+ Gtk.Window.hide(self)
def _on_window_show(self, window):
child = self.get_child()
border = self.get_border_width()
- w, h = child.size_request()
- self.resize(w + border, h + border)
+ req = child.size_request()
+ self.resize(req.width + border, req.height + border)
class CaribouWindowDocked(CaribouWindow,
animation.AnimatedWindowBase,
@@ -202,15 +207,11 @@ class CaribouWindowDocked(CaribouWindow,
def _roll_in(self):
x, y = self.get_position()
self.move(x + self.allocation.width, y)
- return self.animated_move(x, y)
+ #return self.animated_move(x, y)
def _roll_out(self):
x, y = self.get_position()
- return self.animated_move(x + self.allocation.width, y)
-
- def hide_all(self):
- animation = self._roll_out()
- animation.connect('completed', lambda x: CaribouWindow.hide_all(self))
+ #return self.animated_move(x + self.allocation.width, y)
def hide(self):
animation = self._roll_out()
@@ -233,9 +234,8 @@ class CaribouWindowEntry(CaribouWindow):
def _calculate_axis(self, axis_placement, root_bbox):
offset = CaribouWindow._calculate_axis(self, axis_placement, root_bbox)
-
if axis_placement.axis == 'y':
- if offset + self.allocation.height > root_bbox.height + root_bbox.y:
+ if offset + self.get_allocated_height() > root_bbox.height + root_bbox.y:
new_axis_placement = axis_placement.copy(align=CaribouWindowPlacement.START)
offset = CaribouWindow._calculate_axis(self, new_axis_placement, root_bbox)
@@ -266,17 +266,20 @@ class CaribouWindowPlacement(object):
stickto or self.stickto,
gravitate or self.gravitate)
- def get_offset(self, bbox):
- return bbox.x if self.axis == 'x' else bbox.y
+ def get_offset(self, x, y):
+ return x if self.axis == 'x' else y
- def get_length(self, bbox):
- return bbox.width if self.axis == 'x' else bbox.height
+ def get_length(self, width, height):
+ return width if self.axis == 'x' else height
def adjust_to_bounds(self, root_bbox, child_bbox):
- child_vector_start = self.get_offset(child_bbox)
- child_vector_end = self.get_length(child_bbox) + child_vector_start
- root_vector_start = self.get_offset(root_bbox)
- root_vector_end = self.get_length(root_bbox) + root_vector_start
+ child_vector_start = self.get_offset(child_bbox.x, child_bbox.y)
+ child_vector_end = \
+ self.get_length(child_bbox.width, child_bbox.height) + \
+ child_vector_start
+ root_vector_start = self.get_offset(root_bbox.x, root_bbox.y)
+ root_vector_end = self.get_length(
+ root_bbox.width, root_bbox.height) + root_vector_start
if root_vector_end < child_vector_end:
return root_vector_end - child_vector_end
@@ -299,3 +302,23 @@ class CaribouWindowPlacement(object):
ystickto or self.CURSOR,
ygravitate or self.OUTSIDE)
+
+class Rectangle(object):
+ def __init__(self, x=0, y=0, width=0, height=0):
+ self.x = x
+ self.y = y
+ self.width = width
+ self.height = height
+
+if __name__ == "__main__":
+ import keyboard
+ import signal
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
+
+ w = CaribouWindowDocked(keyboard.CaribouKeyboard)
+ w.show_all()
+
+ try:
+ Gtk.main()
+ except KeyboardInterrupt:
+ Gtk.main_quit()