def keyPressEvent( self, event ) : kkey = int( int(event.modifiers()) & C.KEYPAD_MOD_CLEAR) | int(event.key() ) if kkey == C.CTL_F : event.accept() self.find_action() elif kkey == C.CTL_G : event.accept() self.find_next_action() elif kkey == C.CTL_SHFT_G : event.accept() self.find_prior_action() elif kkey in C.KEYS_WEB_BACK : event.accept() if self.view.history().canGoBack() : self.view.history().back() elif self.help_url is not None: self.view.load( self.help_url ) else: # try to reload the default text self.path_change() elif kkey in C.KEYS_WEB_FORWARD : if self.view.history().canGoForward() : self.view.history().forward() else: utilities.beep() else : super().keyPressEvent(event)
def keyPressEvent(self, event): kkey = int(int(event.modifiers()) & C.KEYPAD_MOD_CLEAR) | int( event.key()) if kkey == C.CTL_F: event.accept() self.find_action() elif kkey == C.CTL_G: event.accept() self.find_next_action() elif kkey == C.CTL_SHFT_G: event.accept() self.find_prior_action() elif kkey in C.KEYS_WEB_BACK: event.accept() if self.view.history().canGoBack(): self.view.history().back() elif self.help_url is not None: self.view.load(self.help_url) else: # try to reload the default text self.path_change() elif kkey in C.KEYS_WEB_FORWARD: if self.view.history().canGoForward(): self.view.history().forward() else: utilities.beep() else: super().keyPressEvent(event)
def go_to_line_number(self, lnum_string): try: lnum = int(lnum_string) - 1 # text block # is origin-0 self.go_to_line(lnum) except ValueError: # from int() or explicit utilities.beep() editview_logger.error('Request to show invalid line number {0}'.format(lnum_string))
def check_path( self ) : if os.access( self.path_edit.text(), self.criterion ) : return if self.path_edit.text() : # is not null utilities.beep() self.path_valid = False self.set_path_color( 'Pink' )
def go_to_line_number(self, lnum_string): try: lnum = int(lnum_string) - 1 # text block # is origin-0 self.go_to_line(lnum) except ValueError: # from int() or explicit utilities.beep() editview_logger.error( 'Request to show invalid line number {0}'.format(lnum_string))
def go_to_line_number(self, lnum_string): try: lnum = int(lnum_string) - 1 # text block is origin-0 tb = self.document.findBlockByLineNumber(lnum) if not tb.isValid() : raise ValueError self.go_to_block(tb) except ValueError: # from int() or explicit utilities.beep() editview_logger.error('Request to show invalid line number {0}'.format(lnum_string))
def go_to_image_name(self, name_string): pn = self.page_model.name_index(name_string) if pn is not None : self.center_position(self.page_model.position(pn)) else : # unknown image filename, restore current value utilities.beep() editview_logger.info('Request for invalid image name {0}'.format(self.ImageFilename.text())) self._cursor_moved() self.Editor.setFocus(Qt.TabFocusReason)
def go_to_image_name(self, name_string): pn = self.page_model.name_index(name_string) if pn is not None: self.center_position(self.page_model.position(pn)) else: # unknown image filename, restore current value utilities.beep() editview_logger.debug('Request for invalid image name {0}'.format( self.ImageFilename.text())) self._cursor_moved() self.Editor.setFocus(Qt.TabFocusReason)
def show_position(self, pos): try: pos = int(pos) if (pos < 0) or (pos >= self.document.characterCount() ) : raise ValueError except: utilities.beep() editview_logger.error('Request to show invalid position {0}'.format(pos)) pos = self.document.characterCount() tc = QTextCursor(self.Editor.textCursor()) tc.setPosition(pos) self.show_this(tc)
def similar_words(self) : # get clicked word in uppercase with hyphens and apostrophes stripped wd = worddata.clean_word(self.contextIndex.data(Qt.DisplayRole)).upper() hits = set() for j in range(self.words.vocab_count()) : wx = self.words.word_at(j) if wd == worddata.clean_word(wx).upper() : hits.add(wx) # will get 1 hit on the word itself if len(hits) > 1 : # did find at least one similar word self.model().set_filter( filter_set = hits ) else: # no matches utilities.beep()
def show_position(self, pos): try: pos = int(pos) if (pos < 0) or (pos >= self.document.characterCount()): raise ValueError except: utilities.beep() editview_logger.error( 'Request to show invalid position {0}'.format(pos)) pos = self.document.characterCount() - 1 tc = QTextCursor(self.Editor.textCursor()) tc.setPosition(pos) self.show_this(tc)
def second_harmonic(self): word = self.contextIndex.data(Qt.DisplayRole) rex = regex.compile('^(' + word + '){1<e<3}$',flags=regex.WORD) hits = set() for j in range(self.words.vocab_count()) : wx = self.words.word_at(j) if rex.match(wx) : hits.add(wx) if len(hits) : # did find at least one fuzzy match hits.add(word) self.model().set_filter( filter_set = hits ) else: # no matches utilities.beep()
def table_click(self, index) : row = index.row() col = index.column() if col > 2 : # column 3 4 or 5 target_line = self.data_model.note_line( row ) else : # column 0 1 or 2 target_line = self.data_model.anchor_line( row ) if col < 2 and target_line == self.edit_view.get_line() : # cannot get here if target_line is None target_line = self.data_model.note_line( row ) # but now it might be if target_line is None : # unmatched Anchor utilities.beep() return self.edit_view.go_to_line( target_line )
def table_click(self, index): row = index.row() col = index.column() if col > 2: # column 3 4 or 5 target_line = self.data_model.note_line(row) else: # column 0 1 or 2 target_line = self.data_model.anchor_line(row) if col < 2 and target_line == self.edit_view.get_line(): # cannot get here if target_line is None target_line = self.data_model.note_line(row) # but now it might be if target_line is None: # unmatched Anchor utilities.beep() return self.edit_view.go_to_line(target_line)
def real_find(self, row, word): for j in range( row, self.model().rowCount( QModelIndex() ) ) : ix = self.model().index( j, 0 ) raw_target = self.model().data( ix, Qt.DisplayRole ) clean_target = worddata.clean_word( raw_target ) if clean_target.startswith( word ) : self.last_find_word = word self.last_find_row = j self.clearSelection() self.selectRow( j ) self.scrollTo( ix, QAbstractItemView.PositionAtCenter ) return # no hit utilities.beep() self.last_find_row = None
def go_to_page(self): tb = self.textCursor().block() line = tb.text() pos = self.textCursor().positionInBlock() # Find the rightmost [ left of the cursor position j = line.rfind('[',0,pos+1) if 0 > j : utilities.beep() return # Find [xxx] starting at that point match = self.rex_page_name.search(line,j) if match is None : utilities.beep() return # Select the found value, then move the editor putting focus in it self.textCursor().setPosition( tb.position()+match.end() ) self.textCursor().setPosition( tb.position()+match.start(), QTextCursor.KeepAnchor ) self.book.get_edit_view().go_to_image_name(match.group(1))
def go_to_page(self): tb = self.textCursor().block() line = tb.text() pos = self.textCursor().positionInBlock() # Find the rightmost [ left of the cursor position j = line.rfind('[', 0, pos + 1) if 0 > j: utilities.beep() return # Find [xxx] starting at that point match = self.rex_page_name.search(line, j) if match is None: utilities.beep() return # Select the found value, then move the editor putting focus in it self.textCursor().setPosition(tb.position() + match.end()) self.textCursor().setPosition(tb.position() + match.start(), QTextCursor.KeepAnchor) self.book.get_edit_view().go_to_image_name(match.group(1))
def go_to_line(self): tb = self.textCursor().block() line = tb.text() pos = self.textCursor().positionInBlock() # Find the rightmost { left of the cursor position j = line.rfind('{',0,pos+1) if 0 > j : utilities.beep() return # Find {nnn} starting at that point match = self.rex_line_number.search(line,j) if match is None : utilities.beep() return try: line_number = int(match.group(1)) except ValueError: utilities.beep() return # Select the found value, then move the editor putting focus in it self.textCursor().setPosition( tb.position()+match.end() ) self.textCursor().setPosition( tb.position()+match.start(), QTextCursor.KeepAnchor ) self.book.get_edit_view().go_to_line_number(line_number)
def go_to_line(self): tb = self.textCursor().block() line = tb.text() pos = self.textCursor().positionInBlock() # Find the rightmost { left of the cursor position j = line.rfind('{', 0, pos + 1) if 0 > j: utilities.beep() return # Find {nnn} starting at that point match = self.rex_line_number.search(line, j) if match is None: utilities.beep() return try: line_number = int(match.group(1)) except ValueError: utilities.beep() return # Select the found value, then move the editor putting focus in it self.textCursor().setPosition(tb.position() + match.end()) self.textCursor().setPosition(tb.position() + match.start(), QTextCursor.KeepAnchor) self.book.get_edit_view().go_to_line_number(line_number)
def _do_find(self): if not self.find(self.find_text): # no hits going down self.moveCursor(QTextCursor.Start) # go to top if not self.find(self.find_text): # still no hit utilities.beep()
def _do_find(self, find_flags): if not self.view.page().findText(self.find_text, find_flags): utilities.beep()
os.remove(foo_path) bar_path = os.path.join(T.path_to_Files,f_bar) if os.path.isfile(bar_path): os.remove(bar_path) fbfoo = utilities.path_to_output(foo_path) assert fbfoo.filename() == f_foo fbfoo.writeLine('some data') assert os.path.isfile(foo_path) fbbar = utilities.related_output(fbfoo,'bar') assert fbbar.filename() == f_bar fbbar.writeLine('some data') assert os.path.isfile(bar_path) # Message routines utilities.info_msg('About to beep', 'When you dismiss this message') utilities.beep() assert utilities.ok_cancel_msg('Did you hear a beep?', 'OK for yes, Cancel for no',parent=T.main) utilities.warning_msg('This is a warning','the very last warning',parent=T.main) assert utilities.save_discard_cancel_msg('Click SAVE','no parent argument') assert not utilities.save_discard_cancel_msg('Click DISCARD (dont save?)','does have parent',parent=T.main) assert utilities.save_discard_cancel_msg('Click CANCEL','no parent') is None result = utilities.get_find_string('Press CANCEL',T.main,prepared='preptext') assert result is None preptext = 'REPLACE-WITH-FOO' result = utilities.get_find_string('Press Find',T.main,prepared=preptext) assert result==preptext # to_roman, to_alpha assert 'mmmmcmxcix' == utilities.to_roman(4999) assert 'i' == utilities.to_roman(1) assert 'XIV' == utilities.to_roman(14, lc=False)
def go_to_block(self, tb): if not tb.isValid(): utilities.beep() editview_logger.error('Request to show invalid text block') tb = self.document.lastBlock() self.show_position(tb.position())
def _do_find( self, find_flags ) : if not self.view.page().findText( self.find_text, find_flags ): utilities.beep()
os.remove(foo_path) bar_path = os.path.join(T.path_to_Files, f_bar) if os.path.isfile(bar_path): os.remove(bar_path) fbfoo = utilities.path_to_output(foo_path) assert fbfoo.filename() == f_foo fbfoo.writeLine('some data') assert os.path.isfile(foo_path) fbbar = utilities.related_output(fbfoo, 'bar') assert fbbar.filename() == f_bar fbbar.writeLine('some data') assert os.path.isfile(bar_path) # Message routines utilities.info_msg('About to beep', 'When you dismiss this message') utilities.beep() assert utilities.ok_cancel_msg('Did you hear a beep?', 'OK for yes, Cancel for no', parent=T.main) utilities.warning_msg('This is a warning', 'the very last warning', parent=T.main) assert utilities.save_discard_cancel_msg('Click SAVE', 'no parent argument') assert not utilities.save_discard_cancel_msg( 'Click DISCARD (dont save?)', 'does have parent', parent=T.main) assert utilities.save_discard_cancel_msg('Click CANCEL', 'no parent') is None result = utilities.get_find_string('Press CANCEL', T.main, prepared='preptext') assert result is None preptext = 'REPLACE-WITH-FOO' result = utilities.get_find_string('Press Find', T.main, prepared=preptext) assert result == preptext