def get_menu_item(self):
        """Overrides method from base class.

           Adds the menu item on the MainWindow if the starters can be found.
           """
        MessageBus.subscribe(MessageBus.Type.CARD_TEXT_MSG, 'post_set_text',
                             self.post_set_card_text)
    def get_menu_item(self):
        """Overrides method from base class.

           Adds the menu item on the MainWindow if the starters can be found.
           """
        MessageBus.subscribe(MessageBus.Type.CARD_TEXT_MSG, 'post_set_text',
                             self.post_set_card_text)
        # Listen for card set changes to manage the cache
        listen_row_update(self.card_set_changed, PhysicalCardSet)
        listen_row_destroy(self.card_set_added_deleted, PhysicalCardSet)
        listen_row_created(self.card_set_added_deleted, PhysicalCardSet)
        self._bDoSignalCleanup = True

        # Make sure we add the tag we need
        oCardTextView = self.parent.card_text_pane.view
        oCardTextView.text_buffer.add_list_tag('starters')

        self.oToggle = Gtk.CheckMenuItem(label="Show Starter Information")
        self.oToggle.connect('toggled', self._toggle_starter)
        self.oToggle.set_active(False)
        if self.check_enabled():
            sPrefsValue = self.get_config_item('show starters')
            if sPrefsValue == 'Yes':
                self.oToggle.set_active(True)
        else:
            self.oToggle.set_sensitive(False)
        oDownload = Gtk.MenuItem(label="Download starter decks")
        oDownload.connect('activate', self.do_download)
        return [('Preferences', self.oToggle), ('Data Downloads', oDownload)]
 def _toggle_starter(self, oToggle):
     """Toggle the show info flag"""
     self.bShowInfo = oToggle.get_active()
     # Update the card text pane to reflect changes
     MessageBus.publish(MessageBus.Type.CARD_TEXT_MSG, 'set_card_text',
                        self.oLastCard)
     if self.bShowInfo:
         self.set_config_item('show starters', 'Yes')
     else:
         self.set_config_item('show starters', 'No')
 def cleanup(self):
     """Remove the listener"""
     if self._bDoSignalCleanup:
         disconnect_row_update(self.card_set_changed, PhysicalCardSet)
         disconnect_row_destroy(self.card_set_added_deleted,
                                PhysicalCardSet)
         disconnect_row_created(self.card_set_added_deleted,
                                PhysicalCardSet)
         MessageBus.unsubscribe(MessageBus.Type.CARD_TEXT_MSG,
                                'post_set_text', self.post_set_card_text)
     super().cleanup()
 def config_activate(self, oMenuWidget):
     """Launch the configuration dialog."""
     bValue = oMenuWidget.get_active()
     self.set_config_item(SuffixTransformer.CONFIG_KEY, bValue)
     MessageBus.publish(MessageBus.Type.CONFIG_MSG,
                        SuffixTransformer.CONFIG_KEY, bValue)
 def cleanup(self):
     """Remove the listener"""
     MessageBus.unsubscribe(MessageBus.Type.CARD_TEXT_MSG, 'post_set_text',
                            self.post_set_card_text)
     super().cleanup()
Esempio n. 7
0
 def set_show_errata_markers(self, bShowErrata):
     """Set the 'show errata markers' option."""
     self._oConfig['main']['show errata markers'] = bShowErrata
     MessageBus.publish(MessageBus.Type.CONFIG_MSG, 'show_errata_markers')
 def test_basic(self):
     """Set of simple tests of the Card List Model"""
     # pylint: disable=too-many-statements, too-many-locals
     # Want a long, sequential test case to minimise
     # repeated setups, so it has lots of lines + variables
     oModel = CardListModel(self.oConfig)
     # We test with illegal cards shown
     oModel.hideillegal = False
     oListener = LocalTestListener(oModel, True)
     self.assertFalse(oListener.bLoadCalled)
     oModel.load()
     self.assertTrue(oListener.bLoadCalled)
     aExpectedCards = set(AbstractCard.select())
     self.assertEqual(aExpectedCards, set(oListener.aCards))
     self.assertEqual(
         oModel.get_card_iterator(None).count(),
         PhysicalCard.select().count())
     # The model as an entry for every AbstractCard and entries
     # below that for every PhysicalCard
     # Set grouping to None for these tests
     oModel.groupby = NullGrouping
     oModel.load()
     self.assertEqual(count_all_cards(oModel),
                      AbstractCard.select().count())
     self.assertEqual(count_second_level(oModel),
                      PhysicalCard.select().count())
     # Check without expansions
     oModel.bExpansions = False
     oModel.load()
     self.assertEqual(count_all_cards(oModel),
                      AbstractCard.select().count())
     self.assertEqual(count_second_level(oModel), 0)
     oModel.bExpansions = True
     oModel.groupby = CryptLibraryGrouping
     oModel.load()
     self.assertEqual(count_all_cards(oModel),
                      AbstractCard.select().count())
     self.assertEqual(count_second_level(oModel),
                      PhysicalCard.select().count())
     self.assertEqual(count_top_level(oModel), 2)
     # Test filtering
     # Test filter which selects nothing works
     oModel.selectfilter = BaseFilters.CardNameFilter('ZZZZZZZ')
     oModel.applyfilter = True
     oModel.load()
     self.assertEqual(count_top_level(oModel), 1)
     self.assertEqual(count_all_cards(oModel), 0)
     oModel.applyfilter = False
     oModel.load()
     self.assertEqual(count_all_cards(oModel),
                      AbstractCard.select().count())
     self.assertEqual(count_second_level(oModel),
                      PhysicalCard.select().count())
     self.assertEqual(count_top_level(oModel), 2)
     # Test card type
     oModel.selectfilter = BaseFilters.CardTypeFilter('Vampire')
     oModel.applyfilter = True
     oModel.load()
     self.assertEqual(count_top_level(oModel), 1)
     self.assertEqual(count_second_level(oModel),
                      oModel.get_card_iterator(oModel.selectfilter).count())
     oModel.groupby = CardTypeGrouping
     oModel.load()
     self.assertEqual(count_top_level(oModel), 1)
     self.assertEqual(count_second_level(oModel),
                      oModel.get_card_iterator(oModel.selectfilter).count())
     # Test path queries
     # The remain tests require a sorted model
     oModel.enable_sorting()
     oPath = '0:0:0'  # First expansion for the first card
     self.assertEqual(oModel.get_exp_name_from_path(oPath),
                      oModel.sUnknownExpansion)
     self.assertEqual(oModel.get_card_name_from_path(oPath),
                      u'Aabbt Kindred (Group 2)')
     tAll = oModel.get_all_from_path(oPath)
     self.assertEqual(tAll[0], u'Aabbt Kindred (Group 2)')
     self.assertEqual(tAll[1], oModel.sUnknownExpansion)
     self.assertEqual(tAll[2], 0)
     self.assertEqual(tAll[3], 2)
     oIter = oModel.get_iter(oPath)
     self.assertEqual(oModel.get_child_entries_from_iter(oIter), [])
     oPath = '0:0'  # First card
     self.assertEqual(oModel.get_exp_name_from_path(oPath), None)
     self.assertEqual(oModel.get_inc_dec_flags_from_path(oPath),
                      (False, False))
     oIter = oModel.get_iter(oPath)
     tAll = oModel.get_all_from_path(oPath)
     self.assertEqual(tAll[0], u'Aabbt Kindred (Group 2)')
     self.assertEqual(tAll[1], None)
     self.assertEqual(tAll[2], 0)
     self.assertEqual(tAll[3], 1)
     oAbbt = IAbstractCard(u'Aabbt Kindred (Group 2)')
     oFirst = IPhysicalCard((oAbbt, None))
     oSecond = IPhysicalCard((oAbbt, IExpansion('Final Nights')))
     self.assertEqual(oModel.get_child_entries_from_iter(oIter),
                      [(oFirst, 0), (oSecond, 0)])
     # Test that the different variants show correctly
     oPath = '0:28:0'  # Harold's position
     self.assertEqual(oModel.get_card_name_from_path(oPath),
                      u"Harold Zettler, Pentex Director (Group 4)")
     self.assertEqual(oModel.get_exp_name_from_path(oPath),
                      oModel.sUnknownExpansion)
     oPath = '0:28:1'
     self.assertEqual(oModel.get_card_name_from_path(oPath),
                      u"Harold Zettler, Pentex Director (Group 4)")
     self.assertEqual(oModel.get_exp_name_from_path(oPath), "Third Edition")
     oPath = '0:28:2'
     self.assertEqual(oModel.get_card_name_from_path(oPath),
                      u"Harold Zettler, Pentex Director (Group 4)")
     self.assertEqual(oModel.get_exp_name_from_path(oPath),
                      "Third Edition (Sketch)")
     oListener.bLoadCalled = False
     # Test MessageBus clear does the right thing
     MessageBus.clear(oModel)
     oModel.load()
     self.assertFalse(oListener.bLoadCalled)
Esempio n. 9
0
 def __init__(self, oIconManager, oMainWindow):
     oBuffer = CardTextBuffer()
     super().__init__(oBuffer, oIconManager, oMainWindow)
     MessageBus.subscribe(MessageBus.Type.CONFIG_MSG, 'show_errata_markers',
                          self._force_reload)