Active Topics

 


Reply
Thread Tools
Posts: 842 | Thanked: 1,197 times | Joined on May 2010
#1
I'm working on a small GUI window that takes my pre-defined sqlite database, pulls out some data(specifically webcomic names, files etc.), and ends up displaying it.
Currently, I'm developing the application on my PC(running Debian), and apparently have both PyQT3 and 4 installed.
I intend to have a two or three column tree view on the left - The first column being the comic name, and any files under that name, second being Date found.
On the right/middle, I'll have some sort of canvas or webbrowser widget which will display the comic itself. I will end up controlling that widget via the tree at the left - Selecting an item will call a function which will end up changing the main widget's SRC.

Now, I've gotten most of this together, but I'm running into trouble. I found a tutorial and some instruction on making a tree view, and was able to understand the concepts and get my tree setup. Unfortunately, I learned that I'm using QT3, and the functionality I was using(multi-column QListView) is obsolete and not usable in QT4.
On -TOP- of that, I can't figure out how to get a signal from the QListView to a function of my own choosing. I just get "No such signal".


Everything -works-, at least on my main computer - I just can't figure out a way to get the commented line to work. I've tried a couple of different signals, including clicked(), but I can't figure it out.

Now, in -addition- to that problem, I'd like to figure out a way to port this to QT4, as I'm gonna need to in order to use it on the N900(I'm gonna end up with a separate mobile-usable GUI though) - I just don't know a good replacement for the functionality I'm using.

Here's my code:
Code:
#!/usr/bin/env python

from qt import * 
import sqlite3
import string
import re
import urllib
import urllib2
import os
import zlib
import time, datetime
import sys
CONFIG = {}
CONFIG['maxattempts'] = 6
CONFIG['sqlitedb'] = '../comicInfoDB.sqlite'
gui = {}
#open comic database
sqliteDBConnection = sqlite3.connect(CONFIG['sqlitedb'])
sqliteDB = sqliteDBConnection.cursor()
#sqliteDB.execute("create table if not exists comicCache (name,filename,date,downurl,parenturl,crc,otherInfo)")
sqliteDB.execute("SELECT name FROM sqlite_master WHERE name='comicList'")
if not (sqliteDB.fetchone()):
	print "Error: 'comicList' table missing from SqliteDB: "+CONFIG['sqlitedb']+" Repair or run configuration script again."
	sys.exit(1)
sqliteDB.execute("SELECT name FROM sqlite_master WHERE name='comicCache'")
if not (sqliteDB.fetchone()):
	print "Error: 'comicCache' table missing from SqliteDB: "+CONFIG['sqlitedb']+" Repair or run configuration script again."
	sys.exit(2)



class MainWindow(QMainWindow):

	def __init__(self, *args):
		QMainWindow.__init__(self)
		#gui['menubar'] = {}
		#gui['menubar']['self'] = self.menuBar()
		
		#gui['menubar']['file'] = gui['menubar']['self'].addMenu('&File')
		#gui['menubar']['file'].addAction(exit)
		gui['mainGrid']=QGrid(2, self)
		self.setCentralWidget(gui['mainGrid'])
		gui['mainGrid'].setFrameShape(QFrame.StyledPanel)

		gui['comicTree'] = QListView(gui['mainGrid'])
		
		gui['comicTree'].addColumn("Comic")
		gui['comicTree'].addColumn("Date")
		gui['comicTree'].setRootIsDecorated(1)
		gui['comicTree'].ListOfComics = {}
		gui['comicTree'].comics = {}
		for comicList in sqliteDBConnection.execute("SELECT name FROM comicList"):
			gui['comicTree'].ListOfComics[comicList[0]] = QListViewItem(gui['comicTree'], comicList[0])
			gui['comicTree'].comics[comicList[0]] = []
			retVar = sqliteDBConnection.execute("SELECT * FROM comicCache WHERE name=?",(comicList[0],))
			for curComic in retVar:
				comicDate = datetime.datetime.utcfromtimestamp(curComic[2])
				gui['comicTree'].comics[comicList[0]].append(QListViewItem(gui['comicTree'].ListOfComics[comicList[0]], curComic[1],comicDate.ctime()))
		gui['browser']= QTextBrowser(gui['mainGrid'])

		gui['button-pushme'] = QPushButton("Push Me", gui['mainGrid'])
		#QObject.connect(gui['comicTree'], SIGNAL("currentChanged()"),self, self.button_pushMe)
	def button_pushMe(value):
		print 'clicked'+value
app=QApplication(sys.argv)
win=MainWindow()
win.show()
app.connect(app, SIGNAL("lastWindowClosed()"),app, SLOT("quit()"))
app.exec_loop()

Edit: Solved:
Code:
#!/usr/bin/env python

from PyQt4 import QtGui, QtCore
import sqlite3
import string
import re
import urllib
import urllib2
import os
import zlib
import time, datetime
import sys
CONFIG = {}
CONFIG['maxattempts'] = 6
CONFIG['sqlitedb'] = '../comicInfoDB.sqlite'
gui = {}
#open comic database
sqliteDBConnection = sqlite3.connect(CONFIG['sqlitedb'])
sqliteDB = sqliteDBConnection.cursor()
#sqliteDB.execute("create table if not exists comicCache (name,filename,date,downurl,parenturl,crc,otherInfo)")
sqliteDB.execute("SELECT name FROM sqlite_master WHERE name='comicList'")
if not (sqliteDB.fetchone()):
	print "Error: 'comicList' table missing from SqliteDB: "+CONFIG['sqlitedb']+" Repair or run configuration script again."
	sys.exit(1)
sqliteDB.execute("SELECT name FROM sqlite_master WHERE name='comicCache'")
if not (sqliteDB.fetchone()):
	print "Error: 'comicCache' table missing from SqliteDB: "+CONFIG['sqlitedb']+" Repair or run configuration script again."
	sys.exit(2)



class MainWindow(QtGui.QMainWindow):

	def __init__(self, *args):
		
		QtGui.QMainWindow.__init__(self)

		gui['browser'] = QtGui.QTextBrowser()
		gui['mainHBox'].addWidget(gui['browser'])



def mainGui():
	gui['mainWindow'] = QtGui.QMainWindow()
	QtGui.QMainWindow.__init__(gui['mainWindow'])
	gui['mainWindow'].resize(640, 480)
	gui['mainWindow'].setWindowTitle('mainwindow')

	setupMenubar() #Add the menuBar
	gui['mainHBox'] = QtGui.QHBoxLayout()
	
	setupComicTree() #Add the ComicTree
	gui['comicTree'] = QtGui.QTreeWidget()
	
	gui['browser'] = QtGui.QTextBrowser()
	gui['mainHBox'].addWidget(gui['browser'])

	
	gui['centralWidget'] = QtGui.QWidget()
	gui['centralWidget'].setLayout(gui['mainHBox'])
	gui['mainWindow'].setCentralWidget(gui['centralWidget'])
	gui['mainWindow'].show()
	sys.exit(app.exec_())

def setupMenubar():
	gui['menubar'] = {}
	gui['menubar']['self'] = gui['mainWindow'].menuBar()
	gui['menubar']['file'] = gui['menubar']['self'].addMenu('&File')
	exit = QtGui.QAction(QtGui.QIcon('icons/exit.png'), 'Exit', gui['mainWindow'])
	exit.setShortcut('Ctrl+Q')
	exit.setStatusTip('Exit application')
	gui['mainWindow'].connect(exit, QtCore.SIGNAL('triggered()'), QtCore.SLOT('close()'))
	gui['menubar']['file'].addAction(exit)

def setupComicTree():
	gui['comicTree'] = QtGui.QTreeWidget()
	gui['comicTree'].setColumnCount(2);
	labels = QtCore.QStringList()
	labels.append('Name')
	labels.append('Date')
	gui['comicTree'].setHeaderLabels(QtCore.QStringList(labels))

	gui['comicTree'].ListOfComics = {}
	gui['comicTree'].comics = {}
	for comicList in sqliteDBConnection.execute("SELECT name FROM comicList"):
		item = QtGui.QTreeWidgetItem(gui['comicTree'])
		item.setText(0,comicList[0]);
		item.setText(2,'0|'+comicList[0]);

		gui['comicTree'].ListOfComics[comicList[0]] = item
		gui['comicTree'].comics[comicList[0]] = []
		retVar = sqliteDBConnection.execute("SELECT * FROM comicCache WHERE name=?",(comicList[0],))
		for curComic in retVar:
			comicDate = datetime.datetime.utcfromtimestamp(curComic[2])
			item = QtGui.QTreeWidgetItem(gui['comicTree'].ListOfComics[comicList[0]])
			item.setText(0,curComic[1])
			item.setText(1,comicDate.ctime())
			item.setText(2,'1|'+comicList[0]+'|'+str(len(gui['comicTree'].comics[comicList[0]])));
			gui['comicTree'].comics[comicList[0]].append(item)
	gui['mainHBox'].addWidget(gui['comicTree'])
	#Signals
	gui['comicTree'].itemDoubleClicked.connect(testFunc)
	gui['comicTree'].itemClicked.connect(testFunc2)
	gui['comicTree'].setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
	gui['comicTree'].customContextMenuRequested.connect(testFunc3)
	
def testFunc(value):
	print 'DoubleClicked:'
	print value.text(2)
def testFunc2(value):
	print 'SingleClicked:'
	print value.text(2)

def testFunc3(value):
	print 'RightClicked:'
	print value
	
app = QtGui.QApplication(sys.argv)
mainGui()
#app.connect(app, SIGNAL("lastWindowClosed()"),app, SLOT("quit()"))
Works great!

Last edited by RobbieThe1st; 2010-10-03 at 07:52. Reason: Solved the problem.
 

The Following User Says Thank You to RobbieThe1st For This Useful Post:
Posts: 291 | Thanked: 435 times | Joined on Apr 2011 @ RO
#2
have a nice birthday
 
Reply


 
Forum Jump


All times are GMT. The time now is 17:26.