2006-06-14 22:30:53 +02:00
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gtk
|
2006-06-15 01:00:56 +02:00
|
|
|
import gobject
|
2006-06-14 22:30:53 +02:00
|
|
|
|
2006-06-20 09:34:14 +02:00
|
|
|
SM_SPACE_PROPORTIONAL = 0
|
|
|
|
SM_STEP = 1
|
|
|
|
|
2006-06-23 18:29:16 +02:00
|
|
|
#SLIDING_TIMEOUT = 50
|
|
|
|
#SLIDING_MODE = SM_SPACE_PROPORTIONAL
|
2006-06-20 09:34:14 +02:00
|
|
|
|
2006-06-23 18:29:16 +02:00
|
|
|
SLIDING_TIMEOUT = 10
|
|
|
|
SLIDING_MODE = SM_STEP
|
|
|
|
SLIDING_STEP = 0.05
|
2006-06-20 09:34:14 +02:00
|
|
|
|
2006-06-14 22:30:53 +02:00
|
|
|
class WindowManager:
|
|
|
|
__managers_list = []
|
|
|
|
|
|
|
|
CENTER = 0
|
|
|
|
LEFT = 1
|
|
|
|
RIGHT = 2
|
2006-06-15 05:24:11 +02:00
|
|
|
TOP = 3
|
|
|
|
BOTTOM = 4
|
2006-06-14 22:30:53 +02:00
|
|
|
|
|
|
|
ABSOLUTE = 0
|
|
|
|
SCREEN_RELATIVE = 1
|
2006-06-15 01:00:56 +02:00
|
|
|
|
2006-06-14 22:30:53 +02:00
|
|
|
def __init__(self, window):
|
|
|
|
self._window = window
|
2006-06-19 21:31:18 +02:00
|
|
|
self._sliding_pos = 0
|
2006-06-15 23:31:41 +02:00
|
|
|
|
|
|
|
WindowManager.__managers_list.append(self)
|
|
|
|
|
2006-06-14 22:30:53 +02:00
|
|
|
window.connect("key-press-event", self.__key_press_event_cb)
|
2006-06-15 23:31:41 +02:00
|
|
|
|
2006-06-14 22:30:53 +02:00
|
|
|
def __key_press_event_cb(self, window, event):
|
|
|
|
manager = None
|
|
|
|
|
|
|
|
if event.keyval == gtk.keysyms.Left and \
|
|
|
|
event.state & gtk.gdk.CONTROL_MASK:
|
|
|
|
for wm in WindowManager.__managers_list:
|
|
|
|
if wm._position == WindowManager.LEFT:
|
|
|
|
manager = wm
|
|
|
|
|
2006-06-15 05:24:11 +02:00
|
|
|
if event.keyval == gtk.keysyms.Up and \
|
|
|
|
event.state & gtk.gdk.CONTROL_MASK:
|
|
|
|
for wm in WindowManager.__managers_list:
|
|
|
|
if wm._position == WindowManager.TOP:
|
|
|
|
manager = wm
|
|
|
|
|
2006-06-23 19:09:58 +02:00
|
|
|
if event.keyval == gtk.keysyms.Down and \
|
|
|
|
event.state & gtk.gdk.CONTROL_MASK:
|
|
|
|
for wm in WindowManager.__managers_list:
|
|
|
|
if wm._position == WindowManager.BOTTOM:
|
|
|
|
manager = wm
|
|
|
|
|
2006-06-14 22:30:53 +02:00
|
|
|
if manager and manager._window.get_property('visible'):
|
|
|
|
manager.slide_window_out()
|
|
|
|
elif manager:
|
|
|
|
manager.slide_window_in()
|
|
|
|
|
|
|
|
def set_width(self, width, width_type):
|
|
|
|
self._width = width
|
|
|
|
self._width_type = width_type
|
2006-06-23 21:26:33 +02:00
|
|
|
|
2006-06-14 22:30:53 +02:00
|
|
|
def set_height(self, height, height_type):
|
|
|
|
self._height = height
|
|
|
|
self._height_type = height_type
|
|
|
|
|
|
|
|
def set_position(self, position):
|
|
|
|
self._position = position
|
2006-06-15 01:00:56 +02:00
|
|
|
|
2006-06-23 21:26:33 +02:00
|
|
|
def _update_size(self):
|
2006-06-14 22:30:53 +02:00
|
|
|
screen_width = self._window.get_screen().get_width()
|
|
|
|
screen_height = self._window.get_screen().get_height()
|
|
|
|
|
|
|
|
if self._width_type is WindowManager.ABSOLUTE:
|
|
|
|
width = self._width
|
|
|
|
elif self._width_type is WindowManager.SCREEN_RELATIVE:
|
2006-06-15 04:08:18 +02:00
|
|
|
width = int(screen_width * self._width)
|
2006-06-14 22:30:53 +02:00
|
|
|
|
|
|
|
if self._height_type is WindowManager.ABSOLUTE:
|
|
|
|
height = self._height
|
|
|
|
elif self._height_type is WindowManager.SCREEN_RELATIVE:
|
2006-06-15 04:08:18 +02:00
|
|
|
height = int(screen_height * self._height)
|
2006-06-14 22:30:53 +02:00
|
|
|
|
2006-06-23 21:26:33 +02:00
|
|
|
self._real_width = width
|
|
|
|
self._real_height = height
|
|
|
|
|
|
|
|
self._window.set_size_request(self._real_width,
|
|
|
|
self._real_height)
|
|
|
|
|
|
|
|
def _update_position(self):
|
|
|
|
screen_width = self._window.get_screen().get_width()
|
|
|
|
screen_height = self._window.get_screen().get_height()
|
|
|
|
|
|
|
|
width = self._real_width
|
|
|
|
height = self._real_height
|
|
|
|
|
2006-06-14 22:30:53 +02:00
|
|
|
if self._position is WindowManager.CENTER:
|
2006-06-20 05:05:25 +02:00
|
|
|
self._x = int((screen_width - width) / 2)
|
|
|
|
self._y = int((screen_height - height) / 2)
|
2006-06-14 22:30:53 +02:00
|
|
|
elif self._position is WindowManager.LEFT:
|
2006-06-20 05:05:25 +02:00
|
|
|
self._x = - int((1.0 - self._sliding_pos) * width)
|
|
|
|
self._y = int((screen_height - height) / 2)
|
2006-06-15 05:24:11 +02:00
|
|
|
elif self._position is WindowManager.TOP:
|
2006-06-20 05:05:25 +02:00
|
|
|
self._x = int((screen_width - width) / 2)
|
|
|
|
self._y = - int((1.0 - self._sliding_pos) * height)
|
2006-06-23 19:09:58 +02:00
|
|
|
elif self._position is WindowManager.BOTTOM:
|
|
|
|
self._x = int((screen_width - width) / 2)
|
|
|
|
self._y = screen_height - int(self._sliding_pos * height)
|
2006-06-20 05:05:25 +02:00
|
|
|
|
|
|
|
self._window.move(self._x, self._y)
|
2006-06-15 01:00:56 +02:00
|
|
|
|
2006-06-19 21:31:18 +02:00
|
|
|
def __slide_in_timeout_cb(self):
|
2006-06-20 05:05:25 +02:00
|
|
|
if self._sliding_pos == 0:
|
|
|
|
self._window.show()
|
2006-06-19 21:31:18 +02:00
|
|
|
|
2006-06-20 09:34:14 +02:00
|
|
|
if SLIDING_MODE == SM_SPACE_PROPORTIONAL:
|
|
|
|
space_to_go = 1.0 - self._sliding_pos
|
|
|
|
self._sliding_pos += (space_to_go / 2)
|
|
|
|
else:
|
|
|
|
self._sliding_pos += SLIDING_STEP
|
2006-06-19 21:31:18 +02:00
|
|
|
|
2006-06-20 05:18:51 +02:00
|
|
|
if self._sliding_pos > .999:
|
2006-06-19 21:31:18 +02:00
|
|
|
self._sliding_pos = 1.0
|
|
|
|
|
2006-06-20 05:05:25 +02:00
|
|
|
self._update_position()
|
2006-06-19 21:31:18 +02:00
|
|
|
|
|
|
|
if self._sliding_pos == 1.0:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
|
|
|
|
def __slide_out_timeout_cb(self):
|
2006-06-20 09:34:14 +02:00
|
|
|
if SLIDING_MODE == SM_SPACE_PROPORTIONAL:
|
|
|
|
space_to_go = self._sliding_pos
|
|
|
|
self._sliding_pos -= (space_to_go / 2)
|
|
|
|
else:
|
|
|
|
self._sliding_pos -= SLIDING_STEP
|
2006-06-19 21:31:18 +02:00
|
|
|
|
2006-06-20 05:18:51 +02:00
|
|
|
if self._sliding_pos < .001:
|
2006-06-19 21:31:18 +02:00
|
|
|
self._sliding_pos = 0
|
|
|
|
|
2006-06-20 05:05:25 +02:00
|
|
|
self._update_position()
|
2006-06-19 21:31:18 +02:00
|
|
|
|
|
|
|
if self._sliding_pos == 0:
|
|
|
|
self._window.hide()
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
|
|
|
|
def slide_window_in(self):
|
|
|
|
self._sliding_pos = 0
|
2006-06-20 09:34:14 +02:00
|
|
|
gobject.timeout_add(SLIDING_TIMEOUT, self.__slide_in_timeout_cb)
|
2006-06-18 07:47:53 +02:00
|
|
|
|
2006-06-14 22:30:53 +02:00
|
|
|
def slide_window_out(self):
|
2006-06-19 21:31:18 +02:00
|
|
|
self._sliding_pos = 1.0
|
2006-06-20 09:34:14 +02:00
|
|
|
gobject.timeout_add(SLIDING_TIMEOUT, self.__slide_out_timeout_cb)
|
2006-06-18 07:47:53 +02:00
|
|
|
|
2006-06-15 01:00:56 +02:00
|
|
|
def show(self):
|
2006-06-18 07:47:53 +02:00
|
|
|
self._window.show()
|
|
|
|
|
|
|
|
def update(self):
|
2006-06-23 21:26:33 +02:00
|
|
|
self._update_position()
|
2006-06-15 01:00:56 +02:00
|
|
|
|
|
|
|
def manage(self):
|
2006-06-23 21:26:33 +02:00
|
|
|
self._update_size()
|
|
|
|
self._update_position()
|