edouard@3573: #!/usr/bin/env python edouard@3573: # -*- coding: utf-8 -*- edouard@3573: edouard@3573: # This file is part of Beremiz edouard@3573: # Copyright (C) 2022: Edouard TISSERANT edouard@3573: # edouard@3573: # See COPYING file for copyrights details. edouard@3573: edouard@3573: kinsamanka@3750: edouard@3573: import wx edouard@3573: edouard@3573: edouard@3573: # class RichMessageDialog is still not available in wxPython 3.0.2 edouard@3573: class MessageBoxOnce(wx.Dialog): edouard@3573: """ edouard@3573: wx.MessageBox that user can ask not to show again edouard@3573: """ edouard@3573: def __init__(self, title, message, config_key): edouard@3573: self.Config = wx.ConfigBase.Get() edouard@3573: self.config_key = config_key edouard@3573: dont_show = self.Config.Read(self.config_key) == "True" edouard@3573: edouard@3573: if dont_show: edouard@3573: return edouard@3573: edouard@3573: wx.Dialog.__init__(self, None, title=title) edouard@3573: edouard@3573: main_sizer = wx.BoxSizer(wx.VERTICAL) edouard@3573: edouard@3573: message = wx.StaticText(self, label=message) edouard@3573: main_sizer.Add(message, border=20, edouard@3573: flag=wx.ALIGN_CENTER_HORIZONTAL | wx.TOP | wx.LEFT | wx.RIGHT) edouard@3573: edouard@3573: self.check = wx.CheckBox(self, label=_("don't show this message again")) edouard@3573: main_sizer.Add(self.check, border=20, edouard@3573: flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.ALIGN_CENTER_HORIZONTAL) edouard@3573: edouard@3573: buttons_sizer = wx.BoxSizer(wx.HORIZONTAL) edouard@3573: edouard@3573: Button = wx.Button(self, label="OK") edouard@3573: edouard@3573: self.Bind(wx.EVT_BUTTON, self.OnOKButton, Button) edouard@3573: buttons_sizer.Add(Button) edouard@3573: edouard@3573: main_sizer.Add(buttons_sizer, border=20, edouard@3573: flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.ALIGN_RIGHT) edouard@3573: edouard@3573: self.SetSizer(main_sizer) edouard@3573: self.Fit() edouard@3573: edouard@3573: self.ShowModal() edouard@3573: edouard@3573: def OnOKButton(self, event): edouard@3573: if self.check.GetValue(): edouard@3573: self.Config.Write(self.config_key, "True") edouard@3573: self.EndModal(wx.ID_OK)