Example #1
0
class MainController(BaseMainController):
    
    def __init__(self, main_script):
        font = wx.NORMAL_FONT
        BaseMainController.__init__(self, main_script, meta, config)
        
        self.view = MainWindow()
        self.settings = BaseSettings(self.settings_path, SETTINGS_DEFAULTS)
        self.model = App(self.settings)
        self.notes = NotesController(self.model, self.settings, self.view, self.settings_path.parent)
        self.commands = CommandController(self, self.settings)
        
        self.view.load_position(self.settings)
        
        pub.subscribe(self.on_program_closed, 'program.closed')
        pub.subscribe(self.on_page_key_down, 'page.key_down')
        pub.subscribe(self.on_options_changing, 'options.changing')
        
        #TODO: use call after? handle exceptions
        self.notes.open_initial()
        
    def quit(self):
        self.view.Close()
        
    def open_options(self):
        opt = Options()
        opt.read(self.settings)
        self.view.open_options(opt)
    
    def hide(self):
        self.notes.save(self.view.pages)
        self.notes.save_opened(self.view.pages)
        self.view.hide()
        
    def find(self):
        self.view.find()
        
    def delete_line(self):
        pub.sendMessage('note.edit.delete_line')
        
    def on_program_closed(self, pages):
        self.view.save_position(self.settings)
        self.notes.save_opened(pages)
        self.settings.save()
        logging.shutdown()
        
    def on_page_key_down(self, key_code, flags):
        if key_code == wx.WXK_ESCAPE:
            self.hide()
            
    def on_options_changing(self, options):
        if options.modifiers is None or options.key_code is None:
            hotkey = ''
        else:
            hotkey = '%d,%d' % (options.modifiers, options.key_code)
        self.settings.set('Options', 'HotKey', hotkey)
        self.settings.set('Options', 'Font', options.font)
Example #2
0
 def test_on_settings_changed(self):
     window = MainWindow()
     mocker = mox.Mox()
     register = mocker.CreateMockAnything()
     window.RegisterHotKey = register
     unregister = mocker.CreateMockAnything()
     window.UnregisterHotKey = unregister
     settings = mocker.CreateMock(BaseSettings)
     
     modifiers = wx.MOD_ALT
     key_code = wx.WXK_F1
     register(1, modifiers, key_code)
     
     window.on_setting_changed(settings, 'Options', 'HotKey', '%d,%d' % (modifiers, key_code))
     
     mocker.ReplayAll()
     self.assertEqual(1, window._last_hotkey)
     
     mocker.ResetAll()
     
     unregister(1)
     
     window.on_setting_changed(settings, 'Options', 'HotKey', '')
     
     mocker.ReplayAll()
     self.assertEqual(None, window._last_hotkey)
Example #3
0
 def __init__(self, main_script):
     font = wx.NORMAL_FONT
     BaseMainController.__init__(self, main_script, meta, config)
     
     self.view = MainWindow()
     self.settings = BaseSettings(self.settings_path, SETTINGS_DEFAULTS)
     self.model = App(self.settings)
     self.notes = NotesController(self.model, self.settings, self.view, self.settings_path.parent)
     self.commands = CommandController(self, self.settings)
     
     self.view.load_position(self.settings)
     
     pub.subscribe(self.on_program_closed, 'program.closed')
     pub.subscribe(self.on_page_key_down, 'page.key_down')
     pub.subscribe(self.on_options_changing, 'options.changing')
     
     #TODO: use call after? handle exceptions
     self.notes.open_initial()