Пример #1
0
 def __init__(self, parent, wlist):
     n_words = str(wlist.count_words())
     avg_length = "%.2f" % wlist.average_word_length()
     avg_score = "%.2f" % wlist.average_word_score()
     props = [(u"Word list:", wlist.name)
         , (u"Number of words:", n_words)
         , (u"Average word length:", avg_length)
         , (u"Average word score:", avg_score)
     ]
     super(WordListPropertiesDialog, self).__init__(parent, u"Word list properties", props)
     self.counts_store, tree, l_window = create_tree((int, int)
         , [(u"Length", 0), (u"Count", 1)], window_size=(300, 300))
     self.score_store, score_tree, s_window = create_tree((int, int)
         , [(u"Score", 0), (u"Count", 1)], window_size=(300, 300))
     pages = [(l_window, u"Words by length"), (s_window, u"Words by score")]
     self.main.pack_start(create_notebook(pages))
     self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
     counts = wlist.get_word_counts()
     scores = wlist.get_score_counts()
     for l in sorted(wlist.words.keys()):
         if counts[l] == 0:
             continue
         self.counts_store.append([l, counts[l]])
     for k in sorted(scores.keys()):
         self.score_store.append([k, scores[k]])
Пример #2
0
 def __init__(self, parent, wlist):
     super(WordListPropertiesDialog, self).__init__(parent, u"Word list properties")
     table = gtk.Table(4, 2)
     table.set_col_spacings(6)
     table.set_row_spacings(6)
     def create_row(y, title, info):
         table.attach(create_label(title), 0, 1, y, y + 1)
         info_label = create_label(info, align=(1, 0))
         table.attach(info_label, 1, 2, y, y + 1)
         return info_label
     create_row(0, u"Word list:", wlist.name)
     self.n_words_label = create_row(1, u"Number of words:", u"0")
     self.avg_word_label = create_row(2, u"Average word length:", u"0")
     self.avg_score_label = create_row(3, u"Average word score:", u"0")
     self.counts_store, tree, l_window = create_tree((int, int)
         , [(u"Length", 0), (u"Count", 1)], window_size=(300, 300))
     self.score_store, score_tree, s_window = create_tree((int, int)
         , [(u"Score", 0), (u"Count", 1)], window_size=(300, 300))
     self.main.pack_start(table)
     pages = [(l_window, u"Words by length"), (s_window, u"Words by score")]
     self.main.pack_start(create_notebook(pages))
     self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
     self.n_words_label.set_text(str(wlist.count_words()))
     counts = wlist.get_word_counts()
     scores = wlist.get_score_counts()
     for l in sorted(wlist.words.keys()):
         if counts[l] == 0:
             continue
         self.counts_store.append([l, counts[l]])
     for k in sorted(scores.keys()):
         self.score_store.append([k, scores[k]])
     self.avg_word_label.set_text("%.2f" % wlist.average_word_length())
     self.avg_score_label.set_text("%.2f" % wlist.average_word_score())
Пример #3
0
 def __init__(self, parent):
     super(WordUsageDialog, self).__init__(parent
         , u"Configure word list usage", horizontal=True)
     self.wordlists = parent.wordlists
     pages = [(self.create_find_words(parent), u"Finding words")
         #, (self.create_blacklist(parent), u"Blacklist")
     ]
     self.main.pack_start(create_notebook(pages, border=(8, 4)))
     self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
     self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
Пример #4
0
    def create(self, puzzle):
        vbox = gtk.VBox()
        vbox.set_spacing(6)
        vbox.set_border_width(6)
        result = self.create_entry(vbox, "text", u"<b>Clue</b>")
        self.clue_entry, self.c_changed_id = result

        def on_cycle_clue(target):
            it = store_get_item(target, *self.tree.get_selection().get_selected())
            self.select_iter(self.tree.get_model(), it)
        f_next = lambda b: on_cycle_clue("next")
        f_prev = lambda b: on_cycle_clue("previous")
        np_box = gtk.HButtonBox()
        self.prev_button = create_button(u"Previous", f_click=f_prev)
        self.next_button = create_button(u"Next", f_click=f_next)
        np_box.pack_start(self.prev_button)
        np_box.pack_start(self.next_button)
        align = gtk.Alignment(1, 0.5)
        align.add(np_box)
        vbox.pack_start(align, False, False, 0)

        # number x y direction word clue explanation displayed_string
        types = (int, int, int, str, str, str, str, str)
        self.store, self.tree, window, self.selection_id = create_tree(types
            , [(u"", 7)]
            , f_sel=self.on_selection_changed
            , return_id=True)
        vbox.pack_start(gtk.HSeparator(), False, False, 0)

        o_vbox = gtk.VBox()
        o_vbox.set_spacing(6)
        o_vbox.set_border_width(6)
        result = self.create_entry(o_vbox, "explanation", u"<b>Explanation</b>")
        self.explanation_entry, self.e_changed_id = result

        w_hbox = gtk.HBox()
        w_hbox.set_spacing(6)
        w_hbox.pack_start(create_label(u"Word:"), False, False, 0)
        w_entry = gtk.Entry()
        def on_word_changed(widget):
            self.load_clues_for_word(widget.get_text().strip())
        w_entry.connect("changed", on_word_changed)
        w_hbox.pack_start(w_entry)

        l_vbox = gtk.VBox()
        l_vbox.set_spacing(6)
        l_vbox.set_border_width(6)

        l_vbox.pack_start(create_label(u"<b>Lookup clues</b>"), False, False, 0)
        l_vbox.pack_start(w_hbox, False, False, 0)
        self.c_store, self.c_tree, c_window = create_tree(str
            , [(u"Clues", 0)]
            , f_sel=self.on_clue_selected)
        l_vbox.pack_start(c_window, True, True, 0)
        self.use_clue_button = create_button(u"Use clue"
            , align=(0, 0.5), f_click=self.on_use_clicked)
        self.use_clue_button.set_sensitive(False)
        l_vbox.pack_start(self.use_clue_button, False, False, 0)

        pages = [(window, u"Words and clues")
            , (l_vbox, u"Lookup")
            , (o_vbox, u"Advanced")
        ]
        vbox.pack_start(create_notebook(pages, border=(4, 2)))
        self.tree.set_headers_visible(False)
        self.load_items(puzzle.grid)
        return vbox