comparison Gtk/importFiebdc.py @ 4:4e976a99efb9

update ImportPriceDatabase
author Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
date Sun, 31 Oct 2010 23:12:06 +0100
parents 2ac1551ad2ab
children 6502bfdaa84d
comparison
equal deleted inserted replaced
3:a221c14c3c31 4:4e976a99efb9
28 import gtk 28 import gtk
29 import gobject 29 import gobject
30 import threading 30 import threading
31 gobject.threads_init() 31 gobject.threads_init()
32 32
33 # pyArq-Presupuestos Modules
33 from Generic import utils 34 from Generic import utils
34 from Generic import globals 35 from Generic import globals
36 from Generic import durusdatabase
35 import gui 37 import gui
36 38
37 class FileSelectionWindow(object): 39 class FileSelectionWindow(object):
38 """importFiebdc.FileSelectionWindow: 40 """importFiebdc.FileSelectionWindow:
39 41
40 Description: 42 Description:
41 Class to show the selection file window 43 Class to show the selection file window
42 Constructor: 44 Constructor:
43 importFiebdc.FileSelectionWindow(mainWindow, readFileMethod, 45 importFiebdc.FileSelectionWindow(mainWindow, readFileMethod, budget,
44 budget, arg_List, cancelMethod) 46 filename, cancelMethod, filetype)
45 Ancestry: 47 Ancestry:
46 +-- object 48 +-- object
47 +-- FileSelectionWindow 49 +-- FileSelectionWindow
48 Atributes: 50 Atributes:
49 "__mainWindow": gui.MainWindow object 51 "__mainWindow": gui.MainWindow object
50 "__readFileMethod": Method to read the selected file 52 "__readFileMethod": Method to read the selected file
51 "__budget": Budget object 53 "__budget": Budget object
52 "__filename": "file" 54 "__filename": "file"
55 "__filetype": "budget" or "database"
53 "__cancelMethod": Method to cancel the read method 56 "__cancelMethod": Method to cancel the read method
54 "__file": The selected file 57 "__file": The selected file
55 "__window": The selection file window 58 "__window": The selection file window
56 Methods: 59 Methods:
57 __init__(self, mainWindow, readFileMethod, budget 60 __init__(self, mainWindow, readFileMethod, budget
62 _openFile(self, w) 65 _openFile(self, w)
63 _openFile2(Self, filename) 66 _openFile2(Self, filename)
64 """ 67 """
65 68
66 def __init__(self, mainWindow, readFileMethod, budget, filename, 69 def __init__(self, mainWindow, readFileMethod, budget, filename,
67 cancelMethod): 70 cancelMethod, filetype):
68 """def __init__(self, mainWindow, readFileMethod, budget, 71 """def __init__(self, mainWindow, readFileMethod, budget,
69 filename, cancelMethod) 72 filename, cancelMethod, filetype)
70 73
71 mainWindow: gui.MainWindow object 74 mainWindow: gui.MainWindow object
72 readFileMethod: Method to read the selected file 75 readFileMethod: Method to read the selected file
73 budget: base.Budget object 76 budget: base.Budget object
74 filename: "file" 77 filename: "file"
75 cancelMethod: Method to cancel the read method 78 cancelMethod: Method to cancel the read method
79 fileytpe: "budget" or "database"
76 Sets the init atributes, creates the file selection window 80 Sets the init atributes, creates the file selection window
77 Connects the events: 81 Connects the events:
78 * clicked ok button: _openFile 82 * clicked ok button: _openFile
79 * clicked cancel button: destroy window 83 * clicked cancel button: destroy window
80 * destroy event: _destroy 84 * destroy event: _destroy
82 # TODO: Add file filter 86 # TODO: Add file filter
83 self.__mainWindow = mainWindow 87 self.__mainWindow = mainWindow
84 self.__readFileMethod = readFileMethod 88 self.__readFileMethod = readFileMethod
85 self.__budget = budget 89 self.__budget = budget
86 self.__filename = filename 90 self.__filename = filename
91 self.__filetype = filetype
87 self.__cancelMethod = cancelMethod 92 self.__cancelMethod = cancelMethod
88 self.__file = None 93 self.__file = None
89 self.__window = gtk.FileChooserDialog(title=_("Open File"), 94 self.__window = gtk.FileChooserDialog(title=_("Open File"),
90 action=gtk.FILE_CHOOSER_ACTION_OPEN, 95 action=gtk.FILE_CHOOSER_ACTION_OPEN,
91 buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL, 96 buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,
103 """ 108 """
104 self.__filename = file 109 self.__filename = file
105 110
106 _emptyPage = gui.EmptyPage(self.__mainWindow, self.__readFileMethod, 111 _emptyPage = gui.EmptyPage(self.__mainWindow, self.__readFileMethod,
107 self.__budget, self.__filename, 112 self.__budget, self.__filename,
108 self.__cancelMethod) 113 self.__cancelMethod, self.__filetype)
109 self.__mainWindow.getNotebook().append_page(_emptyPage.widget, 114 self.__mainWindow.getNotebook().append_page(_emptyPage.widget,
110 _emptyPage.title) 115 _emptyPage.title)
111 self.__mainWindow.getPageList().append(_emptyPage) 116 self.__mainWindow.getPageList().append(_emptyPage)
112 _emptyPage.run() 117 _emptyPage.run()
113 118
368 373
369 Description: 374 Description:
370 Thread class to read a file without freeze the gui 375 Thread class to read a file without freeze the gui
371 Constructor: 376 Constructor:
372 importFiebdc.Thread(page, mainWindow, 377 importFiebdc.Thread(page, mainWindow,
373 readFileMethod, arg_tuple, cancelMethod) 378 readFileMethod, budget, filename, cancelMethod, filetype)
374 Ancestry: 379 Ancestry:
375 +--threading.Thread 380 +--threading.Thread
376 +-- importFiebdc.Thread 381 +-- importFiebdc.Thread
377 Atributes: 382 Atributes:
378 "__page": The page instanca that launch the thread 383 "__page": The page instanca that launch the thread
379 "__mainWindow": gui.MainWindow instance 384 "__mainWindow": gui.MainWindow instance
380 "__readFileMethod": Method to read the selected file 385 "__readFileMethod": Method to read the selected file
381 "__arg_tuple": ("file", base.Budget()) 386 "__budget
387 "__filename": "file"
382 "__cancelMethod": Method to cancel the read method 388 "__cancelMethod": Method to cancel the read method
389 "__filetype": "budget" or "database"
383 "__cancel": Boolean value, True: the thread is stoped 390 "__cancel": Boolean value, True: the thread is stoped
384 Methods: 391 Methods:
385 __init__(self, page, mainWindow, 392 __init__(self, page, mainWindow,
386 readFileMethod, arg_tuple, cancelMethod) 393 readFileMethod, arg_tuple, cancelMethod)
387 run(self) 394 run(self)
388 cancel(self) 395 cancel(self)
389 isCanceled(self) 396 isCanceled(self)
390 """ 397 """
391 398
392 def __init__(self, page, mainWindow, 399 def __init__(self, page, mainWindow,
393 readFileMethod, budget, filename, cancelMethod): 400 readFileMethod, budget, filename, cancelMethod, filetype):
394 """def __init__(self, page, mainWindow, 401 """def __init__(self, page, mainWindow,
395 readFileMethod, budget, filename, cancelMethod) 402 readFileMethod, budget, filename, cancelMethod)
396 403
397 page: The page instance that launch the thread 404 page: The page instance that launch the thread
398 mainWindow: gui.Mainwindow object 405 mainWindow: gui.Mainwindow object
399 readFileMethod: Method to read the selected file 406 readFileMethod: Method to read the selected file
400 budget: base.Budget object 407 budget: base.Budget object
401 filename: "file" 408 filename: "file"
402 cancelMethod: Method to cancel the read method 409 cancelMethod: Method to cancel the read method
410 feletype: "budget" or "basedate"
403 Sets the instance atributes. 411 Sets the instance atributes.
404 """ 412 """
405 super(Thread, self).__init__() 413 super(Thread, self).__init__()
406 self.__page = page 414 self.__page = page
407 self.__mainWindow = mainWindow 415 self.__mainWindow = mainWindow
408 self.__readFileMethod = readFileMethod 416 self.__readFileMethod = readFileMethod
409 self.__budget = budget 417 self.__budget = budget
410 self.__filename = filename 418 self.__filename = filename
411 self.__cancelMethod = cancelMethod 419 self.__cancelMethod = cancelMethod
420 self.__filetype = filetype
412 self.__cancel = False 421 self.__cancel = False
413 422
414 def run(self): 423 def run(self):
415 """run(self) 424 """run(self)
416 425
422 self.__page.threadCanceled() 431 self.__page.threadCanceled()
423 else: 432 else:
424 _mainWindow = self.__mainWindow 433 _mainWindow = self.__mainWindow
425 _mainWindow._addBudget(_result) 434 _mainWindow._addBudget(_result)
426 self.__page.closeWindow() 435 self.__page.closeWindow()
436
437 if self.__filetype == "basedate":
438 self.saveDurusDatabase()
427 self.clear() 439 self.clear()
440
441 def saveDurusDatabase(self):
442 _path = globals.getHomePath("DURUS-DATABASE")
443 _file_whit_path_bc3 = self.__budget.filename
444 _filename_bc3 = _file_whit_path_bc3.split("/")[-1]
445 _filename = _filename_bc3.split(".")[-2]
446 _file = _path + _filename + ".durus"
447 print utils.mapping(_("Saving file: $1"), (_file,))
448 _time = time.time()
449 _durus_file = durusdatabase.DurusFile(_file,True)
450 _durus_file.setBudget(self.__budget)
451 _durus_file.close()
452 print utils.mapping(_("Saving time: $1 seconds"),
453 (("%.2f" %(time.time()-_time) ),))
428 454
429 def cancel(self): 455 def cancel(self):
430 """cancel(self) 456 """cancel(self)
431 457
432 Sets the "__cancel" atribute to True and call "__cancelMethod" to stop 458 Sets the "__cancel" atribute to True and call "__cancelMethod" to stop