PDA

View Full Version : PyQt savestate



Dariusz
2nd October 2013, 09:54
Heya

I'm quite new to PyQt. I'm trying to find some examples as to how to use savestate but so far I come up empty handed with python examples. Maybe I'm missing the elephant in the room so maybe point me out to it please. Most of my QT code learning experience come from zetcode and few other tutorials. Also I use pyuic4 to convert QT code to python and then study it. Now if some one could either point me to a way to set up savestate in QT Creator - then I could pyuic4 and back learn it and its all good but if Its not doable in creator here is my piece of code. If some1 could be so kind to show me few examples how I can add save/load states to it it would be great!


import os
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from subprocess import Popen, PIPE, STDOUT
import subprocess
global loc
global des
def main():
app = QApplication(sys.argv)
w = MyWindow()
w.show()
sys.exit(app.exec_())
class MyWindow(QMainWindow):
def __init__(self, *args):
QMainWindow.__init__(self, *args)
#Window Main Settings
MainWindow = self.setWindowTitle('Data')# Name
self.centralwidget = QWidget(MainWindow) # Create Widget
self.gridLayout = QGridLayout(self.centralwidget) # Create Grid Layout
self.gridLayout.setSpacing(2)
self.gridLayout.setMargin(2)
self.setStyleSheet("""
*
{
background-color: rgb(65,65,65);
color : rgb(210,210,210);
}
QMenuBar::item
{
background-color: rbg(100,0,100);
}
QMenuBar::item:selected
{
background-color: rbg(0,0,255);
}
QMenuBar::item:pressed
{
background-color: rgb(100,100,100);
}
""")
#Create Menu and status info
self.menubar = QMenuBar(MainWindow) # Create Menu Bar
self.menubar.setGeometry(QRect(0, 0, 800, 21)) # Menubar Settings
self.setMenuBar(self.menubar)
self.statusbar = QStatusBar(MainWindow) # Create Status Bar
self.setStatusBar(self.statusbar)
#Create Labels
self.l_dirLoc = QLabel('Location Dir',self)
#Create Buttons
self.pb_getDir = QPushButton('...',self.centralwidget)
#Create Q Line Edits
self.q_fileType = QLineEdit('Type File',self.centralwidget)
#Create List Views
self.lv_list = QListView(self.centralwidget)
#Create Check Box
self.bx_Display = QCheckBox('Display Data',self)

#Create Text Edit
self.te_dbrList = QTextEdit('',self)

#Menubar Action
exitAction = QAction(QIcon('exit.png'), '&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(qApp.quit)
menubar = self.menuBar()
file_menu = menubar.addMenu('&File')
file_menu.addAction(exitAction)

#Layout Order
self.gridLayout.addWidget(self.l_dirLoc)
self.gridLayout.addWidget(self.pb_getDir)
self.gridLayout.addWidget(self.q_fileType)
self.gridLayout.addWidget(self.lv_list)
self.gridLayout.addWidget(self.bx_Display)
self.gridLayout.addWidget(self.te_dbrList)
self.gridLayout.addItem(QSpacerItem(0,0, QSizePolicy.Minimum, QSizePolicy.Expanding))
self.setCentralWidget(self.centralwidget)

if __name__ == "__main__":
main()