Thursday, 25 February 2010

Graphical database application with 67 lines of python

Following some discussion in the #pyqt chatroom on freenode.net, I decided to play with the QtSql module of pyqt.

Here's the results, the table allows direct editing of the db.


note - you may need to install some dependencies
sudo apt-get install python-qt4 python-qt4-sql libqt4-sql-sqlite
#! /usr/bin/env python
'''
###########################################################
##   A Demo Application showing the use of sqlite3     ##
##   and the QSqlTableModel    Class                    ##
##   written by rowinggolfer 24th Feb 2010              ##
##   version 0.1 and NOT YET WORKING!!                  ##
##   this work is in the public domain,                 ##
##   do with it as you please                           ##
###########################################################
'''
import os, sys
from PyQt4 import QtCore, QtGui, QtSql

def makeDB():
    import sqlite3
    db = sqlite3.connect("test.db")
    db.execute("create table if not exists table1 (value text, data text)")
    
    query = "insert into table1 (value, data) values (?, ?)"
    
    valueSet = (("day","today"),("time","noon"),("food","cheese"))
    for values in valueSet:
        db.execute(query, values)
    db.commit()

class TestApp(QtGui.QDialog):
    def __init__(self, model, parent = None):
        super(TestApp, self).__init__(parent)
        self.model = model
        
        table = QtGui.QTableView()
        table.setModel(self.model)

        button = QtGui.QPushButton("Add a row")
        layout = QtGui.QVBoxLayout(self)
        layout.addWidget(table)
        layout.addWidget(button)

        self.connect(button, QtCore.SIGNAL("clicked()"), self.addRow)

    def addRow(self):
        self.model.insertRows(self.model.rowCount(), 1)

class myModel(QtSql.QSqlTableModel):
    def __init__(self, parent = None):
        super(myModel, self).__init__(parent)
        self.setEditStrategy(QtSql.QSqlTableModel.OnFieldChange)

        self.setTable("table1")
        self.select()
        
if __name__ == "__main__":
    if not os.path.exists("test.db"):
        makeDB()
    
    myDb = QtSql.QSqlDatabase.addDatabase("QSQLITE")
    myDb.setDatabaseName("test.db")
    if not myDb.open():
        print "Unable to create connection!"
        print "have you installed the sqlite driver?"
        print "sudo apt-get install libqt4-sql-sqlite"
        sys.exit(1)
    model = myModel()
    
    app = QtGui.QApplication(sys.argv)
    dl = TestApp(model)
    dl.exec_()

Wednesday, 24 February 2010

Ubuntu Update manager - feature request

Ubuntu handles updates really well, no question. The user is prompted to update, but without annoying pop ups that disrupt a workflow (cf M$ windows reboot in 5 minutes - ARGHH!)
However, there's one thing I would like to see altered.
Once one has clicked "install", the top level dialog box prevents access to all the wonderful information about the updates being installed. Granted, one should check before accepting these.. but....
I would prefer if I could still read details about what is being installed... as it happens.

As a hobby coder, I realise this is extra work, but if the scrollArea and Description widgets were still acessible.. I would be delighted.


update - I've filed a bug
https://bugs.launchpad.net/update-manager/+bug/526937

watch this space

Wednesday, 10 February 2010

pitivi

There's been a lot of buzz about pitivi perhaps being in ubuntu lucid by default.


So I thought I would try the latest version.


I was surprised to learn that there isn't a ppa version available, so I set one up, and made a deb from the latest git version of pitivi. It works very well indeed, and is very intuitive.

My ppa for pitivi "unstable" is here, and can be added using the new add-apt-repository command, which saves a lot of key hassle.

sudo add-apt-repository ppa:rowinggolfer/pitivi-unstable


add the g-streamer ppa while you are at it (pitivi uses gstreamer for the heavy lifting)
sudo add-apt-repository ppa:gstreamer-developers/ppa


Here's my first attempt with the new pitivi.. a title page tacked onto the front of a wee video.

How did I make the title page? Gimp. But that's another issue altogether....