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


Python World.connect方法代码示例

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


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

示例1: Window

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import connect [as 别名]
class Window(Gtk.ApplicationWindow):
    def __init__(self, app):
        Gtk.ApplicationWindow.__init__(self, title=_("Clocks"),
                                       application=app,
                                       hide_titlebar_when_maximized=True)

        action = Gio.SimpleAction.new("new", None)
        action.connect("activate", self._on_new_activated)
        self.add_action(action)
        app.add_accelerator("<Primary>n", "win.new", None)

        action = Gio.SimpleAction.new("about", None)
        action.connect("activate", self._on_about_activated)
        self.add_action(action)

        css_provider = Gtk.CssProvider()
        css_provider.load_from_path(os.path.join(Dirs.get_data_dir(),
                                                 "gtk-style.css"))
        context = Gtk.StyleContext()
        context.add_provider_for_screen(Gdk.Screen.get_default(),
                                         css_provider,
                                         Gtk.STYLE_PROVIDER_PRIORITY_USER)

        self.set_size_request(640, 480)
        self.vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.embed = Embed(self.vbox)
        self.add(self.embed)
        self.notebook = Gtk.Notebook()
        self.notebook.set_show_tabs(False)
        self.notebook.set_show_border(False)

        self.world = World()
        self.alarm = Alarm()
        self.stopwatch = Stopwatch()
        self.timer = Timer()

        self.views = (self.world, self.alarm, self.stopwatch, self.timer)

        self.toolbar = ClocksToolbar(self.views, self.embed)

        self.vbox.pack_start(self.toolbar, False, False, 0)

        self.single_evbox = Gtk.EventBox()

        self.vbox.pack_end(self.notebook, True, True, 0)
        for view in self.views:
            self.notebook.append_page(view, None)
        self.notebook.append_page(self.single_evbox, None)

        self.world.connect("show-standalone", self._on_show_standalone)
        self.alarm.connect("show-standalone", self._on_show_standalone)

        self.toolbar.connect("view-clock", self._on_view_clock)
        self.vbox.show_all()
        self.show_all()
        self.toolbar.show_overview_toolbar()

    def show_clock(self, view):
        self.toolbar.activate_view(view)

    def _on_show_standalone(self, widget, d):
        def show_standalone_page():
            widget = d.get_standalone_widget()
            self.toolbar.show_standalone_toolbar(widget)
            self.single_evbox.add(widget)
            self.notebook.set_current_page(-1)

        if self.notebook.get_current_page() != len(self.views):
            self.embed.spotlight(show_standalone_page)

    def _on_view_clock(self, button, view):
        def show_clock_view():
            for child in self.single_evbox.get_children():
                self.single_evbox.remove(child)
            view.unselect_all()
            self.notebook.set_current_page(self.views.index(view))
            self.toolbar.show_overview_toolbar()

        if self.single_evbox.get_children():
            self.embed.spotlight(show_clock_view)
        else:
            show_clock_view()

    def _on_new_activated(self, action, param):
        self.toolbar.current_view.open_new_dialog()

    def _on_about_activated(self, action, param):
        about = Gtk.AboutDialog()
        about.set_title(_("About Clocks"))
        about.set_program_name(_("GNOME Clocks"))
        about.set_logo_icon_name("clocks")
        about.set_version(__version__)
        about.set_copyright(COPYRIGHTS)
        about.set_comments(
            _("Utilities to help you with the time."))
        about.set_authors(AUTHORS)
        about.set_translator_credits(_("translator-credits"))
        about.set_website("http://live.gnome.org/GnomeClocks")
        about.set_website_label(_("GNOME Clocks"))
        about.set_wrap_license("true")
#.........这里部分代码省略.........
开发者ID:DylanMcCall,项目名称:gnome-clocks-time-slider,代码行数:103,代码来源:app.py

示例2: __init__

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import connect [as 别名]
class Server:
	def __init__(self):
		self.clients = dict()
		self.world = World()

		self.frame_duration = 0.5 # seconds
		self.frame_start_time = time.time() # TODO: Use in python3: time.perf_counter()
		self.frame_elapsed_time = 0

	def update(self):
		self.frame_elapsed_time = time.time() - self.frame_start_time # TODO: Use in python3: time.perf_counter()
		if self.frame_elapsed_time >= self.frame_duration:
			self.world.update()
			self.send_world_all()
			self.send_entities_all()
			self.frame_elapsed_time -= self.frame_duration
			self.frame_start_time += self.frame_duration

	def check_permission(self, client):
		return client in self.clients

	def check_permission_admin(self, client):
		return True

	def receive_connect(self, client):
		if not client in self.clients:
			entity = Entity((0, 0) if self.world.is_empty else self.world.find_random_empty)
			index = self.world.connect(entity)

			self.clients[client] = index

			self.send_base(client, self.frame_duration)
			self.send_world(client)
			self.send_entities_all()

	def receive_create_random_world(self, client, i_count, j_count, fill_percent):
		if not self.check_permission_admin(client):
			return

		self.world.fill_random(i_count, j_count, fill_percent)

		self.send_world_all()
		self.send_entities_all()

	def receive_add_bot(self, client, bot_count):
		if not self.check_permission_admin(client):
			return

		for i in range(bot_count):
			entity = Entity((0, 0) if self.world.is_empty else self.world.find_random_empty)
			self.world.connect(entity)

		self.send_entities_all()

	def receive_restart_game(self, client):
		if not self.check_permission_admin(client):
			return

		self.receive_create_random_world(self, self.world.i_count, self.world.j_count, self.world.fill_percent)

		self.frame_start_time = time.time() # TODO: Use in python3: time.perf_counter()
		self.frame_elapsed_time = 0

	def receive_entity_command(self, client, command):
		if not self.check_permission(client):
			return

		index = self.clients[client]
		self.world.entities[index].command = command

	def send_base(self, client, frame_duration):
		client.receive_base(self, self.frame_duration)

	def send_world(self, client):
		client.receive_world(self, self.world)

	def send_world_all(self):
		for client in self.clients:
			self.send_world(client)

	def send_entities(self, client):
		client.receive_entities(self, self.world.entities)

	def send_entities_all(self):
		for client in self.clients:
			self.send_entities(client)
开发者ID:Ring-r,项目名称:sandbox,代码行数:88,代码来源:server.py


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