def __init__(self, *args, **kwds): # begin wxGlade: GestionProduits.__init__ kwds["style"] = wx.TAB_TRAVERSAL wx.Panel.__init__(self, *args, **kwds) self.label_serveur = wx.StaticText(self, -1, "Serveur SMTP") self.tc_serveur = wx.TextCtrl(self, -1, "", validator=GenericTextValidator()) self.label_port = wx.StaticText(self, -1, "Port") self.tc_port = wx.TextCtrl(self, -1, "", validator=GenericTextValidator(flag=VALIDATE_INT)) self.label_securite = wx.StaticText(self, -1, "Cryptage") self.cb_securite = wx.ComboBox(self, -1, choices=["Aucun", "STARTTLS", "SSL/TLS"], style=wx.CB_DROPDOWN|wx.CB_READONLY) self.label_login = wx.StaticText(self, -1, "Login") self.tc_login = wx.TextCtrl(self, -1, "") self.label_mdp = wx.StaticText(self, -1, "Mot de passe") self.tc_mdp = wx.TextCtrl(self, -1, "", style=wx.TE_PASSWORD) self.bouton_test_serveur = wx.Button(self, -1, u"Tester les paramètres du Serveur") self.bouton_sauvegarder = wx.Button(self, -1, u"Sauvegarder la configuration SMTP") self.throbber = AnimationCtrl(self) self.throbber.SetAnimation(Animation("../icons/32x32/throbber6.gif")) self.throbber.Play() self.server = None self.thread = None self.__set_properties() self.__set_values() self.__do_layout() self.throbber.Hide() self.Bind(wx.EVT_BUTTON, self.OnTestServeur, self.bouton_test_serveur) self.Bind(wx.EVT_BUTTON, self.OnSauvegarde, self.bouton_sauvegarder)
def __init__(self, parent, log): self.controls = [None] * 5 self.timeStart = None self.log = log wx.StatusBar.__init__(self, parent, -1) self.SetFieldsCount(len(self.controls)) self.controls[0] = wx.StaticText(self, label=self.TEXT_GENERAL, style=wx.ST_NO_AUTORESIZE) self.controls[1] = wx.StaticText(self, label=self.TEXT_INFO, style=wx.ST_NO_AUTORESIZE) self.controls[2] = Led(self, label=self.TEXT_GPS) self.controls[3] = wx.Gauge(self, -1, style=wx.GA_HORIZONTAL | wx.GA_SMOOTH) animation = Animation(get_resource_path('busy.gif')) busy = AnimationCtrl(self, anim=animation) busy.SetToolTipString('Updating plot') self.controls[4] = busy self.controls[3].Hide() self.controls[4].Hide() self.SetStatusWidths([-1, -1, -1, -1, busy.GetSize()[0] * 4]) self.Bind(wx.EVT_SIZE, self.__on_size) wx.CallAfter(self.__on_size, None) self.Fit()
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self._animate = Animation(self.value) self.control = AnimationCtrl(parent, -1, self._animate) self.control.SetUseWindowBackgroundColour() self.sync_value(self.factory.playing, "playing", "from") self.set_tooltip()
class _AnimatedGIFEditor(Editor): """ Editor that displays an animated GIF file. """ #--------------------------------------------------------------------------- # Trait definitions: #--------------------------------------------------------------------------- # Is the animated GIF file currently playing? playing = Bool(True) #--------------------------------------------------------------------------- # Finishes initializing the editor by creating the underlying toolkit # widget: #--------------------------------------------------------------------------- def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self._animate = Animation(self.value) self.control = AnimationCtrl(parent, -1, self._animate) self.control.SetUseWindowBackgroundColour() self.sync_value(self.factory.playing, 'playing', 'from') self.set_tooltip() #--------------------------------------------------------------------------- # Updates the editor when the object trait changes external to the editor: #--------------------------------------------------------------------------- def update_editor(self): """ Updates the editor when the object trait changes externally to the editor. """ if not self.playing: self.control.Stop() self.control.LoadFile(self.value) self._file_loaded = True if self.playing: self.control.Play() #--------------------------------------------------------------------------- # Handles the editor 'playing' trait being changed: #--------------------------------------------------------------------------- def _playing_changed(self): if self._file_loaded: if self.playing: self.control.Play() else: self.control.Stop()
class ConfigSMTP(wx.Panel): def __init__(self, *args, **kwds): # begin wxGlade: GestionProduits.__init__ kwds["style"] = wx.TAB_TRAVERSAL wx.Panel.__init__(self, *args, **kwds) self.label_serveur = wx.StaticText(self, -1, "Serveur SMTP") self.tc_serveur = wx.TextCtrl(self, -1, "", validator=GenericTextValidator()) self.label_port = wx.StaticText(self, -1, "Port") self.tc_port = wx.TextCtrl(self, -1, "", validator=GenericTextValidator(flag=VALIDATE_INT)) self.label_securite = wx.StaticText(self, -1, "Cryptage") self.cb_securite = wx.ComboBox(self, -1, choices=["Aucun", "STARTTLS", "SSL/TLS"], style=wx.CB_DROPDOWN|wx.CB_READONLY) self.label_login = wx.StaticText(self, -1, "Login") self.tc_login = wx.TextCtrl(self, -1, "") self.label_mdp = wx.StaticText(self, -1, "Mot de passe") self.tc_mdp = wx.TextCtrl(self, -1, "", style=wx.TE_PASSWORD) self.bouton_test_serveur = wx.Button(self, -1, u"Tester les paramètres du Serveur") self.bouton_sauvegarder = wx.Button(self, -1, u"Sauvegarder la configuration SMTP") self.throbber = AnimationCtrl(self) self.throbber.SetAnimation(Animation("../icons/32x32/throbber6.gif")) self.throbber.Play() self.server = None self.thread = None self.__set_properties() self.__set_values() self.__do_layout() self.throbber.Hide() self.Bind(wx.EVT_BUTTON, self.OnTestServeur, self.bouton_test_serveur) self.Bind(wx.EVT_BUTTON, self.OnSauvegarde, self.bouton_sauvegarder) # end wxGlade def __set_properties(self): # begin wxGlade: MyFrame.__set_properties self.tc_serveur.SetMinSize((200, -1)) self.cb_securite.SetSelection(0) self.bouton_sauvegarder.Disable() # end wxGlade def __set_values(self): self.SMTP_serveur = Parametre.get_or_create(nom="SMTP_serveur") self.SMTP_serveurport = Parametre.get_or_create(nom="SMTP_serveurport") self.SMTP_serveursecurite = Parametre.get_or_create(nom="SMTP_serveursecurite") self.SMTP_login = Parametre.get_or_create(nom="SMTP_login") self.SMTP_motdepasse = Parametre.get_or_create(nom="SMTP_motdepasse") self.tc_serveur.SetValue(self.SMTP_serveur.valeur,) self.tc_port.SetValue(self.SMTP_serveurport.valeur,) try: self.cb_securite.SetSelection(int(self.SMTP_serveursecurite.valeur),) except ValueError: self.cb_securite.SetSelection(0,) self.tc_login.SetValue(self.SMTP_login.valeur,) self.tc_mdp.SetValue(self.SMTP_motdepasse.valeur,) def __do_layout(self): # begin wxGlade: MyFrame.__do_layout sizer = wx.BoxSizer(wx.VERTICAL) sizer_haut = wx.BoxSizer(wx.HORIZONTAL) sizer_test = wx.BoxSizer(wx.VERTICAL) #sizer_boutons = wx.BoxSizer(wx.HORIZONTAL) grid_sizer = wx.FlexGridSizer(5, 2, 5, 10) grid_sizer.Add(self.label_serveur, 0, wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer.Add(self.tc_serveur, 0, 0, 0) grid_sizer.Add(self.label_port, 0, wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer.Add(self.tc_port, 0, wx.EXPAND, 0) grid_sizer.Add(self.label_securite, 0, wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer.Add(self.cb_securite, 0, wx.EXPAND, 0) grid_sizer.Add(self.label_login, 0, wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer.Add(self.tc_login, 0, wx.EXPAND, 0) grid_sizer.Add(self.label_mdp, 0, wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer.Add(self.tc_mdp, 0, wx.EXPAND, 0) sizer_haut.Add(grid_sizer, 0, wx.ALL|wx.EXPAND, 0) sizer_test.Add(self.bouton_test_serveur, 0, wx.BOTTOM, 10) sizer_test.Add(self.throbber, 0, wx.ALIGN_CENTER_HORIZONTAL, 0) sizer_haut.Add(sizer_test, 0, wx.LEFT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, 10) sizer.Add(sizer_haut, 0, wx.ALL, 5) sizer.Add(self.bouton_sauvegarder, 0, wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 10) self.SetSizer(sizer) sizer.Fit(self) self.Layout() # end wxGlade #Permet de tester la connection internet def TestConnectionInternet(self): try: urllib2.urlopen("http://www.google.com/") return True except: return False def ConnectionServeur(self): if self.cb_securite.GetSelection() == 2: server = smtplib.SMTP_SSL(self.tc_serveur.GetValue(), int(self.tc_port.GetValue())) else: server = smtplib.SMTP(self.tc_serveur.GetValue(), int(self.tc_port.GetValue())) server.ehlo() if self.cb_securite.GetSelection() == 1: server.starttls() server.ehlo() server.login(self.tc_login.GetValue(), self.tc_mdp.GetValue()) return server def TestConnectionServeur(self): if self.TestConnectionInternet(): try: self.ConnectionServeur() self.throbber.Hide() self.bouton_sauvegarder.Enable() wx.MessageBox(u"La connection au serveur SMTP est valide", "Valide", wx.ICON_INFORMATION) except smtplib.SMTPAuthenticationError: self.bouton_sauvegarder.Disable() self.throbber.Hide() wx.MessageBox(u"Login ou mot de passe incorrect", "Erreur", wx.ICON_ERROR) except Exception as ex: self.bouton_sauvegarder.Disable() self.throbber.Hide() wx.MessageBox(u"Problème de connection au serveur SMTP\n\n %s" % ex, "Erreur", wx.ICON_ERROR) else: self.bouton_sauvegarder.Disable() self.throbber.Hide() wx.MessageBox(u"Problème de connection internet", "Erreur", wx.ICON_ERROR) def OnTestServeur(self, event): if self.Validate(): self.throbber.Show() self.thread = Thread(target=self.TestConnectionServeur) self.thread.start() def OnSauvegarde(self, event): with DATABASE.transaction(): self.SMTP_serveur.value = self.tc_serveur.GetValue() self.SMTP_serveurport = self.tc_port.GetValue() self.SMTP_serveursecurite = self.cb_securite.GetSelection() self.SMTP_login = self.tc_login.GetValue() self.SMTP_motdepasse = self.tc_mdp.GetValue() self.SMTP_serveur.save() self.SMTP_serveurport.save() self.SMTP_serveursecurite.save() self.SMTP_login.save() self.SMTP_motdepasse.save() self.bouton_sauvegarder.Disable() def OnEmail(self, event): self.mail("*****@*****.**", "Email de test", "Bla bla bla bla", "../../dernier_bon_imprime.pdf")