コード例 #1
0
    def test_get_selection(self):
        # text = Text(master=self.root)
        text = mockText()
        text.insert("1.0", "Hello World!")

        # fix text.index result when called in get_selection
        def sel(s):
            # select entire text, cursor irrelevant
            if s == "sel.first":
                return "1.0"
            if s == "sel.last":
                return "1.12"
            raise TclError

        text.index = sel  # replaces .tag_add('sel', '1.0, '1.12')
        self.assertEqual(se.get_selection(text), ("1.0", "1.12"))

        def mark(s):
            # no selection, cursor after 'Hello'
            if s == "insert":
                return "1.5"
            raise TclError

        text.index = mark  # replaces .mark_set('insert', '1.5')
        self.assertEqual(se.get_selection(text), ("1.5", "1.5"))
コード例 #2
0
 def test_search_reverse(self):
     Equal = self.assertEqual
     line = "Here is an 'is' test text."
     prog = re.compile('is')
     Equal(se.search_reverse(prog, line, len(line)).span(), (12, 14))
     Equal(se.search_reverse(prog, line, 14).span(), (12, 14))
     Equal(se.search_reverse(prog, line, 13).span(), (5, 7))
     Equal(se.search_reverse(prog, line, 7).span(), (5, 7))
     Equal(se.search_reverse(prog, line, 6), None)
コード例 #3
0
 def test_search_reverse(self):
     Equal = self.assertEqual
     line = "Here is an 'is' test text."
     prog = re.compile('is')
     Equal(se.search_reverse(prog, line, len(line)).span(), (12, 14))
     Equal(se.search_reverse(prog, line, 14).span(), (12, 14))
     Equal(se.search_reverse(prog, line, 13).span(), (5, 7))
     Equal(se.search_reverse(prog, line, 7).span(), (5, 7))
     Equal(se.search_reverse(prog, line, 6), None)
コード例 #4
0
 def test_get(self):
     saved_Engine = se.SearchEngine
     se.SearchEngine = Mock
     try:
         root = Mock()
         engine = se.get(root)
         self.assertIsInstance(engine, se.SearchEngine)
         self.assertIs(root._searchengine, engine)
         self.assertIs(se.get(root), engine)
     finally:
         se.SearchEngine = saved_Engine
コード例 #5
0
 def test_get(self):
     saved_Engine = se.SearchEngine
     se.SearchEngine = Mock  # monkey-patch class
     try:
         root = Mock()
         engine = se.get(root)
         self.assertIsInstance(engine, se.SearchEngine)
         self.assertIs(root._searchengine, engine)
         self.assertIs(se.get(root), engine)
     finally:
         se.SearchEngine = saved_Engine  # restore class to module
コード例 #6
0
 def test_get(self):
     saved_Engine = se.SearchEngine
     se.SearchEngine = Mock  # monkey-patch class
     try:
         root = Mock()
         engine = se.get(root)
         self.assertIsInstance(engine, se.SearchEngine)
         self.assertIs(root._searchengine, engine)
         self.assertIs(se.get(root), engine)
     finally:
         se.SearchEngine = saved_Engine  # restore class to module
コード例 #7
0
 def test_get(self):
     saved_Engine = se.SearchEngine
     se.SearchEngine = Mock
     try:
         root = Mock()
         engine = se.get(root)
         self.assertIsInstance(engine, se.SearchEngine)
         self.assertIs(root._searchengine, engine)
         self.assertIs(se.get(root), engine)
     finally:
         se.SearchEngine = saved_Engine
コード例 #8
0
ファイル: SearchDialog.py プロジェクト: little-tee/GTC
def _setup(text):
    "Create or find the singleton SearchDialog instance."
    root = text._root()
    engine = SearchEngine.get(root)
    if not hasattr(engine, "_searchdialog"):
        engine._searchdialog = SearchDialog(root, engine)
    return engine._searchdialog
コード例 #9
0
 def do_replace(self):
     prog = self.engine.getprog()
     if not prog:
         return False
     text = self.text
     try:
         first = pos = text.index("sel.first")
         last = text.index("sel.last")
     except TclError:
         pos = None
     if not pos:
         first = last = pos = text.index("insert")
     line, col = SearchEngine.get_line_col(pos)
     chars = text.get("%d.0" % line, "%d.0" % (line + 1))
     m = prog.match(chars, col)
     if not prog:
         return False
     new = self._replace_expand(m, self.replvar.get())
     if new is None:
         return False
     text.mark_set("insert", first)
     text.undo_block_start()
     if m.group():
         text.delete(first, last)
     if new:
         text.insert(first, new)
     text.undo_block_stop()
     self.show_hit(first, text.index("insert"))
     self.ok = 0
     return True
コード例 #10
0
ファイル: ReplaceDialog.py プロジェクト: 0xcc/pyston
def replace(text):
    root = text._root()
    engine = SearchEngine.get(root)
    if not hasattr(engine, "_replacedialog"):
        engine._replacedialog = ReplaceDialog(root, engine)
    dialog = engine._replacedialog
    dialog.open(text)
コード例 #11
0
 def do_replace(self):
     prog = self.engine.getprog()
     if not prog:
         return False
     text = self.text
     try:
         first = pos = text.index("sel.first")
         last = text.index("sel.last")
     except TclError:
         pos = None
     if not pos:
         first = last = pos = text.index("insert")
     line, col = SearchEngine.get_line_col(pos)
     chars = text.get("%d.0" % line, "%d.0" % (line + 1))
     m = prog.match(chars, col)
     if not prog:
         return False
     new = self._replace_expand(m, self.replvar.get())
     if new is None:
         return False
     text.mark_set("insert", first)
     text.undo_block_start()
     if m.group():
         text.delete(first, last)
     if new:
         text.insert(first, new)
     text.undo_block_stop()
     self.show_hit(first, text.index("insert"))
     self.ok = 0
     return True
コード例 #12
0
def replace(text):
    root = text._root()
    engine = SearchEngine.get(root)
    if not hasattr(engine, "_replacedialog"):
        engine._replacedialog = ReplaceDialog(root, engine)
    dialog = engine._replacedialog
    dialog.open(text)
コード例 #13
0
def grep(text, io=None, flist=None):
    root = text._root()
    engine = SearchEngine.get(root)
    if not hasattr(engine, "_grepdialog"):
        engine._grepdialog = GrepDialog(root, engine, flist)
    dialog = engine._grepdialog
    searchphrase = text.get("sel.first", "sel.last")
    dialog.open(text, searchphrase, io)
コード例 #14
0
def grep(text, io=None, flist=None):
    root = text._root()
    engine = SearchEngine.get(root)
    if not hasattr(engine, '_grepdialog'):
        engine._grepdialog = GrepDialog(root, engine, flist)
    dialog = engine._grepdialog
    searchphrase = text.get('sel.first', 'sel.last')
    dialog.open(text, searchphrase, io)
コード例 #15
0
def replace(text):
    """Returns a singleton ReplaceDialog instance.The single dialog
     saves user entries and preferences across instances."""
    root = text._root()
    engine = SearchEngine.get(root)
    if not hasattr(engine, "_replacedialog"):
        engine._replacedialog = ReplaceDialog(root, engine)
    dialog = engine._replacedialog
    dialog.open(text)
コード例 #16
0
 def setUpClass(cls):
     cls.text = mockText()
     test_text = 'First line\nLine with target\nLast line\n'
     cls.text.insert('1.0', test_text)
     cls.pat = re.compile('target')
     cls.engine = se.SearchEngine(None)
     cls.engine.search_forward = lambda *args: ('f', args)
     cls.engine.search_backward = lambda *args: ('b', args)
     return
コード例 #17
0
ファイル: ReplaceDialog.py プロジェクト: little-tee/GTC
def replace(text):
    """Returns a singleton ReplaceDialog instance.The single dialog
     saves user entries and preferences across instances."""
    root = text._root()
    engine = SearchEngine.get(root)
    if not hasattr(engine, "_replacedialog"):
        engine._replacedialog = ReplaceDialog(root, engine)
    dialog = engine._replacedialog
    dialog.open(text)
コード例 #18
0
    def test_get_selection(self):
        # text = Text(master=self.root)
        text = mockText()
        text.insert('1.0',  'Hello World!')

        # fix text.index result when called in get_selection
        def sel(s):
            # select entire text, cursor irrelevant
            if s == 'sel.first': return '1.0'
            if s == 'sel.last': return '1.12'
            raise TclError
        text.index = sel  # replaces .tag_add('sel', '1.0, '1.12')
        self.assertEqual(se.get_selection(text), ('1.0', '1.12'))

        def mark(s):
            # no selection, cursor after 'Hello'
            if s == 'insert': return '1.5'
            raise TclError
        text.index = mark  # replaces .mark_set('insert', '1.5')
        self.assertEqual(se.get_selection(text), ('1.5', '1.5'))
コード例 #19
0
 def setUpClass(cls):
     cls.root = Tk()
     cls.root.withdraw()
     se.tkMessageBox = Mbox
     cls.engine = se.SearchEngine(cls.root)
     cls.dialog = rd.ReplaceDialog(cls.root, cls.engine)
     cls.dialog.ok = Mock()
     cls.text = Text(cls.root)
     cls.text.undo_block_start = Mock()
     cls.text.undo_block_stop = Mock()
     cls.dialog.text = cls.text
コード例 #20
0
 def setUpClass(cls):
     cls.engine = se.SearchEngine(None)
     cls.text = mockText()
     cls.text.index = lambda index: '4.0'
     test_text = 'First line\nLine with target\nLast line\n'
     cls.text.insert('1.0', test_text)
     cls.pat = re.compile('target')
     cls.res = (2, (10, 16))
     cls.failpat = re.compile('xyz')
     cls.emptypat = re.compile('\\w*')
     return
コード例 #21
0
    def test_get_selection(self):
        text = mockText()
        text.insert('1.0', 'Hello World!')

        def sel(s):
            if s == 'sel.first':
                return '1.0'
            if s == 'sel.last':
                return '1.12'
            raise TclError

        text.index = sel
        self.assertEqual(se.get_selection(text), ('1.0', '1.12'))

        def mark(s):
            if s == 'insert':
                return '1.5'
            raise TclError

        text.index = mark
        self.assertEqual(se.get_selection(text), ('1.5', '1.5'))
コード例 #22
0
    def test_get_selection(self):
        text = mockText()
        text.insert('1.0', 'Hello World!')

        def sel(s):
            if s == 'sel.first':
                return '1.0'
            if s == 'sel.last':
                return '1.12'
            raise TclError

        text.index = sel
        self.assertEqual(se.get_selection(text), ('1.0', '1.12'))

        def mark(s):
            if s == 'insert':
                return '1.5'
            raise TclError

        text.index = mark
        self.assertEqual(se.get_selection(text), ('1.5', '1.5'))
コード例 #23
0
    def setUpClass(cls):
        ##        requires('gui')
        ##        cls.root = Tk()
        ##        cls.text = Text(master=cls.root)
        cls.text = mockText()
        test_text = ('First line\n' 'Line with target\n' 'Last line\n')
        cls.text.insert('1.0', test_text)
        cls.pat = re.compile('target')

        cls.engine = se.SearchEngine(None)
        cls.engine.search_forward = lambda *args: ('f', args)
        cls.engine.search_backward = lambda *args: ('b', args)
コード例 #24
0
    def test_get_selection(self):
        text = mockText()
        text.insert("1.0", "Hello World!")

        def sel(s):
            if s == "sel.first":
                return "1.0"
            if s == "sel.last":
                return "1.12"
            raise TclError

        text.index = sel
        self.assertEqual(se.get_selection(text), ("1.0", "1.12"))

        def mark(s):
            if s == "insert":
                return "1.5"
            raise TclError

        text.index = mark
        self.assertEqual(se.get_selection(text), ("1.5", "1.5"))
コード例 #25
0
 def setUpClass(cls):
     cls.engine = se.SearchEngine(None)
     ##        requires('gui')
     ##        cls.root = Tk()
     ##        cls.text = Text(master=cls.root)
     cls.text = mockText()
     # search_backward calls index('end-1c')
     cls.text.index = lambda index: '4.0'
     test_text = ('First line\n' 'Line with target\n' 'Last line\n')
     cls.text.insert('1.0', test_text)
     cls.pat = re.compile('target')
     cls.res = (2, (10, 16))  # line, slice indexes of 'target'
     cls.failpat = re.compile('xyz')  # not in text
     cls.emptypat = re.compile('\w*')  # empty match possible
コード例 #26
0
def _setup(text):
    root = text._root()
    engine = SearchEngine.get(root)
    if not hasattr(engine, "_searchdialog"):
        engine._searchdialog = SearchDialog(root, engine)
    return engine._searchdialog
コード例 #27
0
 def setUp(self):
     self.engine = se.SearchEngine(self.root)
     self.dialog = sd.SearchDialog(self.root, self.engine)
     self.text = tk.Text(self.root)
     self.text.insert('1.0', 'Hello World!')
コード例 #28
0
 def setUp(self):
     self.engine = se.SearchEngine(self.root)  # None also seems to work
     self.dialog = sdb.SearchDialogBase(root=self.root, engine=self.engine)
コード例 #29
0
    def test_get_line_col(self):
        self.assertEqual(se.get_line_col("1.0"), (1, 0))
        self.assertEqual(se.get_line_col("1.11"), (1, 11))

        self.assertRaises(ValueError, se.get_line_col, ("1.0 lineend"))
        self.assertRaises(ValueError, se.get_line_col, ("end"))
コード例 #30
0
ファイル: idlelibsearchdialog.py プロジェクト: aevitas/wotsdk
def _setup(text):
    root = text._root()
    engine = SearchEngine.get(root)
    if not hasattr(engine, '_searchdialog'):
        engine._searchdialog = SearchDialog(root, engine)
    return engine._searchdialog
コード例 #31
0
 def test_get_line_col(self):
     self.assertEqual(se.get_line_col('1.0'), (1, 0))
     self.assertEqual(se.get_line_col('1.11'), (1, 11))
     self.assertRaises(ValueError, se.get_line_col, '1.0 lineend')
     self.assertRaises(ValueError, se.get_line_col, 'end')
コード例 #32
0
    def test_get_line_col(self):
        self.assertEqual(se.get_line_col('1.0'), (1, 0))
        self.assertEqual(se.get_line_col('1.11'), (1, 11))

        self.assertRaises(ValueError, se.get_line_col, ('1.0 lineend'))
        self.assertRaises(ValueError, se.get_line_col, ('end'))
コード例 #33
0
 def setUp(self):
     self.engine = se.SearchEngine(root=None)
     return