def init_qs_autocomplete(self): """Initialize the quicksearch entry autocompletion""" completion = gtk.EntryCompletion() completion.set_model(self.liststore_qs_autocomplete) completion.set_property("text-column", 0) completion.set_inline_completion(False) completion.set_minimum_key_length(3) completion.set_popup_set_width(False) completion.connect("match-selected", self.qs_autocomplete_pick) renderer = gtk.CellRendererText() completion.pack_start(renderer, True) completion.set_attributes(renderer, markup=1) descrenderer = gtk.CellRendererText() completion.pack_end(descrenderer) self.quicksearch_entry.set_completion(completion) # Populate quicksearch autocomplete for setname in cards.sets: desc1 = setname + " <span size=\"x-small\">" \ "(Card set - all in set)</span>" desc2 = setname + " <span size=\"x-small\">" \ "(Card set - new in that set)</span>" self.liststore_qs_autocomplete.append((setname, desc1, '"setname" = ?', setname)) self.liststore_qs_autocomplete.append((setname, desc2, _query_new_in_set, setname)) if not settings.save_ram: # Because it requires a lot of RAM, the card and card type # autocomplete feature is not available in the reduced RAM mode subtypes = dict() for card in cards.cards: for subtype in card.subtype.split(" "): yield if subtype in subtypes: subtypes[subtype] += 1 else: subtypes[subtype] = 1 for subtype in subtypes: if subtypes[subtype] >= 3: # Only use subtypes that occur more than 3 times on cards desc = (subtype + " <span size=\"x-small\">(Creature type)</span>") self.liststore_qs_autocomplete.append((subtype, desc, '"subtype" LIKE ?', "%" + subtype + "%")) cardnames = yield set(card.name for card in cards.cards) for cardname in cardnames: card = yield cards.find_by_name(cardname)[0] desc = card.name + " <span size=\"x-small\">" + card.cardtype if card.subtype != "": desc += " - " + card.subtype if card.manacost != "": desc += " (%s)" % card.manacost desc += "</span>" self.liststore_qs_autocomplete.append((cardname, desc, '"name" = ?', card.name))
def create_carditem(self, cardid, cardname, itemid=None, x=0, y=0): # Check for card id card = cards.get(cardid) if card is None: l = cards.find_by_name(cardname) if l == []: raise RuntimeError(_("'%s' not found in database. Update?") % cardname) else: card = l[0] item = self.new_item(card, self, x, y) if itemid is None: itemid = self._get_new_itemid(item) item.itemid = itemid else: self._set_itemid(itemid, item) self.send_network_cmd("enter", cardid, cardname, itemid, item.x, item.y) self.battlefield.append(item) return item
def load(filename, progresscallback=None, returncallback=None): """Load a magic deck from a file; asynchronious method""" deck, cardlist = yield _parse_file(filename) # check for write-protection if not os.access(filename, os.W_OK): deck.readonly = True # lookup in the db for i in range(len(cardlist)): num, name, setname, sb = cardlist[i] try: l = yield cards.find_by_name(name) except RuntimeError: # try to find card by adding parenthesis name = "%(" + name + ")%" if setname is not None: l = yield cards.search('"setname" = ? AND "name" LIKE ?' ' ORDER BY "releasedate" DESC', (setname, name)) if setname is None or l == []: l = yield cards.search('"name" LIKE ?' + ' ORDER BY "releasedate" DESC', (name,)) if l == []: logging.error("Card '%s' not found.", name[2:-2]) continue if setname is not None: ll = filter(lambda card: card.setname == setname, l) if ll != []: l = ll card = random.choice(l) assert(0 <= num < 1000) targetlist = deck.sideboard if sb else deck.decklist for j in range(num): targetlist.append(copy.copy(card)) if progresscallback is not None: progresscallback(float(i) / len(cardlist)) if returncallback is not None: returncallback(deck)