def do_get_info_widget(self, proposal): if not self.info_widget: view = Gedit.View.new_with_buffer(Gedit.Document()) manager = get_language_manager() lang = manager.get_language('snippets') view.get_buffer().set_language(lang) sw = Gtk.ScrolledWindow() sw.add(view) self.info_view = view self.info_widget = sw return self.info_widget
def setUp(self): self.plugin_actions = DictonatorActionHandler( f_bottom_bar_changer=self.bottom_bar_changer_fake, f_bottom_bar_adder=self.bottom_bar_adder_fake) try: with open(TEXT_PATH + 'original' + '.txt') as file: self.org = file.read() # read the entire text file with open(TEXT_PATH + 'deleted_line' + '.txt') as file: self.dl = file.read() # read the entire text file with open(TEXT_PATH + 'deleted_sentence' + '.txt') as file: self.ds = file.read() # read the entire text file with open(TEXT_PATH + 'deleted_word' + '.txt') as file: self.dw = file.read() # read the entire text file with open(TEXT_PATH + 'inserted_text' + '.txt') as file: self.ti = file.read() # read the entire text file self.cd = "" self.plugin_actions.document = Gedit.Document() self.plugin_actions.document.set_text(self.org) self.plugin_actions.recogniser.is_listening = True return True except FileNotFoundError: print("Texts files not found, skipping this test") return False
def find_all_in_dir(self, parent_it, dir_path, file_pattern, search_pattern, find_options, replace_flg = False): #start_time = time.time() if search_pattern == "": return #d_list = [] file_list = [] grep_cmd = ['grep', '-l', '-I'] if find_options['MATCH_WHOLE_WORD'] == True: grep_cmd.append('-w') if find_options['MATCH_CASE'] == False: grep_cmd.append('-i') if find_options['INCLUDE_SUBFOLDER'] == True: grep_cmd.append('-R') if not file_pattern == '': pattern_list = re.split('\s*\|\s*', file_pattern) for f_pattern in pattern_list: if f_pattern.startswith('-'): grep_cmd.append('--exclude=' + f_pattern[1:]) else: grep_cmd.append('--include=' + f_pattern) if find_options['REGEX_SEARCH'] == True: grep_cmd = grep_cmd + ['-E', '-e', search_pattern, dir_path] else: grep_cmd = grep_cmd + ['-F', '-e', search_pattern, dir_path] #print(grep_cmd) p = subprocess.Popen(grep_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) for e in p.stderr: print(e) for f in p.stdout: file_list.append(f[:-1]) ''' for root, dirs, files in os.walk(unicode(dir_path, 'utf-8')): for d in dirs: d_list.append(os.path.join(root, d)) for f in files: if self.check_file_pattern(f, unicode(file_pattern, 'utf-8')): if find_options['INCLUDE_SUBFOLDER'] == True: file_list.append(os.path.join(root, f)) else: if os.path.dirname(f) not in d_list: file_list.append(os.path.join(root, f)) self.find_ui.do_events() #''' #mid_time = time.time() #print('Use ' + str(mid_time-start_time) + ' seconds to find files.') self._results_view.is_busy(True) self._results_view.do_events() for file_path in file_list: if os.path.isfile(file_path): temp_doc = Gedit.Document() #file_uri = 'file://' + file_path #temp_doc.load(Gio.file_new_for_uri(file_uri), Gedit.encoding_get_from_charset('utf-8'), 0, 0, False) temp_doc.load(Gio.file_new_for_path(bytes.decode(file_path)), Gedit.encoding_get_from_charset('utf-8'), 0, 0, False) f_temp = open(file_path, 'r') try: text = str(f_temp.read()) except: text = f_temp.read() f_temp.close() temp_doc.set_text(text) self.advanced_find_all_in_doc(parent_it, temp_doc, search_pattern, find_options, replace_flg) self.find_ui.do_events() if self._results_view.stopButton.get_sensitive() == False: break self._results_view.is_busy(False)