Exemplo n.º 1
0
    def __init__(self):
        Gtk.Grid.__init__(self)
        self.set_column_spacing(5)
        self.current_card = None
        self.card_lib = {}

        # region Search Box
        self.searchbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
                                 spacing=5,
                                 margin_end=5,
                                 margin_start=5,
                                 margin_top=5,
                                 margin_bottom=5)
        self.searchEntry = Gtk.Entry()
        self.searchEntry.connect("activate", self.online_search_clicked)
        self.searchbutton = Gtk.Button("Search Online")
        self.searchbutton.connect("clicked", self.online_search_clicked)
        self.searchEntryLabel = Gtk.Label(xalign=0, yalign=0)
        self.searchEntryLabel.set_markup("<big>Search for Cards:</big>")

        self.progressbar = Gtk.ProgressBar()
        self.progressbar.set_no_show_all(True)

        self.searchbox.add(self.searchEntryLabel)
        self.searchbox.add(self.searchEntry)
        self.searchbox.add(self.searchbutton)
        self.searchbox.add(self.progressbar)
        self.searchbox.add(Gtk.HSeparator())
        # endregion

        # region Filters

        # Color of the cards
        color_cooser_label = Gtk.Label("Mana Color", xalign=0, yalign=0)

        self.red_mana_button = Gtk.ToggleButton(name="R", active=True)
        self.red_mana_button.connect("toggled", self.mana_toggled)
        self.blue_mana_button = Gtk.ToggleButton(name="U", active=True)
        self.blue_mana_button.connect("toggled", self.mana_toggled)
        self.green_mana_button = Gtk.ToggleButton(name="G", active=True)
        self.green_mana_button.connect("toggled", self.mana_toggled)
        self.black_mana_button = Gtk.ToggleButton(name="B", active=True)
        self.black_mana_button.connect("toggled", self.mana_toggled)
        self.white_mana_button = Gtk.ToggleButton(name="W", active=True)
        self.white_mana_button.connect("toggled", self.mana_toggled)
        self.colorless_mana_button = Gtk.ToggleButton(name="C", active=True)
        self.colorless_mana_button.connect("toggled", self.mana_toggled)

        self.color_chooser = Gtk.Grid(row_spacing=5, column_spacing=5)
        self.color_chooser.attach(self.white_mana_button, 0, 0, 1, 1)
        self.color_chooser.attach(self.blue_mana_button, 1, 0, 1, 1)
        self.color_chooser.attach(self.black_mana_button, 2, 0, 1, 1)
        self.color_chooser.attach(self.red_mana_button, 0, 1, 1, 1)
        self.color_chooser.attach(self.green_mana_button, 1, 1, 1, 1)
        self.color_chooser.attach(self.colorless_mana_button, 2, 1, 1, 1)

        # Text renderer for the Combo Boxes
        renderer_text = Gtk.CellRendererText()
        renderer_text.set_property("wrap-width", 5)
        renderer_text.set_property("wrap-mode", Pango.WrapMode.CHAR)
        renderer_text.props.ellipsize = Pango.EllipsizeMode.END

        # Rarity
        rarity_label = Gtk.Label("Rarity", xalign=0)
        self.rarity_store = Gtk.ListStore(str, str)
        self.rarity_store.append(["", "Any"])
        self.rarity_store.append(["common", "Common"])
        self.rarity_store.append(["uncommon", "Uncommon"])
        self.rarity_store.append(["rare", "Rare"])
        self.rarity_store.append(["mythic rare", "Mythic Rare"])
        self.rarity_combo = Gtk.ComboBox.new_with_model(self.rarity_store)
        self.rarity_combo.pack_start(renderer_text, True)
        self.rarity_combo.add_attribute(renderer_text, "text", 1)

        # Set
        set_label = Gtk.Label("Set", xalign=0)
        self.set_store = Gtk.ListStore(str, str)
        self.set_store.append(["", "Any"])
        for set in util.set_list:
            self.set_store.append([set.code, set.name])

        self.set_combo = Gtk.ComboBox.new_with_model(self.set_store)
        self.set_combo.pack_start(renderer_text, True)
        self.set_combo.add_attribute(renderer_text, "text", 1)
        self.set_combo.set_entry_text_column(1)
        self.set_combo.set_wrap_width(5)
        self.set_combo.set_hexpand(False)

        # Autocomplete search in Set Combobox
        completer = Gtk.EntryCompletion()
        completer.set_model(self.set_store)
        completer.set_text_column(1)

        self.set_entry = Gtk.Entry()
        self.set_entry.set_completion(completer)

        # completer.connect("match-selected", self.match_selected)
        # self.set_combo.get_child().set_completion(completer)

        # Type
        type_label = Gtk.Label("Type", xalign=0)
        self.type_store = Gtk.ListStore(str)
        types = [
            "Any", "Creature", "Artifact", "Instant", "Enchantment", "Sorcery",
            "Land", "Planeswalker"
        ]
        for cardtype in types:
            self.type_store.append([cardtype])
        self.type_combo = Gtk.ComboBox.new_with_model(self.type_store)
        self.type_combo.pack_start(renderer_text, True)
        self.type_combo.add_attribute(renderer_text, "text", 0)

        self.filters_grid = Gtk.Grid(row_spacing=5, column_spacing=5)
        self.filters_grid.attach(color_cooser_label, 0, 0, 1, 1)
        self.filters_grid.attach(self.color_chooser, 1, 0, 1, 1)

        self.filters_grid.attach(rarity_label, 0, 1, 1, 1)
        self.filters_grid.attach(self.rarity_combo, 1, 1, 1, 1)

        self.filters_grid.attach(type_label, 0, 2, 1, 1)
        self.filters_grid.attach(self.type_combo, 1, 2, 1, 1)

        self.filters_grid.attach(set_label, 0, 3, 1, 1)
        self.filters_grid.attach(self.set_entry, 1, 3, 1, 1)

        self.filters_title = Gtk.Label(xalign=0, yalign=0)
        self.filters_title.set_markup("<big>Filter search results</big>")

        self.filters = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
                               spacing=5,
                               margin_end=5,
                               margin_start=5,
                               margin_top=5,
                               margin_bottom=5)
        self.filters.pack_start(self.filters_title, False, False, 5)
        self.filters.pack_start(self.filters_grid, False, False, 0)

        # endregion

        # Set all Buttons active
        self._do_init_filter_controls()

        # Card List
        self.search_results = cardlist.CardList(False)
        self.search_results.selection.connect("changed", self.on_card_selected)

        # Detail View for selected Card
        self.details = details.DetailBar()

        # Button to add to library
        self.add_delete_button = Gtk.Button()
        self.add_delete_button.set_no_show_all(True)
        self.add_delete_button.connect("clicked", self.on_add_delete)

        # Bring it all together
        left_pane = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        left_pane.pack_start(self.searchbox, False, False, 0)
        left_pane.pack_start(self.filters, False, False, 0)
        left_pane.set_hexpand(False)

        right_pane = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        right_pane.pack_start(self.details, True, True, 0)
        right_pane.pack_start(Gtk.VSeparator(), False, False, 2)
        right_pane.pack_start(self.add_delete_button, False, False, 2)

        # Search
        self.attach(left_pane, 0, 0, 1, 1)
        # Separator
        self.attach(Gtk.VSeparator(), 1, 0, 1, 1)
        # List
        self.attach(self.search_results, 2, 0, 1, 1)
        # Separator
        self.attach(Gtk.VSeparator(), 3, 0, 1, 1)
        # Details and Add/Remove Button
        self.attach(right_pane, 4, 0, 1, 1)
Exemplo n.º 2
0
    def __init__(self):
        Gtk.Grid.__init__(self)
        self.set_column_spacing(5)
        self.current_card = None

        # region Tag Bar

        tag_bar = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        tag_label = Gtk.Label("Organize Tags here")
        tag_bar.pack_start(tag_label, True, True, 0)

        # endregion

        self.lib_list = cardlist.CardList(True)
        self.lib_list.selection.connect("changed", self.on_card_selected)
        self.lib_list.filter.set_visible_func(self.lib_filter_func)

        # Detailed Card View
        self.details = details.DetailBar()

        self.remove_button = Gtk.Button("Remove from Library")
        self.remove_button.modify_bg(Gtk.StateType.NORMAL, config.red_color)
        self.remove_button.set_no_show_all(True)
        self.remove_button.connect("clicked", self.remove_button_clicked)

        # region Top bar

        topbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL,
                         margin_top=2,
                         margin_bottom=2)
        search_label = Gtk.Label()
        search_label.set_markup("<big>Search</big>")

        search_completer = Gtk.EntryCompletion()
        search_completer.set_model(self.lib_list.store)
        search_completer.set_text_column(1)

        self.search_entry = Gtk.Entry()
        self.search_entry.set_completion(search_completer)
        self.search_entry.connect("activate", self.search_activated)

        self.refresh_button = Gtk.Button("Refresh")
        self.refresh_button.set_image(
            Gtk.Image.new_from_icon_name(Gtk.STOCK_REFRESH, 0))
        self.refresh_button.connect("clicked", self.refresh_library)

        topbox.pack_start(search_label, False, False, 2)
        topbox.pack_start(self.search_entry, False, False, 2)
        topbox.pack_start(self.refresh_button, False, False, 2)

        # endregion

        right_pane = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        right_pane.pack_start(self.details, True, True, 0)
        right_pane.pack_start(Gtk.VSeparator(), False, False, 2)
        right_pane.pack_start(self.remove_button, False, False, 2)

        spinner = Gtk.Spinner()
        spinner.start()
        label = Gtk.Label("Loading List")

        self.spinner_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.spinner_box.pack_start(spinner, True, False, 0)
        self.overlay = Gtk.Overlay()
        self.overlay.add(self.lib_list)
        self.overlay.add_overlay(self.spinner_box)
        self.overlay.show_all()

        # Bring it all together

        self.attach(topbox, 0, 0, 3, 1)

        self.attach(Gtk.VSeparator(), 0, 1, 3, 1)

        self.attach(tag_bar, 0, 2, 1, 1)

        self.attach(Gtk.VSeparator(), 1, 2, 1, 1)

        self.attach(self.overlay, 2, 2, 1, 1)

        self.attach(Gtk.VSeparator(), 3, 0, 1, 3)

        self.attach(right_pane, 4, 0, 1, 3)
Exemplo n.º 3
0
    def __init__(self, handle):
        Activity.__init__(self, handle)

        self.play_mode = None

        toolbar_box = ToolbarBox()
        self.set_toolbar_box(toolbar_box)

        self.activity_button = ActivityToolbarButton(self)
        toolbar_box.toolbar.insert(self.activity_button, -1)

        self._memorizeToolbarBuilder = \
            memorizetoolbar.MemorizeToolbarBuilder(self)

        toolbar_box.toolbar.insert(Gtk.SeparatorToolItem(), -1)

        self._edit_button = ToggleToolButton('view-source')
        self._edit_button.set_tooltip(_('Edit game'))
        self._edit_button.set_active(False)
        toolbar_box.toolbar.insert(self._edit_button, -1)

        self._createToolbarBuilder = \
            createtoolbar.CreateToolbarBuilder(self)

        separator = Gtk.SeparatorToolItem()
        separator.set_expand(True)
        separator.set_draw(False)
        separator.set_size_request(0, -1)
        toolbar_box.toolbar.insert(separator, -1)

        toolbar_box.toolbar.insert(StopButton(self), -1)

        self.game = game.MemorizeGame()
        # Play game mode
        self.table = cardtable.CardTable()
        self.scoreboard = scoreboard.Scoreboard()
        self.cardlist = cardlist.CardList()
        self.createcardpanel = createcardpanel.CreateCardPanel(self.game)
        self.cardlist.connect('pair-selected',
                              self.createcardpanel.pair_selected)
        self.cardlist.connect(
            'update-create-toolbar',
            self._createToolbarBuilder.update_create_toolbar)
        self.createcardpanel.connect('add-pair',
                                     self.cardlist.add_pair)
        self.createcardpanel.connect('update-pair',
                                     self.cardlist.update_selected)
        self.createcardpanel.connect('change-font',
                                     self.cardlist.change_font)
        self.createcardpanel.connect('pair-closed',
                                     self.cardlist.rem_current_pair)

        self._createToolbarBuilder.connect('create_new_game',
                                           self.cardlist.clean_list)
        self._createToolbarBuilder.connect('create_new_game',
                                           self.createcardpanel.clean)
        self._createToolbarBuilder.connect(
            'create_new_game',
            self._memorizeToolbarBuilder.reset)
        self._createToolbarBuilder.connect('create_equal_pairs',
                                           self.change_equal_pairs)

        self._edit_button.connect('toggled', self._change_mode_bt)

        self.connect('key-press-event', self.table.key_press_event)
        self.table.connect('card-flipped', self.game.card_flipped)
        self.table.connect('card-highlighted', self.game.card_highlighted)

        self.game.connect('set-border', self.table.set_border)
        self.game.connect('flop-card', self.table.flop_card)
        self.game.connect('flip-card', self.table.flip_card)
        self.game.connect('cement-card', self.table.cement_card)
        self.game.connect('highlight-card', self.table.highlight_card)
        self.game.connect('load_mode', self.table.load_msg)

        self.game.connect('msg_buddy', self.scoreboard.set_buddy_message)
        self.game.connect('add_buddy', self.scoreboard.add_buddy)
        self.game.connect('rem_buddy', self.scoreboard.rem_buddy)
        self.game.connect('increase-score', self.scoreboard.increase_score)
        self.game.connect('wait_mode_buddy', self.scoreboard.set_wait_mode)
        self.game.connect('change-turn', self.scoreboard.set_selected)
        self.game.connect('change_game', self.scoreboard.change_game)

        self.game.connect('reset_scoreboard', self.scoreboard.reset)
        self.game.connect('reset_table', self.table.reset)

        self.game.connect('load_game', self.table.load_game)
        self.game.connect('change_game', self.table.change_game)
        self.game.connect('load_game',
                          self._memorizeToolbarBuilder.update_toolbar)
        self.game.connect('change_game',
                          self._memorizeToolbarBuilder.update_toolbar)
        self.game.connect('change_game',
                          self.createcardpanel.update_font_combos)

        self._memorizeToolbarBuilder.connect('game_changed',
                                             self.change_game)

        self.box = Gtk.HBox(orientation=Gtk.Orientation.VERTICAL,
                            homogeneous=False)

        width = Gdk.Screen.width()
        height = Gdk.Screen.height() - style.GRID_CELL_SIZE
        self.table.resize(width, height - style.GRID_CELL_SIZE)
        self.scoreboard.set_size_request(-1, style.GRID_CELL_SIZE)
        self.box.pack_start(self.table, True, True, 0)
        self.box.pack_start(self.scoreboard, False, False, 0)
        self.set_canvas(self.box)

        # connect to the in/out events of the memorize activity
        self.connect('focus_in_event', self._focus_in)
        self.connect('focus_out_event', self._focus_out)
        self.connect('destroy', self._cleanup_cb)

        self.add_events(Gdk.EventMask.POINTER_MOTION_MASK)
        self.connect('motion_notify_event',
                     lambda widget, event: face.look_at())

        Gdk.Screen.get_default().connect('size-changed',
                                         self.__configure_cb)

        # start on the game toolbar, might change this
        # to the create toolbar later
        self._change_mode(_MODE_PLAY)

        # Get the Presence Service
        self.pservice = presenceservice.get_instance()
        self.initiating = None

        # Buddy object for you
        owner = self.pservice.get_owner()
        self.owner = owner
        self.current = 0

        self.game.set_myself(self.owner)
        self.connect('shared', self._shared_cb)

        # Owner.props.key
        if self.get_shared_activity():
            # We are joining the activity
            self.connect('joined', self._joined_cb)
            if self.get_shared():
                # We've already joined
                self._joined_cb(self)
        elif not self._jobject.file_path:
            logging.debug('buddy joined - __init__: %s', self.owner.props.nick)
            game_file = os.path.join(os.path.dirname(__file__), 'demos',
                                     'addition.zip')
            self.game.load_game(game_file, 4, 'demo')
            logging.debug('loading conventional')
            self.game.add_buddy(self.owner)
        else:
            self.game.add_buddy(self.owner)
        self.show_all()
Exemplo n.º 4
0
    def __init__(self, handle):
        Activity.__init__(self, handle)

        self.play_mode = None

        toolbar_box = ToolbarBox()
        self.set_toolbar_box(toolbar_box)

        self.activity_button = ActivityToolbarButton(self)
        toolbar_box.toolbar.insert(self.activity_button, -1)

        self._memorizeToolbarBuilder = \
            memorizetoolbar.MemorizeToolbarBuilder(self)

        toolbar_box.toolbar.insert(Gtk.SeparatorToolItem(), -1)

        self._edit_button = ToggleToolButton('view-source')
        self._edit_button.set_tooltip(_('Edit game'))
        self._edit_button.set_active(False)
        toolbar_box.toolbar.insert(self._edit_button, -1)

        self._createToolbarBuilder = \
            createtoolbar.CreateToolbarBuilder(self)

        separator = Gtk.SeparatorToolItem()
        separator.set_expand(True)
        separator.set_draw(False)
        separator.set_size_request(0, -1)
        toolbar_box.toolbar.insert(separator, -1)

        toolbar_box.toolbar.insert(StopButton(self), -1)

        self.game = game.MemorizeGame()
        # Play game mode
        self.table = cardtable.CardTable()
        self.scoreboard = scoreboard.Scoreboard()
        self.cardlist = cardlist.CardList()
        self.createcardpanel = createcardpanel.CreateCardPanel(self.game)
        self.cardlist.connect('pair-selected',
                              self.createcardpanel.pair_selected)
        self.cardlist.connect('update-create-toolbar',
                              self._createToolbarBuilder.update_create_toolbar)
        self.createcardpanel.connect('add-pair', self.cardlist.add_pair)
        self.createcardpanel.connect('update-pair',
                                     self.cardlist.update_selected)
        self.createcardpanel.connect('change-font', self.cardlist.change_font)
        self.createcardpanel.connect('pair-closed',
                                     self.cardlist.rem_current_pair)

        self._createToolbarBuilder.connect('create_new_game',
                                           self.cardlist.clean_list)
        self._createToolbarBuilder.connect('create_new_game',
                                           self.createcardpanel.clean)
        self._createToolbarBuilder.connect('create_new_game',
                                           self._memorizeToolbarBuilder.reset)
        self._createToolbarBuilder.connect('create_equal_pairs',
                                           self.change_equal_pairs)

        self._edit_button.connect('toggled', self._change_mode_bt)

        self.connect('key-press-event', self.table.key_press_event)
        self.table.connect('card-flipped', self.game.card_flipped)
        self.table.connect('card-highlighted', self.game.card_highlighted)

        self.game.connect('set-border', self.table.set_border)
        self.game.connect('flop-card', self.table.flop_card)
        self.game.connect('flip-card', self.table.flip_card)
        self.game.connect('cement-card', self.table.cement_card)
        self.game.connect('highlight-card', self.table.highlight_card)
        self.game.connect('load_mode', self.table.load_msg)

        self.game.connect('msg_buddy', self.scoreboard.set_buddy_message)
        self.game.connect('add_buddy', self.scoreboard.add_buddy)
        self.game.connect('rem_buddy', self.scoreboard.rem_buddy)
        self.game.connect('increase-score', self.scoreboard.increase_score)
        self.game.connect('wait_mode_buddy', self.scoreboard.set_wait_mode)
        self.game.connect('change-turn', self.scoreboard.set_selected)
        self.game.connect('change_game', self.scoreboard.change_game)

        self.game.connect('reset_scoreboard', self.scoreboard.reset)
        self.game.connect('reset_table', self.table.reset)

        self.game.connect('load_game', self.table.load_game)
        self.game.connect('change_game', self.table.change_game)
        self.game.connect('load_game',
                          self._memorizeToolbarBuilder.update_toolbar)
        self.game.connect('change_game',
                          self._memorizeToolbarBuilder.update_toolbar)
        self.game.connect('change_game',
                          self.createcardpanel.update_font_combos)

        self._memorizeToolbarBuilder.connect('game_changed', self.change_game)

        self.box = Gtk.HBox(orientation=Gtk.Orientation.VERTICAL,
                            homogeneous=False)

        width = Gdk.Screen.width()
        height = Gdk.Screen.height() - style.GRID_CELL_SIZE
        self.table.resize(width, height - style.GRID_CELL_SIZE)
        self.scoreboard.set_size_request(-1, style.GRID_CELL_SIZE)
        self.set_canvas(self.box)

        # connect to the in/out events of the memorize activity
        self.connect('focus_in_event', self._focus_in)
        self.connect('focus_out_event', self._focus_out)
        self.connect('destroy', self._cleanup_cb)

        self.add_events(Gdk.EventMask.POINTER_MOTION_MASK)
        self.connect('motion_notify_event',
                     lambda widget, event: face.look_at())

        Gdk.Screen.get_default().connect('size-changed', self.__configure_cb)

        # start on the game toolbar, might change this
        # to the create toolbar later
        self._change_mode(_MODE_PLAY)

        def on_activity_joined_cb(me):
            logging.debug('activity joined')
            self.game.add_buddy(self._collab.props.owner)

        self.connect('joined', on_activity_joined_cb)

        def on_activity_shared_cb(me):
            logging.debug('activity shared')

        self.connect('shared', on_activity_shared_cb)

        self._collab = CollabWrapper(self)
        self.game.set_myself(self._collab.props.owner)

        def on_message_cb(collab, buddy, msg):
            logging.debug('on_message_cb buddy %r msg %r' % (buddy, msg))
            action = msg.get('action')
            if action == 'flip':
                n = msg.get('n')
                self.game.card_flipped(None, n, True)
            elif action == 'change':
                self.get_canvas().hide()

                def momentary_blank_timeout_cb():
                    self.set_data(msg)
                    self.get_canvas().show()

                GLib.timeout_add(100, momentary_blank_timeout_cb)

        self._collab.connect('message', on_message_cb)

        def on_joined_cb(collab, msg):
            logging.debug('joined')

        self._collab.connect('joined', on_joined_cb, 'joined')

        def on_buddy_joined_cb(collab, buddy, msg):
            logging.debug('on_buddy_joined_cb buddy %r msg %r' % (buddy, msg))
            self.game.add_buddy(buddy)

        self._collab.connect('buddy_joined', on_buddy_joined_cb,
                             'buddy_joined')

        def on_buddy_left_cb(collab, buddy, msg):
            logging.debug('on_buddy_left_cb buddy %r msg %r' % (buddy, msg))
            self.game.rem_buddy(buddy)

        self._collab.connect('buddy_left', on_buddy_left_cb, 'buddy_left')

        self._files = {}  # local temporary copies of shared games

        self._collab.setup()

        def on_flip_card_cb(game, n):
            logging.debug('on_flip_card_cb n %r' % (n))
            self._collab.post({'action': 'flip', 'n': n})

        self.game.connect('flip-card-signal', on_flip_card_cb)

        def on_change_game_cb(sender, mode, grid, data, waiting_list, zip):
            logging.debug('on_change_game_cb')
            blob = self.get_data()
            blob['action'] = 'change'

            self._collab.post(blob)

        self.game.connect('change_game_signal', on_change_game_cb)

        if self._collab.props.leader:
            logging.debug('is leader')
            game_file = os.path.join(os.path.dirname(__file__), 'demos',
                                     'addition.zip')
            self.game.load_game(game_file, 4, 'demo')
            self.game.add_buddy(self._collab.props.owner)

        self.show_all()