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


Python Observable.set方法代码示例

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


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

示例1: ClockModel

# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import set [as 别名]
class ClockModel(object):
    """
    The class is responsible for handling time.
    Specifically, it can retrieve time form the environment (OS), which is default or overridden to read from some
    other source (like hardware clock)
    """
    def __init__(self):
        self.time = Observable(datetime.time)

    def update_time(self):
        self.time.set(datetime.datetime.now())

    def get_hour(self):
        return self.time.hour

    def get_minute(self):
        return self.time.minute

    def get_second(self):
        return self.time.second
开发者ID:IrekRybark,项目名称:malinka,代码行数:22,代码来源:clockmvc.py

示例2: diskMounterBaseClass

# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import set [as 别名]
class diskMounterBaseClass(object):
    mounted = mountedModel()

    def __init__(self):
        self.log = logging.getLogger("vmDiskAbstract.diskMounterBaseClass")
        # 1 Unknown
        # 2 Mounted (is it mounted)
        # 4 Released
        # 8 Can be mounted
        # 16 and higher are implementation specific
        self.state = Observable(0)

    def updateFromMtab(self, ByTarget, BySource):
        # self.log.debug("ByTarget=%s" % (ByTarget))
        # self.log.debug("BySource=%s" % (BySource))
        mounted = True
        if not hasattr(self, "target"):
            mounted = False
        if not self.target in ByTarget.keys():
            print "no match", ByTarget.keys(), self.target
            mounted = False
        oldState = self.state.get()
        currentState = oldState
        # self.log.info("statechange=%s->%s" % (oldState,currentState))
        if ((currentState & 2) == 2) and (not mounted):
            currentState -= 2
        if ((currentState & 2) == 0) and (mounted):
            currentState += 2

        if currentState != oldState:
            # self.log.info("statechange=%s->%s" % (oldState,currentState))
            self.state.set(currentState)
        return currentState

    def mount(self):
        currentState = self.state.get()
        if (currentState & 2) == 2:
            return currentState
        if (currentState & 2) == 0:
            currentState += 2
            self.state.set(currentState)
        return currentState

    def release(self):
        currentState = self.state.get()
        if (currentState & 2) == 0:
            return currentState
        if (currentState & 2) == 2:
            currentState -= 2
            self.state.set(currentState)
        return currentState
开发者ID:hepix-virtualisation,项目名称:vmimagemanager,代码行数:53,代码来源:vmDiskAbstract.py

示例3: __init__

# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import set [as 别名]
class Model:
	"""Provides fields and logic for a tennnis match."""
	def __init__(self):
		self.noEndingTiebreak = Observable(False)
		self.doublesMatch = Observable(False)
		self.mensMatch = Observable(0)
		self.team = Observable(["",""])
		self.gameScore = Observable([0,0])
		self.setScore = Observable([[0,0],[0,0],[0,0],[0,0],[0,0]])
		self.currentSet = Observable(0)
		self.matchScore = Observable([0,0])
		self.tiebreak = Observable(False)
		self.message = Observable("")
		self.server = Observable(-1)
		self.winner = Observable(-1)
		self.numberOfSets = Observable(0)
		self.matchOver = False
		self.winSets = Observable(0)
		self.matchType = Observable("")
		self.tiebreakToWin = 7 # Default for normal tiebreak game. Will set to 10 for end tiebreak in doubles match.
		self.matchPointCount = [0,0]
		self.setPointCount = [0,0]
		self.breakPointCount = [0,0]
		self.deuceCount = 0
		self.duplicateLastName = set([])
		self.specialCaseNames = []
		self.teamScoreNames = ["",""]

	def setNoEndingTiebreak(self,bool):
		"""
		Establishes whether final set can end with a tiebreak.
		@type bool: boolean
		@param bool: Flag, True if final set can NOT end with a tiebreak.
		"""
		self.noEndingTiebreak.set(bool)

	def setDoublesMatch(self,bool):
		"""
		Establishes whether this is a doubles or singles match.
		@type bool: boolean
		@param bool: Flag, True if this is a doubles match.
		"""
		self.doublesMatch.set(bool)

	def setMensMatch(self,i):
		"""
		Establishes whether this is a men's match, women's, or some form of doubles. Sets that field, also the corresponding number of sets.
		@type i: integer
		@param i: Flag, 0 = women's match, 1 = men's match, 2 = mixed doubles match.
		"""
		self.mensMatch.set(i)
		if (self.mensMatch.get() == 1):
			self.numberOfSets.set(5) # I'm assuming 5 sets for men. This may not always be the case, in which case I'll include in dialog.
			self.winSets.set(3) # I'm assuming 5 sets for men. This may not always be the case, in which case I'll include in dialog.
		else: # either womens, or some form of doubles. All have three sets.
			self.numberOfSets.set(3)
			self.winSets.set(2)

	def changeServer(self):
		"""
		Swaps the serving team / player.
		"""
		# Simple toggle of server team
		if self.server.get() == 0:
			self.server.set(1)
		else:
			self.server.set(0)

	def gameDelta(self):
		"""
		Returns the absolute value of the difference in the current game score.
		@rtype: integer
		@return: The absolute value of the difference in the current game score.
		"""
		return scoreDelta(self.gameScore.get())

	def gamePoint(self, score):
		"""
		Returns whether the current score corresponds to game point.
		@type score: list of integers
		@param score: The current game score.
		@rtype: boolean
		@return: Whether the current score corresponds to game point.
		"""
		gameLeader = leader(score)
		if gameLeader == -1: # Game is tied
			return False
		# All below, game is not tied.
		# Tiebreak game
		if (self.tiebreak.get()) and (score[gameLeader] > self.tiebreakToWin - 2):
			return True
		# Regular game
		if (not self.tiebreak.get()) and (score[gameLeader] > 2):
			return True
		return False

	def breakPoint(self,score):
		"""
		Returns whether the current score corresponds to break point.
		@type score: list of integers
#.........这里部分代码省略.........
开发者ID:talasky,项目名称:tennis-score,代码行数:103,代码来源:tennisModel.py


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