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