mirror of
https://github.com/gryf/pygtktalog.git
synced 2025-12-18 12:00:21 +01:00
* Moved experimental MVC project as a current mainstream.
This commit is contained in:
3
src/__init__.py
Normal file
3
src/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
__all__ = ["models", "views", "controllers", "utils"]
|
||||
0
src/controllers/__init__.py
Normal file
0
src/controllers/__init__.py
Normal file
299
src/controllers/c_config.py
Normal file
299
src/controllers/c_config.py
Normal file
@@ -0,0 +1,299 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
import utils._importer
|
||||
import utils.globals
|
||||
from gtkmvc import Controller
|
||||
|
||||
import gtk
|
||||
|
||||
class ConfigController(Controller):
|
||||
category_dict = {'Disk options':'disk_group','General':'general_group','Scan options':'scan_group'}
|
||||
category_order = ['General','Disk options','Scan options']
|
||||
|
||||
def __init__(self, model):
|
||||
Controller.__init__(self, model)
|
||||
return
|
||||
|
||||
def register_view(self, view):
|
||||
Controller.register_view(self, view)
|
||||
|
||||
# get data from Config object and put it into view
|
||||
self.view['mnt_entry'].set_text(self.model.confd['cd'])
|
||||
self.view['ejt_entry'].set_text(self.model.confd['ejectapp'])
|
||||
self.view['ch_win'].set_active(self.model.confd['savewin'])
|
||||
self.view['ch_pan'].set_active(self.model.confd['savepan'])
|
||||
self.view['ch_eject'].set_active(self.model.confd['eject'])
|
||||
self.view['ch_xls'].set_active(self.model.confd['exportxls'])
|
||||
self.view['ch_quit'].set_active(self.model.confd['confirmquit'])
|
||||
self.view['ch_wrnmount'].set_active(self.model.confd['mntwarn'])
|
||||
self.view['ch_warnnew'].set_active(self.model.confd['confirmabandon'])
|
||||
self.view['ch_thumb'].set_active(self.model.confd['pil'])
|
||||
self.view['ch_exif'].set_active(self.model.confd['exif'])
|
||||
self.view['ch_gthumb'].set_active(self.model.confd['gthumb'])
|
||||
|
||||
# initialize tree view
|
||||
self.__setup_category_tree()
|
||||
self.view['config'].show();
|
||||
return
|
||||
# Podłącz sygnały:
|
||||
|
||||
#################
|
||||
# connect signals
|
||||
def on_category_tree_cursor_changed(self, tree):
|
||||
"""change view to selected row corresponding to group of properties"""
|
||||
model = tree.get_model()
|
||||
selected = model.get_value(model.get_iter(tree.get_cursor()[0]),0)
|
||||
iterator = tree.get_model().get_iter_first();
|
||||
while iterator != None:
|
||||
if model.get_value(iterator,0) == selected:
|
||||
self.view[self.category_dict[model.get_value(iterator,0)]].show()
|
||||
self.view['desc'].set_markup("<b>%s</b>" % selected)
|
||||
else:
|
||||
self.view[self.category_dict[model.get_value(iterator,0)]].hide()
|
||||
iterator = tree.get_model().iter_next(iterator);
|
||||
return
|
||||
|
||||
def on_cancelbutton_clicked(self, button):
|
||||
self.view['config'].destroy()
|
||||
return
|
||||
|
||||
def on_okbutton_clicked(self, button):
|
||||
# get data from view and put it into Config object
|
||||
self.model.confd['cd'] = self.view['mnt_entry'].get_text()
|
||||
self.model.confd['ejectapp'] = self.view['ejt_entry'].get_text()
|
||||
self.model.confd['savewin'] = self.view['ch_win'].get_active()
|
||||
self.model.confd['savepan'] = self.view['ch_pan'].get_active()
|
||||
self.model.confd['eject'] = self.view['ch_eject'].get_active()
|
||||
self.model.confd['exportxls'] = self.view['ch_xls'].get_active()
|
||||
self.model.confd['confirmquit'] = self.view['ch_quit'].get_active()
|
||||
self.model.confd['mntwarn'] = self.view['ch_wrnmount'].get_active()
|
||||
self.model.confd['confirmabandon'] = self.view['ch_warnnew'].get_active()
|
||||
self.model.confd['pil'] = self.view['ch_thumb'].get_active()
|
||||
self.model.confd['exif'] = self.view['ch_exif'].get_active()
|
||||
self.model.confd['gthumb'] = self.view['ch_gthumb'].get_active()
|
||||
self.model.save()
|
||||
self.view['config'].destroy()
|
||||
return
|
||||
|
||||
def on_button_ejt_clicked(self,button):
|
||||
self.__show_filechooser()
|
||||
return
|
||||
|
||||
def on_button_mnt_clicked(self,button):
|
||||
self.__show_dirchooser()
|
||||
return
|
||||
|
||||
############################
|
||||
# private controller methods
|
||||
def __setup_category_tree(self):
|
||||
category_tree = self.view['category_tree']
|
||||
category_tree.set_model(self.model.category_tree)
|
||||
|
||||
self.model.category_tree.clear()
|
||||
for i in ['General','Disk options','Scan options']:
|
||||
myiter = self.model.category_tree.insert_before(None,None)
|
||||
self.model.category_tree.set_value(myiter,0,i)
|
||||
|
||||
cell = gtk.CellRendererText()
|
||||
column = gtk.TreeViewColumn("Name",cell,text=0)
|
||||
column.set_resizable(True)
|
||||
category_tree.append_column(column)
|
||||
|
||||
def __show_filechooser(self):
|
||||
"""dialog for choose eject"""
|
||||
dialog = gtk.FileChooserDialog(
|
||||
title="Choose eject program",
|
||||
action=gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||
buttons=(
|
||||
gtk.STOCK_CANCEL,
|
||||
gtk.RESPONSE_CANCEL,
|
||||
gtk.STOCK_OPEN,
|
||||
gtk.RESPONSE_OK
|
||||
)
|
||||
)
|
||||
|
||||
dialog.set_default_response(gtk.RESPONSE_OK)
|
||||
|
||||
response = dialog.run()
|
||||
if response == gtk.RESPONSE_OK:
|
||||
print dialog.get_filename()
|
||||
self.view['ejt_entry'].set_text(dialog.get_filename())
|
||||
|
||||
dialog.destroy()
|
||||
|
||||
def __show_dirchooser(self):
|
||||
"""dialog for point the mountpoint"""
|
||||
dialog = gtk.FileChooserDialog(
|
||||
title="Choose mount point",
|
||||
action=gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||
buttons=(
|
||||
gtk.STOCK_CANCEL,
|
||||
gtk.RESPONSE_CANCEL,
|
||||
gtk.STOCK_OPEN,
|
||||
gtk.RESPONSE_OK
|
||||
)
|
||||
)
|
||||
|
||||
dialog.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
||||
dialog.set_filename(self.view['mnt_entry'].get_text())
|
||||
dialog.set_default_response(gtk.RESPONSE_OK)
|
||||
|
||||
response = dialog.run()
|
||||
if response == gtk.RESPONSE_OK:
|
||||
self.view['mnt_entry'].set_text(dialog.get_filename())
|
||||
dialog.destroy()
|
||||
|
||||
pass # end of class
|
||||
'''
|
||||
import sys
|
||||
import os
|
||||
|
||||
import pygtk
|
||||
import gtk
|
||||
import gtk.glade
|
||||
import gobject
|
||||
|
||||
from config import Config
|
||||
import dialogs
|
||||
|
||||
class Preferences:
|
||||
def __init__(self):
|
||||
self.category_dict = {'Disk options':'disk_group','General':'general_group','Scan options':'scan_group'}
|
||||
self.category_order = ['General','Disk options','Scan options']
|
||||
self.conf = Config()
|
||||
self.conf.load()
|
||||
|
||||
self.gladefile = "glade/prefs.glade"
|
||||
|
||||
self.glade = gtk.glade.XML(self.gladefile,"prefs")
|
||||
dic = {
|
||||
"on_button_ejt_clicked" :self.show_filechooser,
|
||||
"on_button_mnt_clicked" :self.show_dirchooser,
|
||||
"on_category_tree_cursor_changed" :self.activate_pan,
|
||||
}
|
||||
self.glade.signal_autoconnect(dic)
|
||||
|
||||
self.pref = self.glade.get_widget("prefs")
|
||||
self.pref.set_title("Preferences - pyGTKtalog")
|
||||
self.desc = self.glade.get_widget("desc")
|
||||
|
||||
self.cd = self.glade.get_widget("mnt_entry")
|
||||
self.cd.set_text(self.conf.confd['cd'])
|
||||
|
||||
self.eject = self.glade.get_widget("ejt_entry")
|
||||
self.eject.set_text(self.conf.confd['ejectapp'])
|
||||
|
||||
self.ch_win = self.glade.get_widget("ch_win")
|
||||
self.ch_win.set_active(self.conf.confd['savewin'])
|
||||
self.ch_pan = self.glade.get_widget("ch_pan")
|
||||
self.ch_pan.set_active(self.conf.confd['savepan'])
|
||||
self.ch_eject = self.glade.get_widget("ch_eject")
|
||||
self.ch_eject.set_active(self.conf.confd['eject'])
|
||||
self.ch_xls = self.glade.get_widget("ch_xls")
|
||||
self.ch_xls.set_active(self.conf.confd['exportxls'])
|
||||
self.ch_quit = self.glade.get_widget("ch_quit")
|
||||
self.ch_quit.set_active(self.conf.confd['confirmquit'])
|
||||
self.ch_wrnmount = self.glade.get_widget("ch_wrnmount")
|
||||
self.ch_wrnmount.set_active(self.conf.confd['mntwarn'])
|
||||
self.ch_warnnew = self.glade.get_widget("ch_warnnew")
|
||||
self.ch_warnnew.set_active(self.conf.confd['confirmabandon'])
|
||||
|
||||
self.ch_thumb = self.glade.get_widget("ch_thumb")
|
||||
self.ch_thumb.set_active(self.conf.confd['pil'])
|
||||
self.ch_exif = self.glade.get_widget("ch_exif")
|
||||
self.ch_exif.set_active(self.conf.confd['exif'])
|
||||
self.ch_gthumb = self.glade.get_widget("ch_gthumb")
|
||||
self.ch_gthumb.set_active(self.conf.confd['gthumb'])
|
||||
|
||||
self.tree = self.glade.get_widget("category_tree")
|
||||
self.model = gtk.ListStore(gobject.TYPE_STRING)
|
||||
self.model.clear()
|
||||
self.tree.set_model(self.model)
|
||||
self.tree.set_headers_visible(False)
|
||||
self.tree.show()
|
||||
|
||||
for i in self.category_order:
|
||||
myiter = self.model.insert_before(None,None)
|
||||
self.model.set_value(myiter,0,i)
|
||||
|
||||
renderer=gtk.CellRendererText()
|
||||
column=gtk.TreeViewColumn("Name",renderer, text=0)
|
||||
column.set_resizable(True)
|
||||
self.tree.append_column(column)
|
||||
if self.pref.run() == gtk.RESPONSE_OK:
|
||||
self.conf.confd['cd'] = self.cd.get_text()
|
||||
self.conf.confd['ejectapp'] = self.eject.get_text()
|
||||
self.conf.confd['savewin'] = self.ch_win.get_active()
|
||||
self.conf.confd['savepan'] = self.ch_pan.get_active()
|
||||
self.conf.confd['eject'] = self.ch_eject.get_active()
|
||||
self.conf.confd['pil'] = self.ch_thumb.get_active()
|
||||
self.conf.confd['exif'] = self.ch_exif.get_active()
|
||||
self.conf.confd['gthumb'] = self.ch_gthumb.get_active()
|
||||
self.conf.confd['exportxls'] = self.ch_xls.get_active()
|
||||
self.conf.confd['confirmquit'] = self.ch_quit.get_active()
|
||||
self.conf.confd['mntwarn'] = self.ch_wrnmount.get_active()
|
||||
self.conf.confd['confirmabandon'] = self.ch_warnnew.get_active()
|
||||
self.conf.save()
|
||||
self.pref.destroy()
|
||||
|
||||
def show_filechooser(self,widget):
|
||||
"""dialog for choose eject"""
|
||||
dialog = gtk.FileChooserDialog(
|
||||
title="Choose eject program",
|
||||
action=gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||
buttons=(
|
||||
gtk.STOCK_CANCEL,
|
||||
gtk.RESPONSE_CANCEL,
|
||||
gtk.STOCK_OPEN,
|
||||
gtk.RESPONSE_OK
|
||||
)
|
||||
)
|
||||
|
||||
dialog.set_default_response(gtk.RESPONSE_OK)
|
||||
|
||||
response = dialog.run()
|
||||
if response == gtk.RESPONSE_OK:
|
||||
self.eject.set_text(dialog.get_filename())
|
||||
|
||||
dialog.destroy()
|
||||
|
||||
def show_dirchooser(self,widget):
|
||||
"""dialog for point the mountpoint"""
|
||||
dialog = gtk.FileChooserDialog(
|
||||
title="Choose mount point",
|
||||
action=gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||
buttons=(
|
||||
gtk.STOCK_CANCEL,
|
||||
gtk.RESPONSE_CANCEL,
|
||||
gtk.STOCK_OPEN,
|
||||
gtk.RESPONSE_OK
|
||||
)
|
||||
)
|
||||
|
||||
dialog.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
||||
dialog.set_filename(self.conf.confd['cd'])
|
||||
dialog.set_default_response(gtk.RESPONSE_OK)
|
||||
|
||||
response = dialog.run()
|
||||
if response == gtk.RESPONSE_OK:
|
||||
self.cd.set_text(dialog.get_filename())
|
||||
dialog.destroy()
|
||||
|
||||
def activate_pan(self,treeview):
|
||||
model = treeview.get_model()
|
||||
selected = model.get_value(model.get_iter(treeview.get_cursor()[0]),0)
|
||||
iterator = treeview.get_model().get_iter_first();
|
||||
while iterator != None:
|
||||
if model.get_value(iterator,0) == selected:
|
||||
self.glade.get_widget(self.category_dict[model.get_value(iterator,0)]).show()
|
||||
self.desc.set_markup("<b>%s</b>" % selected)
|
||||
else:
|
||||
self.glade.get_widget(self.category_dict[model.get_value(iterator,0)]).hide()
|
||||
iterator = treeview.get_model().iter_next(iterator);
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
app=Preferences()
|
||||
gtk.main()
|
||||
except KeyboardInterrupt:
|
||||
gtk.main_quit
|
||||
'''
|
||||
464
src/controllers/c_main.py
Normal file
464
src/controllers/c_main.py
Normal file
@@ -0,0 +1,464 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
|
||||
__version__ = "0.7"
|
||||
licence = \
|
||||
"""
|
||||
GPL v2
|
||||
http://www.gnu.org/licenses/gpl.txt
|
||||
"""
|
||||
|
||||
import utils._importer
|
||||
import utils.globals
|
||||
from utils import deviceHelper
|
||||
from gtkmvc import Controller
|
||||
|
||||
from c_config import ConfigController
|
||||
from views.v_config import ConfigView
|
||||
from models.m_config import ConfigModel
|
||||
|
||||
import views.v_dialogs as Dialogs
|
||||
|
||||
import gtk
|
||||
|
||||
import datetime
|
||||
|
||||
class MainController(Controller):
|
||||
"""Kontroler głównego okna aplikacji"""
|
||||
scan_cd = False
|
||||
widgets = (
|
||||
"discs","files","details",
|
||||
'save1','save_as1','cut1','copy1','paste1','delete1','add_cd','add_directory1',
|
||||
'tb_save','tb_addcd','tb_find',
|
||||
)
|
||||
widgets_all = (
|
||||
"discs","files","details",
|
||||
'file1','edit1','add_cd','add_directory1','help1',
|
||||
'tb_save','tb_addcd','tb_find','tb_new','tb_open','tb_quit',
|
||||
)
|
||||
widgets_cancel = ('cancel','cancel1')
|
||||
|
||||
def __init__(self, model):
|
||||
"""Initialize controller"""
|
||||
Controller.__init__(self, model)
|
||||
return
|
||||
|
||||
def register_view(self, view):
|
||||
Controller.register_view(self, view)
|
||||
|
||||
# deaktywuj na starcie te oto widżety
|
||||
for widget in self.widgets:
|
||||
self.view[widget].set_sensitive(False)
|
||||
# dodatkowo deaktywuj knefle 'cancel'
|
||||
for widget in self.widgets_cancel:
|
||||
self.view[widget].set_sensitive(False)
|
||||
|
||||
# ukryj przycisk "debug", jeśli nie debugujemy.
|
||||
if __debug__:
|
||||
self.view['debugbtn'].show()
|
||||
else:
|
||||
self.view['debugbtn'].hide()
|
||||
|
||||
# ustaw domyślne właściwości dla poszczególnych widżetów
|
||||
self.view['main'].set_title('pyGTKtalog');
|
||||
self.view['main'].set_icon_list(gtk.gdk.pixbuf_new_from_file("pixmaps/mainicon.png"))
|
||||
self.view['detailplace'].set_sensitive(False)
|
||||
self.view['details'].hide()
|
||||
|
||||
# załaduj konfigurację/domyślne ustawienia i przypisz je właściwościom
|
||||
|
||||
self.view['toolbar1'].set_active(self.model.config.confd['showtoolbar'])
|
||||
if self.model.config.confd['showtoolbar']:
|
||||
self.view['maintoolbar'].show()
|
||||
else:
|
||||
self.view['maintoolbar'].hide()
|
||||
self.view['status_bar1'].set_active(self.model.config.confd['showstatusbar'])
|
||||
if self.model.config.confd['showstatusbar']:
|
||||
self.view['statusprogress'].show()
|
||||
else:
|
||||
self.view['statusprogress'].hide()
|
||||
self.view['hpaned1'].set_position(self.model.config.confd['h'])
|
||||
self.view['vpaned1'].set_position(self.model.config.confd['v'])
|
||||
self.view['main'].resize(self.model.config.confd['wx'],self.model.config.confd['wy'])
|
||||
|
||||
# zainicjalizuj statusbar
|
||||
self.context_id = self.view['mainStatus'].get_context_id('detailed res')
|
||||
self.statusbar_id = self.view['mainStatus'].push(self.context_id, "Idle")
|
||||
|
||||
# inicjalizacja drzew
|
||||
self.__setup_disc_treeview()
|
||||
self.__setup_files_treeview()
|
||||
|
||||
# Show main window
|
||||
self.view['main'].show();
|
||||
return
|
||||
|
||||
#########################################################################
|
||||
# Connect signals from GUI, like menu objects, toolbar buttons and so on.
|
||||
def on_main_destroy_event(self, window, event):
|
||||
self.__doQuit()
|
||||
return True
|
||||
|
||||
def on_tb_quit_clicked(self,widget):
|
||||
self.__doQuit()
|
||||
|
||||
def on_quit1_activate(self,widget):
|
||||
self.__doQuit()
|
||||
|
||||
def on_new1_activate(self,widget):
|
||||
self.__newDB()
|
||||
|
||||
def on_tb_new_clicked(self,widget):
|
||||
self.__newDB()
|
||||
|
||||
def on_add_cd_activate(self,widget):
|
||||
self.__addCD()
|
||||
|
||||
def on_tb_addcd_clicked(self,widget):
|
||||
self.__addCD()
|
||||
|
||||
def on_add_directory1_activate(self,widget):
|
||||
"""Show dialog for choose drectory to add from filesystem."""
|
||||
res = Dialogs.PointDirectoryToAdd().run()
|
||||
if res !=(None,None):
|
||||
self.model.scan(res[1],res[0])
|
||||
return
|
||||
|
||||
def on_about1_activate(self,widget):
|
||||
"""Show about dialog"""
|
||||
Dialogs.Abt("pyGTKtalog", __version__, "About", ["Roman 'gryf' Dobosz"], licence)
|
||||
return
|
||||
|
||||
def on_preferences_activate(self,widget):
|
||||
c = ConfigController(self.model.config)
|
||||
v = ConfigView(c)
|
||||
return
|
||||
|
||||
def on_status_bar1_activate(self,widget):
|
||||
"""Toggle visibility of statusbat and progress bar."""
|
||||
self.model.config.confd['showstatusbar'] = self.view['status_bar1'].get_active()
|
||||
if self.view['status_bar1'].get_active():
|
||||
self.view['statusprogress'].show()
|
||||
else:
|
||||
self.view['statusprogress'].hide()
|
||||
|
||||
def on_toolbar1_activate(self,widget):
|
||||
"""Toggle visibility of toolbar bar."""
|
||||
self.model.config.confd['showtoolbar'] = self.view['toolbar1'].get_active()
|
||||
if self.view['toolbar1'].get_active():
|
||||
self.view['maintoolbar'].show()
|
||||
else:
|
||||
self.view['maintoolbar'].hide()
|
||||
|
||||
def on_save1_activate(self,widget):
|
||||
self.__save()
|
||||
|
||||
def on_tb_save_clicked(self,widget):
|
||||
self.__save()
|
||||
|
||||
def on_save_as1_activate(self,widget):
|
||||
self.__save_as()
|
||||
|
||||
def on_tb_open_clicked(self,widget):
|
||||
self.__open()
|
||||
|
||||
def on_open1_activate(self,widget):
|
||||
self.__open()
|
||||
|
||||
def on_discs_cursor_changed(self,widget):
|
||||
"""Show files on right treeview, after clicking the left disc treeview."""
|
||||
model = self.view['discs'].get_model()
|
||||
selected_item = self.model.discsTree.get_value(self.model.discsTree.get_iter(self.view['discs'].get_cursor()[0]),0)
|
||||
if __debug__:
|
||||
print "on_discs_cursor_changed ",selected_item
|
||||
self.model.get_root_entries(selected_item)
|
||||
|
||||
self.view['details'].show()
|
||||
txt = self.model.get_file_info(selected_item)
|
||||
buf = self.view['details'].get_buffer()
|
||||
buf.set_text(txt)
|
||||
self.view['details'].set_buffer(buf)
|
||||
return
|
||||
|
||||
def on_discs_row_activated(self, treeview, path, treecolumn):
|
||||
"""If possible, expand or collapse branch of discs tree"""
|
||||
if treeview.row_expanded(path):
|
||||
treeview.collapse_row(path)
|
||||
else:
|
||||
treeview.expand_row(path,False)
|
||||
|
||||
def on_files_cursor_changed(self,treeview):
|
||||
"""Show details of selected file"""
|
||||
model, paths = treeview.get_selection().get_selected_rows()
|
||||
try:
|
||||
itera = model.get_iter(paths[0])
|
||||
if model.get_value(itera,4) == 1:
|
||||
#directory, do nothin', just turn off view
|
||||
self.view['details'].hide()
|
||||
buf = self.view['details'].get_buffer()
|
||||
buf.set_text('')
|
||||
self.view['details'].set_buffer(buf)
|
||||
if __debug__:
|
||||
print "on_files_cursor_changed: directory selected"
|
||||
else:
|
||||
#file, show what you got.
|
||||
self.view['details'].show()
|
||||
selected_item = self.model.filesList.get_value(model.get_iter(treeview.get_cursor()[0]),0)
|
||||
txt = self.model.get_file_info(selected_item)
|
||||
|
||||
buf = self.view['details'].get_buffer()
|
||||
buf.set_text(txt)
|
||||
self.view['details'].set_buffer(buf)
|
||||
if __debug__:
|
||||
print "on_files_cursor_changed: some other thing selected"
|
||||
except:
|
||||
if __debug__:
|
||||
print "on_files_cursor_changed: insufficient iterator"
|
||||
return
|
||||
|
||||
def on_files_row_activated(self, files_obj, row, column):
|
||||
"""On directory doubleclick in files listview dive into desired branch."""
|
||||
# TODO: można by też podczepić klawisz backspace do przechodzenia poziom wyżej.
|
||||
f_iter = self.model.filesList.get_iter(row)
|
||||
current_id = self.model.filesList.get_value(f_iter,0)
|
||||
|
||||
if self.model.filesList.get_value(f_iter,4) == 1:
|
||||
# ONLY directories. files are omitted.
|
||||
self.model.get_root_entries(current_id)
|
||||
|
||||
d_path, d_column = self.view['discs'].get_cursor()
|
||||
if d_path!=None:
|
||||
if not self.view['discs'].row_expanded(d_path):
|
||||
self.view['discs'].expand_row(d_path,False)
|
||||
|
||||
new_iter = self.model.discsTree.iter_children(self.model.discsTree.get_iter(d_path))
|
||||
if new_iter:
|
||||
while new_iter:
|
||||
if self.model.discsTree.get_value(new_iter,0) == current_id:
|
||||
self.view['discs'].set_cursor(self.model.discsTree.get_path(new_iter))
|
||||
new_iter = self.model.discsTree.iter_next(new_iter)
|
||||
return
|
||||
|
||||
def on_cancel1_activate(self,widget):
|
||||
self.__abort()
|
||||
|
||||
def on_cancel_clicked(self,widget):
|
||||
self.__abort()
|
||||
|
||||
def on_tb_find_clicked(self,widget):
|
||||
# TODO: zaimplementować wyszukiwarkę
|
||||
return
|
||||
|
||||
def on_debugbtn_clicked(self,widget):
|
||||
"""Debug, do usunięcia w wersji stable, włącznie z kneflem w GUI"""
|
||||
if __debug__:
|
||||
print "\ndebug:"
|
||||
print "------"
|
||||
print "unsaved_project = %s" % self.model.unsaved_project
|
||||
print "filename = %s" % self.model.filename
|
||||
print "internal_filename = %s" % self.model.internal_filename
|
||||
print "db_connection = %s" % self.model.db_connection
|
||||
print "abort = %s" % self.model.abort
|
||||
|
||||
#####################
|
||||
# observed properetis
|
||||
def property_statusmsg_value_change(self, model, old, new):
|
||||
if self.statusbar_id != 0:
|
||||
self.view['mainStatus'].remove(self.context_id, self.statusbar_id)
|
||||
self.statusbar_id = self.view['mainStatus'].push(self.context_id, "%s" % new)
|
||||
return
|
||||
|
||||
def property_busy_value_change(self, model, old, new):
|
||||
if new != old:
|
||||
for w in self.widgets_all:
|
||||
self.view[w].set_sensitive(not new)
|
||||
for widget in self.widgets_cancel:
|
||||
self.view[widget].set_sensitive(new)
|
||||
if not new and self.scan_cd:
|
||||
self.scan_cd = False
|
||||
# umount/eject cd
|
||||
if self.model.config.confd['eject']:
|
||||
msg = deviceHelper.eject_cd(self.model.config.confd['ejectapp'],self.model.config.confd['cd'])
|
||||
if msg != 'ok':
|
||||
Dialogs.Wrn("error ejecting device - pyGTKtalog",
|
||||
"Cannot eject device pointed to %s" % self.model.config.confd['cd'],
|
||||
"Last eject message:\n%s" % msg)
|
||||
else:
|
||||
msg = deviceHelper.volumount(self.model.config.confd['cd'])
|
||||
if msg != 'ok':
|
||||
Dialogs.Wrn("error unmounting device - pyGTKtalog",
|
||||
"Cannot unmount device pointed to %s" % self.model.config.confd['cd'],
|
||||
"Last umount message:\n%s" % msg)
|
||||
return
|
||||
|
||||
def property_progress_value_change(self, model, old, new):
|
||||
self.view['progressbar1'].set_fraction(new)
|
||||
return
|
||||
|
||||
#########################
|
||||
# private class functions
|
||||
def __open(self):
|
||||
"""Open catalog file"""
|
||||
if self.model.unsaved_project and self.model.config.confd['confirmabandon']:
|
||||
obj = dialogs.Qst('Unsaved data - pyGTKtalog','There is not saved database','Pressing "Ok" will abandon catalog.')
|
||||
if not obj.run():
|
||||
return
|
||||
path = Dialogs.LoadDBFile().run()
|
||||
if path:
|
||||
if not self.model.open(path):
|
||||
Dialogs.Err("Error opening file - pyGTKtalog","Cannot open file %s." % self.opened_catalog)
|
||||
else:
|
||||
self.__activateUI(path)
|
||||
|
||||
def __save(self):
|
||||
"""Save catalog to file"""
|
||||
#{{{
|
||||
if self.model.filename:
|
||||
self.model.save()
|
||||
else:
|
||||
self.__save_as()
|
||||
pass
|
||||
|
||||
def __save_as(self):
|
||||
"""Save database to file under different filename."""
|
||||
path = Dialogs.ChooseDBFilename().show_dialog()
|
||||
if path:
|
||||
self.view['main'].set_title("%s - pyGTKtalog" % path)
|
||||
self.model.save(path)
|
||||
pass
|
||||
|
||||
def __addCD(self):
|
||||
"""Add directory structure from cd/dvd disc"""
|
||||
mount = deviceHelper.volmount(self.model.config.confd['cd'])
|
||||
if mount == 'ok':
|
||||
guessed_label = deviceHelper.volname(self.model.config.confd['cd'])
|
||||
label = Dialogs.InputDiskLabel(guessed_label).run()
|
||||
if label != None:
|
||||
self.scan_cd = True
|
||||
for widget in self.widgets_all:
|
||||
self.view[widget].set_sensitive(False)
|
||||
self.model.scan(self.model.config.confd['cd'],label)
|
||||
else:
|
||||
Dialogs.Wrn("Error mounting device - pyGTKtalog",
|
||||
"Cannot mount device pointed to %s" % self.model.config.confd['cd'],
|
||||
"Last mount message:\n%s" % mount)
|
||||
|
||||
def __doQuit(self):
|
||||
"""Quit and save window parameters to config file"""
|
||||
# check if any unsaved project is on go.
|
||||
if self.model.unsaved_project and self.model.config.confd['confirmquit']:
|
||||
if not Dialogs.Qst('Quit application - pyGTKtalog',
|
||||
'Do you really want to quit?',
|
||||
"Current database is not saved, any changes will be lost.").run():
|
||||
return
|
||||
|
||||
self.__storeSettings()
|
||||
self.model.cleanup()
|
||||
gtk.main_quit()
|
||||
return False
|
||||
|
||||
def __newDB(self):
|
||||
"""Create new database file"""
|
||||
if self.model.unsaved_project:
|
||||
if not Dialogs.Qst('Unsaved data - pyGTKtalog',
|
||||
"Current database isn't saved",
|
||||
'All changes will be lost. Do you really want to abandon it?').run():
|
||||
return
|
||||
self.model.new()
|
||||
|
||||
# clear "details" buffer
|
||||
txt = ""
|
||||
buf = self.view['details'].get_buffer()
|
||||
buf.set_text(txt)
|
||||
self.view['details'].set_buffer(buf)
|
||||
|
||||
self.__activateUI()
|
||||
|
||||
return
|
||||
|
||||
def __setup_disc_treeview(self):
|
||||
"""Setup TreeView discs widget as tree."""
|
||||
self.view['discs'].set_model(self.model.discsTree)
|
||||
|
||||
c = gtk.TreeViewColumn('Filename')
|
||||
|
||||
# one row contains image and text
|
||||
cellpb = gtk.CellRendererPixbuf()
|
||||
cell = gtk.CellRendererText()
|
||||
c.pack_start(cellpb, False)
|
||||
c.pack_start(cell, True)
|
||||
c.set_attributes(cellpb, stock_id=2)
|
||||
c.set_attributes(cell, text=1)
|
||||
|
||||
self.view['discs'].append_column(c)
|
||||
|
||||
# registration of treeview signals:
|
||||
|
||||
return
|
||||
|
||||
def __setup_files_treeview(self):
|
||||
"""Setup TreeView files widget, as columned list."""
|
||||
self.view['files'].set_model(self.model.filesList)
|
||||
|
||||
self.view['files'].get_selection().set_mode(gtk.SELECTION_MULTIPLE)
|
||||
|
||||
c = gtk.TreeViewColumn('Filename')
|
||||
cellpb = gtk.CellRendererPixbuf()
|
||||
cell = gtk.CellRendererText()
|
||||
c.pack_start(cellpb, False)
|
||||
c.pack_start(cell, True)
|
||||
c.set_attributes(cellpb, stock_id=6)
|
||||
c.set_attributes(cell, text=1)
|
||||
|
||||
c.set_sort_column_id(1)
|
||||
c.set_resizable(True)
|
||||
self.view['files'].append_column(c)
|
||||
|
||||
c = gtk.TreeViewColumn('Size',gtk.CellRendererText(), text=2)
|
||||
c.set_sort_column_id(2)
|
||||
c.set_resizable(True)
|
||||
self.view['files'].append_column(c)
|
||||
|
||||
c = gtk.TreeViewColumn('Date',gtk.CellRendererText(), text=3)
|
||||
c.set_sort_column_id(3)
|
||||
c.set_resizable(True)
|
||||
self.view['files'].append_column(c)
|
||||
|
||||
c = gtk.TreeViewColumn('Category',gtk.CellRendererText(), text=5)
|
||||
c.set_sort_column_id(5)
|
||||
c.set_resizable(True)
|
||||
self.view['files'].append_column(c)
|
||||
|
||||
# registration of treeview signals:
|
||||
|
||||
return
|
||||
|
||||
def __abort(self):
|
||||
"""When scanning thread is activated and user push the cancel button,
|
||||
models abort attribute trigger cancelation for scan operation"""
|
||||
self.model.abort = True
|
||||
return
|
||||
|
||||
def __activateUI(self, name='untitled'):
|
||||
"""Make UI active, and set title"""
|
||||
self.model.unsaved_project = False
|
||||
self.view['main'].set_title("%s - pyGTKtalog" % name)
|
||||
for widget in self.widgets:
|
||||
try:
|
||||
self.view[widget].set_sensitive(True)
|
||||
except:
|
||||
pass
|
||||
# PyGTK FAQ entry 23.20
|
||||
while gtk.events_pending():
|
||||
gtk.main_iteration()
|
||||
return
|
||||
|
||||
def __storeSettings(self):
|
||||
"""Store window size and pane position in config file (using config object from model)"""
|
||||
if self.model.config.confd['savewin']:
|
||||
self.model.config.confd['wx'], self.model.config.confd['wy'] = self.view['main'].get_size()
|
||||
if self.model.config.confd['savepan']:
|
||||
self.model.config.confd['h'],self.model.config.confd['v'] = self.view['hpaned1'].get_position(), self.view['vpaned1'].get_position()
|
||||
self.model.config.save()
|
||||
pass
|
||||
|
||||
pass # end of class
|
||||
0
src/models/__init__.py
Normal file
0
src/models/__init__.py
Normal file
155
src/models/m_config.py
Normal file
155
src/models/m_config.py
Normal file
@@ -0,0 +1,155 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
import utils._importer
|
||||
import utils.globals
|
||||
from gtkmvc import Model
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
import gtk
|
||||
import gobject
|
||||
|
||||
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 ConfigModel(Model):
|
||||
ini = Ini()
|
||||
|
||||
__properties__ = {}
|
||||
|
||||
confd = {
|
||||
'savewin' : True,
|
||||
'savepan' : True,
|
||||
'wx' : 800,
|
||||
'wy' : 600,
|
||||
'h' : 200,
|
||||
'v' : 300,
|
||||
'exportxls' : False,
|
||||
'cd' : '/cdrom',
|
||||
'ejectapp' : 'eject -r',
|
||||
'eject' : True,
|
||||
'pil': False,
|
||||
'gthumb':False,
|
||||
'exif':False,
|
||||
'confirmquit':True,
|
||||
'mntwarn':True,
|
||||
'confirmabandon':True,
|
||||
'showtoolbar':True,
|
||||
'showstatusbar':True,
|
||||
}
|
||||
|
||||
dictconf = {
|
||||
"save main window size" : "savewin",
|
||||
"save panes size" : "savepan",
|
||||
"main window width" : "wx",
|
||||
"main window height": "wy",
|
||||
"horizontal panes": "h",
|
||||
"vertical panes":"v",
|
||||
"export xls":"exportxls",
|
||||
"cd drive":"cd",
|
||||
"eject command":"ejectapp",
|
||||
"eject":"eject",
|
||||
"image support":"pil",
|
||||
'confirm quit':'confirmquit',
|
||||
'warn mount/umount errors':'mntwarn',
|
||||
'confirm abandon current catalog':'confirmabandon',
|
||||
'show toolbar':'showtoolbar',
|
||||
'show statusbar and progress bar':'showstatusbar',
|
||||
}
|
||||
|
||||
dbool = (
|
||||
'exportxls',
|
||||
'pil',
|
||||
'savewin',
|
||||
'savepan',
|
||||
'eject',
|
||||
'gthumb',
|
||||
'exif',
|
||||
'confirmquit',
|
||||
'mntwarn',
|
||||
'confirmabandon',
|
||||
'showtoolbar',
|
||||
'showstatusbar',
|
||||
)
|
||||
|
||||
dstring = ('cd','ejectapp')
|
||||
|
||||
try:
|
||||
path = os.environ['HOME']
|
||||
except:
|
||||
path = "/tmp"
|
||||
|
||||
def __init__(self):
|
||||
Model.__init__(self)
|
||||
self.category_tree = gtk.ListStore(gobject.TYPE_STRING)
|
||||
return
|
||||
|
||||
def save(self):
|
||||
try:
|
||||
os.lstat("%s/.pygtktalog" % self.path)
|
||||
except:
|
||||
if __debug__:
|
||||
print "Saving preferences to %s/.pygtktalog" % self.path
|
||||
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")
|
||||
success = True
|
||||
except:
|
||||
if __debug__:
|
||||
print "Cannot open config file %s for writing." % (self.path, "/.pygtktalog")
|
||||
success = False
|
||||
f.write(newIni.show())
|
||||
f.close()
|
||||
return success
|
||||
|
||||
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:
|
||||
if __debug__:
|
||||
print "failed to parse option:", opt
|
||||
pass
|
||||
except:
|
||||
if __debug__:
|
||||
print "load config file failed"
|
||||
pass
|
||||
|
||||
def __str__(self):
|
||||
"""show prefs in string way"""
|
||||
string = "[varname]\tvalue\n"
|
||||
for i in self.confd:
|
||||
string+="%s\t%s\n" % (i,self.confd[i])
|
||||
return string
|
||||
419
src/models/m_main.py
Normal file
419
src/models/m_main.py
Normal file
@@ -0,0 +1,419 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
|
||||
import utils._importer
|
||||
import utils.globals
|
||||
from gtkmvc.model_mt import ModelMT
|
||||
|
||||
try:
|
||||
import threading as _threading
|
||||
except ImportError:
|
||||
if __debug__:
|
||||
print "import exception: _threading"
|
||||
import dummy_threading as _threading
|
||||
|
||||
from pysqlite2 import dbapi2 as sqlite
|
||||
import datetime
|
||||
import mx.DateTime
|
||||
import os
|
||||
import sys
|
||||
import mimetypes
|
||||
import bz2
|
||||
|
||||
import gtk
|
||||
import gobject
|
||||
|
||||
from m_config import ConfigModel
|
||||
|
||||
class MainModel(ModelMT):
|
||||
"""Create, load, save, manipulate db file which is container for our data"""
|
||||
|
||||
__properties__ = {'busy': False, 'statusmsg': '', 'progress': 0}
|
||||
|
||||
config = ConfigModel()
|
||||
unsaved_project = False
|
||||
filename = None
|
||||
internal_filename = None
|
||||
db_connection = None
|
||||
db_cursor = None
|
||||
abort = False
|
||||
# Drzewo katalogów: id, nazwa
|
||||
discsTree = gtk.TreeStore(gobject.TYPE_INT, gobject.TYPE_STRING,str)
|
||||
# Lista plików wskazanego katalogu: child_id (?), filename, size, date, typ, ikonka
|
||||
filesList = gtk.ListStore(gobject.TYPE_INT, gobject.TYPE_STRING, gobject.TYPE_UINT64, gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING,str)
|
||||
|
||||
LAB = 0 # label/nazwa kolekcji --- najwyższy poziom drzewa przypiętego do korzenia
|
||||
DIR = 1 # katalog - podlega innemu katalogu lub lejbelu
|
||||
FIL = 2 # plik - podleka katalogu lub lejbelu
|
||||
|
||||
def __init__(self):
|
||||
ModelMT.__init__(self)
|
||||
self.config.load()
|
||||
return
|
||||
|
||||
def cleanup(self):
|
||||
self.__close_db_connection()
|
||||
if self.internal_filename != None:
|
||||
try:
|
||||
os.unlink(self.internal_filename)
|
||||
except:
|
||||
if __debug__:
|
||||
print "cleanup()", self.internal_filename
|
||||
pass
|
||||
try:
|
||||
os.unlink(self.internal_filename + '-journal')
|
||||
except:
|
||||
if __debug__:
|
||||
print "cleanup()", self.internal_filename+'-journal'
|
||||
pass
|
||||
return
|
||||
|
||||
def load(self):
|
||||
pass
|
||||
|
||||
def new(self):
|
||||
self.unsaved_project = False
|
||||
self.__create_internal_filename()
|
||||
self.__connect_to_db()
|
||||
self.__create_database()
|
||||
|
||||
try:
|
||||
self.discsTree.clear()
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
self.filesList.clear()
|
||||
except:
|
||||
pass
|
||||
|
||||
return
|
||||
|
||||
def save(self, filename=None):
|
||||
if filename:
|
||||
self.filename = filename
|
||||
self.__compress_and_save()
|
||||
return
|
||||
|
||||
def open(self, filename=None):
|
||||
"""try to open db file"""
|
||||
self.unsaved_project = False
|
||||
self.__create_internal_filename()
|
||||
self.filename = filename
|
||||
|
||||
source = bz2.BZ2File(filename, 'rb')
|
||||
destination = open(self.internal_filename, 'wb')
|
||||
while True:
|
||||
try:
|
||||
data = source.read(1024000)
|
||||
except:
|
||||
# smth went wrong
|
||||
if __debug__:
|
||||
print "something goes bad"
|
||||
self.filename = None
|
||||
self.internal_filename = None
|
||||
try:
|
||||
self.discsTree.clear()
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
self.filesList.clear()
|
||||
except:
|
||||
pass
|
||||
return False
|
||||
if not data: break
|
||||
destination.write(data)
|
||||
destination.close()
|
||||
source.close()
|
||||
|
||||
self.__connect_to_db()
|
||||
self.__fetch_db_into_treestore()
|
||||
|
||||
return True
|
||||
|
||||
def scan(self,path,label):
|
||||
"""scan files in separated thread"""
|
||||
|
||||
# flush buffer to release db lock.
|
||||
self.db_connection.commit()
|
||||
|
||||
self.path = path
|
||||
self.label = label
|
||||
|
||||
if self.busy:
|
||||
return
|
||||
self.thread = _threading.Thread(target=self.__scan)
|
||||
self.thread.start()
|
||||
return
|
||||
|
||||
def get_root_entries(self,id=None):
|
||||
try:
|
||||
self.filesList.clear()
|
||||
except:
|
||||
pass
|
||||
# parent for virtual '..' dir
|
||||
#myiter = self.filemodel.insert_before(None,None)
|
||||
#self.cur.execute("SELECT parent FROM files_connect WHERE child=? AND depth = 1",(id,))
|
||||
#self.filemodel.set_value(myiter,0,self.cur.fetchone()[0])
|
||||
#self.filemodel.set_value(myiter,1,'..')
|
||||
#if __debug__:
|
||||
# print datetime.datetime.fromtimestamp(ch[3])
|
||||
|
||||
# directories first
|
||||
self.db_cursor.execute("SELECT id, filename, size, date FROM files WHERE parent_id=? AND type=1 ORDER BY filename",(id,))
|
||||
data = self.db_cursor.fetchall()
|
||||
for ch in data:
|
||||
myiter = self.filesList.insert_before(None,None)
|
||||
self.filesList.set_value(myiter,0,ch[0])
|
||||
self.filesList.set_value(myiter,1,ch[1])
|
||||
self.filesList.set_value(myiter,2,ch[2])
|
||||
self.filesList.set_value(myiter,3,datetime.datetime.fromtimestamp(ch[3]))
|
||||
self.filesList.set_value(myiter,4,1)
|
||||
self.filesList.set_value(myiter,5,'direktorja')
|
||||
self.filesList.set_value(myiter,6,gtk.STOCK_DIRECTORY)
|
||||
|
||||
# all the rest
|
||||
self.db_cursor.execute("SELECT id, filename, size, date, type FROM files WHERE parent_id=? AND type!=1 ORDER BY filename",(id,))
|
||||
data = self.db_cursor.fetchall()
|
||||
for ch in data:
|
||||
myiter = self.filesList.insert_before(None,None)
|
||||
self.filesList.set_value(myiter,0,ch[0])
|
||||
self.filesList.set_value(myiter,1,ch[1])
|
||||
self.filesList.set_value(myiter,2,ch[2])
|
||||
self.filesList.set_value(myiter,3,datetime.datetime.fromtimestamp(ch[3]))
|
||||
self.filesList.set_value(myiter,4,ch[4])
|
||||
self.filesList.set_value(myiter,5,'kategoria srategoria')
|
||||
self.filesList.set_value(myiter,6,gtk.STOCK_FILE)
|
||||
#print datetime.datetime.fromtimestamp(ch[3])
|
||||
return
|
||||
|
||||
def get_file_info(self,id):
|
||||
"""get file info from database"""
|
||||
self.db_cursor.execute("SELECT filename, date, size, type FROM files WHERE id = ?",(id,))
|
||||
set = self.db_cursor.fetchone()
|
||||
if set == None:
|
||||
return ''
|
||||
|
||||
string = "Filename: %s\nDate: %s\nSize: %s\ntype: %s" % (set[0],datetime.datetime.fromtimestamp(set[1]),set[2],set[3])
|
||||
return string
|
||||
|
||||
# private class functions
|
||||
def __connect_to_db(self):
|
||||
self.db_connection = sqlite.connect("%s" % self.internal_filename, detect_types=sqlite.PARSE_DECLTYPES|sqlite.PARSE_COLNAMES)
|
||||
self.db_cursor = self.db_connection.cursor()
|
||||
return
|
||||
|
||||
def __close_db_connection(self):
|
||||
if self.db_cursor != None:
|
||||
self.db_cursor.close()
|
||||
self.db_cursor = None
|
||||
if self.db_connection != None:
|
||||
self.db_connection.close()
|
||||
self.db_connection = None
|
||||
return
|
||||
|
||||
def __create_internal_filename(self):
|
||||
self.cleanup()
|
||||
self.internal_filename = "/tmp/pygtktalog%d.db" % datetime.datetime.now().microsecond
|
||||
return
|
||||
|
||||
def __compress_and_save(self):
|
||||
source = open(self.internal_filename, 'rb')
|
||||
destination = bz2.BZ2File(self.filename, 'w')
|
||||
|
||||
while True:
|
||||
data = source.read(1024000)
|
||||
if not data: break
|
||||
destination.write(data)
|
||||
|
||||
destination.close()
|
||||
source.close()
|
||||
self.unsaved_project = False
|
||||
return
|
||||
|
||||
def __create_database(self):
|
||||
"""make all necessary tables in db file"""
|
||||
self.db_cursor.execute("""create table
|
||||
files(id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
parent_id INTEGER,
|
||||
filename TEXT,
|
||||
filepath TEXT,
|
||||
date datetime,
|
||||
size integer,
|
||||
type integer);""")
|
||||
self.db_cursor.execute("insert into files values(1, 1, 'root', null, 0, 0, 0);")
|
||||
|
||||
def __scan(self):
|
||||
"""scan content of the given path"""
|
||||
# TODO: Recursive data processing is damn slow! Think about different, faster solution
|
||||
self.busy = True
|
||||
|
||||
# jako, że to jest w osobnym wątku, a sqlite się przypieprza, że musi mieć
|
||||
# konekszyn dla tego samego wątku, więc robimy osobne połączenie dla tego zadania.
|
||||
db_connection = sqlite.connect("%s" % self.internal_filename,
|
||||
detect_types=sqlite.PARSE_DECLTYPES|sqlite.PARSE_COLNAMES,
|
||||
isolation_level="EXCLUSIVE")
|
||||
db_cursor = db_connection.cursor()
|
||||
|
||||
timestamp = datetime.datetime.now()
|
||||
|
||||
mime = mimetypes.MimeTypes()
|
||||
mov_ext = ('mkv','avi','ogg','mpg','wmv','mp4','mpeg')
|
||||
img_ext = ('jpg','jpeg','png','gif','bmp','tga','tif','tiff','ilbm','iff','pcx')
|
||||
|
||||
# count files in directory tree
|
||||
count = 0
|
||||
self.statusmsg = "Calculating number of files in directory tree..."
|
||||
|
||||
for root,kat,plik in os.walk(self.path):
|
||||
for p in plik:
|
||||
count+=1
|
||||
if count > 0:
|
||||
step = 1.0/count
|
||||
else:
|
||||
step = 1.0
|
||||
self.count = 0
|
||||
|
||||
# guess filesystem encoding
|
||||
self.fsenc = sys.getfilesystemencoding()
|
||||
|
||||
def __recurse(parent_id, name, path, date, size, filetype):
|
||||
"""recursive scans the path"""
|
||||
if self.abort:
|
||||
return -1
|
||||
|
||||
_size = size
|
||||
db_cursor.execute("insert into files(parent_id, filename, filepath, date, size, type) values(?,?,?,?,?,?)",
|
||||
(parent_id, name, path, date, size, filetype))
|
||||
db_cursor.execute("select seq FROM sqlite_sequence WHERE name='files'")
|
||||
currentid=db_cursor.fetchone()[0]
|
||||
root,dirs,files = os.walk(path).next()
|
||||
|
||||
for i in dirs:
|
||||
if self.fsenc:
|
||||
j = i.decode(self.fsenc)
|
||||
else:
|
||||
j = i
|
||||
try:
|
||||
st = os.stat(os.path.join(root,i))
|
||||
st_mtime = st.st_mtime
|
||||
except OSError:
|
||||
st_mtime = 0
|
||||
|
||||
dirsize = __recurse(currentid, j, os.path.join(path,i), st_mtime, 0, self.DIR)
|
||||
|
||||
if dirsize == -1:
|
||||
break
|
||||
else:
|
||||
_size = _size + dirsize
|
||||
|
||||
for i in files:
|
||||
if self.abort:
|
||||
break
|
||||
self.count = self.count + 1
|
||||
try:
|
||||
st = os.stat(os.path.join(root,i))
|
||||
st_mtime = st.st_mtime
|
||||
st_size = st.st_size
|
||||
except OSError:
|
||||
st_mtime = 0
|
||||
st_size = 0
|
||||
|
||||
### scan files
|
||||
# if i[-3:].lower() in mov_ext or \
|
||||
# mime.guess_type(i)!= (None,None) and \
|
||||
# mime.guess_type(i)[0].split("/")[0] == 'video':
|
||||
# # video only
|
||||
# info = filetypeHelper.guess_video(os.path.join(root,i))
|
||||
# elif i[-3:].lower() in img_ext or \
|
||||
# mime.guess_type(i)!= (None,None) and \
|
||||
# mime.guess_type(i)[0].split("/")[0] == 'image':
|
||||
# pass
|
||||
### end of scan
|
||||
|
||||
### progress/status
|
||||
# if wobj.sbid != 0:
|
||||
# wobj.status.remove(wobj.sbSearchCId, wobj.sbid)
|
||||
if self.count % 32 == 0:
|
||||
self.statusmsg = "Scannig: %s" % (os.path.join(root,i))
|
||||
self.progress = step * self.count
|
||||
# # PyGTK FAQ entry 23.20
|
||||
# while gtk.events_pending(): gtk.main_iteration()
|
||||
|
||||
_size = _size + st_size
|
||||
j = i
|
||||
if self.fsenc:
|
||||
j = i.decode(self.fsenc)
|
||||
db_cursor.execute("insert into files(parent_id, filename, filepath, date, size, type) values(?,?,?,?,?,?)",
|
||||
(currentid, j, os.path.join(path,i), st_mtime, st_size, self.FIL))
|
||||
|
||||
db_cursor.execute("update files set size=? where id=?",(_size, currentid))
|
||||
if self.abort:
|
||||
return -1
|
||||
else:
|
||||
return _size
|
||||
|
||||
if __recurse(1, self.label, self.path, 0, 0, self.DIR) == -1:
|
||||
if __debug__:
|
||||
print "__scan: __recurse returns -1"
|
||||
db_cursor.close()
|
||||
db_connection.rollback()
|
||||
else:
|
||||
if __debug__:
|
||||
print "__scan: __recurse returns something else"
|
||||
db_cursor.close()
|
||||
db_connection.commit()
|
||||
self.__fetch_db_into_treestore()
|
||||
db_connection.close()
|
||||
|
||||
if __debug__:
|
||||
print "scan time: ", (datetime.datetime.now() - timestamp)
|
||||
|
||||
self.unsaved_project = True
|
||||
self.busy = False
|
||||
|
||||
self.statusmsg = "Idle"
|
||||
self.progress = 0
|
||||
self.abort = False
|
||||
|
||||
def __fetch_db_into_treestore(self):
|
||||
"""load data from DB to tree model"""
|
||||
# cleanup treeStore
|
||||
self.discsTree.clear()
|
||||
|
||||
#connect
|
||||
db_connection = sqlite.connect("%s" % self.internal_filename,
|
||||
detect_types=sqlite.PARSE_DECLTYPES|sqlite.PARSE_COLNAMES)
|
||||
db_cursor = db_connection.cursor()
|
||||
|
||||
# fetch all the directories
|
||||
db_cursor.execute("SELECT id, parent_id, filename FROM files WHERE type=1 ORDER BY parent_id, filename")
|
||||
data = db_cursor.fetchall()
|
||||
print data
|
||||
|
||||
def get_children(parent_id = 1, iterator = None):
|
||||
"""fetch all children and place them in model"""
|
||||
for row in data:
|
||||
if row[1] == parent_id:
|
||||
myiter = self.discsTree.insert_before(iterator,None)
|
||||
self.discsTree.set_value(myiter,0,row[0])
|
||||
self.discsTree.set_value(myiter,1,row[2])
|
||||
get_children(row[0], myiter)
|
||||
|
||||
# isroot?
|
||||
if iterator == None:
|
||||
self.discsTree.set_value(myiter,2,gtk.STOCK_CDROM)
|
||||
else:
|
||||
self.discsTree.set_value(myiter,2,gtk.STOCK_DIRECTORY)
|
||||
return
|
||||
|
||||
if __debug__:
|
||||
start_date = datetime.datetime.now()
|
||||
# launch scanning.
|
||||
get_children()
|
||||
if __debug__:
|
||||
print "tree generation time: ", (datetime.datetime.now() - start_date)
|
||||
db_connection.close()
|
||||
return
|
||||
|
||||
pass # end of class
|
||||
3
src/utils/__init__.py
Normal file
3
src/utils/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
__all__ = ["globals", "_importer"]
|
||||
44
src/utils/_importer.py
Normal file
44
src/utils/_importer.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# Author: Roberto Cavada <cavada@irst.itc.it>
|
||||
#
|
||||
# Copyright (c) 2006 by Roberto Cavada
|
||||
#
|
||||
# pygtkmvc is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# pygtkmvc 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
||||
#
|
||||
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
|
||||
# or email to the author <cavada@irst.itc.it>.
|
||||
# Please report bugs to <cavada@irst.itc.it>.
|
||||
|
||||
|
||||
|
||||
# ======================================================================
|
||||
# This module is used only as a utility to import gtkmvc when not
|
||||
# installed.
|
||||
|
||||
import utils.globals
|
||||
|
||||
if __name__ != "__main__":
|
||||
try: import gtkmvc
|
||||
except:
|
||||
import os.path; import sys
|
||||
|
||||
rel_path = os.path.join(utils.globals.TOP_DIR, "..")
|
||||
top_dir = os.path.dirname(os.path.abspath(rel_path))
|
||||
sys.path = [top_dir] + sys.path
|
||||
import gtkmvc
|
||||
pass
|
||||
|
||||
gtkmvc.require("1.0.0")
|
||||
pass
|
||||
|
||||
84
src/utils/deviceHelper.py
Normal file
84
src/utils/deviceHelper.py
Normal file
@@ -0,0 +1,84 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
"""
|
||||
device (cd, dvd) helper
|
||||
"""
|
||||
|
||||
import string
|
||||
import os
|
||||
import popen2
|
||||
|
||||
def volname(mntp):
|
||||
"""read volume name from cd/dvd"""
|
||||
dev = mountpoint_to_dev(mntp)
|
||||
if dev != None:
|
||||
try:
|
||||
a = open(dev,"rb")
|
||||
a.seek(32808)
|
||||
b = a.read(32).strip()
|
||||
a.close()
|
||||
except:
|
||||
return None
|
||||
return b
|
||||
return None
|
||||
|
||||
def volmount(mntp):
|
||||
"""mount device, return True/False"""
|
||||
_in,_out,_err = popen2.popen3("mount %s" % mntp)
|
||||
inf = _err.readlines()
|
||||
if len(inf) > 0:
|
||||
for i in inf:
|
||||
i.strip()
|
||||
return i
|
||||
else:
|
||||
return 'ok'
|
||||
|
||||
def volumount(mntp):
|
||||
"""mount device, return True/False"""
|
||||
_in,_out,_err = popen2.popen3("umount %s" % mntp)
|
||||
inf = _err.readlines()
|
||||
if len(inf) > 0:
|
||||
for error in inf:
|
||||
error.strip()
|
||||
|
||||
if error.strip()[:7] == 'umount:':
|
||||
return error.strip()
|
||||
return 'ok'
|
||||
|
||||
def check_mount(dev):
|
||||
"""Refresh the entries from fstab or mount."""
|
||||
mounts = os.popen('mount')
|
||||
for line in mounts.readlines():
|
||||
parts = line.split()
|
||||
device, txt1, mount_point, txt2, filesystem, options = parts
|
||||
if device == dev:
|
||||
return True
|
||||
return False
|
||||
|
||||
def mountpoint_to_dev(mntp):
|
||||
"""guess mountpoint from fstab"""
|
||||
fstab = open("/etc/fstab")
|
||||
for line in fstab.readlines():
|
||||
a = line.split()
|
||||
try:
|
||||
if a[1] == mntp and a[0][0] != '#':
|
||||
fstab.close()
|
||||
return a[0]
|
||||
except:
|
||||
pass
|
||||
fstab.close()
|
||||
return None
|
||||
|
||||
def eject_cd(eject_app,cd):
|
||||
"""mount device, return True/False"""
|
||||
if len(eject_app) > 0:
|
||||
_in,_out,_err = popen2.popen3("%s %s" %(eject_app,cd))
|
||||
inf = _err.readlines()
|
||||
error = ''
|
||||
for error in inf:
|
||||
error.strip()
|
||||
|
||||
if error.strip()[:6] == 'eject:':
|
||||
return error.strip()
|
||||
else:
|
||||
return 'ok'
|
||||
return "Mount point does'nt exist in fstab"
|
||||
33
src/utils/globals.py
Normal file
33
src/utils/globals.py
Normal file
@@ -0,0 +1,33 @@
|
||||
# Author: Roberto Cavada <cavada@irst.itc.it>
|
||||
#
|
||||
# Copyright (c) 2006 by Roberto Cavada
|
||||
#
|
||||
# pygtkmvc is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# pygtkmvc 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
||||
#
|
||||
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
|
||||
# or email to the author <cavada@irst.itc.it>.
|
||||
# Please report bugs to <cavada@irst.itc.it>.
|
||||
|
||||
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
if sys.argv[0]: top_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
||||
else: top_dir = "."
|
||||
|
||||
|
||||
# A set of global vars
|
||||
TOP_DIR = top_dir
|
||||
GLADE_DIR = os.path.join(TOP_DIR, "glade")
|
||||
0
src/views/__init__.py
Normal file
0
src/views/__init__.py
Normal file
14
src/views/v_config.py
Normal file
14
src/views/v_config.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
|
||||
import utils._importer
|
||||
import utils.globals
|
||||
from gtkmvc import View
|
||||
import os.path
|
||||
|
||||
class ConfigView(View):
|
||||
"""Preferences window from glade file """
|
||||
GLADE = os.path.join(utils.globals.GLADE_DIR, "config.glade")
|
||||
def __init__(self, ctrl):
|
||||
View.__init__(self, ctrl, self.GLADE)
|
||||
return
|
||||
pass # end of class
|
||||
257
src/views/v_dialogs.py
Normal file
257
src/views/v_dialogs.py
Normal file
@@ -0,0 +1,257 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
|
||||
import gtk
|
||||
import os
|
||||
|
||||
class Qst(object):
|
||||
"""Show simple dialog for questions
|
||||
if "OK" button pressed, return "True"
|
||||
"Cancel" button return "False"
|
||||
"""
|
||||
def __init__(self, title="", message="", secondarymsg=""):
|
||||
self.dialog = gtk.MessageDialog(
|
||||
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||
type = gtk.MESSAGE_QUESTION,
|
||||
buttons = gtk.BUTTONS_OK_CANCEL,
|
||||
message_format = message,
|
||||
)
|
||||
self.dialog.set_title(title)
|
||||
self.dialog.format_secondary_text(secondarymsg)
|
||||
def run(self):
|
||||
retval = self.dialog.run()
|
||||
self.dialog.destroy()
|
||||
if retval == gtk.RESPONSE_OK:
|
||||
return True
|
||||
return False
|
||||
|
||||
class Inf(object):
|
||||
"""Show simple dialog for notices"""
|
||||
def __init__(self, title="", message="", secondarymsg=""):
|
||||
self.dialog = gtk.MessageDialog(
|
||||
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||
type = gtk.MESSAGE_INFO,
|
||||
buttons = gtk.BUTTONS_OK,
|
||||
message_format = message,
|
||||
)
|
||||
self.dialog.set_title(title)
|
||||
self.dialog.format_secondary_text(secondarymsg)
|
||||
self.dialog.connect('response', lambda dialog, response: self.ret(response))
|
||||
self.dialog.show()
|
||||
def ret(self,result):
|
||||
self.dialog.destroy()
|
||||
return True
|
||||
|
||||
class Wrn(object):
|
||||
"""Show simple dialog for warnings"""
|
||||
def __init__(self, title="", message="", secondarymsg=""):
|
||||
self.dialog = gtk.MessageDialog(
|
||||
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||
type = gtk.MESSAGE_WARNING,
|
||||
buttons = gtk.BUTTONS_CLOSE,
|
||||
message_format = message,
|
||||
)
|
||||
self.dialog.set_title(title)
|
||||
self.dialog.format_secondary_text(secondarymsg)
|
||||
self.dialog.connect('response', lambda dialog, response: self.ret(response))
|
||||
self.dialog.show()
|
||||
def ret(self,result):
|
||||
self.dialog.destroy()
|
||||
return True
|
||||
|
||||
class Err(object):
|
||||
"""Show simple dialog for errors"""
|
||||
def __init__(self, title="", message="", secondarymsg=""):
|
||||
self.dialog = gtk.MessageDialog(
|
||||
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||
type = gtk.MESSAGE_ERROR,
|
||||
buttons = gtk.BUTTONS_CLOSE,
|
||||
message_format = message,
|
||||
)
|
||||
self.dialog.set_title(title)
|
||||
self.dialog.format_secondary_text(secondarymsg)
|
||||
self.dialog.connect('response', lambda dialog, response: self.ret(response))
|
||||
self.dialog.run()
|
||||
def ret(self,result):
|
||||
self.dialog.destroy()
|
||||
return True
|
||||
|
||||
class Abt(object):
|
||||
"""Show simple about dialog"""
|
||||
#{{{
|
||||
def __init__(self, name=None, ver="", title="", authors=[],licence=""):
|
||||
self.dialog = gtk.AboutDialog()
|
||||
self.dialog.set_title(title)
|
||||
self.dialog.set_version(ver)
|
||||
self.dialog.set_license(licence)
|
||||
self.dialog.set_name(name)
|
||||
self.dialog.set_authors(authors)
|
||||
self.dialog.connect('response', lambda dialog, response: self.dialog.destroy())
|
||||
self.dialog.show()
|
||||
#}}}
|
||||
|
||||
class InputDiskLabel(object):
|
||||
"""Sepcific dialog for quering user for a disc label"""
|
||||
def __init__(self, label=""):
|
||||
self.gladefile = "glade/dialogs.glade"
|
||||
self.label = ""
|
||||
if label!= None:
|
||||
self.label = label
|
||||
|
||||
def run(self):
|
||||
gladexml = gtk.glade.XML(self.gladefile, "inputDialog")
|
||||
dialog = gladexml.get_widget("inputDialog")
|
||||
entry = gladexml.get_widget("volname")
|
||||
entry.set_text(self.label)
|
||||
result = dialog.run()
|
||||
dialog.destroy()
|
||||
if result == gtk.RESPONSE_OK:
|
||||
return entry.get_text()
|
||||
return None
|
||||
|
||||
class PointDirectoryToAdd(object):
|
||||
"""Sepcific dialog for quering user for selecting directory to add"""
|
||||
def __init__(self,volname='',dirname=''):
|
||||
self.gladefile = "glade/dialogs.glade"
|
||||
self.gladexml = gtk.glade.XML(self.gladefile, "addDirDialog")
|
||||
self.volname = self.gladexml.get_widget("dirvolname")
|
||||
self.volname.set_text(volname)
|
||||
self.directory = self.gladexml.get_widget("directory")
|
||||
self.directory.set_text(dirname)
|
||||
self.gladexml.signal_autoconnect({"on_browse_activate":self.show_dirchooser,"on_browse_clicked":self.show_dirchooser})
|
||||
|
||||
def show_dirchooser(self,widget):
|
||||
"""dialog for point the mountpoint"""
|
||||
dialog = gtk.FileChooserDialog(
|
||||
title="Choose directory to add",
|
||||
action=gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||
buttons=(
|
||||
gtk.STOCK_CANCEL,
|
||||
gtk.RESPONSE_CANCEL,
|
||||
gtk.STOCK_OPEN,
|
||||
gtk.RESPONSE_OK
|
||||
)
|
||||
)
|
||||
|
||||
dialog.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
||||
dialog.set_default_response(gtk.RESPONSE_OK)
|
||||
|
||||
response = dialog.run()
|
||||
if response == gtk.RESPONSE_OK:
|
||||
self.directory.set_text(dialog.get_filename())
|
||||
dialog.destroy()
|
||||
|
||||
def run(self):
|
||||
dialog = self.gladexml.get_widget("addDirDialog")
|
||||
ch = True
|
||||
result = dialog.run()
|
||||
while ch:
|
||||
if result == gtk.RESPONSE_OK and (self.volname.get_text()=='' or self.directory.get_text() == ''):
|
||||
a = Err("Error - pyGTKtalog","There are fields needed to be filled.","Cannot add directory without path and disc label.")
|
||||
ch = True
|
||||
result = dialog.run()
|
||||
else:
|
||||
ch = False
|
||||
dialog.destroy()
|
||||
if result == gtk.RESPONSE_OK:
|
||||
return self.volname.get_text(),self.directory.get_text()
|
||||
else:
|
||||
return None,None
|
||||
|
||||
class ChooseDBFilename(object):
|
||||
"""Sepcific dialog for quering user for selecting filename for database"""
|
||||
def __init__(self):
|
||||
self.dialog = gtk.FileChooserDialog(
|
||||
title="Save catalog as...",
|
||||
action=gtk.FILE_CHOOSER_ACTION_SAVE,
|
||||
buttons=(
|
||||
gtk.STOCK_CANCEL,
|
||||
gtk.RESPONSE_CANCEL,
|
||||
gtk.STOCK_SAVE,
|
||||
gtk.RESPONSE_OK
|
||||
)
|
||||
)
|
||||
|
||||
self.dialog.set_action(gtk.FILE_CHOOSER_ACTION_SAVE)
|
||||
self.dialog.set_default_response(gtk.RESPONSE_OK)
|
||||
self.dialog.set_do_overwrite_confirmation(True)
|
||||
self.dialog.set_title('Save catalog to file...')
|
||||
|
||||
f = gtk.FileFilter()
|
||||
f.set_name("Catalog files")
|
||||
f.add_pattern("*.pgt")
|
||||
self.dialog.add_filter(f)
|
||||
f = gtk.FileFilter()
|
||||
f.set_name("All files")
|
||||
f.add_pattern("*.*")
|
||||
self.dialog.add_filter(f)
|
||||
|
||||
def show_dialog(self):
|
||||
response = self.dialog.run()
|
||||
if response == gtk.RESPONSE_OK:
|
||||
filename = self.dialog.get_filename()
|
||||
if filename[-4] == '.':
|
||||
if filename[-3:].lower() != 'pgt':
|
||||
filename = filename + '.pgt'
|
||||
else:
|
||||
filename = filename[:-3] + 'pgt'
|
||||
else:
|
||||
filename = filename + '.pgt'
|
||||
self.dialog.destroy()
|
||||
return filename
|
||||
else:
|
||||
self.dialog.destroy()
|
||||
return None
|
||||
pass
|
||||
class LoadDBFile(object):
|
||||
"""Specific class for displaying openFile dialog. It has veryfication for file existence."""
|
||||
def __init__(self):
|
||||
self.dialog = gtk.FileChooserDialog(
|
||||
title="Open catalog",
|
||||
action=gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||
buttons=(
|
||||
gtk.STOCK_CANCEL,
|
||||
gtk.RESPONSE_CANCEL,
|
||||
gtk.STOCK_OPEN,
|
||||
gtk.RESPONSE_OK
|
||||
)
|
||||
)
|
||||
|
||||
self.dialog.set_default_response(gtk.RESPONSE_OK)
|
||||
|
||||
f = gtk.FileFilter()
|
||||
f.set_name("Catalog files")
|
||||
f.add_pattern("*.pgt")
|
||||
self.dialog.add_filter(f)
|
||||
f = gtk.FileFilter()
|
||||
f.set_name("All files")
|
||||
f.add_pattern("*.*")
|
||||
self.dialog.add_filter(f)
|
||||
|
||||
def show_dialog(self):
|
||||
response = self.dialog.run()
|
||||
filename = None
|
||||
if response == gtk.RESPONSE_OK:
|
||||
try:
|
||||
filename = self.dialog.get_filename()
|
||||
except:
|
||||
pass
|
||||
#self.dialog.destroy()
|
||||
return 'ok',filename
|
||||
else:
|
||||
return 'cancel',None
|
||||
|
||||
def run(self):
|
||||
res,filename = self.show_dialog()
|
||||
ch = True
|
||||
while ch:
|
||||
if res == 'cancel':
|
||||
self.dialog.destroy()
|
||||
return None
|
||||
try:
|
||||
os.stat(filename)
|
||||
self.dialog.destroy()
|
||||
return filename
|
||||
except:
|
||||
a = Err("Error - pyGTKtalog","File doesn't exist.","The file that you choose does not exist. Choose another one, or cancel operation.")
|
||||
ch = True
|
||||
res,filename = self.show_dialog()
|
||||
17
src/views/v_main.py
Normal file
17
src/views/v_main.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
|
||||
import utils._importer
|
||||
import utils.globals
|
||||
from gtkmvc import View
|
||||
import os.path
|
||||
|
||||
class MainView(View):
|
||||
"""This handles only the graphical representation of the
|
||||
application. The widgets set is loaded from glade file"""
|
||||
|
||||
GLADE = os.path.join(utils.globals.GLADE_DIR, "main.glade")
|
||||
def __init__(self, ctrl):
|
||||
View.__init__(self, ctrl, self.GLADE)
|
||||
return
|
||||
|
||||
pass # end of class
|
||||
Reference in New Issue
Block a user