Esempio n. 1
0
 def __init_attributes(self, manager, editor):
     self.__manager = manager
     self.__editor = editor
     self.__visible = False
     from SCRIBES.GObjectTimerManager import Manager
     self.__timer_manager = Manager()
     return False
Esempio n. 2
0
	def __init_attributes(self, manager, editor):
		self.__manager = manager
		self.__editor = editor
		self.__view = editor.textview
		self.__visible = False
		self.__blocked = None
		from SCRIBES.GObjectTimerManager import Manager
		self.__timer_manager = Manager()
		return
Esempio n. 3
0
 def __init_attributes(self, manager, editor):
     self.__manager = manager
     self.__editor = editor
     self.__view = editor.textview
     self.__width = 0
     self.__height = 0
     from SCRIBES.GObjectTimerManager import Manager
     self.__timer_manager = Manager()
     return
Esempio n. 4
0
 def __init_attributes(self, editor):
     self.__editor = editor
     self.__uri = ""
     from SCRIBES.GObjectTimerManager import Manager
     self.__timer_manager = Manager()
     from gio import File, FILE_MONITOR_NONE, Cancellable
     self.__cancellable = Cancellable()
     self.__file_monitor = File("").monitor_file(FILE_MONITOR_NONE,
                                                 self.__cancellable)
     self.__can_reload = True
     return
Esempio n. 5
0
	def __init_attributes(self, manager, editor):
		self.__manager = manager
		self.__editor = editor
		self.__visible = False
		from SCRIBES.GObjectTimerManager import Manager
		self.__timer_manager = Manager()
		return False
Esempio n. 6
0
 def __init_attributes(self, manager, editor):
     self.__manager = manager
     self.__editor = editor
     self.__view = editor.view
     self.__container = editor.get_data("ToolContainer")
     self.__start_point = 0
     self.__end_point = 0
     self.__hdelta = 0
     self.__vdelta = 0
     self.__height = 0
     self.__width = 0
     self.__busy = False
     self.__count = 0
     from SCRIBES.GObjectTimerManager import Manager
     self.__timer_manager = Manager()
     return
Esempio n. 7
0
	def __init_attributes(self, manager, editor):
		self.__manager = manager
		self.__editor = editor
		self.__view = editor.textview
		self.__width = 0
		self.__height = 0
		from SCRIBES.GObjectTimerManager import Manager
		self.__timer_manager = Manager()
		return
Esempio n. 8
0
class Updater(SignalManager):

	def __init__(self, manager, editor):
		SignalManager.__init__(self)
		self.__init_attributes(manager, editor)
		self.connect(editor, "close", self.__quit_cb)
		self.connect(self.__view, "size-allocate", self.__update_cb, True)
		self.connect(editor, "scrollbar-visibility-update", self.__update_cb, True)
		self.connect(editor.window, "configure-event", self.__update_cb)
		editor.register_object(self)

	def __init_attributes(self, manager, editor):
		self.__manager = manager
		self.__editor = editor
		self.__view = editor.textview
		self.__width = 0
		self.__height = 0
		from SCRIBES.GObjectTimerManager import Manager
		self.__timer_manager = Manager()
		return

	def __destroy(self):
		self.disconnect()
		self.__timer_manager.destroy()
		self.__editor.unregister_object(self)
		del self
		return False

	def __update(self):
		self.__editor.refresh(False)
		geometry = self.__view.window.get_geometry()
		width, height = geometry[2], geometry[3]
		if self.__width == width and self.__height == height: return False
		self.__width, self.__height = width, height
		self.__manager.emit("view-size", (width, height))
		return False

	def __update_on_idle(self):
		from gobject import idle_add
		self.__timer2 = idle_add(self.__update)
		self.__timer_manager.add(self.__timer2)
		return False

	def __quit_cb(self, *args):
		self.__destroy()
		return False

	def __update_cb(self, *args):
		self.__timer_manager.remove_all()
		from gobject import timeout_add
		self.__timer1 = timeout_add(25, self.__update_on_idle)
		self.__timer_manager.add(self.__timer1)
		return False
Esempio n. 9
0
	def __init_attributes(self, manager, editor):
		self.__manager = manager
		self.__editor = editor
		self.__view = editor.textview
		self.__bar = None
		self.__start_point = 0
		self.__end_point = 0
		self.__hdelta = 0
		self.__vdelta = 0
		self.__bheight = 0
		self.__bwidth = 0
		self.__vheight = 0
		self.__vwidth = 0
		self.__busy = False
		self.__direction = ""
		self.__cycle_count = 0
		from SCRIBES.GObjectTimerManager import Manager
		self.__timer_manager = Manager()
		return
Esempio n. 10
0
	def __init_attributes(self, editor):
		self.__editor = editor
		self.__uri = ""
		from SCRIBES.GObjectTimerManager import Manager
		self.__timer_manager = Manager()
		from gio import File, FILE_MONITOR_NONE, Cancellable
		self.__cancellable = Cancellable()
		self.__file_monitor = File("").monitor_file(FILE_MONITOR_NONE, self.__cancellable)
		self.__can_reload = True
		return
Esempio n. 11
0
class Updater(SignalManager):
    def __init__(self, manager, editor):
        SignalManager.__init__(self)
        self.__init_attributes(manager, editor)
        self.connect(editor, "close", self.__quit_cb)
        self.connect(self.__view, "size-allocate", self.__update_cb, True)
        self.connect(editor, "scrollbar-visibility-update", self.__update_cb,
                     True)
        self.connect(editor.window, "configure-event", self.__update_cb)
        editor.register_object(self)

    def __init_attributes(self, manager, editor):
        self.__manager = manager
        self.__editor = editor
        self.__view = editor.textview
        self.__width = 0
        self.__height = 0
        from SCRIBES.GObjectTimerManager import Manager
        self.__timer_manager = Manager()
        return

    def __destroy(self):
        self.disconnect()
        self.__timer_manager.destroy()
        self.__editor.unregister_object(self)
        del self
        return False

    def __update(self):
        self.__editor.refresh(False)
        geometry = self.__view.window.get_geometry()
        width, height = geometry[2], geometry[3]
        if self.__width == width and self.__height == height: return False
        self.__width, self.__height = width, height
        self.__manager.emit("view-size", (width, height))
        return False

    def __update_on_idle(self):
        from gobject import idle_add
        self.__timer2 = idle_add(self.__update)
        self.__timer_manager.add(self.__timer2)
        return False

    def __quit_cb(self, *args):
        self.__destroy()
        return False

    def __update_cb(self, *args):
        self.__timer_manager.remove_all()
        from gobject import timeout_add
        self.__timer1 = timeout_add(25, self.__update_on_idle)
        self.__timer_manager.add(self.__timer1)
        return False
Esempio n. 12
0
 def __reload(self):
     if self.__file_exists() is False: return False
     if self.__file_is_remote(): return False
     from URILoader.Manager import Manager
     Manager(self.__editor, self.__uri, self.__editor.encoding)
     from gobject import timeout_add, PRIORITY_LOW
     timeout_add(1000,
                 self.__reload_feedback_message,
                 priority=PRIORITY_LOW)
     return False
Esempio n. 13
0
class Updater(SignalManager):

	def __init__(self, manager, editor):
		SignalManager.__init__(self)
		self.__init_attributes(manager, editor)
		self.connect(editor, "quit", self.__quit_cb)
		self.connect(editor.window, "configure-event", self.__event_cb)
		self.connect(editor, "scrollbar-visibility-update", self.__event_cb)
		editor.register_object(self)

	def __init_attributes(self, manager, editor):
		self.__manager = manager
		self.__editor = editor
		self.__width = 0
		self.__height = 0
		self.__count = 0
		self.__pount = 0
		from SCRIBES.GObjectTimerManager import Manager
		self.__timer_manager = Manager()
		return False

	def __destroy(self):
		self.disconnect()
		self.__timer_manager.destroy()
		self.__editor.unregister_object(self)
		del self
		return False

	def __update(self):
		width = self.__get_width()
		height = self.__get_height()
		if width == self.__width and height == self.__height: return False
		self.__width, self.__height = width, height
		self.__manager.emit("size", (width, height))
		return False

	def __get_width(self):
		from gtk import TEXT_WINDOW_WIDGET
		window = self.__editor.textview.get_window(TEXT_WINDOW_WIDGET)
		return window.get_geometry()[2]

	def __get_height(self):
		height = self.__editor.toolbar.size_request()[1]
		return height

	def __quit_cb(self, *args):
		self.__destroy()
		return False

	def __event_cb(self, *args):
		self.__timer_manager.remove_all()
		from gobject import idle_add, PRIORITY_LOW
		self.__timer1 = idle_add(self.__update, priority=PRIORITY_LOW)
		self.__timer_manager.add(self.__timer1)
		return False
Esempio n. 14
0
	def __init_attributes(self, manager, editor):
		self.__manager = manager
		self.__editor = editor
		self.__view = editor.view
		self.__container = editor.get_data("ToolContainer")
		self.__start_point = 0
		self.__end_point = 0
		self.__hdelta = 0
		self.__vdelta = 0
		self.__height = 0
		self.__width = 0
		self.__busy = False
		self.__count = 0
		from SCRIBES.GObjectTimerManager import Manager
		self.__timer_manager = Manager()
		return
Esempio n. 15
0
class Updater(SignalManager):
    def __init__(self, manager, editor):
        SignalManager.__init__(self)
        self.__init_attributes(manager, editor)
        self.connect(editor, "quit", self.__quit_cb)
        self.connect(editor.window, "configure-event", self.__event_cb)
        self.connect(editor, "scrollbar-visibility-update", self.__event_cb)
        editor.register_object(self)

    def __init_attributes(self, manager, editor):
        self.__manager = manager
        self.__editor = editor
        self.__width = 0
        self.__height = 0
        self.__count = 0
        self.__pount = 0
        from SCRIBES.GObjectTimerManager import Manager
        self.__timer_manager = Manager()
        return False

    def __destroy(self):
        self.disconnect()
        self.__timer_manager.destroy()
        self.__editor.unregister_object(self)
        del self
        return False

    def __update(self):
        width = self.__get_width()
        height = self.__get_height()
        if width == self.__width and height == self.__height: return False
        self.__width, self.__height = width, height
        self.__manager.emit("size", (width, height))
        return False

    def __get_width(self):
        from gtk import TEXT_WINDOW_WIDGET
        window = self.__editor.textview.get_window(TEXT_WINDOW_WIDGET)
        return window.get_geometry()[2]

    def __get_height(self):
        height = self.__editor.toolbar.size_request()[1]
        return height

    def __quit_cb(self, *args):
        self.__destroy()
        return False

    def __event_cb(self, *args):
        self.__timer_manager.remove_all()
        from gobject import idle_add, PRIORITY_LOW
        self.__timer1 = idle_add(self.__update, priority=PRIORITY_LOW)
        self.__timer_manager.add(self.__timer1)
        return False
Esempio n. 16
0
class Calculator(SignalManager):

	def __init__(self, manager, editor):
		SignalManager.__init__(self)
		self.__init_attributes(manager, editor)
		self.connect(editor, "quit", self.__quit_cb)
		self.connect(manager, "bar-size", self.__size_cb)
		editor.register_object(self)

	def __init_attributes(self, manager, editor):
		self.__manager = manager
		self.__editor = editor
		from SCRIBES.GObjectTimerManager import Manager
		self.__timer_manager = Manager()
		return

	def __destroy(self):
		self.__timer_manager.destroy()
		self.disconnect()
		self.__editor.unregister_object(self)
		del self
		return False

	def __update(self, size):
		width, height = size
		hdelta = float(width) / float(ANIMATION_TIME / REFRESH_TIME)
		vdelta = float(height) / float(ANIMATION_TIME / REFRESH_TIME)
		self.__manager.emit("deltas", (int(round(hdelta)), int(round(vdelta))))
		return False

	def __quit_cb(self, *args):
		self.__destroy()
		return False

	def __size_cb(self, manager, size):
		self.__timer_manager.remove_all()
		from gobject import idle_add
		self.__timer1 = idle_add(self.__update, size)
		self.__timer_manager.add(self.__timer1)
		return False
Esempio n. 17
0
class Animator(SignalManager):
    def __init__(self, manager, editor):
        SignalManager.__init__(self)
        self.__init_attributes(manager, editor)
        self.connect(editor, "quit", self.__quit_cb)
        self.connect(manager, "slide", self.__slide_cb)
        self.connect(manager, "deltas", self.__deltas_cb)
        self.connect(manager, "size", self.__size_cb)
        from gobject import idle_add, PRIORITY_LOW
        idle_add(self.__compile, priority=PRIORITY_LOW)
        editor.register_object(self)

    def __init_attributes(self, manager, editor):
        self.__manager = manager
        self.__editor = editor
        self.__view = editor.view
        self.__container = editor.get_data("ToolContainer")
        self.__start_point = 0
        self.__end_point = 0
        self.__hdelta = 0
        self.__vdelta = 0
        self.__height = 0
        self.__width = 0
        self.__busy = False
        self.__count = 0
        from SCRIBES.GObjectTimerManager import Manager
        self.__timer_manager = Manager()
        return

    def __slide(self, direction="left"):
        self.__manager.emit("animation", "begin")
        self.__update_animation_start_point(direction)
        self.__update_animation_end_point(direction)
        from gobject import timeout_add
        self.__timer1 = timeout_add(REFRESH_TIME, self.__move, direction)
        self.__timer_manager.add(self.__timer1)
        return False

    def __move(self, direction):
        try:
            if self.__count >= 50: raise ValueError
            self.__count += 1
            self.__editor.refresh(False)
            animate = True
            self.__can_end(direction)
            self.__reposition_in(direction)
        except ValueError:
            self.__timer_manager.remove_all()
            self.__editor.refresh(False)
            if direction == "up": self.__container.hide()
            self.__editor.refresh(False)
            self.__manager.emit("animation", "end")
            animate = False
            self.__busy = False
            self.__count = 0
        return animate

    def __can_end(self, direction):
        self.__editor.refresh(False)
        if direction == "up" and self.__start_point <= -self.__height - 4:
            raise ValueError
        if direction == "down" and self.__start_point >= -2: raise ValueError
        return False

    def __reposition_in(self, direction):
        try:
            x = int(self.__get_x(direction))
            y = int(self.__get_y(direction))
            self.__editor.refresh(False)
            self.__view.move_child(self.__container, x, y)
            self.__editor.refresh(False)
            self.__container.show_all()
            self.__editor.refresh(False)
        except AttributeError:
            pass
        return False

    def __get_x(self, direction):
        self.__editor.refresh(False)
        if direction in ("up", "down"): return -2
        if direction == "left": self.__start_point -= self.__hdelta
        if direction == "right": self.__start_point += self.__hdelta
        if self.__start_point < -2: return -2
        return self.__start_point

    def __get_y(self, direction):
        self.__editor.refresh(False)
        if direction in ("left", "right"): return -2
        if direction == "up": self.__start_point -= self.__vdelta
        if direction == "down": self.__start_point += self.__vdelta
        if self.__start_point >= -2: return -2
        return self.__start_point

    def __update_animation_start_point(self, direction):
        dictionary = {
            "up": -2,
            "down": -self.__height,
            "left": self.__width,
            "right": 0,
        }
        self.__start_point = dictionary[direction]
        return False

    def __update_animation_end_point(self, direction):
        dictionary = {
            "up": -self.__height - 4,
            "down": -2,
            "left": -2,
            "right": self.__width,
        }
        self.__end_point = dictionary[direction]
        return False

    def __compile(self):
        self.__editor.optimize((self.__move, self.__reposition_in))
        return False

    def __destroy(self):
        self.disconnect()
        self.__timer_manager.destroy()
        self.__editor.unregister_object(self)
        del self
        return False

    def __slide_cb(self, manager, direction):
        if self.__busy: return False
        self.__busy = True
        self.__timer_manager.remove_all()
        from gobject import idle_add, PRIORITY_LOW
        self.__timer2 = idle_add(self.__slide,
                                 direction,
                                 priority=PRIORITY_LOW)
        self.__timer_manager.add(self.__timer2)
        return False

    def __deltas_cb(self, manager, deltas):
        self.__hdelta, self.__vdelta = deltas
        return False

    def __size_cb(self, manager, size):
        self.__width, self.__height = size
        return False

    def __quit_cb(self, *args):
        from gobject import idle_add
        idle_add(self.__destroy)
        return False
Esempio n. 18
0
class Monitor(SignalManager):

	def __init__(self, editor):
		SignalManager.__init__(self)
		self.__init_attributes(editor)
		self.connect(editor, "close", self.__close_cb)
		self.connect(editor, "quit", self.__quit_cb)
		self.connect(editor, "saved-file", self.__saved_file_cb)
		self.connect(editor, "save-file", self.__busy_cb)
		self.connect(editor, "save-error", self.__nobusy_cb, True)
		self.connect(editor, "saved-file", self.__nobusy_cb, True)
		self.connect(editor, "loaded-file", self.__monitor_cb, True)
		editor.register_object(self)

	def __init_attributes(self, editor):
		self.__editor = editor
		self.__uri = ""
		from SCRIBES.GObjectTimerManager import Manager
		self.__timer_manager = Manager()
		from gio import File, FILE_MONITOR_NONE, Cancellable
		self.__cancellable = Cancellable()
		self.__file_monitor = File("").monitor_file(FILE_MONITOR_NONE, self.__cancellable)
		self.__can_reload = True
		return

	def __monitor(self, uri):
		self.__uri = uri
		from gio import File, FILE_MONITOR_NONE
		self.__unmonitor()
		self.__file_monitor = File(uri).monitor_file(FILE_MONITOR_NONE, self.__cancellable)
		self.__file_monitor.connect("changed", self.__changed_cb)
		self.__file_monitor.set_rate_limit(RATE_LIMIT)
		return False

	def __unmonitor(self):
		self.__file_monitor.cancel()
		self.__cancellable.cancel()
		self.__cancellable.reset()
		return False

	def __remove_monitor(self):
		self.__timer_manager.remove_all()
		self.__unmonitor()
		return False

	def __set_can_reload(self, can_reload):
		self.__can_reload = can_reload
		return False

	def __reload(self):
		if self.__file_exists() is False: return False
		if self.__file_is_remote(): return False
		from URILoader.Manager import Manager
		Manager(self.__editor, self.__uri, self.__editor.encoding)
		from gobject import timeout_add, PRIORITY_LOW
		timeout_add(1000, self.__reload_feedback_message, priority=PRIORITY_LOW)
		return False

	def __reload_feedback_message(self):
		from gettext import gettext as _
		message = _("File modification detected. Reloaded file")
		self.__editor.update_message(message, "info", 10)
		return False

	def __file_exists(self):
		from gio import File
		return File(self.__uri).query_exists()

	def __file_is_remote(self):
		if not self.__uri: return False
		from Utils import uri_is_remote
		return uri_is_remote(self.__uri)

	def __change_handler(self, event):
		if self.__can_reload is False or event not in (1, 2, 3, 4): return False
		from gobject import idle_add, PRIORITY_LOW
		idle_add(self.__reload, priority=PRIORITY_LOW)
		return False

	def __destroy(self):
		self.__timer_manager.destroy()
		self.disconnect()
		self.__editor.unregister_object(self)
		del self
		return False

	def __quit_cb(self, *args):
		self.__destroy()
		return False

	def __monitor_cb(self, editor, uri, *args):
		self.__timer_manager.remove_all()
		from gobject import idle_add, PRIORITY_LOW
		idle_add(self.__monitor, uri, priority=PRIORITY_LOW)
		return False

	def __changed_cb(self, monitor, child, other_child, event):
		self.__timer_manager.remove_all()
		from gobject import timeout_add
		self.__timer1 = timeout_add(WAIT_INTERVAL, self.__change_handler, event)
		self.__timer_manager.add(self.__timer1)
		return False

	def __busy_cb(self, *args):
		self.__can_reload = False
		self.__timer_manager.remove_all()
		return False

	def __nobusy_cb(self, *args):
		self.__timer_manager.remove_all()
		from gobject import timeout_add, PRIORITY_LOW
		self.__timer2 = timeout_add(IGNORE_MONITORING_INTERVAL, self.__set_can_reload, True, priority=PRIORITY_LOW)
		self.__timer_manager.add(self.__timer2)
		return False

	def __saved_file_cb(self, editor, uri, *args):
		if self.__uri == uri: return False
		self.__timer_manager.remove_all()
		self.__monitor(uri)
		return False

	def __close_cb(self, *args):
		self.__remove_monitor()
		return False
Esempio n. 19
0
class Manager(SignalManager):

	def __init__(self, manager, editor):
		SignalManager.__init__(self)
		self.__init_attributes(manager, editor)
		self.connect(editor, "quit", self.__quit_cb)
		self.connect(editor, "show-full-view", self.__show_cb)
		self.connect(editor, "hide-full-view", self.__hide_cb)
#		self.connect(editor, "toolbar-is-visible", self.__toolbar_cb)
		self.connect(manager, "hide", self.__hide_cb, True)
		self.connect(manager, "show", self.__show_cb, True)
#		self.connect(manager, "visible", self.__visible_cb)
#		self.connect(manager, "animation", self.__animate_cb)
		editor.register_object(self)

	def __init_attributes(self, manager, editor):
		self.__manager = manager
		self.__editor = editor
		self.__visible = False
		from SCRIBES.GObjectTimerManager import Manager
		self.__timer_manager = Manager()
		return False

	def __destroy(self):
		self.__timer_manager.destroy()
		self.disconnect()
		self.__editor.unregister_object(self)
		del self
		return False

	def __hide(self):
		# if self.__visible is False: return False
		self.__manager.emit("_hide")
		self.__visible = False
		return False

	def __show(self):
		if self.__visible: return False
		self.__manager.emit("_show")
		self.__visible = True
		return False

	def __show_on_idle(self):
		from gobject import idle_add, PRIORITY_LOW
		self.__timer2 = idle_add(self.__show, priority=PRIORITY_LOW)
		self.__timer_manager.add(self.__timer2)
		return False

	def __hide_cb(self, *args):
		self.__timer_manager.remove_all()
		# from gobject import idle_add, PRIORITY_LOW
		# idle_add(self.__hide, priority=PRIORITY_LOW)
		self.__hide()
		return False

	def __show_cb(self, *args):
		self.__timer_manager.remove_all()
		self.__hide()
		from gobject import timeout_add, PRIORITY_LOW
		self.__timer1 = timeout_add(150, self.__show_on_idle, priority=PRIORITY_LOW)
		self.__timer_manager.add(self.__timer1)
		return False

	def __quit_cb(self, *args):
		self.__destroy()
		return False
Esempio n. 20
0
class Timer(SignalManager):

	def __init__(self, manager, editor):
		SignalManager.__init__(self)
		self.__init_attributes(manager, editor)
		self.__id = self.connect(editor.textview, "motion-notify-event", self.__motion_cb)
		self.connect(editor, "toolbar-is-visible", self.__visible_cb)
		self.connect(editor, "quit", self.__quit_cb)
		self.__block()
		editor.register_object(self)

	def __init_attributes(self, manager, editor):
		self.__manager = manager
		self.__editor = editor
		self.__view = editor.textview
		self.__visible = False
		self.__blocked = None
		from SCRIBES.GObjectTimerManager import Manager
		self.__timer_manager = Manager()
		return

	def __destroy(self):
		self.__timer_manager.destroy()
		self.disconnect()
		self.__editor.unregister_object(self)
		del self
		return False

	def __hide(self):
		hide = lambda: self.__manager.emit("hide")
		from gobject import idle_add, PRIORITY_LOW
		self.__timer1 = idle_add(hide, priority=PRIORITY_LOW)
		self.__timer_manager.add(self.__timer1)
		return False

	def __block(self):
		if self.__blocked is True: return False
		self.__blocked = True
		self.__view.handler_block(self.__id)
		return False

	def __unblock(self):
		if self.__blocked is False: return False
		self.__blocked = False
		self.__view.handler_unblock(self.__id)
		return False

	def __motion_cb(self, *args):
		if self.__visible is False: return False
		self.__timer_manager.remove_all()
		from gobject import timeout_add, PRIORITY_LOW
		self.__timer2 = timeout_add(HIDE_TIMER, self.__hide, priority=PRIORITY_LOW)
		self.__timer_manager.add(self.__timer2)
		return False

	def __quit_cb(self, *args):
		self.__destroy()
		return False

	def __visible_cb(self, manager, visible):
		self.__visible = visible
		self.__unblock() if visible else self.__block()
		if visible is False: return False
		self.__timer_manager.remove_all()
		from gobject import timeout_add, PRIORITY_LOW
		self.__timer3 = timeout_add(HIDE_TIMER, self.__hide, priority=PRIORITY_LOW)
		self.__timer_manager.add(self.__timer3)
		return False
Esempio n. 21
0
class Animator(SignalManager):

	def __init__(self, manager, editor):
		SignalManager.__init__(self)
		self.__init_attributes(manager, editor)
		self.connect(editor, "quit", self.__quit_cb)
		self.connect(manager, "slide", self.__slide_cb, True)
		self.connect(manager, "deltas", self.__deltas_cb)
		self.connect(manager, "bar-size", self.__bsize_cb)
		self.connect(manager, "view-size", self.__vsize_cb)
		self.connect(manager, "bar", self.__bar_cb)
		from gobject import idle_add, PRIORITY_LOW
		idle_add(self.__compile, priority=PRIORITY_LOW)
		editor.register_object(self)

	def __init_attributes(self, manager, editor):
		self.__manager = manager
		self.__editor = editor
		self.__view = editor.textview
		self.__bar = None
		self.__start_point = 0
		self.__end_point = 0
		self.__hdelta = 0
		self.__vdelta = 0
		self.__bheight = 0
		self.__bwidth = 0
		self.__vheight = 0
		self.__vwidth = 0
		self.__busy = False
		self.__direction = ""
		self.__cycle_count = 0
		from SCRIBES.GObjectTimerManager import Manager
		self.__timer_manager = Manager()
		return

	def __slide(self, direction):
		self.__manager.emit("animation", "begin")
		self.__update_animation_start_point(direction)
		self.__update_animation_end_point(direction)
		from gobject import timeout_add, PRIORITY_LOW
		self.__timer1 = timeout_add(REFRESH_TIME, self.__move, direction, priority=PRIORITY_LOW)
		self.__timer_manager.add(self.__timer1)
		return False

	def __move(self, direction):
		try:
			self.__editor.refresh(False)
			if self.__cycle_count >= 50: raise AssertionError
			self.__cycle_count += 1
			animate = True
			self.__can_end(direction)
			from gobject import idle_add
			idle_add(self.__reposition_in, direction)
		except AssertionError:
			self.__timer_manager.remove_all()
			animate = False
			self.__editor.refresh(False)
			if direction == "down": self.__bar.hide()
			self.__editor.refresh(False)
			self.__manager.emit("animation", "end")
			self.__busy = False
			self.__cycle_count = 0
		return animate

	def __reposition_in(self, direction):
		try:
			x = int(self.__get_x(direction))
			y = int(self.__get_y(direction))
			self.__editor.refresh(False)
			self.__view.move_child(self.__bar, x, y)
			self.__editor.refresh(False)
			self.__bar.show_all()
			self.__editor.refresh(False)
		except AttributeError:
			pass
		return False

	def __can_end(self, direction):
		self.__editor.refresh(False)
		if direction == "down" and self.__start_point >= self.__end_point: raise AssertionError
		if direction == "up" and self.__start_point <= self.__end_point: raise AssertionError
		return False

	def __get_x(self, direction):
		self.__editor.refresh(False)
		if direction in ("up", "down"): return self.__vwidth - self.__bwidth + 4
		if direction == "left": self.__start_point -= self.__hdelta
		if direction == "right": self.__start_point += self.__hdelta
		x = self.__vwidth - self.__bwidth
		if self.__start_point <= x: return x + OFFSET
		return self.__start_point

	def __get_y(self, direction):
		self.__editor.refresh(False)
		if direction in ("left", "right"): return self.__vheight - self.__bheight + 4
		if direction == "up": self.__start_point -= self.__vdelta
		if direction == "down": self.__start_point += self.__vdelta
		return self.__start_point

	def __update_animation_start_point(self, direction):
		dictionary = {
			"up": self.__vheight,
			"down": self.__vheight - self.__bheight + 4,
			"left": self.__vwidth,
			"right":0,
		}
		self.__start_point = dictionary[direction]
		return False

	def __update_animation_end_point(self, direction):
		dictionary = {
			"up": self.__vheight - self.__bheight + 4,
			"down": self.__vheight + 4,
			"left": self.__vwidth - self.__bwidth + 4,
			"right": self.__bwidth,
		}
		self.__end_point = dictionary[direction]
		return False

	def __compile(self):
		self.__editor.optimize((self.__move, self.__reposition_in))
		return False

	def __destroy(self):
		self.__timer_manager.destroy()
		self.disconnect()
		self.__editor.unregister_object(self)
		del self
		return False

	def __slide_cb(self, manager, direction):
		if direction == self.__direction: return False
		self.__direction = direction
		if not self.__bar: return False
		self.__timer_manager.remove_all()
		self.__busy = True
		from gobject import idle_add, PRIORITY_LOW as LOW
		self.__timer2 = idle_add(self.__slide, direction, priority=LOW)
		self.__timer_manager.add(self.__timer2)
		return False

	def __deltas_cb(self, manager, deltas):
		self.__hdelta, self.__vdelta = deltas
		return False

	def __bsize_cb(self, manager, size):
		self.__bwidth, self.__bheight = size
		return False

	def __vsize_cb(self, manager, size):
		self.__vwidth, self.__vheight = size
		if self.__direction == "up": self.__reposition_in(self.__direction)
		return False

	def __bar_cb(self, manager, bar):
		self.__bar = bar
		self.__bar.show_all()
		return False

	def __quit_cb(self, *args):
		from gobject import idle_add
		idle_add(self.__destroy)
		return False
Esempio n. 22
0
class Animator(SignalManager):

	def __init__(self, manager, editor):
		SignalManager.__init__(self)
		self.__init_attributes(manager, editor)
		self.connect(editor, "quit", self.__quit_cb)
		self.connect(manager, "slide", self.__slide_cb)
		self.connect(manager, "deltas", self.__deltas_cb)
		self.connect(manager, "size", self.__size_cb)
		from gobject import idle_add, PRIORITY_LOW
		idle_add(self.__compile, priority=PRIORITY_LOW)
		editor.register_object(self)

	def __init_attributes(self, manager, editor):
		self.__manager = manager
		self.__editor = editor
		self.__view = editor.view
		self.__container = editor.get_data("ToolContainer")
		self.__start_point = 0
		self.__end_point = 0
		self.__hdelta = 0
		self.__vdelta = 0
		self.__height = 0
		self.__width = 0
		self.__busy = False
		self.__count = 0
		from SCRIBES.GObjectTimerManager import Manager
		self.__timer_manager = Manager()
		return

	def __slide(self, direction="left"):
		self.__manager.emit("animation", "begin")
		self.__update_animation_start_point(direction)
		self.__update_animation_end_point(direction)
		from gobject import timeout_add
		self.__timer1 = timeout_add(REFRESH_TIME, self.__move, direction)
		self.__timer_manager.add(self.__timer1)
		return False

	def __move(self, direction):
		try:
			if self.__count >= 50: raise ValueError
			self.__count += 1
			self.__editor.refresh(False)
			animate = True
			self.__can_end(direction)
			self.__reposition_in(direction)
		except ValueError:
			self.__timer_manager.remove_all()
			self.__editor.refresh(False)
			if direction == "up": self.__container.hide()
			self.__editor.refresh(False)
			self.__manager.emit("animation", "end")
			animate = False
			self.__busy = False
			self.__count = 0
		return animate

	def __can_end(self, direction):
		self.__editor.refresh(False)
		if direction == "up" and self.__start_point <= -self.__height - 4: raise ValueError
		if direction == "down" and self.__start_point >= -2: raise ValueError
		return False

	def __reposition_in(self, direction):
		try:
			x = int(self.__get_x(direction))
			y = int(self.__get_y(direction))
			self.__editor.refresh(False)
			self.__view.move_child(self.__container, x, y)
			self.__editor.refresh(False)
			self.__container.show_all()
			self.__editor.refresh(False)
		except AttributeError:
			pass
		return False

	def __get_x(self, direction):
		self.__editor.refresh(False)
		if direction in ("up", "down"): return -2
		if direction == "left": self.__start_point -= self.__hdelta
		if direction == "right": self.__start_point += self.__hdelta
		if self.__start_point < -2: return -2
		return self.__start_point

	def __get_y(self, direction):
		self.__editor.refresh(False)
		if direction in ("left", "right"): return -2
		if direction == "up": self.__start_point -= self.__vdelta
		if direction == "down": self.__start_point += self.__vdelta
		if self.__start_point >= -2: return -2
		return self.__start_point

	def __update_animation_start_point(self, direction):
		dictionary = {
			"up": -2,
			"down": -self.__height,
			"left": self.__width,
			"right":0,
		}
		self.__start_point = dictionary[direction]
		return False

	def __update_animation_end_point(self, direction):
		dictionary = {
			"up": -self.__height - 4,
			"down": -2,
			"left": -2,
			"right": self.__width,
		}
		self.__end_point = dictionary[direction]
		return False

	def __compile(self):
		self.__editor.optimize((self.__move, self.__reposition_in))
		return False

	def __destroy(self):
		self.disconnect()
		self.__timer_manager.destroy()
		self.__editor.unregister_object(self)
		del self
		return False

	def __slide_cb(self, manager, direction):
		if self.__busy: return False
		self.__busy = True
		self.__timer_manager.remove_all()
		from gobject import idle_add, PRIORITY_LOW
		self.__timer2 = idle_add(self.__slide, direction, priority=PRIORITY_LOW)
		self.__timer_manager.add(self.__timer2)
		return False

	def __deltas_cb(self, manager, deltas):
		self.__hdelta, self.__vdelta = deltas
		return False

	def __size_cb(self, manager, size):
		self.__width, self.__height = size
		return False

	def __quit_cb(self, *args):
		from gobject import idle_add
		idle_add(self.__destroy)
		return False
Esempio n. 23
0
class Manager(SignalManager):
    def __init__(self, manager, editor):
        SignalManager.__init__(self)
        self.__init_attributes(manager, editor)
        self.connect(editor, "quit", self.__quit_cb)
        self.connect(editor, "show-full-view", self.__show_cb)
        self.connect(editor, "hide-full-view", self.__hide_cb)
        #		self.connect(editor, "toolbar-is-visible", self.__toolbar_cb)
        self.connect(manager, "hide", self.__hide_cb, True)
        self.connect(manager, "show", self.__show_cb, True)
        #		self.connect(manager, "visible", self.__visible_cb)
        #		self.connect(manager, "animation", self.__animate_cb)
        editor.register_object(self)

    def __init_attributes(self, manager, editor):
        self.__manager = manager
        self.__editor = editor
        self.__visible = False
        from SCRIBES.GObjectTimerManager import Manager
        self.__timer_manager = Manager()
        return False

    def __destroy(self):
        self.__timer_manager.destroy()
        self.disconnect()
        self.__editor.unregister_object(self)
        del self
        return False

    def __hide(self):
        # if self.__visible is False: return False
        self.__manager.emit("_hide")
        self.__visible = False
        return False

    def __show(self):
        if self.__visible: return False
        self.__manager.emit("_show")
        self.__visible = True
        return False

    def __show_on_idle(self):
        from gobject import idle_add, PRIORITY_LOW
        self.__timer2 = idle_add(self.__show, priority=PRIORITY_LOW)
        self.__timer_manager.add(self.__timer2)
        return False

    def __hide_cb(self, *args):
        self.__timer_manager.remove_all()
        # from gobject import idle_add, PRIORITY_LOW
        # idle_add(self.__hide, priority=PRIORITY_LOW)
        self.__hide()
        return False

    def __show_cb(self, *args):
        self.__timer_manager.remove_all()
        self.__hide()
        from gobject import timeout_add, PRIORITY_LOW
        self.__timer1 = timeout_add(150,
                                    self.__show_on_idle,
                                    priority=PRIORITY_LOW)
        self.__timer_manager.add(self.__timer1)
        return False

    def __quit_cb(self, *args):
        self.__destroy()
        return False
Esempio n. 24
0
class Monitor(SignalManager):
    def __init__(self, editor):
        SignalManager.__init__(self)
        self.__init_attributes(editor)
        self.connect(editor, "close", self.__close_cb)
        self.connect(editor, "quit", self.__quit_cb)
        self.connect(editor, "saved-file", self.__saved_file_cb)
        self.connect(editor, "save-file", self.__busy_cb)
        self.connect(editor, "save-error", self.__nobusy_cb, True)
        self.connect(editor, "saved-file", self.__nobusy_cb, True)
        self.connect(editor, "loaded-file", self.__monitor_cb, True)
        editor.register_object(self)

    def __init_attributes(self, editor):
        self.__editor = editor
        self.__uri = ""
        from SCRIBES.GObjectTimerManager import Manager
        self.__timer_manager = Manager()
        from gio import File, FILE_MONITOR_NONE, Cancellable
        self.__cancellable = Cancellable()
        self.__file_monitor = File("").monitor_file(FILE_MONITOR_NONE,
                                                    self.__cancellable)
        self.__can_reload = True
        return

    def __monitor(self, uri):
        self.__uri = uri
        from gio import File, FILE_MONITOR_NONE
        self.__unmonitor()
        self.__file_monitor = File(uri).monitor_file(FILE_MONITOR_NONE,
                                                     self.__cancellable)
        self.__file_monitor.connect("changed", self.__changed_cb)
        self.__file_monitor.set_rate_limit(RATE_LIMIT)
        return False

    def __unmonitor(self):
        self.__file_monitor.cancel()
        self.__cancellable.cancel()
        self.__cancellable.reset()
        return False

    def __remove_monitor(self):
        self.__timer_manager.remove_all()
        self.__unmonitor()
        return False

    def __set_can_reload(self, can_reload):
        self.__can_reload = can_reload
        return False

    def __reload(self):
        if self.__file_exists() is False: return False
        if self.__file_is_remote(): return False
        from URILoader.Manager import Manager
        Manager(self.__editor, self.__uri, self.__editor.encoding)
        from gobject import timeout_add, PRIORITY_LOW
        timeout_add(1000,
                    self.__reload_feedback_message,
                    priority=PRIORITY_LOW)
        return False

    def __reload_feedback_message(self):
        from gettext import gettext as _
        message = _("File modification detected. Reloaded file")
        self.__editor.update_message(message, "info", 10)
        return False

    def __file_exists(self):
        from gio import File
        return File(self.__uri).query_exists()

    def __file_is_remote(self):
        if not self.__uri: return False
        from Utils import uri_is_remote
        return uri_is_remote(self.__uri)

    def __change_handler(self, event):
        if self.__can_reload is False or event not in (1, 2, 3, 4):
            return False
        from gobject import idle_add, PRIORITY_LOW
        idle_add(self.__reload, priority=PRIORITY_LOW)
        return False

    def __destroy(self):
        self.__timer_manager.destroy()
        self.disconnect()
        self.__editor.unregister_object(self)
        del self
        return False

    def __quit_cb(self, *args):
        self.__destroy()
        return False

    def __monitor_cb(self, editor, uri, *args):
        self.__timer_manager.remove_all()
        from gobject import idle_add, PRIORITY_LOW
        idle_add(self.__monitor, uri, priority=PRIORITY_LOW)
        return False

    def __changed_cb(self, monitor, child, other_child, event):
        self.__timer_manager.remove_all()
        from gobject import timeout_add
        self.__timer1 = timeout_add(WAIT_INTERVAL, self.__change_handler,
                                    event)
        self.__timer_manager.add(self.__timer1)
        return False

    def __busy_cb(self, *args):
        self.__can_reload = False
        self.__timer_manager.remove_all()
        return False

    def __nobusy_cb(self, *args):
        self.__timer_manager.remove_all()
        from gobject import timeout_add, PRIORITY_LOW
        self.__timer2 = timeout_add(IGNORE_MONITORING_INTERVAL,
                                    self.__set_can_reload,
                                    True,
                                    priority=PRIORITY_LOW)
        self.__timer_manager.add(self.__timer2)
        return False

    def __saved_file_cb(self, editor, uri, *args):
        if self.__uri == uri: return False
        self.__timer_manager.remove_all()
        self.__monitor(uri)
        return False

    def __close_cb(self, *args):
        self.__remove_monitor()
        return False