本文整理汇总了Python中bot.Bot.play方法的典型用法代码示例。如果您正苦于以下问题:Python Bot.play方法的具体用法?Python Bot.play怎么用?Python Bot.play使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bot.Bot
的用法示例。
在下文中一共展示了Bot.play方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Handler
# 需要导入模块: from bot import Bot [as 别名]
# 或者: from bot.Bot import play [as 别名]
class Handler(BaseHandler):
"""Class for holding signal handlers. Do not directly call methods."""
def __init__(self, app):
"""Connect the signals"""
self.app = app
self.builder = Gtk.Builder.new_from_file("gui/main.ui")
self.builder.connect_signals(self)
self.bot = Bot([])
self.error_message = self.builder.get_object("error_message")
self.error_dialog = self.builder.get_object("error_dialog")
self.window = self.builder.get_object("window")
self.play_handler = PlayHandler(self)
file_handler = FileHandler(self)
self.builder.get_object("file_menu").set_submenu(file_handler.menu)
self.actionbox = ActionBox(self.bot,
self.builder.get_object("actionbox"))
css = Gtk.CssProvider()
css.load_from_path("css/input.css")
self.window.get_style_context().add_provider_for_screen(
Gdk.Screen.get_default(),
css,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
self.app.add_window(self.window)
self.window.show_all()
def add_card(self, _):
"""Event handler for added card."""
new_card_entry = self.builder.get_object("new_card_entry")
new_card = tuple_from_s(new_card_entry.get_text())
add_frame = self.builder.get_object("add_frame")
if new_card:
self.bot.add_card(new_card)
new_card_entry.set_text("")
add_frame = self.builder.get_object("add_frame")
add_frame.get_style_context().remove_class("invalid")
else:
add_frame.get_style_context().add_class("invalid")
def play_card(self, _):
"""Event handler for play card button."""
prev_card_entry = self.builder.get_object("prevcard_entry")
label = self.builder.get_object("instructions")
prev_card = tuple_from_s(prev_card_entry.get_text())
play_frame = self.builder.get_object("play_frame")
if not prev_card:
play_frame.get_style_context().add_class("invalid")
return
prev_card_entry.set_text("")
play_frame.get_style_context().remove_class("invalid")
try:
play = self.bot.play(prev_card)
except:
self.show_error("Hand is Empty")
return
if play:
card, actions = play
self.play_handler.show(card, prev_card, actions)
else:
self.show_error("Pass")
def toggle_valid(self, button):
"""
Activate or deactivate the action checkboxes, depending on whether
valid checkbox is clicked.
"""
self.builder.get_object("actionbox").set_sensitive(button.get_active())
def add_sample(self, button):
"""
Add a sample to the bot, based on the sample input fields.
"""
prev_card_entry = self.builder.get_object("sample_prevcard_entry")
card_entry = self.builder.get_object("sample_card_entry")
valid_button = self.builder.get_object("valid_checkbox")
prev_card = tuple_from_s(prev_card_entry.get_text())
card = tuple_from_s(card_entry.get_text())
prev_card_frame = self.builder.get_object("prev_card_frame")
card_frame = self.builder.get_object("card_frame")
if not prev_card:
prev_card_frame.get_style_context().add_class("invalid")
if not card:
card_frame.get_style_context().add_class("invalid")
if not prev_card or not card:
return
prev_card_entry.set_text("")
card_entry.set_text("")
prev_card_frame.get_style_context().remove_class("invalid")
card_frame.get_style_context().remove_class("invalid")
actions = self.actionbox.get_actions()
self.actionbox.reset_actions()
self.bot.add_sample(card,
prev_card,
valid_button.get_active(),
actions)
valid_button.set_active(False)
def show_error(self, message):
self.error_message.set_text(message)
self.error_dialog.show()
#.........这里部分代码省略.........