]> git.phdru.name Git - m_librarian.git/blob - m_librarian/wx/AWindow.py
Feat(wx/search): List found authors
[m_librarian.git] / m_librarian / wx / AWindow.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 AWindow(wx.Frame):
9
10     '''
11     A universal parent class for all top-level application windows
12
13     Standard menu and ability to save/restore window size.
14     '''
15
16     # Subclasses should override these
17     session_config_section_name = None
18     window_title = None
19
20     def __init__(self, parent=None):
21         if self.session_config_section_name:
22             session_config = get_session_config()
23             width = session_config.getint(
24                 self.session_config_section_name, 'width', 600)
25             height = session_config.getint(
26                 self.session_config_section_name, 'height', 400)
27         else:
28             width = 600
29             height = 400
30         wx.Frame.__init__(
31             self,
32             parent=parent, id=-1, title=self.window_title,
33             size=wx.Size(width=width, height=height),
34         )
35         self.OnInit()
36         self.Show(True)
37
38     def OnInit(self):
39         if self.Parent:
40             self.Parent.Disable()
41         self.InitMenu()
42         if self.session_config_section_name:
43             self.Bind(wx.EVT_SIZE, self.OnSize)
44         self.Bind(wx.EVT_CLOSE, self.OnClose)
45
46     def InitMenu(self):
47         MenuBar = wx.MenuBar()
48         self.SetMenuBar(MenuBar)
49
50         file_menu = wx.Menu()
51
52         if self.Parent:
53             close_win = \
54                 file_menu.Append(wx.ID_CLOSE, u"&Закрыть", u"Закрыть окно")
55             self.Bind(wx.EVT_MENU, self.OnCloseCommand, close_win)
56
57         quit = file_menu.Append(wx.ID_EXIT, u"&Выход", u"Выйти из программы")
58         self.Bind(wx.EVT_MENU, self.OnQuit, quit)
59         MenuBar.Append(file_menu, u"&Файл")
60
61         about_menu = wx.Menu()
62         about = about_menu.Append(wx.ID_ABOUT,
63                                   u"&О m_Librarian", u"О m_Librarian")
64         self.Bind(wx.EVT_MENU, self.OnAbout, about)
65         MenuBar.Append(about_menu, u"&О программе")
66
67     def OnCloseCommand(self, event):
68         self.Close(True)
69
70     def OnClose(self, event):
71         if self.Parent:
72             self.Parent.Enable()
73         event.Skip()  # Call other handlers
74
75     def OnQuit(self, event):
76         wx.GetApp().ExitMainLoop()
77
78     def OnAbout(self, event):
79         aboutInfo = wx.adv.AboutDialogInfo()
80         aboutInfo.SetName(u'm_Librarian')
81         aboutInfo.SetVersion(__version__)
82         aboutInfo.SetDescription(
83             u'Библиотекарь для библиотек LibRusEc/Flibusta')
84         aboutInfo.AddDeveloper(u'Олег Бройтман')
85         aboutInfo.SetWebSite(
86             u'https://phdru.name/Software/Python/m_librarian/')
87         aboutInfo.SetCopyright(u'(C) 2023, 2024 Олег Бройтман')
88         aboutInfo.SetLicense(u'GPL')
89         wx.adv.AboutBox(aboutInfo)
90
91     def OnSize(self, event):
92         """Save window size in the session config"""
93         if self.session_config_section_name:
94             size = event.GetSize()
95             session_config = get_session_config()
96             session_config.set(
97                 self.session_config_section_name, 'width', str(size.width))
98             session_config.set(
99                 self.session_config_section_name, 'height', str(size.height))
100             session_config.save()
101         event.Skip()  # Call other handlers