當前位置: 首頁>>代碼示例>>Python>>正文


Python CList.changed方法代碼示例

本文整理匯總了Python中Tools.CList.CList.changed方法的典型用法代碼示例。如果您正苦於以下問題:Python CList.changed方法的具體用法?Python CList.changed怎麽用?Python CList.changed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Tools.CList.CList的用法示例。


在下文中一共展示了CList.changed方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Element

# 需要導入模塊: from Tools.CList import CList [as 別名]
# 或者: from Tools.CList.CList import changed [as 別名]
class Element(object):
	CHANGED_DEFAULT = 0   # initial "pull" state
	CHANGED_ALL = 1       # really everything changed
	CHANGED_CLEAR = 2     # we're expecting a real update soon. don't bother polling NOW, but clear data.
	CHANGED_SPECIFIC = 3  # second tuple will specify what exactly changed
	CHANGED_POLL = 4      # a timer expired

	SINGLE_SOURCE = True

	def __init__(self):
		self.downstream_elements = CList()
		self.master = None
		self.sources = [ ]
		self.source = None
		self.__suspended = True
		self.cache = None

	def connectDownstream(self, downstream):
		self.downstream_elements.append(downstream)
		if self.master is None:
			self.master = downstream

	def connectUpstream(self, upstream):
		assert not self.SINGLE_SOURCE or self.source is None
		self.sources.append(upstream)
		# self.source always refers to the last recent source added.
		self.source = upstream
		self.changed((self.CHANGED_DEFAULT,))

	def connect(self, upstream):
		self.connectUpstream(upstream)
		upstream.connectDownstream(self)

	# we disconnect from down to up
	def disconnectAll(self):
		# we should not disconnect from upstream if
		# there are still elements depending on us.
		assert len(self.downstream_elements) == 0, "there are still downstream elements left"

		# Sources don't have a source themselves. don't do anything here.
		for s in self.sources:
			s.disconnectDownstream(self)

		if self.source:
			# sources are owned by the Screen, so don't destroy them here.
			self.destroy()
		self.source = None
		self.sources = [ ]

	def disconnectDownstream(self, downstream):
		self.downstream_elements.remove(downstream)
		if self.master == downstream:
			self.master = None

		if len(self.downstream_elements) == 0:
			self.disconnectAll()

	# default action: push downstream
	def changed(self, *args, **kwargs):
		self.cache = { }
		self.downstream_elements.changed(*args, **kwargs)
		self.cache = None

	def setSuspend(self, suspended):
		changed = self.__suspended != suspended
		if not self.__suspended and suspended:
			self.doSuspend(1)
		elif self.__suspended and not suspended:
			self.doSuspend(0)

		self.__suspended = suspended
		if changed:
			for s in self.sources:
				s.checkSuspend()

	suspended = property(lambda self: self.__suspended, setSuspend)

	def checkSuspend(self):
		self.suspended = reduce(lambda x, y: x and y.__suspended, self.downstream_elements, True)

	def doSuspend(self, suspend):
		pass

	def destroy(self):
		pass
開發者ID:1198s,項目名稱:enigma2,代碼行數:87,代碼來源:Element.py

示例2: Element

# 需要導入模塊: from Tools.CList import CList [as 別名]
# 或者: from Tools.CList.CList import changed [as 別名]
class Element(object):
    CHANGED_DEFAULT = 0
    CHANGED_ALL = 1
    CHANGED_CLEAR = 2
    CHANGED_SPECIFIC = 3
    CHANGED_POLL = 4
    SINGLE_SOURCE = True

    def __init__(self):
        self.downstream_elements = CList()
        self.master = None
        self.sources = []
        self.source = None
        self.__suspended = True
        self.cache = None
        return

    def connectDownstream(self, downstream):
        self.downstream_elements.append(downstream)
        if self.master is None:
            self.master = downstream
        return

    def connectUpstream(self, upstream):
        self.sources.append(upstream)
        self.source = upstream
        self.changed((self.CHANGED_DEFAULT,))

    def connect(self, upstream):
        self.connectUpstream(upstream)
        upstream.connectDownstream(self)

    def disconnectAll(self):
        for s in self.sources:
            s.disconnectDownstream(self)

        if self.source:
            self.destroy()
        self.source = None
        self.sources = []
        return

    def disconnectDownstream(self, downstream):
        self.downstream_elements.remove(downstream)
        if self.master == downstream:
            self.master = None
        if len(self.downstream_elements) == 0:
            self.disconnectAll()
        return

    def changed(self, *args, **kwargs):
        self.cache = {}
        self.downstream_elements.changed(*args, **kwargs)
        self.cache = None
        return

    def setSuspend(self, suspended):
        changed = self.__suspended != suspended
        if not self.__suspended and suspended:
            self.doSuspend(1)
        elif self.__suspended and not suspended:
            self.doSuspend(0)
        self.__suspended = suspended
        if changed:
            for s in self.sources:
                s.checkSuspend()

    suspended = property(lambda self: self.__suspended, setSuspend)

    def checkSuspend(self):
        self.suspended = reduce(lambda x, y: x and y.__suspended, self.downstream_elements, True)

    def doSuspend(self, suspend):
        pass

    def destroy(self):
        pass
開發者ID:kingvuplus,項目名稱:boom,代碼行數:79,代碼來源:Element.py


注:本文中的Tools.CList.CList.changed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。