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