import wx, wx.adv
from ..__version__ import __version__
+from .session_config import get_session_config
class MainWindow(wx.Frame):
self.Bind(wx.EVT_MENU, self.OnAbout, about)
MenuBar.Append(about_menu, u"&О программе")
+ self.Bind(wx.EVT_SIZE, self.OnSize)
+
def OnQuit(self, event):
self.Close(True)
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):
_ml_session_config = None
+class SessionConfigWrapper(ConfigWrapper):
+ def __init__(self, config, config_path):
+ ConfigWrapper.__init__(self, config)
+ self.config_path = config_path
+
+ def set(self, section, option, value):
+ if not self.config.has_section(section):
+ self.config.add_section(section)
+ super(SessionConfigWrapper, self).set(section, option, value)
+
+ def save(self):
+ if self.config_path is None:
+ config_dirs = _find_config_dirs()
+ self.config_path = \
+ os.path.join(config_dirs[0], 'm_librarian_session.conf')
+ with open(self.config_path, 'wt') as fp:
+ self.config.write(fp)
+
+
def get_session_config(config_path=None):
global _ml_session_config
if _ml_session_config is None:
find_config_file(config_dirs, 'm_librarian_session.conf')
if config_path is not None:
_ml_session_config.read(config_path)
- _ml_session_config = ConfigWrapper(_ml_session_config)
+ _ml_session_config = \
+ SessionConfigWrapper(_ml_session_config, config_path)
return _ml_session_config