mirror of
https://github.com/gryf/pygtktalog.git
synced 2025-12-17 11:30:19 +01:00
* Refactored code in configuration and main controllers.
This commit is contained in:
@@ -2,8 +2,7 @@
|
||||
import utils._importer
|
||||
import utils.globals
|
||||
from gtkmvc import Controller
|
||||
from models.m_config import ConfigModel
|
||||
import views.v_dialogs as Dialogs
|
||||
|
||||
import gtk
|
||||
|
||||
class ConfigController(Controller):
|
||||
@@ -11,20 +10,139 @@ class ConfigController(Controller):
|
||||
category_order = ['General','Disk options','Scan options']
|
||||
|
||||
def __init__(self, model):
|
||||
self.conf = ConfigModel()
|
||||
self.conf.load()
|
||||
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:
|
||||
# Obserwowalne właściwości
|
||||
# funkcje obsługi formularza
|
||||
pass # end of class
|
||||
|
||||
#################
|
||||
# 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
|
||||
|
||||
@@ -9,20 +9,28 @@ http://www.gnu.org/licenses/gpl.txt
|
||||
|
||||
import utils._importer
|
||||
import utils.globals
|
||||
from utils import deviceHelper
|
||||
from gtkmvc import Controller
|
||||
|
||||
from controllers.c_config import ConfigController
|
||||
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"""
|
||||
db_tmp_filename = None
|
||||
unsaved_project = False
|
||||
|
||||
scan_cd = False
|
||||
widgets = (
|
||||
"discs","files","details",'save1','save_as1','cut1','copy1','paste1',
|
||||
'delete1','add_cd','add_directory1','tb_save','tb_addcd','tb_find'
|
||||
)
|
||||
def __init__(self, model):
|
||||
Controller.__init__(self, model)
|
||||
return
|
||||
@@ -31,11 +39,7 @@ class MainController(Controller):
|
||||
Controller.register_view(self, view)
|
||||
|
||||
# deaktywuj na starcie te oto widżety
|
||||
widgets = (
|
||||
"discs","files","details",'save1','save_as1','cut1','copy1','paste1',
|
||||
'delete1','add_cd','add_directory1','tb_save','tb_addcd','tb_find'
|
||||
)
|
||||
for widget in widgets:
|
||||
for widget in self.widgets:
|
||||
self.view[widget].set_sensitive(False)
|
||||
|
||||
# ustaw domyślne właściwości dla poszczególnych widżetów
|
||||
@@ -61,8 +65,8 @@ class MainController(Controller):
|
||||
self.view['main'].resize(self.model.config.confd['wx'],self.model.config.confd['wy'])
|
||||
|
||||
# zainicjalizuj statusbar
|
||||
ContextID = self.view['mainStatus'].get_context_id('detailed res')
|
||||
StatusbarID = self.view['mainStatus'].push(ContextID, "Idle")
|
||||
self.context_id = self.view['mainStatus'].get_context_id('detailed res')
|
||||
self.statusbar_id = self.view['mainStatus'].push(self.context_id, "Idle")
|
||||
|
||||
# pokaż główne okno
|
||||
self.view['main'].show();
|
||||
@@ -70,45 +74,54 @@ class MainController(Controller):
|
||||
|
||||
# Podłącz sygnały:
|
||||
def on_main_destroy_event(self, window, event):
|
||||
self.doQuit()
|
||||
self.__doQuit()
|
||||
return True
|
||||
|
||||
def on_tb_quit_clicked(self,widget):
|
||||
self.doQuit()
|
||||
self.__doQuit()
|
||||
|
||||
def on_quit1_activate(self,widget):
|
||||
self.doQuit()
|
||||
self.__doQuit()
|
||||
|
||||
def on_new1_activate(self,widget):
|
||||
self.newDB()
|
||||
self.__newDB()
|
||||
|
||||
def on_tb_new_clicked(self,widget):
|
||||
self.newDB()
|
||||
self.__newDB()
|
||||
|
||||
def on_add_cd_activate(self,widget):
|
||||
self.addCD()
|
||||
self.__addCD()
|
||||
|
||||
def on_tb_addcd_clicked(self,widget):
|
||||
self.addCD()
|
||||
self.__addCD()
|
||||
|
||||
def on_add_directory1_activate(self,widget):
|
||||
self.addDirectory()
|
||||
self.__addDirectory()
|
||||
|
||||
def on_about1_activate(self,widget):
|
||||
Dialogs.Abt("pyGTKtalog", __version__, "About", ["Roman 'gryf' Dobosz"], licence)
|
||||
return
|
||||
|
||||
def on_preferences_activate(self,widget):
|
||||
print 'aaa'
|
||||
c = ConfigController(self.model.config)
|
||||
v = ConfigView(c)
|
||||
return
|
||||
|
||||
def on_status_bar1_activate(self,widget):
|
||||
self.toggle_status_bar()
|
||||
"""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):
|
||||
self.toggle_toolbar()
|
||||
"""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()
|
||||
@@ -141,23 +154,6 @@ class MainController(Controller):
|
||||
|
||||
|
||||
# funkcje do obsługi formularza
|
||||
def doQuit(self):
|
||||
"""quit and save window parameters to config file"""
|
||||
#{{{
|
||||
# check if any unsaved project is on go.
|
||||
if self.unsaved_project:
|
||||
if self.model.config.confd['confirmquit']:
|
||||
obj = Dialogs.Qst('Quit application - pyGTKtalog','There is not saved database\nDo you really want to quit?')
|
||||
if not obj.run():
|
||||
return
|
||||
|
||||
self.storeSettings()
|
||||
gtk.main_quit()
|
||||
try:
|
||||
os.unlink(self.db_tmp_filename)
|
||||
except:
|
||||
pass
|
||||
return False
|
||||
|
||||
def storeSettings(self):
|
||||
"""Store window size and pane position in config file (using config object)"""
|
||||
@@ -168,20 +164,18 @@ class MainController(Controller):
|
||||
self.model.config.save()
|
||||
pass
|
||||
|
||||
def newDB(self):
|
||||
pass
|
||||
|
||||
def addCD(self):
|
||||
pass
|
||||
|
||||
def addDirectory(self):
|
||||
pass
|
||||
|
||||
def toggle_toolbar(self):
|
||||
pass
|
||||
|
||||
def toggle_status_bar(self):
|
||||
pass
|
||||
def __addCD(self):
|
||||
"""add directory structure from cd/dvd disc"""
|
||||
self.scan_cd = True
|
||||
mount = deviceHelper.volmount(self.model.config.confd['cd'])
|
||||
if mount == 'ok':
|
||||
guessed_label = deviceHelper.volname(self.model.config.confd['cd'])
|
||||
obj = Dialogs.InputDiskLabel(guessed_label)
|
||||
label = obj.run()
|
||||
if label != None:
|
||||
self.model.scan(self.model.config.confd['cd'],label)
|
||||
else:
|
||||
Dialogs.Wrn("error mounting device - pyGTKtalog","Cannot mount device pointed to %s.\nLast mount message:\n<tt>%s</tt>" % (self.model.config.confd['cd'],mount))
|
||||
|
||||
def save(self):
|
||||
pass
|
||||
@@ -204,4 +198,71 @@ class MainController(Controller):
|
||||
def change_view(self):
|
||||
pass
|
||||
|
||||
#####################
|
||||
# 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:
|
||||
self.view[w].set_sensitive(not 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.\nLast eject message:\n<tt>%s</tt>" % (self.model.config.confd['cd'],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.\nLast umount message:\n<tt>%s</tt>" % (self.model.config.confd['cd'],msg))
|
||||
return
|
||||
|
||||
def property_progress_value_change(self, model, old, new):
|
||||
self.view['progressbar1'].set_fraction(new)
|
||||
return
|
||||
|
||||
#########################
|
||||
# private class functions
|
||||
def __addDirectory(self):
|
||||
"""add directory structure from given location"""
|
||||
res = Dialogs.PointDirectoryToAdd().run()
|
||||
if res !=(None,None):
|
||||
self.model.scan(res[1],res[0])
|
||||
return
|
||||
|
||||
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','Current database is not saved\nDo you really want to quit?').run():
|
||||
return
|
||||
|
||||
self.storeSettings()
|
||||
self.model.cleanup()
|
||||
gtk.main_quit()
|
||||
return False
|
||||
|
||||
def __newDB(self):
|
||||
if self.model.modified:
|
||||
if not Dialogs.Qst('Unsaved data - pyGTKtalog','Current database is not saved\nDo you really want to abandon it?').run():
|
||||
return
|
||||
self.model.new()
|
||||
self.model.unsaved_project = True
|
||||
self.view['main'].set_title("untitled - pyGTKtalog")
|
||||
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
|
||||
|
||||
pass # end of class
|
||||
|
||||
Reference in New Issue
Block a user