コード例 #1
0
ファイル: corpora.py プロジェクト: muranava/openconc
 def clear_concordance_view(self):
     misc.enable_all_in_frame(self.conc_results_frame)
     self.conc_line_text.delete("0.0", "end")
     self.conc_index_text.delete("0.0", "end")
     for key, m_text in self.conc_meta_text.items():
         m_text.delete("0.0", "end")
     misc.disable_all_in_frame(self.conc_results_frame)
コード例 #2
0
 def clear_concordance_view(self):
     misc.enable_all_in_frame(self.results_frame)
     self.line_text.delete("0.0", "end")
     self.index_text.delete("0.0", "end")
     for key, m_text in self.meta_text.items():
         m_text.delete("0.0", "end")
     misc.disable_all_in_frame(self.results_frame)
コード例 #3
0
 def display_concordance(self):
     if self.concordance is not None:
         misc.enable_all_in_frame(self.results_frame)
         for i, l in enumerate(self.concordance):
             self.add_concordance_line(l, i)
         self.parent.root.update_idletasks()
         if len(self.concordance) > 0:
             self.improve_concordance_display()
         misc.disable_all_in_frame(self.results_frame)
コード例 #4
0
ファイル: concordance.py プロジェクト: muranava/openconc
 def display_concordance(self):
     if self.concordance is not None:
         misc.enable_all_in_frame(self.results_frame)
         for i, l in enumerate(self.concordance):
             self.add_concordance_line(l, i)
         self.parent.root.update_idletasks()
         if len(self.concordance) > 0:
             self.improve_concordance_display()
         misc.disable_all_in_frame(self.results_frame)
コード例 #5
0
 def create_concordance(self):
     self.clear_concordance_view()
     self.concordance = []
     self.concordance_filtered = []
     if self.start_button["text"] == "Search all corpora":
         self.cancelled = False
         self.export_button["state"] = "disabled"
         self.filter_button["state"] = "disabled"
         self.parent.set_status("Creating concordance ...")
         self.start_button["text"] = "Abort"
         self.index_text["width"] = 6
         options = misc.get_tk_vars(self.parent.settings_frame.definition)
         options.update(misc.get_tk_vars(self.parent.settings_frame.file))
         options.update(
             misc.get_tk_vars(self.parent.settings_frame.concordance))
         options.update(misc.get_tk_vars(self.parent.settings_frame.xml))
         options[
             "SearchTerm"] = self.parent.concordance_frame.search_var.get()
         self.options = options
         self.add_search_term(options["SearchTerm"])
         self.pipes = []
         self.jobs = []
         self.corpora = []
         self.shared = []
         misc.enable_all_in_frame(self.results_frame)
         self.q = mp.Queue()
         for i, corpus in enumerate(self.parent.corpus):
             corpus_tag = "C{}".format(corpus.name_var.get().replace(
                 " ", ""))
             self.meta_text["Corpus"].tag_configure(corpus_tag,
                                                    background=corpus.color)
             misc.enable_all_in_frame(corpus.conc_results_frame)
             misc.disable_all_in_frame(corpus.conc_button_frame)
             options["CorpusIndex"] = i
             options["Corpus"] = corpus.name_var.get()
             corpus.conc_options = options
             manager = mp.Manager()
             corpus.conc_return_shared = manager.list()
             job = mp.Process(target=worker_search_files,
                              args=(
                                  corpus.files,
                                  options,
                                  corpus.conc_return_shared,
                                  self.q,
                              ))
             self.jobs.append(job)
             job.start()
         self.parent.root.update_idletasks()
         self.parent.root.after(500, self.check_proc_statuses)
     elif self.start_button["text"] == "Abort":
         self.cancelled = True
         self.parent.set_status("Concordance creation was aborted.", True)
         self.start_button.configure(text="Search", state="normal")
         self.parent.root.update_idletasks()
         for job in self.jobs:
             job.terminate()
コード例 #6
0
ファイル: corpora.py プロジェクト: muranava/openconc
 def finish_conc_search(self):
     self.concordance = sorted(self.conc_return_shared,
                               key=operator.itemgetter('Filename', 'N'))
     self.parent.set_status("Found {} results in '{}'.".format(len(self.concordance),
                                                               self.name_var.get()))
     self.display_concordance()
     self.conc_export_button["state"] = "normal"
     misc.disable_all_in_frame(self.conc_results_frame)
     if len(self.concordance) > 0:
         self.conc_export_button["state"] = "normal"
         self.conc_sort_button["state"] = "normal"
         self.conc_start_button["state"] = "normal"
         self.conc_start_button["text"] = "Search all corpora"
         self.conc_filter_button["state"] = "normal"
         self.conc_filter_entry["state"] = "normal"
コード例 #7
0
 def finish_conc_search(self):
     self.concordance = sorted(self.conc_return_shared,
                               key=operator.itemgetter('Filename', 'N'))
     self.parent.set_status("Found {} results in '{}'.".format(
         len(self.concordance), self.name_var.get()))
     self.display_concordance()
     self.conc_export_button["state"] = "normal"
     misc.disable_all_in_frame(self.conc_results_frame)
     if len(self.concordance) > 0:
         self.conc_export_button["state"] = "normal"
         self.conc_sort_button["state"] = "normal"
         self.conc_start_button["state"] = "normal"
         self.conc_start_button["text"] = "Search all corpora"
         self.conc_filter_button["state"] = "normal"
         self.conc_filter_entry["state"] = "normal"
コード例 #8
0
ファイル: concordance.py プロジェクト: muranava/openconc
 def create_concordance(self):
     self.clear_concordance_view()
     self.concordance = []
     self.concordance_filtered = []
     if self.start_button["text"] == "Search all corpora":
         self.cancelled = False
         self.export_button["state"] = "disabled"
         self.filter_button["state"] = "disabled"
         self.parent.set_status("Creating concordance ...")
         self.start_button["text"] = "Abort"
         self.index_text["width"] = 6
         options = misc.get_tk_vars(self.parent.settings_frame.definition)
         options.update(misc.get_tk_vars(self.parent.settings_frame.file))
         options.update(misc.get_tk_vars(self.parent.settings_frame.concordance))
         options.update(misc.get_tk_vars(self.parent.settings_frame.xml))
         options["SearchTerm"] = self.parent.concordance_frame.search_var.get()
         self.options = options
         self.add_search_term(options["SearchTerm"])
         self.pipes = []
         self.jobs = []
         self.corpora = []
         self.shared = []
         misc.enable_all_in_frame(self.results_frame)
         self.q = mp.Queue()
         for i, corpus in enumerate(self.parent.corpus):
             corpus_tag = "C{}".format(corpus.name_var.get().replace(" ", ""))
             self.meta_text["Corpus"].tag_configure(corpus_tag, background=corpus.color)
             misc.enable_all_in_frame(corpus.conc_results_frame)
             misc.disable_all_in_frame(corpus.conc_button_frame)
             options["CorpusIndex"] = i
             options["Corpus"] = corpus.name_var.get()
             corpus.conc_options = options
             manager = mp.Manager()
             corpus.conc_return_shared = manager.list()
             job = mp.Process(target=worker_search_files,
                              args=(corpus.files, options,
                                    corpus.conc_return_shared, self.q,))
             self.jobs.append(job)
             job.start()
         self.parent.root.update_idletasks()
         self.parent.root.after(500, self.check_proc_statuses)
     elif self.start_button["text"] == "Abort":
         self.cancelled = True
         self.parent.set_status("Concordance creation was aborted.", True)
         self.start_button.configure(text="Search", state="normal")
         self.parent.root.update_idletasks()
         for job in self.jobs:
             job.terminate()
コード例 #9
0
 def filter_concordance(self):
     if len(self.concordance) > 0:
         self.concordance_filtered = []
         filter_by = self.filter_var.get()
         what = self.filter_what_combo.get()
         case = bool(self.parent.settings_frame.concordance['Case'].get())
         regex = bool(
             self.parent.settings_frame.concordance['IsRegEx'].get())
         if case and not regex:
             filter_by = filter_by.lower()
         elif regex:
             if case:
                 flags = re.UNICODE
             else:
                 flags = re.UNICODE | re.IGNORECASE
             s = r'{0}'.format(filter_by)
             re_pattern = re.compile(s, flags=flags)
         for l in self.concordance:
             if what == "Line":
                 line = "{} {} {}".format(l['Left'], l['Key'], l['Right'])
                 if not regex:
                     if not case:
                         line = line.lower()
                     if filter_by in line:
                         self.concordance_filtered.append(l)
                 else:
                     if re_pattern.search(line):
                         self.concordance_filtered.append(l)
             else:
                 if not regex:
                     if not case:
                         l[what] = l[what].lower()
                     if filter_by in l[what]:
                         self.concordance_filtered.append(l)
                 else:
                     if re_pattern.search(l[what]):
                         self.concordance_filtered.append(l)
         self.clear_concordance_view()
         misc.enable_all_in_frame(self.results_frame)
         for i, l in enumerate(self.concordance_filtered):
             self.add_concordance_line(l, i)
         self.parent.root.update_idletasks()
         misc.disable_all_in_frame(self.results_frame)
         self.unfilter_button["state"] = "enabled"
コード例 #10
0
ファイル: corpora.py プロジェクト: muranava/openconc
 def filter_concordance(self):
     if len(self.concordance) > 0:
         self.concordance_filtered = []
         filter_by = self.conc_filter_var.get()
         what = self.conc_filter_what_combo.get()
         case = bool(self.parent.settings_frame.concordance['Case'].get())
         regex = bool(self.parent.settings_frame.concordance['IsRegEx'].get())
         if case and not regex:
             filter_by = filter_by.lower()
         elif regex:
             if case:
                 flags = re.UNICODE
             else:
                 flags = re.UNICODE | re.IGNORECASE
             s = r'{0}'.format(filter_by)
             re_pattern = re.compile(s, flags=flags)
         for l in self.concordance:
             if what == "Line":
                 line = "{} {} {}".format(l['Left'], l['Key'], l['Right'])
                 if not regex:
                     if not case:
                         line = line.lower()
                     if filter_by in line:
                         self.concordance_filtered.append(l)
                 else:
                     if re_pattern.search(line):
                         self.concordance_filtered.append(l)
             else:
                 if not regex:
                     if not case:
                         l[what] = l[what].lower()
                     if filter_by in l[what]:
                         self.concordance_filtered.append(l)
                 else:
                     if re_pattern.search(l[what]):
                         self.concordance_filtered.append(l)
         self.clear_concordance_view()
         misc.enable_all_in_frame(self.conc_results_frame)
         for i, l in enumerate(self.concordance_filtered):
             self.add_concordance_line(l, i)
         self.parent.root.update_idletasks()
         misc.disable_all_in_frame(self.conc_results_frame)
         self.conc_unfilter_button["state"] = "enabled"
コード例 #11
0
ファイル: corpora.py プロジェクト: muranava/openconc
    def draw_conc_ui(self):
        parent = self.parent.concordance_frame
        self.button_style = "C{}.TButton".format(self.n)
        self.conc_frame = ttk.Frame(parent)
        self.conc_frame.rowconfigure(0, weight=1)
        self.conc_frame.rowconfigure(1, weight=0)
        self.conc_frame.columnconfigure(0, weight=1)
        parent.book.add(self.conc_frame, text=self.name_var.get())
        # row 1
        self.conc_button_frame = ttk.Frame(self.conc_frame)
        self.conc_button_frame.grid(row=1, column=0, sticky="news")
        # row 0
        self.conc_results_frame = ttk.Frame(self.conc_frame)
        self.conc_results_frame.grid(row=0, column=0, sticky="news")
        self.conc_results_frame.rowconfigure(0, weight=1)
        self.conc_results_frame.rowconfigure(1, weight=0)  # x scrollbars
        self.conc_results_frame.columnconfigure(0, weight=0)  # index
        self.conc_results_frame.columnconfigure(1, weight=1)  # conc line
        self.conc_results_frame.columnconfigure(2, weight=0)  # y  scrollbar
        self.conc_results_frame.columnconfigure(3, weight=0)   # metadata
        self.conc_ybar = ttk.Scrollbar(self.conc_results_frame, command=self.concordance_yview)
        self.conc_ybar.grid(row=0, column=2, sticky="news")
        self.conc_line_xbar = ttk.Scrollbar(self.conc_results_frame, orient="horizontal")
        self.conc_line_xbar.grid(row=1, column=1, sticky="news")
        self.conc_line_text = tk.Text(self.conc_results_frame, wrap="none", yscrollcommand=self.conc_ybar.set,
                                      xscrollcommand=self.conc_line_xbar.set, font='courier 10')
        self.conc_line_text.grid(row=0, column=1, sticky="news")
        self.conc_line_text.tag_configure('key', foreground='black', font='courier 10 bold')
        self.conc_line_xbar.config(command=self.conc_line_text.xview)
        self.conc_index_text = tk.Text(self.conc_results_frame, width=8, yscrollcommand=self.conc_ybar.set,
                                       font='courier 10', wrap="none")
        self.conc_index_text.grid(row=0, column=0, sticky="nesw")
        self.conc_meta_xbar = ttk.Scrollbar(self.conc_results_frame, orient="horizontal")
        self.conc_meta_xbar.grid(row=1, column=3, sticky="news")
        self.conc_meta_canvas = tk.Canvas(self.conc_results_frame, background="white",
                                          xscrollcommand=self.conc_meta_xbar.set)
        self.conc_meta_canvas.grid(row=0, column=3, sticky="news")
        self.conc_meta_xbar.config(command=self.conc_meta_canvas.xview)
        self.conc_meta_canvas_frame = tk.Frame(self.conc_meta_canvas)
        self.conc_meta_text = {}  # corpus & file name, later more with XML corpora if attributes
        metadata = ["Corpus", "Filename"]
        for i, m in enumerate(metadata):
            self.conc_meta_text[m] = tk.Text(self.conc_meta_canvas_frame, wrap="none", font='courier 10')
            self.conc_meta_text[m].grid(row=0, column=i, sticky="news")
        misc.disable_all_in_frame(self.conc_results_frame)
        self.parent.root.update_idletasks()
        x2 = self.conc_meta_canvas_frame.winfo_reqwidth()
        self.conc_meta_canvas.create_window(0, 0, anchor="nw", window=self.conc_meta_canvas_frame)
        self.conc_meta_canvas.config(scrollregion=(0, 0, x2, 0))
        h = self.conc_meta_canvas_frame.winfo_reqheight()
        for i, m_text in self.conc_meta_text.items():
            m_text["height"] = h
            m_text["width"] = 20

        # row 1 BUTTONS
        self.conc_button_frame = ttk.Frame(self.conc_frame)
        self.conc_button_frame.columnconfigure(0, weight=0)
        self.conc_button_frame.columnconfigure(1, weight=0)
        self.conc_button_frame.columnconfigure(5, weight=1)
        self.conc_button_frame.grid(row=1, column=0, sticky="news")
        self.conc_start_button = ttk.Button(self.conc_button_frame, text="Search this corpus",
                                            command=self.create_concordance,
                                            style=self.button_style)
        self.conc_start_button.grid(row=1, column=0, sticky="news", columnspan=3)
        self.conc_export_button = ttk.Button(self.conc_button_frame, text="Export concordance",
                                             command=self.export_concordance, state="disabled",
                                             style="Small.TButton")
        self.conc_export_button.grid(row=1, column=3, sticky="news")
        self.conc_sort_button = ttk.Button(self.conc_button_frame, text="Sort by",
                                           command=self.sort_concordance, state="disabled",
                                           style="Small.TButton")
        self.conc_sort_button.grid(row=0, column=0, sticky="news")
        self.conc_sort_combo = []
        self.conc_sort_var = []
        for i in range(0, 3):
            self.conc_sort_var.append(tk.StringVar())
            cb = ttk.Combobox(self.conc_button_frame, textvariable=self.conc_sort_var[i],
                              values=["Left", "Key", "Right", "Corpus", "Filename"],
                              state="readonly", style="Small.TCombobox")
            cb.grid(row=0, column=i+1, sticky="news")
            self.conc_sort_combo.append(cb)
        self.conc_sort_var[0].set("Key")
        self.conc_sort_var[1].set("Right")
        self.conc_sort_var[2].set("Corpus")
        self.conc_filter_var = tk.StringVar()
        tk.Label(self.conc_button_frame, text="Filter text",
                 font="verdana 9").grid(column=4, row=0, sticky="news")
        self.conc_filter_entry = ttk.Entry(self.conc_button_frame,
                                           textvariable=self.conc_filter_var,
                                           style="Small.TEntry", state="disabled")
        self.conc_filter_entry.grid(row=0, column=5, sticky="news", columnspan=3)
        self.conc_filter_button = ttk.Button(self.conc_button_frame, text="Filter",
                                             command=self.filter_concordance,
                                             style="Small.TButton", state="disabled")
        self.conc_filter_button.grid(row=1, column=4, columnspan=2, sticky="news")
        self.conc_filter_what_var = tk.StringVar()
        self.conc_filter_what_combo = ttk.Combobox(self.conc_button_frame, textvariable=self.conc_filter_what_var,
                                                   values=['Key', "Left", "Right", "Line"], state="readonly")
        self.conc_filter_what_var.set('Key')
        self.conc_filter_what_combo.grid(row=1, column=6, sticky="news")
        self.conc_unfilter_button = ttk.Button(self.conc_button_frame, text="Undo filter",
                                               command=self.unfilter_concordance,
                                               style="Small.TButton", state="disabled")
        self.conc_unfilter_button.grid(row=1, column=7, sticky="news")
        misc.pad_children(self.conc_button_frame, 5, 5)
コード例 #12
0
    def draw_conc_ui(self):
        parent = self.parent.concordance_frame
        self.button_style = "C{}.TButton".format(self.n)
        self.conc_frame = ttk.Frame(parent)
        self.conc_frame.rowconfigure(0, weight=1)
        self.conc_frame.rowconfigure(1, weight=0)
        self.conc_frame.columnconfigure(0, weight=1)
        parent.book.add(self.conc_frame, text=self.name_var.get())
        # row 1
        self.conc_button_frame = ttk.Frame(self.conc_frame)
        self.conc_button_frame.grid(row=1, column=0, sticky="news")
        # row 0
        self.conc_results_frame = ttk.Frame(self.conc_frame)
        self.conc_results_frame.grid(row=0, column=0, sticky="news")
        self.conc_results_frame.rowconfigure(0, weight=1)
        self.conc_results_frame.rowconfigure(1, weight=0)  # x scrollbars
        self.conc_results_frame.columnconfigure(0, weight=0)  # index
        self.conc_results_frame.columnconfigure(1, weight=1)  # conc line
        self.conc_results_frame.columnconfigure(2, weight=0)  # y  scrollbar
        self.conc_results_frame.columnconfigure(3, weight=0)  # metadata
        self.conc_ybar = ttk.Scrollbar(self.conc_results_frame,
                                       command=self.concordance_yview)
        self.conc_ybar.grid(row=0, column=2, sticky="news")
        self.conc_line_xbar = ttk.Scrollbar(self.conc_results_frame,
                                            orient="horizontal")
        self.conc_line_xbar.grid(row=1, column=1, sticky="news")
        self.conc_line_text = tk.Text(self.conc_results_frame,
                                      wrap="none",
                                      yscrollcommand=self.conc_ybar.set,
                                      xscrollcommand=self.conc_line_xbar.set,
                                      font='courier 10')
        self.conc_line_text.grid(row=0, column=1, sticky="news")
        self.conc_line_text.tag_configure('key',
                                          foreground='black',
                                          font='courier 10 bold')
        self.conc_line_xbar.config(command=self.conc_line_text.xview)
        self.conc_index_text = tk.Text(self.conc_results_frame,
                                       width=8,
                                       yscrollcommand=self.conc_ybar.set,
                                       font='courier 10',
                                       wrap="none")
        self.conc_index_text.grid(row=0, column=0, sticky="nesw")
        self.conc_meta_xbar = ttk.Scrollbar(self.conc_results_frame,
                                            orient="horizontal")
        self.conc_meta_xbar.grid(row=1, column=3, sticky="news")
        self.conc_meta_canvas = tk.Canvas(
            self.conc_results_frame,
            background="white",
            xscrollcommand=self.conc_meta_xbar.set)
        self.conc_meta_canvas.grid(row=0, column=3, sticky="news")
        self.conc_meta_xbar.config(command=self.conc_meta_canvas.xview)
        self.conc_meta_canvas_frame = tk.Frame(self.conc_meta_canvas)
        self.conc_meta_text = {
        }  # corpus & file name, later more with XML corpora if attributes
        metadata = ["Corpus", "Filename"]
        for i, m in enumerate(metadata):
            self.conc_meta_text[m] = tk.Text(self.conc_meta_canvas_frame,
                                             wrap="none",
                                             font='courier 10')
            self.conc_meta_text[m].grid(row=0, column=i, sticky="news")
        misc.disable_all_in_frame(self.conc_results_frame)
        self.parent.root.update_idletasks()
        x2 = self.conc_meta_canvas_frame.winfo_reqwidth()
        self.conc_meta_canvas.create_window(0,
                                            0,
                                            anchor="nw",
                                            window=self.conc_meta_canvas_frame)
        self.conc_meta_canvas.config(scrollregion=(0, 0, x2, 0))
        h = self.conc_meta_canvas_frame.winfo_reqheight()
        for i, m_text in self.conc_meta_text.items():
            m_text["height"] = h
            m_text["width"] = 20

        # row 1 BUTTONS
        self.conc_button_frame = ttk.Frame(self.conc_frame)
        self.conc_button_frame.columnconfigure(0, weight=0)
        self.conc_button_frame.columnconfigure(1, weight=0)
        self.conc_button_frame.columnconfigure(5, weight=1)
        self.conc_button_frame.grid(row=1, column=0, sticky="news")
        self.conc_start_button = ttk.Button(self.conc_button_frame,
                                            text="Search this corpus",
                                            command=self.create_concordance,
                                            style=self.button_style)
        self.conc_start_button.grid(row=1,
                                    column=0,
                                    sticky="news",
                                    columnspan=3)
        self.conc_export_button = ttk.Button(self.conc_button_frame,
                                             text="Export concordance",
                                             command=self.export_concordance,
                                             state="disabled",
                                             style="Small.TButton")
        self.conc_export_button.grid(row=1, column=3, sticky="news")
        self.conc_sort_button = ttk.Button(self.conc_button_frame,
                                           text="Sort by",
                                           command=self.sort_concordance,
                                           state="disabled",
                                           style="Small.TButton")
        self.conc_sort_button.grid(row=0, column=0, sticky="news")
        self.conc_sort_combo = []
        self.conc_sort_var = []
        for i in range(0, 3):
            self.conc_sort_var.append(tk.StringVar())
            cb = ttk.Combobox(
                self.conc_button_frame,
                textvariable=self.conc_sort_var[i],
                values=["Left", "Key", "Right", "Corpus", "Filename"],
                state="readonly",
                style="Small.TCombobox")
            cb.grid(row=0, column=i + 1, sticky="news")
            self.conc_sort_combo.append(cb)
        self.conc_sort_var[0].set("Key")
        self.conc_sort_var[1].set("Right")
        self.conc_sort_var[2].set("Corpus")
        self.conc_filter_var = tk.StringVar()
        tk.Label(self.conc_button_frame, text="Filter text",
                 font="verdana 9").grid(column=4, row=0, sticky="news")
        self.conc_filter_entry = ttk.Entry(self.conc_button_frame,
                                           textvariable=self.conc_filter_var,
                                           style="Small.TEntry",
                                           state="disabled")
        self.conc_filter_entry.grid(row=0,
                                    column=5,
                                    sticky="news",
                                    columnspan=3)
        self.conc_filter_button = ttk.Button(self.conc_button_frame,
                                             text="Filter",
                                             command=self.filter_concordance,
                                             style="Small.TButton",
                                             state="disabled")
        self.conc_filter_button.grid(row=1,
                                     column=4,
                                     columnspan=2,
                                     sticky="news")
        self.conc_filter_what_var = tk.StringVar()
        self.conc_filter_what_combo = ttk.Combobox(
            self.conc_button_frame,
            textvariable=self.conc_filter_what_var,
            values=['Key', "Left", "Right", "Line"],
            state="readonly")
        self.conc_filter_what_var.set('Key')
        self.conc_filter_what_combo.grid(row=1, column=6, sticky="news")
        self.conc_unfilter_button = ttk.Button(
            self.conc_button_frame,
            text="Undo filter",
            command=self.unfilter_concordance,
            style="Small.TButton",
            state="disabled")
        self.conc_unfilter_button.grid(row=1, column=7, sticky="news")
        misc.pad_children(self.conc_button_frame, 5, 5)