#!/usr/bin/python
# -*- coding: utf-8 -*-


import sys
from PyQt4 import QtGui, QtCore

class MainWindow(QtGui.QMainWindow):
    def __init__(self):
         QtGui.QMainWindow.__init__(self)

         #initial window size
         self.resize(350, 250)
         self.setWindowTitle('mainwindow')

         #set central Widget to fill out the rest space
         self.lay_out = Layout(self)
         self.setCentralWidget(self.lay_out)

         #file menu: exit 
         exit = QtGui.QAction(QtGui.QIcon('icons/exit.png'), 'Exit', self)
         exit.setShortcut('Ctrl+Q')
         exit.setStatusTip('Exit application')

         #file menu: open
         openFile = QtGui.QAction(QtGui.QIcon('open.png'), 'Open', self)
         openFile.setShortcut('Ctrl+O')
         openFile.setStatusTip('Open new File')
         openFile.triggered.connect(self.showDialog)
         

         #exit when 'exit' is triggered
         self.connect(exit, QtCore.SIGNAL('triggered()'), QtCore.SLOT('close()'))

         self.statusBar()

         menubar = self.menuBar()
         file = menubar.addMenu('&File')
         file.addAction(exit)
         file.addAction(openFile)   

         toolbar = self.addToolBar('Exit')
         toolbar.addAction(exit)

    def showDialog(self):

        fname = QtGui.QFileDialog.getOpenFileName(self, 'Open file', '/home')
        
        f = open(fname, 'r')
        
        with f:        
            data = f.read()
            
         
class Layout(QtGui.QWidget):
    def __init__(self,parent):
        super(Layout, self).__init__(parent)

        location = QtGui.QLabel('Location')
        title = QtGui.QLabel('Title')
        author = QtGui.QLabel('Author')
        review = QtGui.QLabel('Review')

        locationEdit = QtGui.QLineEdit()
        titleEdit = QtGui.QLineEdit()
        authorEdit = QtGui.QLineEdit()
        reviewEdit = QtGui.QTextEdit()

        grid = QtGui.QGridLayout()
        grid.setSpacing(10)

        grid.addWidget(location, 1, 0)
        grid.addWidget(locationEdit, 1, 1)

        grid.addWidget(title, 2, 0)
        grid.addWidget(titleEdit, 2, 1)

        grid.addWidget(author, 3, 0)
        grid.addWidget(authorEdit, 3, 1)

        grid.addWidget(review, 4, 0)
        grid.addWidget(reviewEdit, 4, 1, 6, 1)
        
        self.setLayout(grid)
         

def main():
    
    app = QtGui.QApplication(sys.argv)
    main = MainWindow()
    main.setGeometry(300, 300, 350, 300)
    main.setWindowTitle('DiRT')
    main.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()


@@ -37,16 +37,33 @@
 8 -*-%0A%0A%0A
+# mainwindow.py%0A%0A
 import s
@@ -1456,16 +1456,216 @@
 f.read()
+%0A%0A            #to avoid garbage character when decoding other languages%0A            data = data.decode('utf-8')%0A%0A            #set the text to TextEdit%0A            self.lay_out.reviewEdit.setText(data)
 %0A       
@@ -1782,24 +1782,48 @@
 __(parent)%0A%0A
+        #testing layout%0A
         loca
@@ -1973,32 +1973,76 @@
 view')%0A%0A        
+#create attributes for lay_out%0A        self.
 locationEdit = Q
@@ -2062,24 +2062,29 @@
 t()%0A        
+self.
 titleEdit = 
@@ -2105,24 +2105,29 @@
 t()%0A        
+self.
 authorEdit =
@@ -2149,24 +2149,29 @@
 t()%0A        
+self.
 reviewEdit =
@@ -2308,32 +2308,37 @@
  grid.addWidget(
+self.
 locationEdit, 1,
@@ -2397,24 +2397,29 @@
 d.addWidget(
+self.
 titleEdit, 2
@@ -2480,24 +2480,29 @@
 d.addWidget(
+self.
 authorEdit, 
@@ -2564,24 +2564,29 @@
 d.addWidget(
+self.
 reviewEdit, 
@@ -2634,16 +2634,25 @@
 ut(grid)
+%0A%0A       
 %0A       

Read Files