]> git.phdru.name Git - m_librarian.git/blob - m_librarian/wx/Application.py
Feat(wx): Add `MainWindow.__init__()`
[m_librarian.git] / m_librarian / wx / Application.py
1 # coding: utf-8
2
3 import wx, wx.adv
4 from ..__version__ import __version__
5 from .session_config import get_session_config
6
7
8 class MainWindow(wx.Frame):
9
10     def __init__(self):
11         session_config = get_session_config()
12         super(wx.Frame, self).__init__(
13             parent=None, id=-1, title=u"m_Librarian",
14         )
15         self.InitMenu()
16         self.Show(True)
17         self.Bind(wx.EVT_SIZE, self.OnSize)
18
19     def InitMenu(self):
20         MenuBar = wx.MenuBar()
21         self.SetMenuBar(MenuBar)
22
23         file_menu = wx.Menu()
24         exit = file_menu.Append(wx.ID_EXIT, u"&Выход", u"Выйти из программы")
25         self.Bind(wx.EVT_MENU, self.OnQuit, exit)
26         MenuBar.Append(file_menu, u"&Файл")
27
28         about_menu = wx.Menu()
29         about = about_menu.Append(wx.ID_ABOUT,
30                                   u"&О m_Librarian", u"О m_Librarian")
31         self.Bind(wx.EVT_MENU, self.OnAbout, about)
32         MenuBar.Append(about_menu, u"&О программе")
33
34     def OnQuit(self, event):
35         self.Close(True)
36
37     def OnAbout(self, event):
38         aboutInfo = wx.adv.AboutDialogInfo()
39         aboutInfo.SetName(u'm_Librarian')
40         aboutInfo.SetVersion(__version__)
41         aboutInfo.SetDescription(
42             u'Библиотекарь для библиотек LibRusEc/Flibusta')
43         aboutInfo.AddDeveloper(u'Олег Бройтман')
44         aboutInfo.SetWebSite(u'https://phdru.name/Software/Python/m_librarian/')
45         aboutInfo.SetCopyright(u'(C) 2023 Олег Бройтман')
46         aboutInfo.SetLicense(u'GPL')
47         wx.adv.AboutBox(aboutInfo)
48
49     def OnSize(self, event):
50         """Save window size in the session config"""
51         size = event.GetSize()
52         session_config = get_session_config()
53         session_config.set('main_window', 'width', str(size.width))
54         session_config.set('main_window', 'height', str(size.height))
55         session_config.save()
56         event.Skip()  # Call other handlers
57
58 class Application(wx.App):
59
60     def OnInit(self):
61         frame = MainWindow()
62         self.SetTopWindow(frame)
63         return True