[PyKDE] Problems with QTextView

Aaron J. Ginn aaron.ginn at motorola.com
Tue Feb 27 23:10:46 GMT 2001


I'm just beginning to look into the PyQt package.  I have previously
used Tkinter to build GUIs, but Qt is just too nice to pass on! :)

Anyway, I'm having difficulty figuring out how to build a QTextView
widget to my liking. I want to read the contents of a file and display
them in a QTextView widget exactly as they appear in the file.  The
problem is that any lines that are only carriage returns are being
ingnored, and any leading whitespace on a line is being ignored as well.

Here's an example.  This is what I want to see in the widget:

********************************************************
                        Help file for semiDRC
                        =====================

--------------
I) What is it?
--------------
semiDRC is a Python script for running DRC in the Semicustom design
environment.  It brings all the tools used for DRC into one single
script.  It was written mainly for running DRC on the TSMC 0.18
technology, but all future technologies will be supported as well.
There are no plans to support older technologies, including NCS18,
at the present time.  DRC flows for these are already tested and
proven (i.e. initdrac, mdaver, mdavamp).


----------------------
II) How do you run it?
----------------------
********************************************************

This is what I'm getting:

********************************************************
Help file for semiDRC
=====================
--------------
I) What is it?
--------------
semiDRC is a Python script for running DRC in the Semicustom design
environment.  It brings all the tools used for DRC into one single
script.  It was written mainly for running DRC on the TSMC 0.18
technology, but all future technologies will be supported as well.
There are no plans to support older technologies, including NCS18,
at the present time.  DRC flows for these are already tested and
proven (i.e. initdrac, mdaver, mdavamp).
----------------------
II) How do you run it?
----------------------
********************************************************

Here's my code for building the QTextView widget.

class QtHelpBrowser(QMainWindow):
    """
    Class thet defines a pop-up help message box.
    """
    
    def __init__(self, file):

	QMainWindow.__init__(self)

        font = QFont("Courier", 12, QFont.Bold)
        self.setFont(font)
        
        lines_in_file = Utils.readlines_open(file)
        tv = QTextView(self)
        self.resize(700,700)
        
        for i in range( len( lines_in_file ) ):
            tv.append( QString(lines_in_file[i]) )

        tv.resize( self.width(), self.height() )


The function Utils.readlines_open is below:

def readlines_open(path):
    """
    Opens a file for read and returns its contents as a list of strings.
    """

    try:
        read_stream = open(path)
    except IOError, info:
        print '%s' %info
        sys.exit(1)

    lines = read_stream.readlines()
    read_stream.close()

    return lines

Has anyone used a QTextView widget that can give me some insight into
how to format this?

Thanks,
Aaron Ginn

-- 
Aaron J. Ginn                    Phone: 480-814-4463
Motorola SemiCustom Solutions    Pager: 877-586-2318
1300 N. Alma School Rd.          Fax  : 480-814-4463
Chandler, AZ 85226 M/D CH260     mailto:aaron.ginn at motorola.com




More information about the PyQt mailing list