当前位置: 首页>>代码示例>>Python>>正文


Python File.set_rate_limit方法代码示例

本文整理汇总了Python中gio.File.set_rate_limit方法的典型用法代码示例。如果您正苦于以下问题:Python File.set_rate_limit方法的具体用法?Python File.set_rate_limit怎么用?Python File.set_rate_limit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gio.File的用法示例。


在下文中一共展示了File.set_rate_limit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Monitor

# 需要导入模块: from gio import File [as 别名]
# 或者: from gio.File import set_rate_limit [as 别名]
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)
#.........这里部分代码省略.........
开发者ID:mystilleef,项目名称:scribes,代码行数:103,代码来源:FileChangeMonitor.py


注:本文中的gio.File.set_rate_limit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。