class Page(wx.Panel): def __init__(self, *args, **kwds): kwds["style"] = wx.TAB_TRAVERSAL wx.Panel.__init__(self, *args, **kwds) self.dictTypes = {} self.sizer_dates_staticbox = wx.StaticBox(self, -1, "Dates du contrat") self.sizer_caract_staticbox = wx.StaticBox( self, -1, _(u"Caractéristiques générales")) self.sizer_essai_staticbox = wx.StaticBox(self, -1, _(u"Période d'essai")) self.label_titre = wx.StaticText( self, -1, _(u"2. Caractéristiques générales du contrat")) self.label_intro = wx.StaticText( self, -1, _(u"Saisissez les caractéristiques générales du contrat :")) self.label_type = wx.StaticText(self, -1, "Type de contrat :") self.choice_type = wx.Choice(self, -1, choices=[]) self.Importation_Type() self.bouton_type = wx.Button(self, -1, "...", style=wx.BU_EXACTFIT) self.label_class = wx.StaticText(self, -1, "Classification :") self.choice_class = wx.Choice(self, -1, choices=[]) self.Importation_classifications() self.bouton_class = wx.Button(self, -1, "...", style=wx.BU_EXACTFIT) self.label_valpoint = wx.StaticText(self, -1, "Valeur du point :") self.choice_valpoint = wx.Choice(self, -1, choices=[]) self.Importation_valPoint() self.bouton_valpoint = wx.Button(self, -1, "...", style=wx.BU_EXACTFIT) self.label_date_debut = wx.StaticText(self, -1, " A partir du :") self.datepicker_date_debut = DatePickerCtrl(self, -1, style=DP_DROPDOWN) self.label_date_fin = wx.StaticText(self, -1, "Jusqu'au :") self.datepicker_date_fin = DatePickerCtrl(self, -1, style=DP_DROPDOWN) self.datepicker_date_debut.Enable(False) self.datepicker_date_fin.Enable(False) self.check_rupture = wx.CheckBox( self, -1, _(u" Rupture anticipée du contrat au :")) self.datepicker_rupture = DatePickerCtrl(self, -1, style=DP_DROPDOWN) self.datepicker_rupture.Enable(False) self.label_essai = wx.StaticText(self, -1, _(u" Nbre de jours :")) self.periode_essai = wx.SpinCtrl(self, -1, "", size=(60, -1)) self.periode_essai.SetRange(0, 99) self.periode_essai.SetValue(0) self.aide_essai = wx.StaticText( self, -1, _(u" (1 jour par semaine travaillée)")) self.aide_essai.SetForegroundColour('Grey') self.__set_properties() self.__do_layout() self.Bind(wx.EVT_BUTTON, self.OnBoutonClassifications, self.bouton_class) self.Bind(wx.EVT_BUTTON, self.OnBoutonValPoint, self.bouton_valpoint) self.Bind(wx.EVT_BUTTON, self.OnBoutonType, self.bouton_type) self.Bind(wx.EVT_CHOICE, self.OnChoiceType, self.choice_type) self.Bind(wx.EVT_CHECKBOX, self.OnCheckRupture, self.check_rupture) self.Affichage_dateFin() # Importation des données if self.GetGrandParent().dictContrats["IDcontrat"] != 0: self.Importation() def __set_properties(self): self.label_titre.SetFont( wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, "")) self.bouton_type.SetMinSize((20, 20)) self.bouton_type.SetToolTip( wx.ToolTip( _(u"Cliquez ici pour ajouter, modifier ou supprimer des types de contrat" ))) self.bouton_class.SetMinSize((20, 20)) self.bouton_class.SetToolTip( wx.ToolTip( _(u"Cliquez ici pour ajouter, modifier ou supprimer des classifications" ))) self.bouton_valpoint.SetMinSize((20, 20)) self.bouton_valpoint.SetToolTip( wx.ToolTip( _(u"Cliquez ici pour ajouter, modifier ou supprimer des valeurs de points" ))) self.check_rupture.SetToolTip( wx.ToolTip( _(u"Cliquez ici pour saisir une date de fin de contrat si l'employeur ou le salarié ont mis fin prématurément au contrat." ))) def __do_layout(self): grid_sizer_base = wx.FlexGridSizer(rows=5, cols=1, vgap=10, hgap=10) sizer_dates = wx.StaticBoxSizer(self.sizer_dates_staticbox, wx.VERTICAL) grid_sizer_dates = wx.FlexGridSizer(rows=1, cols=4, vgap=10, hgap=10) grid_sizer_rupture = wx.FlexGridSizer(rows=1, cols=3, vgap=5, hgap=5) sizer_caract = wx.StaticBoxSizer(self.sizer_caract_staticbox, wx.VERTICAL) grid_sizer_caract = wx.FlexGridSizer(rows=3, cols=3, vgap=5, hgap=5) grid_sizer_base.Add(self.label_titre, 0, 0, 0) grid_sizer_base.Add(self.label_intro, 0, wx.LEFT, 20) grid_sizer_caract.Add(self.label_type, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer_caract.Add(self.choice_type, 0, wx.EXPAND, 0) grid_sizer_caract.Add(self.bouton_type, 0, 0, 0) grid_sizer_caract.Add(self.label_class, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer_caract.Add(self.choice_class, 0, wx.EXPAND, 0) grid_sizer_caract.Add(self.bouton_class, 0, 0, 0) grid_sizer_caract.Add(self.label_valpoint, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer_caract.Add(self.choice_valpoint, 0, wx.EXPAND, 0) grid_sizer_caract.Add(self.bouton_valpoint, 0, 0, 0) grid_sizer_caract.AddGrowableCol(1) sizer_caract.Add(grid_sizer_caract, 1, wx.ALL | wx.EXPAND, 5) grid_sizer_base.Add(sizer_caract, 1, wx.LEFT | wx.EXPAND, 20) grid_sizer_dates.Add(self.label_date_debut, 0, wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer_dates.Add(self.datepicker_date_debut, 0, 0, 0) grid_sizer_dates.Add(self.label_date_fin, 0, wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer_dates.Add(self.datepicker_date_fin, 0, 0, 0) sizer_dates.Add(grid_sizer_dates, 1, wx.ALL | wx.EXPAND, 5) grid_sizer_rupture.Add((90, 10), 1, wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer_rupture.Add(self.check_rupture, 0, wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer_rupture.Add(self.datepicker_rupture, 0, wx.ALIGN_CENTER_VERTICAL, 0) sizer_dates.Add(grid_sizer_rupture, 1, wx.EXPAND, 0) grid_sizer_base.Add(sizer_dates, 1, wx.LEFT | wx.EXPAND, 20) sizer_essai = wx.StaticBoxSizer(self.sizer_essai_staticbox, wx.VERTICAL) grid_sizer_essai = wx.FlexGridSizer(rows=1, cols=3, vgap=5, hgap=5) grid_sizer_essai.Add(self.label_essai, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer_essai.Add(self.periode_essai, 0, wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer_essai.Add(self.aide_essai, 0, wx.ALIGN_CENTER_VERTICAL, 0) sizer_essai.Add(grid_sizer_essai, 1, wx.ALL | wx.EXPAND, 5) grid_sizer_base.Add(sizer_essai, 1, wx.LEFT | wx.EXPAND, 20) self.SetSizer(grid_sizer_base) grid_sizer_base.Fit(self) grid_sizer_base.AddGrowableCol(0) def Importation(self): """ Remplit les controles avec les données importées si c'est une modification """ dictContrats = self.GetGrandParent().dictContrats # Controles Choice type = dictContrats["IDtype"] self.SelectChoice(self.choice_type, data=type) classification = dictContrats["IDclassification"] self.SelectChoice(self.choice_class, data=classification) valeur_point = dictContrats["valeur_point"] self.SelectChoice(self.choice_valpoint, data=valeur_point) # Radio et Date de Rupture if dictContrats["date_rupture"] != "": self.check_rupture.SetValue(True) self.datepicker_rupture.Enable(True) self.SetDatePicker(self.datepicker_rupture, dictContrats["date_rupture"]) else: self.check_rupture.SetValue(False) self.datepicker_rupture.Enable(False) # Dates de début et de fin date_debut = dictContrats["date_debut"] date_fin = dictContrats["date_fin"] if date_debut != "": self.SetDatePicker(self.datepicker_date_debut, dictContrats["date_debut"]) if date_fin != "" and date_fin != "2999-01-01": self.SetDatePicker(self.datepicker_date_fin, dictContrats["date_fin"]) self.datepicker_date_debut.Enable(True) self.datepicker_date_fin.Enable(True) if self.dictTypes[type] == "non": self.label_date_fin.Show(True) self.datepicker_date_fin.Show(True) else: self.label_date_fin.Show(False) self.datepicker_date_fin.Show(False) # Période d'essai essai = dictContrats["essai"] self.periode_essai.SetValue(essai) def CalcEssai(self): """ Calcule la durée de la période d'essai en fonction des dates du contrat """ essai = 0 # Si CDI if self.dictTypes[self.choice_type.GetClientData( self.choice_type.GetSelection())] == "oui": self.periode_essai.SetValue(30) return # Si CDD # Calcul de la durée du contrat date_tmp = self.datepicker_date_debut.GetValue() date_debut = datetime.date(date_tmp.GetYear(), date_tmp.GetMonth() + 1, date_tmp.GetDay()) date_tmp = self.datepicker_date_fin.GetValue() date_fin = datetime.date(date_tmp.GetYear(), date_tmp.GetMonth() + 1, date_tmp.GetDay()) if date_debut > date_fin: self.periode_essai.SetValue(0) return nbreJours = (date_fin - date_debut).days nbreSemaines = nbreJours // 7 print(nbreJours, nbreSemaines) self.periode_essai.SetValue(essai) def SetDatePicker(self, controle, date): """ Met une date dans un datePicker donné """ annee = int(date[:4]) mois = int(date[5:7]) - 1 jour = int(date[8:10]) date = wx.DateTime() date.Set(jour, mois, annee) controle.SetValue(date) def OnCheckRupture(self, event): if self.check_rupture.GetValue() == True: self.datepicker_rupture.Enable(True) else: self.datepicker_rupture.Enable(False) def OnChoiceType(self, event): self.datepicker_date_debut.Enable(True) self.datepicker_date_fin.Enable(True) self.Affichage_dateFin() self.CalcEssai() def Affichage_dateFin(self): """ Faire apparaitre ou disparaitre le controle DateFin en fonction du type de contrat choisi """ selection = self.choice_type.GetSelection() if selection != -1: IDselection = self.choice_type.GetClientData(selection) else: return if self.dictTypes[IDselection] == "non": self.label_date_fin.Show(True) self.datepicker_date_fin.Show(True) else: self.label_date_fin.Show(False) self.datepicker_date_fin.Show(False) def OnBoutonClassifications(self, event): dlg = DLG_Config_classifications.Dialog(self) dlg.ShowModal() dlg.Destroy() self.MAJ_choice_Class() def OnBoutonValPoint(self, event): dlg = DLG_Config_val_point.Dialog(self) dlg.ShowModal() dlg.Destroy() self.MAJ_choice_ValPoint() def OnBoutonType(self, event): dlg = DLG_Config_types_contrats.Dialog(self) dlg.ShowModal() dlg.Destroy() self.MAJ_choice_Type() def MAJ_choice_Class(self): self.Importation_classifications() def Importation_classifications(self): controle = self.choice_class selection = controle.GetSelection() IDselection = None if selection != -1: IDselection = controle.GetClientData(selection) # Récupération des données DB = GestionDB.DB() req = """SELECT * FROM contrats_class """ DB.ExecuterReq(req) liste = DB.ResultatReq() DB.Close() # Placement de la liste dans le Choice controle.Clear() x = 0 for key, valeur in liste: controle.Append(valeur, key) if IDselection == key: controle.SetSelection(x) x += 1 def MAJ_choice_ValPoint(self): self.Importation_valPoint() def Importation_valPoint(self): controle = self.choice_valpoint selection = controle.GetSelection() IDselection = None if selection != -1: IDselection = controle.GetClientData(selection) # Récupération des données DB = GestionDB.DB() req = """SELECT * FROM valeurs_point ORDER BY date_debut """ DB.ExecuterReq(req) liste = DB.ResultatReq() DB.Close() # Recherche de la valeur actuelle dateJour = str(datetime.date.today()) valeurActuelle = None for ID, valeur, dateDebut in liste: if dateJour >= dateDebut: valeurActuelle = ID # Placement de la liste dans le Choice controle.Clear() x = 0 for ID, valeur, dateDebut in liste: txt = str(valeur) + _(u" ¤ (à partir du " ) + FonctionsPerso.DateEngFr(dateDebut) + ")" controle.Append(txt, ID) # Sélection de l'ancienne valeur sélectionnée if IDselection == ID: controle.SetSelection(x) # Sélection de la valeur actuelle si rien n'a été sélectionnée if IDselection == None and valeurActuelle == ID: controle.SetSelection(x) x += 1 self.listeValPoint = liste def MAJ_choice_Type(self): self.Importation_Type() def Importation_Type(self): controle = self.choice_type selection = controle.GetSelection() IDselection = None if selection != -1: IDselection = controle.GetClientData(selection) # Récupération des données DB = GestionDB.DB() req = """SELECT * FROM contrats_types """ DB.ExecuterReq(req) liste = DB.ResultatReq() DB.Close() # Placement de la liste dans le Choice controle.Clear() self.dictTypes = {} x = 0 for key, nom, nom_abrege, duree_indeterminee in liste: self.dictTypes[key] = duree_indeterminee controle.Append(nom, key) if IDselection == key: controle.SetSelection(x) x += 1 if selection != -1: self.Affichage_dateFin() def GetDatePickerValue(self, controle): date_tmp = controle.GetValue() return str( datetime.date(date_tmp.GetYear(), date_tmp.GetMonth() + 1, date_tmp.GetDay())) def GetChoiceData(self, controle): selection = controle.GetSelection() if selection != -1: IDselection = controle.GetClientData(selection) else: IDselection = None return IDselection def SelectChoice(self, controle, data): nbreItems = controle.GetCount() index = 0 for item in range(nbreItems): if controle.GetClientData(index) == data: controle.SetSelection(index) return index += 1 def Validation(self): # Récupération des valeurs saisies type = self.GetChoiceData(self.choice_type) classification = self.GetChoiceData(self.choice_class) valPoint = self.GetChoiceData(self.choice_valpoint) date_debut = self.GetDatePickerValue(self.datepicker_date_debut) date_fin = self.GetDatePickerValue(self.datepicker_date_fin) rupture = self.check_rupture.GetValue() date_rupture = self.GetDatePickerValue(self.datepicker_rupture) essai = self.periode_essai.GetValue() # Vérifie que des valeurs ont été saisies if type == None: dlg = wx.MessageDialog( self, _(u"Vous devez sélectionner un type de contrat dans la liste proposée." ), "Erreur", wx.OK) dlg.ShowModal() dlg.Destroy() self.choice_type.SetFocus() return False if classification == None: dlg = wx.MessageDialog( self, _(u"Vous devez sélectionner une classification dans la liste proposée." ), "Erreur", wx.OK) dlg.ShowModal() dlg.Destroy() self.choice_class.SetFocus() return False if valPoint == None: dlg = wx.MessageDialog( self, _(u"Vous devez sélectionner une valeur de point dans la liste proposée." ), "Erreur", wx.OK) dlg.ShowModal() dlg.Destroy() self.choice_valpoint.SetFocus() return False # Vérifie que la date de fin est supérieure à la date de début de contrat if date_debut > date_fin and self.datepicker_date_fin.IsShown(): dlg = wx.MessageDialog( self, _(u"La date de fin de contrat que vous avez saisie est inférieure à la date de début !" ), "Erreur", wx.OK) dlg.ShowModal() dlg.Destroy() self.datepicker_date_fin.SetFocus() return False # Vérifie que la date de rupture est supérieure à la date de début de contrat if date_debut > date_rupture and rupture == True: dlg = wx.MessageDialog( self, _(u"La date de rupture de contrat que vous avez saisie est inférieure à la date de début !" ), "Erreur", wx.OK) dlg.ShowModal() dlg.Destroy() self.datepicker_date_fin.SetFocus() return False # Vérifie que la date de rupture est supérieure à la date de début de contrat et inférieure à la date de fin si contrat à durée déterminée : if self.datepicker_date_fin.IsShown( ) and date_rupture >= date_fin and rupture == True: dlg = wx.MessageDialog( self, _(u"La date de rupture de contrat que vous avez saisie est égale ou supérieure à la date de fin de contrat !" ), "Erreur", wx.OK) dlg.ShowModal() dlg.Destroy() self.datepicker_date_fin.SetFocus() return False # Vérifie que la valeur du point correspondant bien à la date de début de contrat valeurNecessaire = None for ID, valeur, dateValeur in self.listeValPoint: if date_debut >= dateValeur: valeurNecessaire = ID if valeurNecessaire == None: dlg = wx.MessageDialog( self, _(u"La valeur du point n'est pas correcte. Il n'existe pas dans la liste proposée de valeur correspondante à la date de début de contrat. \n\nVous devez donc créer une nouvelle valeur. \n\nSouhaitez-vous le faire maintenant ?" ), "Erreur", wx.ICON_QUESTION | wx.YES_NO | wx.NO_DEFAULT) if dlg.ShowModal() == wx.ID_NO: dlg.Destroy() return False else: dlg.Destroy() self.OnBoutonValPoint(None) return False if valeurNecessaire != valPoint: dlg = wx.MessageDialog( self, _(u"La valeur du point ne correspond pas à la date de début du contrat. Vous devez sélectionner une autre valeur de points dans la liste proposée.\n\nVoulez-vous que je le fasse à votre place ?" ), "Erreur", wx.ICON_QUESTION | wx.YES_NO | wx.NO_DEFAULT) if dlg.ShowModal() == wx.ID_NO: dlg.Destroy() return False else: dlg.Destroy() # Sélection automatique de la bonne valeur de point for index in range(self.choice_valpoint.GetCount()): if self.choice_valpoint.GetClientData( index) == valeurNecessaire: self.choice_valpoint.SetSelection(index) return False # Période d'essai if essai == "": dlg = wx.MessageDialog( self, _(u"Vous devez saisir un nombre de jours pour période d'essai." ), "Erreur", wx.OK) dlg.ShowModal() dlg.Destroy() return False if essai == 0: dlg = wx.MessageDialog( self, _(u"Vous n'avez pas défini de période d'essai. \n\nSouhaitez-vous quand même continuer ? \n(Sinon cliquez 'non' ou 'annuler')" ), "Erreur de saisie", wx.ICON_QUESTION | wx.YES_NO | wx.CANCEL | wx.NO_DEFAULT) if dlg.ShowModal() == wx.ID_YES: dlg.Destroy() else: dlg.Destroy() return False # Mémorisation des données dictContrats = self.GetGrandParent().dictContrats dictContrats["IDtype"] = type dictContrats["IDclassification"] = classification dictContrats["valeur_point"] = valPoint dictContrats["date_debut"] = date_debut if self.datepicker_date_fin.IsShown(): dictContrats["date_fin"] = date_fin else: dictContrats["date_fin"] = "2999-01-01" if rupture == True: dictContrats["date_rupture"] = date_rupture else: dictContrats["date_rupture"] = "" dictContrats["essai"] = essai return True
class DataBaseManagement(scrolled.ScrolledPanel): def __init__(self, parent, statusbar): scrolled.ScrolledPanel.__init__(self, parent) self.statusbar = statusbar self.parent = parent if _platform == "linux" or _platform == "linux2": size_StaticBox = (950, 140) size_combobox = (130, -1) font = wx.Font(10, wx.DEFAULT, wx.ITALIC, wx.BOLD) font_combobox = wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, u'Arial') font_TextCtrl = wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, u'Arial') vStatictextsize = 16 size_text = (85, 22) elif _platform == "win32": size_StaticBox = (960, 140) size_combobox = (130, -1) font = wx.Font(9, wx.DEFAULT, wx.ITALIC, wx.BOLD) font_combobox = wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, u'Arial') font_TextCtrl = wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, u'Arial') vStatictextsize = 16 size_text = (85, 22) elif _platform == 'darwin': size_StaticBox = (980, 140) size_combobox = (130, -1) font = wx.Font(12, wx.DEFAULT, wx.ITALIC, wx.BOLD) font_combobox = wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, u'Arial') font_TextCtrl = wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, u'Arial') vStatictextsize = 18 size_text = (85, 22) flagSizer = wx.ALL | wx.ALIGN_CENTER_VERTICAL """Action box""" action_box = wx.StaticBox(self, -1, " Select your action ", size=size_StaticBox) action_box.SetFont(font) action_box_sizer = wx.StaticBoxSizer(action_box, wx.VERTICAL) in_action_box_sizer = wx.GridBagSizer(hgap=2, vgap=0) label_1 = b"Show selected data" label_2 = b"Delete some data" self.rb1 = wx.RadioButton(self, label=label_1, style=wx.RB_GROUP) self.rb2 = wx.RadioButton(self, label=label_2) self.rb1.Bind(wx.EVT_RADIOBUTTON, self.on_set_val) self.rb2.Bind(wx.EVT_RADIOBUTTON, self.on_set_val) self.state = [True, False] self.rb1.SetValue(True) in_action_box_sizer.Add(self.rb1, pos=(0, 0), flag=flagSizer) in_action_box_sizer.Add(self.rb2, pos=(2, 0), flag=flagSizer) action_box_sizer.Add(in_action_box_sizer, 0, wx.ALL, 5) """ Id part """ self.search_Id = wx.NewId() self.cb_name_Id = wx.NewId() self.name_Id = wx.NewId() self.cb_crystal_Id = wx.NewId() self.crystal_Id = wx.NewId() self.cb_geom_Id = wx.NewId() self.geom_Id = wx.NewId() self.cb_model_Id = wx.NewId() self.model_Id = wx.NewId() self.cb_date_Id = wx.NewId() self.date_Id = wx.NewId() self.Id_cb_list = [ self.cb_name_Id, self.cb_crystal_Id, self.cb_geom_Id, self.cb_model_Id, self.cb_date_Id ] self.Id_combo_list = [ self.name_Id, self.crystal_Id, self.geom_Id, self.model_Id ] cb_name = wx.CheckBox(self, id=self.cb_name_Id, label='Name', pos=(20, 20)) cb_name.SetValue(False) cb_name.Bind(wx.EVT_CHECKBOX, self.un_check_choice) name_choice = ["None"] self.name = wx.ComboBox(self, id=self.name_Id, pos=(50, 30), choices=name_choice, style=wx.CB_READONLY, size=size_combobox) self.name.SetFont(font_combobox) self.Bind(wx.EVT_COMBOBOX, self.on_select_combobox, self.name) cb_crystal = wx.CheckBox(self, id=self.cb_crystal_Id, label='Crystal', pos=(20, 20)) cb_crystal.SetValue(False) cb_crystal.Bind(wx.EVT_CHECKBOX, self.un_check_choice) crystal_choice = ["None"] self.crystal = wx.ComboBox(self, id=self.crystal_Id, pos=(50, 30), choices=crystal_choice, style=wx.CB_READONLY, size=size_combobox) self.crystal.SetFont(font_combobox) self.Bind(wx.EVT_COMBOBOX, self.on_select_combobox, self.crystal) cb_geom = wx.CheckBox(self, id=self.cb_geom_Id, label='Geometry', pos=(20, 20)) cb_geom.SetValue(False) cb_geom.Bind(wx.EVT_CHECKBOX, self.un_check_choice) geom_choice = ["None"] self.geom = wx.ComboBox(self, id=self.geom_Id, pos=(50, 30), choices=geom_choice, style=wx.CB_READONLY, size=size_combobox) self.geom.SetFont(font_combobox) self.Bind(wx.EVT_COMBOBOX, self.on_select_combobox, self.geom) cb_model = wx.CheckBox(self, id=self.cb_model_Id, label='Model', pos=(20, 20)) cb_model.SetValue(False) cb_model.Bind(wx.EVT_CHECKBOX, self.un_check_choice) model_choice = ["None"] self.model = wx.ComboBox(self, id=self.model_Id, pos=(50, 30), choices=model_choice, style=wx.CB_READONLY, size=size_combobox) self.model.SetFont(font_combobox) self.Bind(wx.EVT_COMBOBOX, self.on_select_combobox, self.model) cb_date = wx.CheckBox(self, id=self.cb_date_Id, label='Date', pos=(20, 20)) cb_date.SetValue(False) cb_date.Bind(wx.EVT_CHECKBOX, self.un_check_choice) now = wx.DateTime().Today() self.dpc_1 = DatePickerCtrl(self, size=(120, -1), style=DP_DROPDOWN | DP_SHOWCENTURY | DP_ALLOWNONE) self.dpc_2 = DatePickerCtrl(self, size=(120, -1), style=DP_DROPDOWN | DP_SHOWCENTURY | DP_ALLOWNONE) self.Bind(EVT_DATE_CHANGED, self.on_select_combobox, self.dpc_1) self.Bind(EVT_DATE_CHANGED, self.on_select_combobox, self.dpc_2) self.dpc_1.SetValue(now) self.dpc_2.SetValue(now) date_choice = ["None"] self.date = wx.ComboBox(self, id=self.date_Id, pos=(50, 30), choices=date_choice, style=wx.CB_READONLY, size=size_combobox) self.date.SetFont(font_combobox) self.Bind(wx.EVT_COMBOBOX, self.on_select_combobox, self.date) self.search_btn = wx.Button(self, id=self.search_Id, label=" Search") self.search_btn.Bind(wx.EVT_BUTTON, self.on_search_in_DB) txt_db = u'DataBase number of lines:' db_nb_lines_txt = wx.StaticText(self, -1, label=txt_db, size=(180, vStatictextsize)) self.db_nb_lines = wx.TextCtrl(self, style=wx.TE_PROCESS_ENTER, size=size_text, validator=TextValidator(DIGIT_ONLY)) self.db_nb_lines.SetFont(font_TextCtrl) self.db_nb_lines.SetValue(str(100)) P4Rm.db_nb_line = 100 bmp = _bp_btn2.GetBitmap() self.nb_lines_btn = wx.BitmapButton(self, -1, bmp) self.nb_lines_btn.SetToolTip("Update database list") # self.nb_lines_btn.SetToolTipString("Update database list") self.Bind(wx.EVT_BUTTON, self.nb_lines_DB, id=self.nb_lines_btn.GetId()) self.Bind(wx.EVT_TEXT_ENTER, self.nb_lines_DB, self.db_nb_lines) self.cb_list = [cb_name, cb_crystal, cb_geom, cb_model, cb_date] self.combo_list = [ self.name, self.crystal, self.geom, self.model, self.date ] for i in range(len(self.combo_list)): self.combo_list[i].Disable() mastersizer = wx.BoxSizer(wx.VERTICAL) DBLine = wx.BoxSizer(wx.HORIZONTAL) choice_sizer = wx.GridBagSizer(hgap=8, vgap=4) DBLine.Add(db_nb_lines_txt, 0, flag=flagSizer) DBLine.Add(self.db_nb_lines, 0, flag=flagSizer) DBLine.Add(self.nb_lines_btn, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 5) choice_sizer.Add(cb_name, pos=(0, 0), flag=flagSizer) choice_sizer.Add(self.name, pos=(0, 1), flag=flagSizer) choice_sizer.Add(cb_crystal, pos=(1, 0), flag=flagSizer) choice_sizer.Add(self.crystal, pos=(1, 1), flag=flagSizer) choice_sizer.Add(cb_geom, pos=(2, 0), flag=flagSizer) choice_sizer.Add(self.geom, pos=(2, 1), flag=flagSizer) choice_sizer.Add(cb_model, pos=(3, 0), flag=flagSizer) choice_sizer.Add(self.model, pos=(3, 1), flag=flagSizer) choice_sizer.Add(cb_date, pos=(4, 0), flag=flagSizer) choice_sizer.Add(self.date, pos=(4, 1), flag=flagSizer) choice_sizer.Add(self.dpc_1, pos=(4, 2), flag=flagSizer) choice_sizer.Add(self.dpc_2, pos=(4, 3), flag=flagSizer) choice_sizer.Add(self.search_btn, pos=(6, 0), flag=flagSizer) mastersizer.Add(action_box_sizer, 0, wx.ALL, 5) mastersizer.Add(DBLine, 0, wx.ALL, 10) mastersizer.Add(choice_sizer, 0, wx.ALL, 10) pub.subscribe(self.on_delete_data, pubsub_sup_data_DB) pub.subscribe(self.on_add_new_name_to_combobox, pubsub_refill_list_name_DB) pub.subscribe(self.on_search_in_DB, pubsub_search_combobox_DB) self.SetSizer(mastersizer) self.Layout() self.SetAutoLayout(1) self.SetupScrolling() self.on_fill_combobox() def on_set_val(self, event): self.state = [] state1 = self.rb1.GetValue() state2 = self.rb2.GetValue() self.state = [state1, state2] def on_fill_combobox(self): a = P4Rm() choice_list = [] c = DataBaseUse() c.on_read_part_DB() if P4Rm.DBDict['name']: choice_list.append(a.DBDict['name']) else: choice_list.append(["List empty"]) choice_list.append(a.crystal_list) choice_list.append(p4R.sample_geometry) choice_list.append(p4R.Strain_DW_choice) choice_list.append(["equal", "=<", ">=", "between"]) for i in range(len(self.combo_list)): self.combo_list[i].SetItems(choice_list[i]) self.combo_list[i].SetStringSelection(choice_list[i][0]) self.dpc_1.Hide() self.dpc_2.Hide() def on_add_new_name_to_combobox(self): a = P4Rm() if not a.PathDict['project_name'] in a.DBDict['name']: c = DataBaseUse() c.on_read_part_DB() self.name.SetItems(a.DBDict['name']) self.name.SetStringSelection(a.DBDict['name'][0]) self.Layout() self.SetAutoLayout(1) def un_check_choice(self, event): widget = event.GetId() isChecked = event.GetEventObject().GetValue() indexx = self.Id_cb_list.index(widget) if isChecked: self.combo_list[indexx].Enable() else: self.combo_list[indexx].Disable() if widget == self.cb_date_Id: if isChecked: self.dpc_1.Show() if self.date.GetStringSelection() == 'between': self.dpc_2.Show() else: self.dpc_1.Hide() self.dpc_2.Hide() def on_select_combobox(self, event): widget = event.GetId() val = event.GetString() if widget == self.date_Id: if val == 'between': self.dpc_2.Show() else: self.dpc_2.Hide() def nb_lines_DB(self, event): obj = self.db_nb_lines.GetValue() P4Rm.db_nb_line = int(obj) pub.sendMessage(pubsub_update_db_nb_line) def on_search_in_DB(self, event=None): list_temp = [] P4Rm.DBDict['choice_state'] = self.rb1.GetValue() for i in range(len(self.cb_list)): if self.cb_list[i].IsChecked(): list_temp.append(self.combo_list[i].GetStringSelection()) else: list_temp.append(None) P4Rm.DBDict['choice_combo'] = list_temp if self.cb_list[-1].IsChecked(): P4Rm.DBDict['date_1'] = '{:%Y-%m-%d %H:%M:%S}'.format( wxdate2pydate(self.dpc_1.GetValue())) P4Rm.DBDict['date_2'] = '{:%Y-%m-%d %H:%M:%S}'.format( wxdate2pydate(self.dpc_2.GetValue())) c = DataBaseUse() c.on_search_in_DB() def on_delete_data(self): a = P4Rm() _msg = "Do you really want to delete these datas?" dlg = GMD.GenericMessageDialog(None, _msg, "Confirm Suppression", agwStyle=wx.OK | wx.CANCEL | wx.ICON_QUESTION) result = dlg.ShowModal() dlg.Destroy() if result == wx.ID_OK: c = DataBaseUse() c.on_delete_data() self.on_fill_combobox() state1 = self.rb1.SetValue(True) state2 = self.rb2.SetValue(False) self.state = [state1, state2] for i in range(len(self.cb_list)): self.cb_list[i].SetValue(False) self.combo_list[i].Disable() empty = a.DBDict['session'].query(RadMaxData).first() if empty is None: s = a.DBDict['session'].query(RadMaxData).order_by( RadMaxData.id) c.on_read_database_and_fill_list(s) else: self.on_search_in_DB()
class Dialog(wx.Dialog): def __init__(self, parent, title="", IDferie=0, type=""): wx.Dialog.__init__(self, parent, -1, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER | wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX) self.typeJour = type self.panel_base = wx.Panel(self, -1) self.staticBox_staticbox = wx.StaticBox(self.panel_base, -1, "") self.label_nom = wx.StaticText(self.panel_base, -1, "Nom :") self.text_ctrl_nom = wx.TextCtrl(self.panel_base, -1, "") self.label_jour_fixe = wx.StaticText(self.panel_base, -1, "Jour :") choices = [] for x in range(1, 32): choices.append(str(x)) self.choice_jour_fixe = wx.Choice(self.panel_base, -1, choices=choices) self.label_mois_fixe = wx.StaticText(self.panel_base, -1, "Mois :") self.choice_mois_fixe = wx.Choice(self.panel_base, -1, choices=[ "Janvier", _(u"Février"), "Mars", "Avril", "Mai", "Juin", "Juillet", _(u"Août"), "Septembre", "Octobre", "Novembre", _(u"Décembre") ]) self.label_date_variable = wx.StaticText(self.panel_base, -1, "Date :") self.datepicker_date_variable = DatePickerCtrl(self.panel_base, -1, style=DP_DROPDOWN) self.bouton_aide = CTRL_Bouton_image.CTRL( self.panel_base, texte=_(u"Aide"), cheminImage=Chemins.GetStaticPath("Images/32x32/Aide.png")) self.bouton_ok = CTRL_Bouton_image.CTRL( self.panel_base, texte=_(u"Ok"), cheminImage=Chemins.GetStaticPath("Images/32x32/Valider.png")) self.bouton_annuler = CTRL_Bouton_image.CTRL( self.panel_base, texte=_(u"Annuler"), cheminImage=Chemins.GetStaticPath("Images/32x32/Annuler.png")) self.IDferie = IDferie if IDferie != 0: self.Importation() self.__set_properties() self.__do_layout() self.Bind(wx.EVT_BUTTON, self.OnBoutonAide, self.bouton_aide) self.Bind(wx.EVT_BUTTON, self.OnBoutonOk, self.bouton_ok) self.Bind(wx.EVT_BUTTON, self.OnBoutonAnnuler, self.bouton_annuler) def __set_properties(self): self.SetTitle(_(u"Saisie d'un jour férié")) if 'phoenix' in wx.PlatformInfo: _icon = wx.Icon() else: _icon = wx.EmptyIcon() _icon.CopyFromBitmap( wx.Bitmap(Chemins.GetStaticPath("Images/16x16/Logo.png"), wx.BITMAP_TYPE_ANY)) self.SetIcon(_icon) self.choice_jour_fixe.SetMinSize((50, -1)) self.choice_mois_fixe.SetMinSize((130, 21)) self.bouton_aide.SetToolTip( wx.ToolTip("Cliquez ici pour obtenir de l'aide")) self.bouton_aide.SetSize(self.bouton_aide.GetBestSize()) self.bouton_ok.SetToolTip(wx.ToolTip("Cliquez ici pour valider")) self.bouton_ok.SetSize(self.bouton_ok.GetBestSize()) self.bouton_annuler.SetToolTip( wx.ToolTip("Cliquez ici pour annuler la saisie")) self.bouton_annuler.SetSize(self.bouton_annuler.GetBestSize()) def __do_layout(self): sizer_base = wx.BoxSizer(wx.VERTICAL) sizer_base_2 = wx.BoxSizer(wx.VERTICAL) grid_sizer_base = wx.FlexGridSizer(rows=2, cols=1, vgap=0, hgap=0) grid_sizer_boutons = wx.FlexGridSizer(rows=1, cols=4, vgap=10, hgap=10) staticBox = wx.StaticBoxSizer(self.staticBox_staticbox, wx.VERTICAL) grid_sizer_staticBox = wx.FlexGridSizer(rows=3, cols=1, vgap=10, hgap=10) grid_sizer_variable = wx.FlexGridSizer(rows=1, cols=2, vgap=5, hgap=5) grid_sizer_fixe = wx.FlexGridSizer(rows=1, cols=5, vgap=5, hgap=5) grid_sizer_nom = wx.FlexGridSizer(rows=1, cols=2, vgap=5, hgap=5) grid_sizer_nom.Add(self.label_nom, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer_nom.Add(self.text_ctrl_nom, 0, wx.EXPAND, 0) grid_sizer_nom.AddGrowableCol(1) grid_sizer_staticBox.Add(grid_sizer_nom, 1, wx.EXPAND, 0) grid_sizer_fixe.Add(self.label_jour_fixe, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer_fixe.Add(self.choice_jour_fixe, 0, wx.RIGHT, 10) grid_sizer_fixe.Add(self.label_mois_fixe, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer_fixe.Add(self.choice_mois_fixe, 0, wx.EXPAND, 0) grid_sizer_fixe.AddGrowableCol(4) grid_sizer_staticBox.Add(grid_sizer_fixe, 1, wx.EXPAND, 0) grid_sizer_variable.Add(self.label_date_variable, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer_variable.Add(self.datepicker_date_variable, 0, 0, 0) grid_sizer_staticBox.Add(grid_sizer_variable, 1, wx.EXPAND, 0) grid_sizer_staticBox.AddGrowableCol(0) staticBox.Add(grid_sizer_staticBox, 1, wx.ALL | wx.EXPAND, 10) grid_sizer_base.Add(staticBox, 1, wx.ALL | wx.EXPAND, 10) grid_sizer_boutons.Add(self.bouton_aide, 0, 0, 0) grid_sizer_boutons.Add((20, 20), 0, 0, 0) grid_sizer_boutons.Add(self.bouton_ok, 0, 0, 0) grid_sizer_boutons.Add(self.bouton_annuler, 0, 0, 0) grid_sizer_boutons.AddGrowableCol(1) grid_sizer_base.Add(grid_sizer_boutons, 1, wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, 10) sizer_base_2.Add(grid_sizer_base, 1, wx.EXPAND, 0) self.panel_base.SetSizer(sizer_base_2) sizer_base.Add(self.panel_base, 1, wx.EXPAND, 0) self.SetSizer(sizer_base) # Affiche en fonction du type de de jour férié if self.typeJour == "fixe": self.label_date_variable.Show(False) self.datepicker_date_variable.Show(False) else: self.label_jour_fixe.Show(False) self.choice_jour_fixe.Show(False) self.label_mois_fixe.Show(False) self.choice_mois_fixe.Show(False) sizer_base.Fit(self) self.Layout() self.CenterOnScreen() def Importation(self): DB = GestionDB.DB() req = "SELECT * FROM jours_feries WHERE IDferie=%d" % self.IDferie DB.ExecuterReq(req) donnees = DB.ResultatReq()[0] DB.Close() if len(donnees) == 0: return # Récupération des données type = donnees[1] nom = donnees[2] jour = donnees[3] mois = donnees[4] annee = donnees[5] # Place le nom self.text_ctrl_nom.SetValue(nom) # Place le jour et le mois si c'est un jour fixe if type == "fixe": self.choice_jour_fixe.SetSelection(jour - 1) self.choice_mois_fixe.SetSelection(mois - 1) # Place la date dans le cdatePicker si c'est une date variable else: date = wx.DateTime() date.Set(jour, mois - 1, annee) self.datepicker_date_variable.SetValue(date) def Sauvegarde(self): """ Sauvegarde des données dans la base de données """ # Récupération ds valeurs saisies varNom = self.text_ctrl_nom.GetValue() if self.typeJour == "fixe": varJour = self.choice_jour_fixe.GetSelection() + 1 varMois = self.choice_mois_fixe.GetSelection() + 1 varAnnee = 0 else: date_tmp = self.datepicker_date_variable.GetValue() varJour = date_tmp.GetDay() varMois = date_tmp.GetMonth() + 1 varAnnee = date_tmp.GetYear() DB = GestionDB.DB() # Création de la liste des données listeDonnees = [ ("type", self.typeJour), ("nom", varNom), ("jour", varJour), ("mois", varMois), ("annee", varAnnee), ] if self.IDferie == 0: # Enregistrement d'une nouvelle valeur newID = DB.ReqInsert("jours_feries", listeDonnees) ID = newID else: # Modification de la valeur DB.ReqMAJ("jours_feries", listeDonnees, "IDferie", self.IDferie) ID = self.IDferie DB.Commit() DB.Close() return ID def OnBoutonAide(self, event): from Utils import UTILS_Aide UTILS_Aide.Aide("Lesjoursfris") def OnBoutonAnnuler(self, event): self.EndModal(wx.ID_CANCEL) def OnBoutonOk(self, event): """ Validation des données saisies """ varNom = self.text_ctrl_nom.GetValue() if varNom == "": dlg = wx.MessageDialog( self, _(u"Vous devez saisir un nom pour ce jour férié. Par exemple : 'Lundi de Pâques'..." ), "Erreur", wx.OK) dlg.ShowModal() dlg.Destroy() self.text_ctrl_nom.SetFocus() return if self.typeJour == "fixe": varJour = self.choice_jour_fixe.GetSelection() if varJour == -1 or varJour == None: dlg = wx.MessageDialog( self, _(u"Vous devez sélectionner un jour pour ce jour férié !" ), "Erreur", wx.OK) dlg.ShowModal() dlg.Destroy() self.choice_jour_fixe.SetFocus() return varMois = self.choice_mois_fixe.GetSelection() if varMois == -1 or varMois == None: dlg = wx.MessageDialog( self, _(u"Vous devez sélectionner un mois pour ce jour férié !" ), "Erreur", wx.OK) dlg.ShowModal() dlg.Destroy() self.choice_mois_fixe.SetFocus() return # Sauvegarde self.Sauvegarde() # MAJ du listCtrl des valeurs de points if FonctionsPerso.FrameOuverte("Config_jours_feries_" + self.typeJour) != None: self.GetParent().MAJ_ListCtrl() # Fermeture self.EndModal(wx.ID_OK)