]> git.phdru.name Git - m_librarian.git/blob - m_librarian/wx/Application.py
Feat(wx): Get initial window size from session config
[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         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(u'https://phdru.name/Software/Python/m_librarian/')
48         aboutInfo.SetCopyright(u'(C) 2023 Олег Бройтман')
49         aboutInfo.SetLicense(u'GPL')
50         wx.adv.AboutBox(aboutInfo)
51
52     def OnSize(self, event):
53         """Save window size in the session config"""
54         size = event.GetSize()
55         session_config = get_session_config()
56         session_config.set('main_window', 'width', str(size.width))
57         session_config.set('main_window', 'height', str(size.height))
58         session_config.save()
59         event.Skip()  # Call other handlers
60
61 class Application(wx.App):
62
63     def OnInit(self):
64         frame = MainWindow()
65         self.SetTopWindow(frame)
66         return True