Пример #1
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())
Пример #2
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]])
Пример #3
0
    def create_find_words(self, parent):
        hbox = gtk.HBox()
        hbox.set_spacing(9)
        # name path
        self.store, self.tree, s_window = create_tree((str, str)
            , [("Available word lists", 0)]
            , f_sel=self.on_tree_selection_changed
            , window_size=(256, 196))
        hbox.pack_start(s_window, True, True, 0)

        button_vbox = gtk.VBox()
        self.add_wlist_button = gtk.Button(stock=gtk.STOCK_ADD)
        self.add_wlist_button.connect("clicked", self.on_add_clicked)
        button_vbox.pack_start(self.add_wlist_button, True, False, 0)
        self.remove_wlist_button = gtk.Button(stock=gtk.STOCK_REMOVE)
        self.remove_wlist_button.connect("clicked", self.on_remove_clicked)
        button_vbox.pack_start(self.remove_wlist_button, True, False, 0)
        self.add_wlist_button.set_sensitive(False)
        self.remove_wlist_button.set_sensitive(False)
        hbox.pack_start(button_vbox, True, True, 0)

        # name path
        self.store2, self.tree2, s_window2 = create_tree((str, str)
            , [("Word lists for finding words", 0)]
            , f_sel=self.on_tree2_selection_changed
            , window_size=(256, 196))
        hbox.pack_start(s_window2, True, True, 0)

        # populate list stores
        c_find = preferences.prefs[constants.PREF_FIND_WORD_FILES]
        wlists1 = [w for w in parent.wordlists if w.path not in c_find]
        wlists2 = [w for w in parent.wordlists if w.path in c_find]
        for wlist in wlists1:
            self.store.append([wlist.name, wlist.path])
        for wlist in wlists2:
            self.store2.append([wlist.name, wlist.path])

        vbox = gtk.VBox()
        vbox.set_border_width(9)
        vbox.set_spacing(9)
        score_hbox = gtk.HBox()
        score_hbox.set_spacing(9)
        score_hbox.pack_start(create_label(u"Minimum word score:"), False, False, 0)
        value = preferences.prefs[constants.PREF_FIND_WORD_MIN_SCORE]
        adj = gtk.Adjustment(value, 0, 100, 1, 0, 0)
        self.find_min_score_spinner = gtk.SpinButton(adj, 0.0, 0)
        score_hbox.pack_start(self.find_min_score_spinner, False, False, 0)
        vbox.pack_start(hbox)
        vbox.pack_start(score_hbox, False, False, 0)
        label = create_label(u"These settings are loaded when you start " + constants.TITLE + ".")
        vbox.pack_start(label, False, False, 0)
        return vbox
Пример #4
0
 def __init__(self, parent):
     PalabraDialog.__init__(self, parent, u"Manage clue databases")
     self.pwindow = parent
     self.store, self.tree, window = create_tree((str, str)
         , [(u"Name", 0), (u"Path", 1)]
         , f_sel=self.on_file_selected
         , window_size=(300, 300))
     self.pack(window)
     buttonbox = gtk.HButtonBox()
     buttonbox.set_layout(gtk.BUTTONBOX_START)
     self.add_file_button = create_stock_button(gtk.STOCK_ADD
         , f_click=lambda b: self.on_add_clue_db())
     buttonbox.pack_start(self.add_file_button, False, False)
     self.props_button = create_stock_button(gtk.STOCK_PROPERTIES, f_click=lambda b: self.on_properties())
     buttonbox.pack_start(self.props_button, False, False)
     self.props_button.set_sensitive(False)
     self.remove_button = create_stock_button(gtk.STOCK_REMOVE
         , f_click=lambda b: self.on_remove_db())
     buttonbox.pack_start(self.remove_button, False, False)
     self.remove_button.set_sensitive(False)
     self.pack(buttonbox)
     label = create_label(u"These clue databases are loaded when you start " + constants.TITLE + ".")
     self.pack(label, False)
     self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
     self.load_clue_files(parent.clues)
Пример #5
0
 def __init__(self, parent):
     super(FindWordsDialog, self).__init__(parent, u"Find words")
     self.wordlists = parent.wordlists
     self.sort_option = 0
     self.pattern = None
     self.pack(create_label(u"Use ? for an unknown letter and * for zero or more unknown letters."))
     def on_entry_changed(widget):
         glib.source_remove(self.timer)
         self.launch_pattern(widget.get_text().strip())
     self.pack(create_entry(f_change=on_entry_changed), False)
     # word path score
     self.store, self.tree, s_window = create_tree((str, str, int)
         , [(u"Word", 0), (u"Word list", 1), (u"Score", 2)]
         , window_size=(-1, 300)
     )
     self.tree.get_column(0).set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
     self.tree.get_column(0).set_fixed_width(250)
     self.pack(s_window)
     self.n_label = create_label("")
     self.set_n_label(0)
     self.pack(self.n_label, False)
     sort_hbox = gtk.HBox(False, 6)
     sort_hbox.pack_start(create_label(u"Sort by:"), False, False, 0)
     def on_sort_changed(combo):
         self.sort_option = combo.get_active()
         self.launch_pattern(self.pattern)
     sort_hbox.pack_start(create_combo(["Alphabet", "Length", "Score"]
         , active=self.sort_option, f_change=on_sort_changed))
     self.pack(sort_hbox, False)
     self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
     self.launch_pattern(None)
Пример #6
0
 def __init__(self, parent, puzzle):
     super(AccidentalWordsDialog, self).__init__(parent, u"View accidental words")
     self.puzzle = puzzle
     self.wordlists = parent.wordlists
     self.index = 0
     self.collapse = True
     self.timer = None
     wlist_hbox = gtk.HBox(False, 0)
     wlist_hbox.pack_start(create_label(u"Check for words in list:"), True, True, 0)
     def on_wordlist_changed(widget):
         self.index = widget.get_active()
         self.launch_accidental(self.puzzle.grid)
     combo = create_combo([w.name for w in self.wordlists]
         , active=self.index, f_change=on_wordlist_changed)
     wlist_hbox.pack_start(combo, False, False, 0)
     self.main.pack_start(wlist_hbox, False, False, 0)
     self.store, self.tree, s_window = create_tree((str, str)
         , [(u"Word", 0)], window_size=(300, 300))
     self.tree.get_selection().connect("changed", self.on_selection_changed)
     self.main.pack_start(s_window, True, True, 0)
     self.main.pack_start(create_label(u"Click to highlight the word(s) in the grid."), False, False, 0)
     def collapse_callback(button):
         self.collapse = button.get_active()
         self.launch_accidental(self.puzzle.grid)
     button = gtk.CheckButton("Collapse multiple occurrences into one item.")
     button.connect("toggled", collapse_callback)
     button.set_active(self.collapse)
     self.main.pack_start(button, False, False, 0)
     self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
     destroy = lambda w: highlight_cells(self.pwindow, self.puzzle, clear=True)
     self.connect("destroy", destroy)
     self.launch_accidental(puzzle.grid)
Пример #7
0
 def __init__(self, parent, unable):
     super(WordListUnableToStoreDialog, self).__init__(parent, u"Unable to store word list(s)")
     self.main.pack_start(create_label(constants.TITLE + " was unable to store the following word lists:"))
     self.store, self.tree, window = create_tree(str, [(u"Word list", 0)])
     for name, error in unable:
         self.store.append([name + " (" + error + ")"])
     window.set_size_request(200, 300)
     self.main.pack_start(window, True, True, 0)
     self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
Пример #8
0
 def __init__(self, parent):
     PalabraDialog.__init__(self, parent, u"Edit word lists", horizontal=True)
     self.wordlists = parent.wordlists
     # name path
     self.store, self.tree, s_window = create_tree((str, str)
         , [("Available word lists", 0)]
         , f_sel=self.on_tree_selection_changed
         , window_size=(256, 196))
     for wlist in self.wordlists:
         self.store.append([wlist.name, wlist.path])
     self.main.pack_start(s_window, True, True, 0)
     self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
Пример #9
0
 def __init__(self, parent, puzzle):
     super(SimilarWordsDialog, self).__init__(parent, u"View similar words")
     self.puzzle = puzzle
     self.store, self.tree, scrolled_window = create_tree((str, str)
         , [(u"Similar words", 1)]
         , f_sel=self.on_selection_changed
         , window_size=(512, 384))
     self.main.pack_start(scrolled_window, True, True, 0)
     self.main.pack_start(create_label(u"Click to highlight the words in the grid."), False, False, 0)
     self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
     destroy = lambda w: highlight_cells(self.pwindow, self.puzzle, clear=True)
     self.connect("destroy", destroy)
     self.entries = word.similar_entries(word.similar_words(puzzle.grid))
     self.load_entries(self.entries)
Пример #10
0
 def __init__(self, parent):
     super(WordListManager, self).__init__(parent, u"Manage word lists")
     self.palabra_window = parent
     self.modifications = set()
     # name path
     self.store, self.tree, s_window = create_tree((str, str)
         , [(u"Name", 0), (u"Path", 1)]
         , f_sel=self.on_selection_changed
         , window_size=(400, 400))
     self.current_wlist = None
     self.add_wlist_button = create_stock_button(gtk.STOCK_ADD, lambda b: self.add_word_list())
     self.rename_button = create_button(u"Rename", f_click=lambda b: self.rename_word_list())
     def show_word_list_props():
         w = WordListPropertiesDialog(self, self.current_wlist)
         w.show_all()
         w.run()
         w.destroy()
     self.props_button = create_stock_button(gtk.STOCK_PROPERTIES, lambda b: show_word_list_props())
     self.remove_button = create_stock_button(gtk.STOCK_REMOVE, lambda b: self.remove_word_list())
     buttonbox = gtk.HButtonBox()
     buttonbox.set_layout(gtk.BUTTONBOX_START)
     buttonbox.pack_start(self.add_wlist_button)
     buttonbox.pack_start(self.rename_button)
     buttonbox.pack_start(self.props_button)
     buttonbox.pack_start(self.remove_button)
     self.wlist_sensitives = [self.rename_button, self.props_button, self.remove_button]
     for b in self.wlist_sensitives:
         b.set_sensitive(False)
     wlist_vbox = gtk.VBox()
     wlist_vbox.set_spacing(12)
     wlist_vbox.pack_start(create_label("<b>Word lists</b>"), False, False, 0)
     wlist_vbox.pack_start(s_window)
     wlist_vbox.pack_start(buttonbox, False, False, 0)
     main = gtk.HBox()
     main.set_spacing(18)
     main.pack_start(wlist_vbox, False, False, 0)
     main.pack_start(self.create_contents_tab())
     self.main.pack_start(main)
     label = create_label(u"These word lists are loaded when you start " + constants.TITLE + ".")
     self.main.pack_start(label, False, False, 0)
     self.display_wordlists()
     self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
Пример #11
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