1
0
mirror of https://github.com/gryf/pygtktalog.git synced 2025-12-17 19:40:21 +01:00

* Rename appllication into pyGTKtalog.

* Added new files to the project.
This commit is contained in:
2006-11-25 08:23:25 +00:00
parent 69aa745d46
commit e980ebb97c
5 changed files with 393 additions and 0 deletions

97
config.py Normal file
View File

@@ -0,0 +1,97 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
config parser object
"""
#{{{ podstawowe importy i sprawdzenia
import sys
import os
from ConfigParser import ConfigParser
class Ini(object):
def __init__(self):
self.ini = []
def add_section(self, section):
self.ini.append("[%s]" % section)
def add_key(self, key, value):
self.ini.append("%s=%s" % (key, value))
def add_comment(self, comment):
self.ini.append(";%s" % comment)
def add_verb(self, verb):
self.ini.append(verb)
def show(self):
return "\n".join(self.ini)
class Config:
ini = Ini()
confd = {
'wx' : 800,
'wy' : 600,
'h' : 200,
'v' : 300,
'exportxls' : False,
'cd' : '/cdrom',
}
dictconf = {
"main window width" : "wx",
"main window height": "wy",
"horizontal panes": "h",
"vertical panes":"v",
"export xls":"exportxls",
"cd drive":"cd",
}
dbool = ('exportxls')
dstring = ('cd')
try:
path = os.environ['HOME']
except:
path = "/tmp"
def __init__(self):
self.load()
def save(self):
self.confd
newIni = Ini()
newIni.add_section("pyGTKtalog conf")
for opt in self.dictconf:
newIni.add_key(opt,self.confd[self.dictconf[opt]])
try:
f = open("%s/.pygtktalog" % self.path,"w")
except:
print "Cannot open config file %s for writing." % (self.path, "/.pygtktalog")
f.write(newIni.show())
f.close()
def load(self):
try:
# try to read config file
parser = ConfigParser()
parser.read("%s/.pygtktalog" % self.path)
for sec in parser.sections():
if sec == 'pyGTKtalog conf':
for opt in parser.options(sec):
try:
if self.dictconf[opt] in self.dbool:
self.confd[self.dictconf[opt]] = parser.getboolean(sec,opt)
elif self.dictconf[opt] in self.dstring:
self.confd[self.dictconf[opt]] = parser.get(sec,opt)
else:
self.confd[self.dictconf[opt]] = parser.getint(sec,opt)
except:
pass
except:
print "No config file"
pass

28
deviceHelper.py Normal file
View File

@@ -0,0 +1,28 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
device (cd, dvd) helper
"""
import string
import os
def volname(dev):
"""read volume name from cd/dvd"""
try:
a = open(dev,"rb")
a.seek(32808)
b = a.read(32).strip()
a.close()
except:
return None
return b
def volmount(dev):
"""mount device, return True/False"""
stout,stin,sterr = popen3("mount %s" % dev)
error = sterr.readline()
stout.close()
stin.close()
sterr.close()
return len(error) == 0

172
mainWindow.py Normal file
View File

@@ -0,0 +1,172 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
GUI, main window class and correspondig methods for pyGTKtalog app.
"""
import sys
import os
import mimetypes
import popen2
import pygtk
import gtk
import gtk.glade
from config import Config
class PyGTKtalog:
def __init__(self):
self.conf = Config()
self.gladefile = "glade/main.glade"
self.pygtkcat = gtk.glade.XML(self.gladefile,"main")
self.window = self.pygtkcat.get_widget("main")
self.window.set_title("pyGTKtalog")
icon = gtk.gdk.pixbuf_new_from_file("pixmaps/mainicon.png")
self.window.set_icon_list(icon)
self.progress = self.pygtkcat.get_widget("progressbar1")
self.status = self.pygtkcat.get_widget("mainStatus")
self.sbSearchCId = self.status.get_context_id('detailed res')
self.sbid = self.status.push(self.sbSearchCId, "Idle")
self.detailplaceholder = self.pygtkcat.get_widget("detailplace")
self.detailplaceholder.set_sensitive(False)
self.details = self.pygtkcat.get_widget("details")
self.details.hide()
self.widgets = ("discs","files","details",'save1','save_as1','cut1','copy1','paste1','delete1','add_cd','add_directory1')
for w in self.widgets:
a = self.pygtkcat.get_widget(w)
a.set_sensitive(False)
a = self.pygtkcat.get_widget('hpaned1')
a.set_position(self.conf.confd['h'])
a = self.pygtkcat.get_widget('vpaned1')
a.set_position(self.conf.confd['v'])
self.window.resize(self.conf.confd['wx'],self.conf.confd['wy'])
# sygnały:
dic = {"on_main_destroy_event" :self.doQuit,
"on_quit1_activate" :self.doQuit,
"on_new1_activate" :self.newDB,
"on_add_cd_activate" :self.addCD,
}
# connect signals
self.pygtkcat.signal_autoconnect(dic)
self.window.connect("delete_event", self.deleteEvent)
def storeSettings(self):
"""Store window size and pane position in config file (using config object)"""
hpan = self.pygtkcat.get_widget('hpaned1')
vpan = self.pygtkcat.get_widget('vpaned1')
self.conf.confd['wx'], self.conf.confd['wy'] = self.window.get_size()
self.conf.confd['h'],self.conf.confd['v'] = hpan.get_position(), vpan.get_position()
self.conf.save()
return
def doQuit(self, widget):
"""quit and save window parameters to config file"""
try:
if widget.title:
pass
except:
self.storeSettings()
gtk.main_quit()
return False
def newDB(self,widget):
"""create database in temporary place"""
self.window.set_title("untitled - pyGTKtalog")
for w in self.widgets:
try:
a = self.pygtkcat.get_widget(w)
a.set_sensitive(True)
# PyGTK FAQ entry 23.20
except:
pass
while gtk.events_pending():
gtk.main_iteration()
#self.details.set_sensitive(True)
#self.details.destroy()
#self.details = gtk.Button("Press mi or daj");
#self.details.set_name("details")
#self.detailplaceholder.add_with_viewport(self.details)
#self.details.show()
return
def deleteEvent(self, widget, event, data=None):
"""checkout actual database changed. If so, do the necessary ask."""
self.storeSettings()
return False
def run(self):
self.window.show();
gtk.main()
def addCD(self,widget):
self.scan(self.conf.confd['cd'])
def scan(self,path):
mime = mimetypes.MimeTypes()
extensions = ('mkv','avi','ogg','mpg','wmv','mp4')
count = 0
for root,kat,plik in os.walk(path):
for p in plik:
count+=1
frac = 1.0/count
count = 1
#self.progress.set_pulse_step(0)
for root,kat,plik in os.walk(path):
for p in plik:
if p[-3:].lower() in extensions or \
mime.guess_type(p)!= (None,None) and \
mime.guess_type(p)[0].split("/")[0] == 'video':
# video only
# TODO: parametrize this loop!
info = popen2.popen4('midentify "' + os.path.join(root,p)+'"')[0].readlines()
video_format = ''
audio_codec = ''
video_codec = ''
video_x = ''
video_y = ''
for line in info:
l = line.split('=')
val = l[1].split('\n')[0]
if l[0] == 'ID_VIDEO_FORMAT':
video_format = val
elif l[0] == 'ID_AUDIO_CODEC':
audio_codec = val
elif l[0] == 'ID_VIDEO_CODEC':
video_codec = val
elif l[0] == 'ID_VIDEO_WIDTH':
video_x = val
elif l[0] == 'ID_VIDEO_HEIGHT':
video_y = val
if self.sbid != 0:
"""jeśli jest jakiś mesedż, usuń go"""
self.status.remove(self.sbSearchCId, self.sbid)
self.sbid = self.status.push(self.sbSearchCId, "Scannig: %s" % (os.path.join(root,p)))
self.progress.set_fraction(frac * count)
count+=1
# PyGTK FAQ entry 23.20
while gtk.events_pending(): gtk.main_iteration()
if self.sbid != 0:
self.status.remove(self.sbSearchCId, self.sbid)
self.sbid = self.status.push(self.sbSearchCId, "Idle")
self.progress.set_fraction(0)

32
pyGTKtalog Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/sh
## gajim
##
## Contributors for this file:
## - Yann Le Boulanger <asterix@lagaule.org>
## - Nikos Kouremenos <kourem@gmail.com>
##
## Copyright (C) 2003-2004 Yann Le Boulanger <asterix@lagaule.org>
## Vincent Hanquez <tab@snarc.org>
## Copyright (C) 2005 Yann Le Boulanger <asterix@lagaule.org>
## Vincent Hanquez <tab@snarc.org>
## Nikos Kouremenos <nkour@jabber.org>
## Dimitur Kirov <dkirov@gmail.com>
## Travis Shirk <travis@pobox.com>
## Norman Rasmussen <norman@rasmussen.co.za>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 2 only.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
if [ `id -u` -eq 0 ]; then
echo "You must not launch Gajim as root, it is INSECURE"
fi
cd /mnt/data/Python/moviedb
#export PYTHONPATH="$PYTHONPATH:/usr/lib/gajim"
exec python -OO pyGTKtalog.py $@

64
pyGTKtalog.py Executable file
View File

@@ -0,0 +1,64 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
pytGTKtalog.
A wannabe replacement for excellent gtktalog application.
pyGTKtalog is an application for catalogue/index files on removable media such
a CD or DVD discs, directories on hard disks or network shares.
"""
#{{{ try to import all necessary modules
import sys
import os
try:
from config import Config
except:
print "Some fundamental files are missing. try runnig pyGTKtalog in his root directory"
sys.exit(1)
conf = Config()
try:
import pygtk
#tell pyGTK, if possible, that we want GTKv2
pygtk.require("2.0")
except:
#Some distributions come with GTK2, but not pyGTK
pass
try:
import gtk
import gtk.glade
except:
print "You need to install pyGTK or GTKv2 ",
print "or set your PYTHONPATH correctly."
print "try: export PYTHONPATH=",
print "/usr/local/lib/python2.2/site-packages/"
sys.exit(1)
try:
from pysqlite2 import dbapi2 as sqlite
except:
print "pyGTKtalog uses SQLite DB.\nYou'll need to get it and the python bindings as well.\nhttp://www.sqlite.org\nhttp://initd.org/tracker/pysqlite"
sys.exit(1)
if conf.confd['exportxls']:
try:
import pyExcelerator
except:
print "You'll need pyExcelerator, if you want to export DB to XLS format.\nhttp://sourceforge.net/projects/pyexcelerator"
sys.exit(1)
# project modules
from mainWindow import PyGTKtalog
if __name__ == "__main__":
app=PyGTKtalog()
try:
app.run()
except KeyboardInterrupt:
app.storeSettings()
gtk.main_quit