PageRenderTime 60ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/core/promogest/ui/Main.py

http://promogest.googlecode.com/
Python | 1002 lines | 935 code | 40 blank | 27 comment | 40 complexity | b90a2f72dd2ad616713d026f7ddea5d9 MD5 | raw file
Possible License(s): GPL-2.0
  1. # -*- coding: utf-8 -*-
  2. # Copyright (C) 2005, 2006, 2007 2008, 2009, 2010, 2011 by Promotux
  3. # di Francesco Meloni snc - http://www.promotux.it/
  4. # Author: Francesco Meloni <francesco@promotux.it>
  5. # Author: Francesco Marella <francesco.marella@gmail.com>
  6. # This file is part of Promogest.
  7. # Promogest is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 2 of the License, or
  10. # (at your option) any later version.
  11. # Promogest is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. # You should have received a copy of the GNU General Public License
  16. # along with Promogest. If not, see <http://www.gnu.org/licenses/>.
  17. import locale
  18. import hashlib
  19. import os
  20. import glob
  21. try:
  22. import ho.pisa as pisa
  23. except:
  24. print """ERRORE NELL'IMPORT DI PISA prova a digitare
  25. 'sudo apt-get install python-pisa" nel terminale' """
  26. # import pisaLib.ho.pisa as pisa
  27. from datetime import datetime
  28. import webbrowser
  29. from subprocess import *
  30. from promogest import Environment
  31. from promogest.ui.GladeWidget import GladeWidget
  32. from promogest.ui.ElencoMagazzini import ElencoMagazzini
  33. from promogest.ui.ElencoListini import ElencoListini
  34. from promogest.ui.VistaPrincipale import VistaPrincipale
  35. from promogest.ui.SendEmail import SendEmail
  36. from promogest.ui.PrintDialog import PrintDialogHandler
  37. from promogest.ui.utils import hasAction, fencemsg, aggiorna, updateScadenzePromemoria,\
  38. setconf, dateTimeToString, dateToString, \
  39. orda, posso, messageInfo, installId , YesNoDialog
  40. from promogest.ui.utilsCombobox import *
  41. from promogest.ui.gtk_compat import *
  42. from ParametriFrame import ParametriFrame
  43. from SetConf import SetConfUI
  44. from AnagraficaPrincipaleFrame import AnagrafichePrincipaliFrame
  45. import promogest.dao.Promemoria
  46. from promogest.dao.Promemoria import Promemoria
  47. from promogest.dao.VariazioneListino import VariazioneListino
  48. from promogest.ui.ConfiguraWindow import ConfiguraWindow
  49. from promogest.ui.PanUi import PanUi, checkPan
  50. from promogest.ui.AzioniVelociNotebookPage import AzioniVelociNotebookPage
  51. from promogest.ui.NewsNotebookPage import NewsNotebookPage
  52. from promogest.ui.CalendarNotebookPage import CalendarNotebookPage
  53. from promogest.ui.NotificaAllarmiNotebookPage import NotificaAllarmiNotebookPage
  54. #inizializzano il customwidget
  55. from promogest.ui.widgets.ArticoloSearchWidget import ArticoloSearchWidget
  56. from promogest.ui.widgets.ClienteSearchWidget import ClienteSearchWidget
  57. from promogest.ui.widgets.FornitoreSearchWidget import FornitoreSearchWidget
  58. from promogest.ui.widgets.PersonaGiuridicaSearchWidget import PersonaGiuridicaSearchWidget
  59. if posso("GN"):
  60. from promogest.modules.GestioneNoleggio.dao.TestataGestioneNoleggio \
  61. import TestataGestioneNoleggio
  62. try:
  63. if Environment.pg3:
  64. from gi.repository.WebKit import WebView
  65. else:
  66. from webkit import WebView
  67. WEBKIT = True
  68. except:
  69. WEBKIT = False
  70. class Main(GladeWidget):
  71. def __init__(self, aziendaStr, anagrafiche_modules, parametri_modules,
  72. anagrafiche_dirette_modules, frame_modules, permanent_frames):
  73. GladeWidget.__init__(self, 'main_window')
  74. self.main_window.set_title('*** PromoGest2 *** Azienda : '+aziendaStr+\
  75. ' *** Utente : '+\
  76. Environment.params['usernameLoggedList'][1]+\
  77. ' ***')
  78. self.aziendaStr = aziendaStr
  79. self.statusBarHandler()
  80. for filename in glob.glob(Environment.promogestDir+\
  81. "temp"+os.sep+'*.cache'):
  82. try:
  83. os.remove(filename)
  84. except:
  85. pass
  86. Environment.windowGroup.append(self.getTopLevel())
  87. self.anagrafiche_modules = anagrafiche_modules
  88. self.parametri_modules = parametri_modules
  89. self.anagrafiche_dirette_modules=anagrafiche_dirette_modules
  90. self.frame_modules = frame_modules
  91. self.permanent_frames = permanent_frames
  92. self.currentFrame = None
  93. self.alarmFrame = None
  94. self.shop = Environment.shop
  95. self.creata = False
  96. if posso("SD"):
  97. self.sincro_db.destroy()
  98. elif posso("SD") and \
  99. Environment.conf.SincroDB.tipo =="client":
  100. self.master_sincro_db.destroy()
  101. elif posso("SD") and \
  102. Environment.conf.SincroDB.tipo =="server":
  103. self.client_sincro_db.destroy()
  104. if Environment.tipodb =="postgresql":
  105. # self.whatcant_button.destroy()
  106. self.test_promowear_button.destroy()
  107. self.test_promoshop_button.destroy()
  108. self.addNoteBookPage()
  109. self.updates()
  110. def show(self):
  111. """ Visualizza la finestra
  112. """
  113. #documenti_image = self.documenti_image.get_image()
  114. self.anno_lavoro_label.set_markup('<b>Anno di lavoro: ' + \
  115. Environment.workingYear + '</b>')
  116. model = self.iconview_listore
  117. model.append([3, "Documenti\n(Fatture,DDT\nPreventivi)",
  118. self.documenti_image.get_pixbuf(), None])
  119. model.append([4, "Prima Nota",
  120. self.primanota_image.get_pixbuf(), None])
  121. model.append([5, "Promemoria",
  122. self.promemoria_image.get_pixbuf(), None])
  123. model.append([10, "Gestione\nCommesse",
  124. self.gest_commesse_image.get_pixbuf(), None])
  125. # right vertical icon list adding modules
  126. # model_right = gtk.ListStore(int, str, gtk.gdk.Pixbuf, object)
  127. ind = 6
  128. for mod in self.anagrafiche_dirette_modules.keys():
  129. currModule = self.anagrafiche_dirette_modules[mod]
  130. if self.shop and currModule["module"].VIEW_TYPE[1] =="Vendita Dettaglio":
  131. anag = currModule["module"].getApplication()
  132. showAnagrafica(self.getTopLevel(), anag, mainClass=self)
  133. #icon_view.unselect_all()
  134. return
  135. pbuf = GDK_PIXBUF_NEW_FROM_FILE(currModule['guiDir']+ currModule['module'].VIEW_TYPE[2])
  136. row = (ind, currModule['module'].VIEW_TYPE[1], pbuf, currModule['module'])
  137. model.append(row)
  138. ind += 1
  139. for mod in self.frame_modules.keys():
  140. currModule = self.frame_modules[mod]
  141. pbuf = GDK_PIXBUF_NEW_FROM_FILE(currModule['guiDir']+ currModule['module'].VIEW_TYPE[2])
  142. row =(ind, currModule['module'].VIEW_TYPE[1], pbuf, currModule['module'])
  143. model.append(row)
  144. ind += 1
  145. self.main_iconview.set_model(model)
  146. self.main_iconview.set_text_column(1)
  147. self.main_iconview.set_pixbuf_column(2)
  148. #self.main_iconview.connect('selection-changed',
  149. #self.on_main_iconview_select, model)
  150. self.main_iconview.set_columns(1)
  151. self.main_iconview.set_item_width(95)
  152. self.main_iconview.set_size_request(115, -1)
  153. if self.currentFrame is None:
  154. # self.main_hbox.remove(self.box_immagini_iniziali)
  155. self._refresh()
  156. self.setModulesButtons()
  157. self.placeWindow(self.main_window)
  158. self.main_window.show_all()
  159. self.on_button_refresh_clicked()
  160. def updates(self):
  161. """ Aggiornamenti e controlli da fare all'avvio del programma
  162. """
  163. #Aggiornamento scadenze promemoria
  164. if posso("PR"):
  165. print "VERIFICA DEI PROMEMORIA IN SCADENZA"
  166. updateScadenzePromemoria()
  167. def _refresh(self):
  168. """
  169. Update the window, setting the appropriate frame
  170. """
  171. self.main_iconview.unselect_all()
  172. self.main_hbox.show_all()
  173. def on_button_help_clicked(self, button):
  174. sendemail = SendEmail()
  175. def on_button_refresh_clicked(self, widget=None):
  176. # if WEBKIT:
  177. # self.create_planning_frame()
  178. if self.creata:
  179. self.main_notebook.remove_page(0)
  180. # self.creata = False
  181. self._refresh()
  182. def on_main_iconview_select(self, icon_view, model=None):
  183. selected = icon_view.get_selected_items()
  184. if len(selected) == 0:
  185. return
  186. if Environment.pg3:
  187. i = selected[0]
  188. else:
  189. i = selected[0][0]
  190. selection = self.iconview_listore[i][0]
  191. if selection == 3:
  192. #self.currentFrame = self.create_registrazioni_frame()
  193. # Andrea
  194. # richiamo diretto dei documenti: evita di dover premere il
  195. # pulsante nel frame registrazioni
  196. if not hasAction(actionID=2):
  197. return
  198. from promogest.ui.anagDocumenti.AnagraficaDocumenti import AnagraficaDocumenti
  199. anag = AnagraficaDocumenti(aziendaStr=self.aziendaStr)
  200. showAnagrafica(self.getTopLevel(), anag, mainClass=self)
  201. icon_view.unselect_all()
  202. return
  203. elif selection == 4:
  204. if not hasAction(actionID=15):
  205. return
  206. from promogest.modules.PrimaNota.ui.AnagraficaPrimaNota import AnagraficaPrimaNota
  207. anag = AnagraficaPrimaNota(aziendaStr=self.aziendaStr)
  208. showAnagrafica(self.getTopLevel(), anag, mainClass=self)
  209. icon_view.unselect_all()
  210. return
  211. elif selection == 5:
  212. if posso("PR"):
  213. from AnagraficaPromemoria import AnagraficaPromemoria
  214. anag = AnagraficaPromemoria(self.aziendaStr)
  215. showAnagrafica(self.getTopLevel(), anag, mainClass=self)
  216. icon_view.unselect_all()
  217. return
  218. else:
  219. fencemsg()
  220. elif selection == 10: #gestione commessa
  221. # messageInfo(msg="""RICORDIAMO CHE QUESTO MODULO E' ANCORA IN FASE DI TEST """)
  222. # if posso("GC"):
  223. from promogest.modules.GestioneCommesse.ui.AnagraficaCommesse import AnagraficaCommesse
  224. anag = AnagraficaCommesse(aziendaStr=self.aziendaStr)
  225. showAnagrafica(self.getTopLevel(), anag, mainClass=self)
  226. icon_view.unselect_all()
  227. return
  228. else:
  229. if Environment.pg3:
  230. i = selected[0]
  231. else:
  232. i = selected[0][0]
  233. selection = self.iconview_listore[i][0]
  234. module = self.iconview_listore[i][3]
  235. if self.currentFrame is not None:
  236. self.main_hbox.remove(self.currentFrame)
  237. self.currentFrame.destroy()
  238. self.currentFrame = None
  239. if module.VIEW_TYPE[0] == 'anagrafica_diretta':
  240. anag = module.getApplication()
  241. showAnagrafica(self.getTopLevel(), anag, mainClass=self)
  242. icon_view.unselect_all()
  243. return
  244. elif module.VIEW_TYPE[0] == 'frame':
  245. frame = module.getApplication()
  246. self.currentFrame = frame.getTopLevel()
  247. self.main_notebook.set_current_page(0)
  248. self._refresh()
  249. def setModulesButtons(self):
  250. if self.anagrafiche_modules is not None:
  251. for module in self.anagrafiche_modules.iteritems():
  252. module_button = gtk.Button()
  253. module_butt_image = gtk.Image()
  254. module_butt_image.set_from_file(module[1]['guiDir']+'/'+module[1]['module'].VIEW_TYPE[2])
  255. module_button.set_image(module_butt_image)
  256. module_button.set_label(module[1]['module'].VIEW_TYPE[1])
  257. module_button.connect('clicked', self.on_module_button_clicked)
  258. self.anagrafiche_moduli_vbox.pack_start(module_button, False, False, 0)
  259. return
  260. else:
  261. return
  262. def on_module_button_clicked(self, button):
  263. label = button.get_label()
  264. for mk in self.anagrafiche_modules.iteritems():
  265. module = mk[1]['module']
  266. if label == module.VIEW_TYPE[1]:
  267. #chiave di tutto il richiamo di passaggio alla classe in module.py che poi fa la vera istanza"
  268. anag = module.getApplication()
  269. showAnagrafica(self.getTopLevel(), anag, button=None, mainClass=self)
  270. def on_articoli_button_clicked(self, toggleButton):
  271. if not hasAction(actionID=2):
  272. return
  273. if toggleButton.get_property('active') is False:
  274. return
  275. from AnagraficaArticoli import AnagraficaArticoli
  276. anag = AnagraficaArticoli(aziendaStr=Environment.azienda)
  277. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  278. def on_forniture_button_clicked(self, toggleButton):
  279. if toggleButton.get_property('active') is False:
  280. return
  281. from promogest.ui.anagForniture.AnagraficaForniture import AnagraficaForniture
  282. anag = AnagraficaForniture(aziendaStr=self.aziendaStr)
  283. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  284. def on_clienti_button_clicked(self, toggleButton):
  285. if toggleButton.get_property('active') is False:
  286. return
  287. from AnagraficaClienti import AnagraficaClienti
  288. anag = AnagraficaClienti(aziendaStr=self.aziendaStr)
  289. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  290. def on_fornitori_button_clicked(self, toggleButton):
  291. if toggleButton.get_property('active') is False:
  292. return
  293. from AnagraficaFornitori import AnagraficaFornitori
  294. anag = AnagraficaFornitori(aziendaStr=self.aziendaStr)
  295. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  296. def on_vettori_button_clicked(self, toggleButton):
  297. if toggleButton.get_property('active') is False:
  298. return
  299. from AnagraficaVettori import AnagraficaVettori
  300. anag = AnagraficaVettori(aziendaStr=self.aziendaStr)
  301. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  302. def on_agenti_button_clicked(self, toggleButton):
  303. if toggleButton.get_property('active') is False:
  304. return
  305. if posso("AG"):
  306. from promogest.modules.Agenti.ui.AnagraficaAgenti import AnagraficaAgenti
  307. anag = AnagraficaAgenti(aziendaStr=self.aziendaStr)
  308. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  309. else:
  310. fencemsg()
  311. toggleButton.set_active(False)
  312. def on_categorie_articoli_button_clicked(self, toggleButton):
  313. if toggleButton.get_property('active') is False:
  314. return
  315. from AnagraficaCategorieArticoli import AnagraficaCategorieArticoli
  316. anag = AnagraficaCategorieArticoli()
  317. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  318. def on_famiglie_articoli_button_clicked(self, toggleButton):
  319. if toggleButton.get_property('active') is False:
  320. return
  321. from AnagraficaFamiglieArticoli import AnagraficaFamiglieArticoli
  322. anag = AnagraficaFamiglieArticoli()
  323. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  324. def on_categorie_clienti_button_clicked(self, toggleButton):
  325. if toggleButton.get_property('active') is False:
  326. return
  327. from AnagraficaCategorieClienti import AnagraficaCategorieClienti
  328. anag = AnagraficaCategorieClienti()
  329. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  330. def on_categorie_fornitori_button_clicked(self, toggleButton):
  331. if toggleButton.get_property('active') is False:
  332. return
  333. from AnagraficaCategorieFornitori import AnagraficaCategorieFornitori
  334. anag = AnagraficaCategorieFornitori()
  335. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  336. def on_utenti_button_toggled(self, toggleButton):
  337. if toggleButton.get_property('active') is False:
  338. return
  339. if posso("RA"):
  340. from promogest.modules.RuoliAzioni.ui.AnagraficaUtenti import AnagraficaUtenti
  341. anag = AnagraficaUtenti()
  342. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  343. else:
  344. fencemsg()
  345. toggleButton.set_property('active', False)
  346. def on_ruoli_button_toggled(self, toggleButton):
  347. if toggleButton.get_property('active') is False:
  348. return
  349. if posso("RA"):
  350. from promogest.modules.RuoliAzioni.ui.AnagraficaRuoli import AnagraficaRuoli
  351. anag = AnagraficaRuoli()
  352. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  353. else:
  354. fencemsg()
  355. toggleButton.set_property('active', False)
  356. def on_ruoli_azioni_button_toggled(self, toggleButton):
  357. if toggleButton.get_property('active') is False:
  358. return
  359. if posso("RA"):
  360. from promogest.modules.RuoliAzioni.ui.ManageRoleAction import ManageRuoloAzioni
  361. anag = ManageRuoloAzioni()
  362. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  363. else:
  364. fencemsg()
  365. toggleButton.set_property('active', False)
  366. def on_multipli_button_clicked(self, toggleButton):
  367. if toggleButton.get_property('active') is False:
  368. return
  369. from AnagraficaMultipli import AnagraficaMultipli
  370. anag = AnagraficaMultipli()
  371. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  372. def on_pagamenti_button_clicked(self, toggleButton):
  373. if toggleButton.get_property('active') is False:
  374. return
  375. from AnagraficaPagamenti import AnagraficaPagamenti
  376. anag = AnagraficaPagamenti()
  377. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  378. def on_banche_button_clicked(self, toggleButton):
  379. if toggleButton.get_property('active') is False:
  380. return
  381. from AnagraficaBanche import AnagraficaBanche
  382. anag = AnagraficaBanche()
  383. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  384. def on_categorie_contatti_button_clicked(self, toggleButton):
  385. if toggleButton.get_property('active') is False:
  386. return
  387. from promogest.modules.Contatti.ui.AnagraficaCategorieContatti import AnagraficaCategorieContatti
  388. anag = AnagraficaCategorieContatti()
  389. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  390. def on_aliquote_iva_button_clicked(self, toggleButton):
  391. if toggleButton.get_property('active') is False:
  392. return
  393. from AnagraficaAliquoteIva import AnagraficaAliquoteIva
  394. anag = AnagraficaAliquoteIva()
  395. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  396. def on_imballaggi_button_clicked(self, toggleButton):
  397. if toggleButton.get_property('active') is False:
  398. return
  399. from AnagraficaImballaggi import AnagraficaImballaggi
  400. anag = AnagraficaImballaggi()
  401. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  402. def on_stadio_commessa_button_toggled(self, toggleButton):
  403. if toggleButton.get_property('active') is False:
  404. return
  405. # if posso("GC"):
  406. # messageInfo(msg="""RICORDIAMO CHE QUESTO MODULO E' ANCORA IN FASE DI TEST """)
  407. from promogest.modules.GestioneCommesse.ui.AnagraficaStadioCommessa import AnagraficaStadioCommessa
  408. anag = AnagraficaStadioCommessa()
  409. showAnagrafica(self.getTopLevel(), anag, toggleButton, mainClass=self)
  410. def on_main_iconview_right_select(self, icon_view, model=None):
  411. selected = icon_view.get_selected_items()
  412. if len(selected) == 0:
  413. return
  414. i = selected[0][0]
  415. selection = model[i][0]
  416. module = model[i][3]
  417. if self.currentFrame is not None:
  418. self.main_hbox.remove(self.currentFrame)
  419. self.currentFrame.destroy()
  420. self.currentFrame = None
  421. if module.VIEW_TYPE[0] == 'anagrafica_diretta':
  422. anag = module.getApplication()
  423. showAnagrafica(self.getTopLevel(), anag, mainClass=self)
  424. icon_view.unselect_all()
  425. return
  426. elif module.VIEW_TYPE[0] == 'frame':
  427. frame = module.getApplication()
  428. self.currentFrame = frame.getTopLevel()
  429. ## icon_view.unselect_all()
  430. self._refresh()
  431. # INIZIO CREAZIONE FRAME
  432. def create_main_window_frame(self):
  433. # if self.currentFrame is not None:
  434. # self.main_hbox.remove(self.currentFrame)
  435. frame = VistaPrincipale(self, self.aziendaStr)
  436. # return frame.vista_principale_frame
  437. return frame
  438. def create_anagrafiche_principali_frame(self):
  439. if not hasAction(actionID=11):return
  440. # if self.currentFrame is not None:
  441. # self.main_hbox.remove(self.currentFrame)
  442. frame = AnagrafichePrincipaliFrame(self.main_window, self.aziendaStr, modules=self.anagrafiche_modules)
  443. return frame.getTopLevel()
  444. def create_registrazioni_frame(self):
  445. if not hasAction(actionID=2):return
  446. if self.currentFrame is not None:
  447. self.main_hbox.remove(self.currentFrame)
  448. frame = RegistrazioniFrame(self.main_window, self.aziendaStr)
  449. return frame.getTopLevel()
  450. def create_parametri_frame(self):
  451. if not hasAction(actionID=6):return
  452. if self.currentFrame is not None:
  453. self.main_hbox.remove(self.currentFrame)
  454. frame = ParametriFrame(self.main_window, self.aziendaStr, modules=self.parametri_modules)
  455. return frame.getTopLevel()
  456. # FINE CREAZIONE FRAME
  457. def on_configurazione_menu_activate(self, widget):
  458. if not hasAction(actionID=14):return
  459. configuraWindow = ConfiguraWindow(self)
  460. # configuraWindow = SetConfUI(self)
  461. showAnagrafica(self.getTopLevel(), configuraWindow)
  462. def on_dati_azienda_activate(self, widget):
  463. from AnagraficaAziende import AnagraficaAziende
  464. anag =AnagraficaAziende(self)
  465. showAnagrafica(self.getTopLevel(), anag)
  466. def on_importa_modulo_activate(self, widget):
  467. return
  468. fileDialog = gtk.FileChooserDialog(title='Importazione modulo',
  469. parent=self.getTopLevel(),
  470. action=GTK_FILE_CHOOSER_ACTION_OPEN,
  471. buttons=(gtk.STOCK_CANCEL,
  472. GTK_RESPONSE_CANCEL,
  473. gtk.STOCK_OK,
  474. GTK_RESPONSE_OK),
  475. backend=None)
  476. fltr = gtk.FileFilter()
  477. fltr.add_pattern('*.pg2')
  478. fltr.set_name('File Pg2 (*.pg2)')
  479. fileDialog.add_filter(fltr)
  480. fltr = gtk.FileFilter()
  481. fltr.add_pattern('*')
  482. fltr.set_name('Tutti i file')
  483. fileDialog.add_filter(fltr)
  484. n = ""
  485. response = fileDialog.run()
  486. if response == GTK_RESPONSE_OK:
  487. filename = fileDialog.get_filename()
  488. f = open(filename)
  489. r = f.readline()
  490. al = f.readlines()
  491. for a in al:
  492. if "MODULES_NAME" in a:
  493. n = a.split("=")[1].strip()[1:-1]
  494. break
  495. else:
  496. continue
  497. c = Environment.PRODOTTO.strip()
  498. v = Environment.VERSIONE.strip()
  499. p = hashlib.sha224(n+c+v).hexdigest()
  500. if p.strip()==r.strip():
  501. pa = os.path.join(Environment.cartella_moduli,n+"/"+"module.py")
  502. g = file(pa,"w")
  503. for a in al:
  504. g.write(a)
  505. g.close()
  506. f.close()
  507. msg = "MODULO CORRETTAMENTE INSTALLATO, CHIUDERE L'APPLICAZIONE\nED AGGIUNGERE I PARAMETRI NECESSARI\n"
  508. else:
  509. msg ="ATTENZIONE, MODULO NON INSTALLATO, CORROTTO O NON CORRETTO, CONTATTARE L'ASSISTENZA"
  510. messageInfo(msg=msg)
  511. #self.path_file_entry.set_text(filename)
  512. fileDialog.destroy()
  513. def on_credits_menu_activate(self, widget):
  514. creditsDialog = GladeWidget('credits_dialog', callbacks_proxy=self)
  515. creditsDialog.getTopLevel().set_transient_for(self.getTopLevel())
  516. creditsDialog.getTopLevel().show_all()
  517. response = creditsDialog.credits_dialog.run()
  518. if response == GTK_RESPONSE_OK:
  519. creditsDialog.credits_dialog.destroy()
  520. def on_inserimento_codice_activate(self,widget):
  521. from promogest.dao.Setconf import SetConf
  522. dialog = gtk.MessageDialog(self.getTopLevel(),
  523. GTK_DIALOG_MODAL
  524. | GTK_DIALOG_DESTROY_WITH_PARENT,
  525. GTK_DIALOG_MESSAGE_INFO, GTK_BUTTON_OK)
  526. dialog.set_markup("""<b> CODICE ATTIVAZIONE PACCHETTO </b>""")
  527. hbox = gtk.HBox()
  528. entry___ = gtk.Entry()
  529. label = gtk.Label()
  530. label.set_markup("<b> Inserisci codice </b>")
  531. hbox.pack_start(label, True, True, 0)
  532. hbox.pack_start(entry___, True, True, 0)
  533. dialog.get_content_area().pack_start(hbox, True, True, 0)
  534. dialog.show_all()
  535. response = dialog.run()
  536. codice = entry___.get_text()
  537. # hascode = str(hashlib.sha224(codice+orda(codice)).hexdigest())
  538. if "cl" and "|" in codice :
  539. d = codice.split("|")
  540. if d[1] == "azienda":
  541. if Environment.tipodb == "sqlite":
  542. from promogest.dao.Azienda import Azienda
  543. oldnomeazienda= d[2]
  544. newnameazienda = d[3]
  545. aa = Azienda().select(schemaa = oldnomeazienda)
  546. if aa:
  547. aa[0].schemaa = newnameazienda.strip()
  548. aa[0].persist()
  549. messageInfo(msg="NOME AZIENDA MODIFICATO")
  550. dialog.destroy()
  551. return
  552. else:
  553. messageInfo(msg="VECCHIO NOME AZIENDA NON TROVATO")
  554. dialog.destroy()
  555. return
  556. return
  557. else:
  558. messageInfo(msg="POSSIBILE SOLO CON LA VERSIONE ONE")
  559. dialog.destroy()
  560. return
  561. elif d[1] == "modulo":
  562. tipo_section = d[2] #Modulo
  563. section = d[3] # Inventario
  564. description = str(d[4]) or "" #Gestione inventario
  565. tipo = d[5] or None # Niente o BOOLEAN o colore
  566. active = bool(d[6]) or True # bool
  567. visible = bool(d[7]) or True #bool
  568. key = d[8] # mod_enable
  569. value = d[9] # yes or no
  570. if section not in Environment.modules_folders:
  571. messageInfo(msg="ERRORE ATTIVAZIONE MODULO")
  572. return
  573. dao = SetConf().select(key=key,section=section)
  574. if dao:
  575. d = dao[0]
  576. else:
  577. d = SetConf()
  578. d.key = key
  579. d.value =value
  580. d.section = section
  581. d.description = description
  582. d.tipo_section = tipo_section
  583. d.tipo = tipo
  584. d.active = active
  585. d.visible = visible
  586. d.date = datetime.datetime.now()
  587. d.persist()
  588. messageInfo(msg="MODULO O OPZIONE MODIFICATO attivato o disattivato")
  589. dialog.destroy()
  590. return
  591. elif d[1] =="registro":
  592. operazione = d[2].strip()+".registro"
  593. registro_da_assegnare = d[3]
  594. from promogest.dao.Setting import Setting
  595. a = Setting().getRecord(id=operazione)
  596. if a:
  597. b = Setting().select(value=registro_da_assegnare)
  598. if b:
  599. a.value = registro_da_assegnare
  600. a.persist()
  601. messageInfo(msg="REGISTRO NUMERAZIONE MODIFICATO\n\nRIAVVIARE")
  602. dialog.destroy()
  603. return True
  604. else:
  605. messageInfo(msg="REGISTRO DA ASSEGNARE NON TROVATO O CORRETTO\n\n RIPROVARE")
  606. return False
  607. else:
  608. messageInfo(msg="OPERAZIONE NON CORRETTA E NON TROVATA\n\nRIPROVARE")
  609. return False
  610. else:
  611. sets = SetConf().select(key="install_code",section="Master")
  612. if sets:
  613. sets[0].delete()
  614. if codice:
  615. k = SetConf()
  616. k.key = "install_code"
  617. k.value =str(hashlib.sha224(codice+orda(codice)).hexdigest())
  618. k.section = "Master"
  619. k.description = "codice identificativo della propria installazione"
  620. k.tipo_section = "General"
  621. k.tipo = "ONE"
  622. k.active = True
  623. k.date = datetime.datetime.now()
  624. k.persist()
  625. messageInfo(msg="ATTIVAZIONE EFFETTUATA, RIAVVIARE IL PROMOGEST")
  626. dialog.destroy()
  627. def on_licenza_menu_activate(self, widget):
  628. licenzaDialog = GladeWidget('licenza_dialog', callbacks_proxy=self)
  629. licenzaDialog.getTopLevel().set_transient_for(self.getTopLevel())
  630. licenseText = ''
  631. try:
  632. lines = open('./LICENSE').readlines()
  633. for l in lines:
  634. licenseText += l
  635. except:
  636. licenseText = 'Lavori in corso ....'
  637. print 'License file not found (LICENSE).'
  638. textBuffer = licenzaDialog.licenza_textview.get_buffer()
  639. textBuffer.set_text(licenseText)
  640. licenzaDialog.licenza_textview.set_buffer(textBuffer)
  641. licenzaDialog.getTopLevel().show_all()
  642. response = licenzaDialog.licenza_dialog.run()
  643. if response == GTK_RESPONSE_OK:
  644. licenzaDialog.licenza_dialog.destroy()
  645. def on_manuale_online_activate(self, widget):
  646. url ="http://help.promotux.it"
  647. webbrowser.open_new_tab(url)
  648. def on_aggiorna_activate(self, widget):
  649. aggiorna(self)
  650. def on_Back_up_Database_activate(self, widget):
  651. """ Si prepara un file zip con il dump del DB """
  652. if Environment.tipodb == "sqlite":
  653. msg = """NELLA VERSIONE LITE IL BACKUP SI
  654. EFFETTUA COPIANDO IL FILE db CHE SI TROVA NELLA CARTELLA
  655. promogest2 IN /HOME/NOMEUTENTE/ O IN C:/UTENTI/NOMEUTENTE"""
  656. messageInfo(msg= msg)
  657. else:
  658. st= Environment.startdir()
  659. nameDump = "promoGest2_dump_"+self.aziendaStr+"_"+datetime.datetime.now().strftime('%d_%m_%Y_%H_%M')
  660. msgg = """Il "dump" del database verrŕ salvato in
  661. %s
  662. ed avrŕ il nome
  663. %s.zip
  664. ATTENZIONE!!!! la procedura potrebbe richiedere diversi minuti.""" %(st, nameDump)
  665. messageInfo(msg= msgg, transient=self.getTopLevel())
  666. #if response == gtk.RESPONSE_OK:
  667. st= Environment.startdir()
  668. stname = st+nameDump
  669. os.environ["PGPASSWORD"]=Environment.password
  670. retcode = call(["pg_dump",
  671. "-h",Environment.host,
  672. "-p",Environment.port,
  673. "-U",Environment.user,
  674. "-Z","7",
  675. "-f",stname,
  676. Environment.database])
  677. Environment.pg2log.info("STO EFFETTUANDO UN BACKUP DEL FILE %s" %stname)
  678. #print "YYYYYYYYYYYYYYYYYY", retcode
  679. if not retcode:
  680. #zfilename = nameDump +".zip"
  681. #zout = zipfile.ZipFile(str(stname) +".zip", "w")
  682. #zout.write(stname,zfilename,zipfile.ZIP_DEFLATED)
  683. #zout.close()
  684. Environment.pg2log.info("DUMP EFFETTUATO CON SUCCESSO")
  685. #os.remove(stname)
  686. else:
  687. Environment.pg2log.info("ATTENZIONE DUMP NON RIUSCITO")
  688. def on_pan_active_clicked(self, button):
  689. # if not hasAction(actionID=14):return
  690. configuraWindow = PanUi(self)
  691. showAnagrafica(self.getTopLevel(), configuraWindow)
  692. def on_seriale_menu_activate(self, widget):
  693. from promogest.dao.Setconf import SetConf
  694. try:
  695. data = SetConf().select(key="install_code",section="Master")
  696. codice = data[0].value
  697. msg = 'Codice installazione:\n\n' + str(codice)
  698. except:
  699. msg = 'Impossibile generare il codice !!!'
  700. messageInfo(msg= msg, transient=self.getTopLevel())
  701. def on_send_Email_activate(self, widget):
  702. sendemail = SendEmail()
  703. def on_master_sincro_db_activate(self, widget):
  704. msg ="SERVER NON ANCORA IMPLEMENTATO"
  705. messageInfo(msg= msg, transient=self.getTopLevel())
  706. def on_client_sincro_db_activate(self, widget):
  707. if posso("SD") and Environment.conf.SincroDB.tipo =="client":
  708. from promogest.modules.SincroDB.ui.SincroDB import SincroDB
  709. anag = SincroDB()
  710. showAnagrafica(self.getTopLevel(), anag)
  711. else:
  712. print "PASSIQUI"
  713. def on_test_promowear_button_clicked(self, button):
  714. msg = """ATTENZIONE!!
  715. QUESTA FUNZIONALITŔ Č STATA AGGIUNTA PER
  716. PERMETTERE DI PROVARE IL PROMOGEST ONE BASIC CON
  717. IL MODULO TAGLIA E COLORE PROMOWEAR
  718. QUESTO MODULO SERVE A CHI DEVE GESTIRE
  719. UNA ATTIVITŔ CHE MOVIMENTA E VENDE
  720. ABBIGLIAMENTO O CALZATURE.
  721. L'OPERAZIONE Č IRREVERSIBILE,AGGIUNGE DIVERSE
  722. TABELLE NEL DATABASE E NUOVE INTERFACCE UTENTE
  723. DEDICATE,NON CAUSA PERDITA DI DATI
  724. MA NON Č CONSIGLIATO FARLO SE NON
  725. NE AVETE BISOGNO
  726. Procedere all'installazione del modulo PromoWear? """
  727. if not YesNoDialog(msg=msg, transient=self.getTopLevel()):
  728. return
  729. if not hasattr(Environment.conf,"PromoWear"):
  730. Environment.conf.add_section("PromoWear")
  731. Environment.conf.save()
  732. Environment.conf.PromoWear.primoavvio = "yes"
  733. Environment.conf.PromoWear.mod_enable = "yes"
  734. Environment.conf.save()
  735. tables = [t.name for t in Environment.params["metadata"].sorted_tables]
  736. if "colore" not in tables and "taglia" not in tables:
  737. from promogest.modules.PromoWear.data.PromoWearDB import *
  738. msg = " TABELLE AGGIUNTE, RIAVVIARE IL PROGRAMMA "
  739. messageInfo(msg=msg)
  740. else:
  741. msg= "PULSANTE DI TEST GIA' PREMUTO"
  742. messageInfo(msg=msg, transient=self.getTopLevel())
  743. def on_test_promoshop_button_clicked(self, button):
  744. from promogest.dao.Setconf import SetConf
  745. msg = """ATTENZIONE!!
  746. QUESTA FUNZIONALITŔ Č STATA AGGIUNTA PER
  747. PERMETTERE DI PROVARE IL PROMOGEST ONE BASIC CON
  748. IL MODULO VENDITA DETTAGLIO
  749. Procedere all'installazione del modulo PromoShop? """
  750. if not YesNoDialog(msg=msg, transient=self.getTopLevel()):
  751. return
  752. if not setconf("VenditaDettaglio", "mod_enable"):
  753. a = SetConf()
  754. a.section = "VenditaDettaglio"
  755. a.tipo_section ="Modulo"
  756. a.description = "Modulo Vendita Dettaglio"
  757. a.tipo = "bool"
  758. a.key = "mod_enable"
  759. a.value = "yes"
  760. a.persist()
  761. a = SetConf()
  762. a.section = "VenditaDettaglio"
  763. a.tipo_section ="Modulo"
  764. a.description = "Nome del movimento generato"
  765. a.tipo = "str"
  766. a.key = "operazione"
  767. a.value = "Scarico venduto da cassa"
  768. a.persist()
  769. a = SetConf()
  770. a.section = "VenditaDettaglio"
  771. a.tipo_section ="Modulo"
  772. a.description = "disabilita_stampa"
  773. a.tipo = "bool"
  774. a.key = "disabilita_stampa"
  775. a.value = "True"
  776. a.active = True
  777. a.persist()
  778. #tables = [t.name for t in Environment.params["metadata"].sorted_tables]
  779. #if "testata_scontrino" not in tables:
  780. #from promogest.modules.VenditaDettaglio.data.VenditaDettaglioDB import *
  781. #msg = " TABELLE AGGIUNTE, RIAVVIARE IL PROGRAMMA "
  782. #messageInfo(msg=msg)
  783. else:
  784. messageInfo(msg="RISULTA GIA' ATTIVATO")
  785. def on_ricmedio_activate(self, widget):
  786. """ entry Menu statistiche Ricarico medio """
  787. from promogest.modules.Statistiche.ui.StatisticaGenerale import StatisticaGenerale
  788. anag = StatisticaGenerale(idMagazzino=None, nome="RICARICO MEDIO e INFLUENZA SULLE VENDITE")
  789. anagWindow = anag.getTopLevel()
  790. def on_controllo_fatturato_activate(self, widget):
  791. print "CONTROLLO FATTURATO NON GESTITO"
  792. def on_whatcant_button_clicked(self, button):
  793. url ="http://www.promogest.me/promoGest/whatCanT"
  794. webbrowser.open_new_tab(url)
  795. def on_export_magazzino_activate(self, button):
  796. from promogest.modules.Statistiche.ui.StatisticheMagazzino import StatisticheMagazzino
  797. anag = StatisticheMagazzino(idMagazzino=None)
  798. anagWindow = anag.getTopLevel()
  799. def on_main_window_key_press_event(self, widget, event):
  800. on_main_window_key_press_eventPart(self,widget, event)
  801. def on_disconnect(self, widget=None):
  802. if YesNoDialog(msg='Confermi l\'eliminazione ?', transient=self.getTopLevel()):
  803. self.destroy()
  804. else:
  805. return
  806. def on_quit(self, widget=None):
  807. if YesNoDialog(msg='Confermi la chiusura?', transient=self.getTopLevel()):
  808. self.hide()
  809. gtk.main_quit()
  810. else:
  811. return
  812. def on_main_notebook_change_current_page(self, notebook):
  813. print "AAAAAAAAAAAAAAAAAAAA", notebook
  814. def on_main_notebook_select_page(self, noteebok):
  815. print "AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH", noteebok
  816. def addNoteBookPage(self):
  817. if WEBKIT:
  818. self.nn = NewsNotebookPage(self, self.aziendaStr).draw()
  819. n = gtk.Label()
  820. n.set_markup("<b>NEWS/A.VEL</b>")
  821. ind = self.main_notebook.append_page(self.nn.notizie_frame, n)
  822. self.main_notebook.set_current_page(ind)
  823. self.pp = checkPan(self)
  824. self.elenco_magazzini_page = ElencoMagazzini(self, self.aziendaStr).draw()
  825. self.main_notebook.append_page(self.elenco_magazzini_page.elenco_magazzini_frame, self.elenco_magazzini_page.magazzini_label)
  826. self.elenco_listini_page = ElencoListini(self, self.aziendaStr).draw()
  827. self.main_notebook.append_page(self.elenco_listini_page.elenco_listini_frame,self.elenco_listini_page.elenco_listini_label)
  828. self.calendar_page = CalendarNotebookPage(self, self.aziendaStr).draw()
  829. calendar_page_label = gtk.Label()
  830. calendar_page_label.set_markup("<b>CALENDARIO</b>")
  831. self.main_notebook.append_page(self.calendar_page.calendario_frame, calendar_page_label)
  832. self.notifica_allarmi = NotificaAllarmiNotebookPage(self, self.aziendaStr)
  833. notifica_allarmi_label = gtk.Label()
  834. notifica_allarmi_label.set_markup("<b>NOTIFICA ALLARMI</b>")
  835. self.main_notebook.append_page(self.notifica_allarmi.notifica_allarmi_frame, notifica_allarmi_label)
  836. # azioni_veloci_page = AzioniVelociNotebookPage(self, self.aziendaStr).draw()
  837. # self.azioni_veloci_page = azioni_veloci_page
  838. # azioni_veloci_page_label = gtk.Label()
  839. # azioni_veloci_page_label.set_markup("<b>AZIONI VELOCI</b>")
  840. # self.main_notebook.append_page(azioni_veloci_page.azioni_veloci_frame, azioni_veloci_page_label)
  841. def statusBarHandler(self):
  842. textStatusBar = " PromoGest2 - 070 8649705 - www.promogest.me - info@promotux.it "
  843. context_id = self.pg2_statusbar.get_context_id("main_window")
  844. self.pg2_statusbar.push(context_id,textStatusBar)
  845. if Environment.rev_locale < Environment.rev_remota:
  846. self.active_img.set_from_file("gui/active_off.png")
  847. self.aggiornamento_label.set_label("DA AGGIORNARE!!! ")
  848. else:
  849. self.active_img.set_from_file("gui/active_on.png")
  850. self.aggiornamento_label.set_label("AGGIORNATO ")
  851. class MainWindowFrame(VistaPrincipale):
  852. def __init__(self, mainWindow, azs):
  853. VistaPrincipale.__init__(self, self.mainWindow, azs)
  854. class RegistrazioniFrame(GladeWidget):
  855. """ Frame per la gestione delle registrazioni """
  856. def __init__(self, mainWindow,azs):
  857. self.mainWindow = mainWindow
  858. self.aziendaStr = azs
  859. GladeWidget.__init__(self, 'registrazioni_select_frame', fileName='_registrazioni_select.glade')
  860. def on_documenti_button_clicked(self, toggleButton):
  861. if toggleButton.get_property('active') is False:
  862. return
  863. if not hasAction(actionID=2):return
  864. from promogest.ui.anagDocumenti.AnagraficaDocumenti import AnagraficaDocumenti
  865. anag = AnagraficaDocumenti(aziendaStr=self.aziendaStr)
  866. showAnagrafica(self.mainWindow, anag, toggleButton)
  867. def on_anagrafica_destroyed(anagrafica_window, argList):
  868. mainWindow = argList[0]
  869. anagraficaButton= argList[1]
  870. mainClass = argList[2]
  871. if anagrafica_window in Environment.windowGroup:
  872. Environment.windowGroup.remove(anagrafica_window)
  873. if anagraficaButton is not None:
  874. anagraficaButton.set_active(False)
  875. if mainClass is not None:
  876. mainClass.on_button_refresh_clicked()
  877. def showAnagrafica(window, anag, button=None, mainClass=None):
  878. anagWindow = anag.getTopLevel()
  879. anagWindow.connect("destroy", on_anagrafica_destroyed, [window, button, mainClass])
  880. #anagWindow.connect("hide", on_anagrafica_destroyed, [window, button,mainClass])
  881. anagWindow.set_transient_for(window)
  882. # setattr(anagWindow, "mainClass",mainClass)
  883. anagWindow.show_all()