Exemple #1
0
def _OpenToLine(fname, line, mainw):
    """Open the given filename to the given line number
    @param fname: File name to open, relative paths will be converted to abs
                  paths.
    @param line: Line number to set the cursor to after opening the file
    @param mainw: MainWindow instance to open the file in

    """
    fname = os.path.abspath(fname)  # Normalize path
    nbook = mainw.GetNotebook()
    buffers = [page.GetFileName() for page in nbook.GetTextControls()]
    for page, name in enumerate(buffers):
        if ebmlib.ComparePaths(fname, name):
            nbook.ChangePage(page)
            nbook.GetPage(page).GotoLine(line)

            #scroll to place the lin in the middle of the window
            los = nbook.GetPage(page).LinesOnScreen()
            nlines = nbook.GetPage(page).GetLineCount()
            scroll_count = int(los / 2)
            if los >= nlines - line:
                scroll_count = int((nlines - line) / 2)
            nbook.GetPage(page).LineScroll(0, -scroll_count)

            break
    else:
        nbook.OnDrop([fname])
        nbook.GetPage(nbook.GetSelection()).GotoLine(line)
Exemple #2
0
def _OpenToLine(fname, line, mainw):
    """Open the given filename to the given line number
    @param fname: File name to open, relative paths will be converted to abs
                  paths.
    @param line: Line number to set the cursor to after opening the file
    @param mainw: MainWindow instance to open the file in

    """
    fname = os.path.abspath(fname)  # Normalize path
    nbook = mainw.GetNotebook()
    buffers = [page.GetFileName() for page in nbook.GetTextControls()]
    for page, name in enumerate(buffers):
        if ebmlib.ComparePaths(fname, name):
            nbook.ChangePage(page)
            nbook.GetPage(page).GotoLine(line)
            break
    else:
        nbook.OnDrop([fname])
        nbook.GetPage(nbook.GetSelection()).GotoLine(line)
Exemple #3
0
    def testComparePaths(self):
        """Test functionality of ComparePaths function"""
        # Test case sensitivity
        if ISWINDOWS:
            self.assertTrue(ebmlib.ComparePaths("C:\\Windows", "C:\\WINDOWS"))
            self.assertTrue(ebmlib.ComparePaths("C:\\Windows", "C:\\Windows"))
        else:
            self.assertFalse(ebmlib.ComparePaths("/usr/bin", "/usr/BIN"))
            self.assertTrue(ebmlib.ComparePaths("/usr/bin", "/usr/bin"))

        # Test wacky path strings
        if ISWINDOWS:
            self.assertTrue(ebmlib.ComparePaths("C:\\Windows\\..\\", "C:\\"))
        else:
            self.assertTrue(ebmlib.ComparePaths("/usr/../", "/"))