Adjust frequency analyzer

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
TheJackiMonster 2023-06-08 17:08:21 +02:00
parent f85e85a159
commit 13b6e26b13
No known key found for this signature in database
GPG key ID: D850A5F772E880F9
2 changed files with 160 additions and 12 deletions

View file

@ -17,15 +17,35 @@ class FrequencyWindow(AbstractDialog):
self.headerBar = None
self.back = None
self.wordLeaflet = None
self.wordsProgress = None
self.analyzeWords = None
self.phrasesProgress = None
self.analyzePhrases = None
self.wordEntry = None
self.removeWord = None
self.addWord = None
self.excludeWordSelection = None
self.excludeWordsStore = None
self.wordsFrequencyStore = None
self.phrasesFrequencyStore = None
def initWindow(self, builder, window):
self.headerBar = builder.get_object("header_bar")
self.back = builder.get_object("back")
self.wordLeaflet = builder.get_object("word_leaflet")
self.wordsProgress = builder.get_object("words_progress")
self.analyzeWords = builder.get_object("analyze_words")
self.phrasesProgress = builder.get_object("phrases_progress")
self.analyzePhrases = builder.get_object("analyze_phrases")
self.wordEntry = builder.get_object("word_entry")
self.removeWord = builder.get_object("remove_word")
self.addWord = builder.get_object("add_word")
self.excludeWordSelection = builder.get_object("exclude_word_selection")
self.excludeWordsStore = builder.get_object("exclude_words_store")
self.wordsFrequencyStore = builder.get_object("words_frequency_store")
self.phrasesFrequencyStore = builder.get_object("phrases_frequency_store")
self.wordLeaflet.bind_property("folded", self.back, "visible",
GObject.BindingFlags.SYNC_CREATE)
@ -35,6 +55,10 @@ class FrequencyWindow(AbstractDialog):
self.back.connect("clicked", self._backClicked)
self.analyzeWords.connect("clicked", self._analyzeWordsClicked)
self.analyzePhrases.connect("clicked", self._analyzePhrasesClicked)
self.excludeWordSelection.connect("changed", self._excludeWordSelectionChanged)
self.removeWord.connect("clicked", self._removeWordClicked)
self.addWord.connect("clicked", self._addWordClicked)
def _backClicked(self, button: Gtk.Button):
if self.wordLeaflet.get_visible_child_name() == "wordlist_view":
@ -44,3 +68,28 @@ class FrequencyWindow(AbstractDialog):
def _analyzeWordsClicked(self, button: Gtk.Button):
self.wordLeaflet.set_visible_child_name("wordlist_view")
def _analyzePhrasesClicked(self, button: Gtk.Button):
pass
def _excludeWordSelectionChanged(self, selection: Gtk.TreeSelection):
model, tree_iter = selection.get_selected()
self.removeWord.set_sensitive(tree_iter is not None)
def _removeWordClicked(self, button: Gtk.Button):
model, tree_iter = self.excludeWordSelection.get_selected()
if tree_iter is None:
return
self.excludeWordsStore.remove(tree_iter)
def _addWordClicked(self, button: Gtk.Button):
tree_iter = self.excludeWordsStore.append()
if tree_iter is None:
return
word = self.wordEntry.get_buffer().get_text()
self.excludeWordsStore.set_value(tree_iter, 0, word)

View file

@ -27,6 +27,12 @@ along with Manuskript. If not, see <http://www.gnu.org/licenses/>.
<!-- interface-name Manuskript -->
<!-- interface-description Manuskript is an open-source tool for writers. -->
<!-- interface-copyright 2015-2021 Olivier Keshavjee et al. -->
<object class="GtkListStore" id="exclude_words_store">
<columns>
<!-- column-name word -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkAdjustment" id="phrase_maximum">
<property name="lower">2</property>
<property name="upper">99</property>
@ -41,6 +47,14 @@ along with Manuskript. If not, see <http://www.gnu.org/licenses/>.
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>
<object class="GtkListStore" id="phrases_frequency_store">
<columns>
<!-- column-name phrase -->
<column type="gchararray"/>
<!-- column-name frequency -->
<column type="guint"/>
</columns>
</object>
<object class="GtkAdjustment" id="word_size">
<property name="lower">1</property>
<property name="upper">99</property>
@ -48,6 +62,14 @@ along with Manuskript. If not, see <http://www.gnu.org/licenses/>.
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>
<object class="GtkListStore" id="words_frequency_store">
<columns>
<!-- column-name word -->
<column type="gchararray"/>
<!-- column-name frequency -->
<column type="guint"/>
</columns>
</object>
<object class="HdyWindow" id="frequency_window">
<property name="can-focus">False</property>
<child>
@ -184,9 +206,26 @@ along with Manuskript. If not, see <http://www.gnu.org/licenses/>.
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkListBox">
<object class="GtkTreeView">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="can-focus">True</property>
<property name="model">exclude_words_store</property>
<property name="headers-visible">False</property>
<property name="headers-clickable">False</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="exclude_word_selection"/>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Word</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
@ -204,8 +243,9 @@ along with Manuskript. If not, see <http://www.gnu.org/licenses/>.
<property name="can-focus">False</property>
<property name="spacing">8</property>
<child>
<object class="GtkButton">
<object class="GtkButton" id="remove_word">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<child>
@ -223,7 +263,7 @@ along with Manuskript. If not, see <http://www.gnu.org/licenses/>.
</packing>
</child>
<child>
<object class="GtkEntry">
<object class="GtkEntry" id="word_entry">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
@ -234,7 +274,7 @@ along with Manuskript. If not, see <http://www.gnu.org/licenses/>.
</packing>
</child>
<child>
<object class="GtkButton">
<object class="GtkButton" id="add_word">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
@ -277,10 +317,9 @@ along with Manuskript. If not, see <http://www.gnu.org/licenses/>.
</packing>
</child>
<child>
<object class="GtkLevelBar">
<object class="GtkProgressBar" id="words_progress">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-top">12</property>
</object>
<packing>
<property name="expand">False</property>
@ -322,9 +361,39 @@ along with Manuskript. If not, see <http://www.gnu.org/licenses/>.
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkListBox">
<object class="GtkTreeView">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="can-focus">True</property>
<property name="model">words_frequency_store</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Word</property>
<property name="expand">True</property>
<property name="sort-indicator">True</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Frequency</property>
<property name="expand">True</property>
<property name="sort-indicator">True</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
@ -490,9 +559,39 @@ along with Manuskript. If not, see <http://www.gnu.org/licenses/>.
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkListBox">
<object class="GtkTreeView">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="can-focus">True</property>
<property name="model">phrases_frequency_store</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Phrase</property>
<property name="expand">True</property>
<property name="sort-indicator">True</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Frequency</property>
<property name="expand">True</property>
<property name="sort-indicator">True</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
@ -506,7 +605,7 @@ along with Manuskript. If not, see <http://www.gnu.org/licenses/>.
</packing>
</child>
<child>
<object class="GtkProgressBar">
<object class="GtkProgressBar" id="phrases_progress">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>