本文整理汇总了Python中view.View.update方法的典型用法代码示例。如果您正苦于以下问题:Python View.update方法的具体用法?Python View.update怎么用?Python View.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类view.View
的用法示例。
在下文中一共展示了View.update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Controller
# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import update [as 别名]
class Controller(object):
""" Window/keyboard controller. """
def __init__(self):
self.model = Model()
self.view = View()
self.socket = UDSClient()
self.socket.register(Protocol.FULL_HISTORY, self.model.history.set)
self.socket.register(Protocol.NEW_ENTRY, self.model.history.add)
self.commands = {"q": self._quit,
"j": lambda: self.view.change_pointer(1),
"k": lambda: self.view.change_pointer(-1),
"y": lambda: self._copy_pointed(None),
"u": lambda: self._copy_pointed("lower"),
"U": lambda: self._copy_pointed("upper"),
"v|V": self._toggle_details_view,
"\t": self._toggle_match_url,
r'\+': lambda: self.view.resize(1),
r'\-': lambda: self.view.resize(-1),
r'/(.*)[^\]]$': self._search}
self.running = True
def _search(self):
"Prepare to filter items by search term."
self.model.set_search()
self.view.highlighted_item = 0
self.view.pointer = 0
def _quit(self):
"Update state so that everyone knows the program should close."
self.running = False
def _clear_buffer(self, how_much=None):
"Clear keyboard buffer."
if how_much is None:
how_much = len(self.model.kb_buffer)
self.model.kb_buffer = self.model.kb_buffer[:-how_much]
def _toggle_details_view(self):
"Show/hide details view."
self.view.details_window_show = not self.view.details_window_show
def _toggle_match_url(self):
"Toggle the match url toggle."
self.model.match_url = not self.model.match_url
self.view.highlighted_item = 0
self.view.pointer = 0
def _copy_pointed(self, mode=""):
"""Copy an item into the clipboard.
Can copy as all upper or all lower, depending on mode chosen."""
pointed = self.model.filtered_items[self.view.pointer].encode("utf-8")
write_text = pointed.upper() if mode == "upper" else \
pointed.lower() if mode == "lower" else \
pointed
ClipboardFactory.create().put_text(write_text)
def update(self):
"Update the visible items and draw."
self.model.filter()
self.view.update(self.model)
def wait_for_key_and_process(self):
"Wait for a key press and process it."
self.update()
key = self.view.get_key()
if key in (None, Keys.LEFT, Keys.RIGHT):
return
if key == Keys.ENTER:
self._clear_buffer()
elif key == Keys.ESCAPE:
self.model.search_text = ""
self.model.kb_buffer = ""
elif key == Keys.BACKSPACE:
self._clear_buffer(1)
elif key == Keys.UP:
self.view.change_pointer(-1)
elif key == Keys.DOWN:
self.view.change_pointer(1)
else:
self.model.kb_buffer += key
for key, value in self.commands.iteritems():
regex = re.compile(r'\A' + key + r'\Z')
match = regex.match(self.model.kb_buffer)
if match is not None:
value()
break
if len(self.model.kb_buffer) == 0 or self.model.kb_buffer[0] != "/":
self._clear_buffer()
def close(self):
#.........这里部分代码省略.........
示例2: second
# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import update [as 别名]
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done = True # Flag that we are done so we exit this loop
if counter == 0:
# only update once per second (n ticks)
for drone in drones:
# give the drones the new map (or maybe don't) and then update
# the map based on the drones' movement
drone.setMap(data)
# move 'em
direction = drone.nextStep()
#
drone.setLocation(drone.x + direction[0], drone.y + direction[1])
# maybe don't update map based on drone (denied comms)
# TODO this *should* be simultaneous
data = drone.update()
data.update() # update the map (steps all of the diff. eqs. forward one)
view.update(data, drones)
counter = (counter+1) % (fps/10)
clock.tick(fps) # max fps
pygame.quit()
示例3: Controller
# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import update [as 别名]
class Controller(IController):
def __init__(self):
DBusGMainLoop(set_as_default=True)
self.__description__ = None
self.__pipelinestatus__ = False
self.__plugins__ = {}
self.__view__ = View(self, None)
self.__bus__ = dbus.SessionBus()
self.__bus__.add_signal_receiver(self.__dbus_process_registration__,
dbus_interface = 'org.freedesktop.Voxgenerator',
signal_name = 'dbus_plugin_registration')
self.__bus__.add_signal_receiver(self.__dbus_process_pipeline_status__,
dbus_interface = 'org.freedesktop.Voxgenerator',
signal_name = 'dbus_pipeline_play')
self.__view__.title('Voxgenerator control')
self.__initializecontroller__()
gobject.idle_add(self.__updateview__)
self.__loop__ = gobject.MainLoop()
self.__loop__.run()
def __updateview__(self):
try:
self.__view__.update()
except:
self.__loop__.quit()
return True
def __initializecontroller__(self):
self.__bus__ = dbus.SessionBus()
""" initialize pipeline status """
try:
pipe = self.__bus__.get_object("org.freedesktop.Voxgenerator.Pipeline",
"/org/freedesktop/Voxgenerator/Pipeline")
description = pipe.dbus_pipeline_request_description()
""" update plugin """
self.set_current_description(description)
""" update description """
self.__pipelinestatus__ = pipe.dbus_pipeline_request_status()
except:
self.__pipelinestatus__ = False
self.__view__.set_description(self.__description__)
self.__view__.set_pipeline_status(self.__pipelinestatus__)
def __update_pipeline_status__(self):
if self.__pipelinestatus__ == False:
try:
pipe = self.__bus__.get_object("org.freedesktop.Voxgenerator.Pipeline",
"/org/freedesktop/Voxgenerator/Pipeline")
pipe.dbus_pipeline_request_stop()
except:
self.__view__.set_pipeline_status(False)
else:
try:
pipe = self.__bus__.get_object("org.freedesktop.Voxgenerator.Pipeline",
"/org/freedesktop/Voxgenerator/Pipeline")
pipe.dbus_pipeline_request_stop()
except:
print "No need to stop the pipeline !"
if self.__description__ is not None and os.path.isfile(self.__description__):
os.system("run_voxgenerator " + self.__description__ + " &")
else:
self.__view__.show_error("Before trying to start the pipeline, you should choose a valid pipeline xml file!")
self.__view__.set_pipeline_status(False)
def __update_plugins_list__(self):
if self.__description__ is not None and os.path.isfile(self.__description__):
pipeline_tree = etree.parse(self.__description__)
root = pipeline_tree.xpath("/pipelines")
includes = root[0].findall("include")
self.__plugins__.clear()
for f in includes:
plugin_xml = f.get("file")
if os.path.isfile(plugin_xml):
plugin_tree = etree.parse(plugin_xml)
plugins = plugin_tree.xpath("/plugins/plugin")
for plugin in plugins:
name = plugin.get("name")
if not self.__plugins__.has_key(name):
self.__plugins__[name] = False
def __update_plugin_status__(self):
for name in self.__plugins__:
try:
proxy = self.__bus__.get_object("org.freedesktop.Voxgenerator." + name,
"/org/freedesktop/Voxgenerator/" + name)
#.........这里部分代码省略.........