]> git.phdru.name Git - m_librarian.git/blobdiff - m_librarian/wx/Application.py
Style(wx): Fix `flake8` warnings
[m_librarian.git] / m_librarian / wx / Application.py
index 308d65d4e6a5635123e5f902d97c9dfb47d929f6..854bba3a09912978b85dccabd1d58c8d845e3b77 100644 (file)
@@ -1,11 +1,24 @@
 # coding: utf-8
 
-import wx, wx.adv
+import wx, wx.adv  # noqa: E401 multiple imports on one line
 from ..__version__ import __version__
+from .session_config import get_session_config
 
 
 class MainWindow(wx.Frame):
 
+    def __init__(self):
+        session_config = get_session_config()
+        width = session_config.getint('main_window', 'width', 600)
+        height = session_config.getint('main_window', 'height', 400)
+        super(wx.Frame, self).__init__(
+            parent=None, id=-1, title=u"m_Librarian",
+            size=wx.Size(width=width, height=height),
+        )
+        self.InitMenu()
+        self.Show(True)
+        self.Bind(wx.EVT_SIZE, self.OnSize)
+
     def InitMenu(self):
         MenuBar = wx.MenuBar()
         self.SetMenuBar(MenuBar)
@@ -31,17 +44,25 @@ class MainWindow(wx.Frame):
         aboutInfo.SetDescription(
             u'Библиотекарь для библиотек LibRusEc/Flibusta')
         aboutInfo.AddDeveloper(u'Олег Бройтман')
-        aboutInfo.SetWebSite(u'https://phdru.name/Software/Python/m_librarian/')
+        aboutInfo.SetWebSite(
+            u'https://phdru.name/Software/Python/m_librarian/')
         aboutInfo.SetCopyright(u'(C) 2023 Олег Бройтман')
         aboutInfo.SetLicense(u'GPL')
         wx.adv.AboutBox(aboutInfo)
 
+    def OnSize(self, event):
+        """Save window size in the session config"""
+        size = event.GetSize()
+        session_config = get_session_config()
+        session_config.set('main_window', 'width', str(size.width))
+        session_config.set('main_window', 'height', str(size.height))
+        session_config.save()
+        event.Skip()  # Call other handlers
+
 
 class Application(wx.App):
 
     def OnInit(self):
-        frame = MainWindow(None, -1, u"m_Librarian")
-        frame.InitMenu()
-        frame.Show(True)
+        frame = MainWindow()
         self.SetTopWindow(frame)
         return True