예제 #1
0
파일: desktop.py 프로젝트: pedrosans/pocoy
	def _change_layout(self, radio_menu_item: Gtk.RadioMenuItem):
		if not self._reloading and radio_menu_item.get_active():
			function_key = radio_menu_item.function_key
			event = UserEvent(time=Gtk.get_current_event_time())
			event.parameters = [function_key]
			import pocoy.service as service
			service.call(self.monitors.setprimarylayout, event)
예제 #2
0
 def test_parse_vim_command_with_parameter(self):
     i = UserEvent(text='buffer  term')
     self.assertEqual(i.vim_command, 'buffer')
     self.assertEqual(i.vim_command_spacer, '  ')
     self.assertEqual(i.vim_command_parameter, 'term')
     self.assertTrue('' is i.terminal_command is i.terminal_command_spacer
                     is i.terminal_command_parameter)
예제 #3
0
def execute(function: Callable = None,
            cmd: str = None,
            timestamp: int = None,
            move_to_main_loop=True):
    if not timestamp:
        timestamp = datetime.now().microsecond
    user_event = UserEvent(text=cmd, time=timestamp)

    if cmd:
        if names.has_multiple_names(cmd):
            raise names.InvalidName('TODO: iterate multiple commands')

        name = names.match(user_event)

        if not name:
            raise names.InvalidName('Not an editor command: ' + cmd)

        function = name.function

    if move_to_main_loop:
        _execute_inside_main_loop(function, user_event)
    else:
        call(function, user_event)

    return True
예제 #4
0
파일: reading.py 프로젝트: pedrosans/pocoy
	def on_entry_key_press(self, widget, event):
		if event.keyval in HISTORY_NAVIGATION_KEYS:
			self.prompt_history.navigate_history(-1 if event.keyval == Gdk.KEY_Up else 1, self.view.get_command())
			self.view.set_command(self.prompt_history.current_command())
			self.view.clean_completions()
			self.completion.clean()
			return True
		else:
			self.prompt_history.reset_history_pointer()

		if event.keyval not in HINT_NAVIGATION_KEYS:
			return False

		if not self.completion.assisting and event.keyval in HINT_LAUNCH_KEYS:
			self.completion.search_for(UserEvent(text=self.view.get_command()))

		if self.completion.assisting:
			shift_mask = event.state & Gdk.ModifierType.SHIFT_MASK
			right = event.keyval in HINT_RIGHT or (event.keyval in HINT_LAUNCH_KEYS and not shift_mask)
			self.completion.cycle(1 if right else -1)
			if len(self.completion.options) == 1:
				self.view.clean_completions()
			else:
				self.view.offer(self.completion.options, self.completion.index, self.completion.should_auto_assist())
			self.view.set_command(self.completion.mount_input())

		return True
예제 #5
0
 def test_parse_terminal_command_with_number(self):
     i = UserEvent(text='!  7z')
     self.assertEqual(i.vim_command, '!')
     self.assertEqual(i.vim_command_spacer, '  ')
     self.assertEqual(i.vim_command_parameter, '7z')
     self.assertEqual(i.terminal_command, '7z')
     self.assertEqual(i.terminal_command_spacer, '')
     self.assertEqual(i.terminal_command_parameter, '')
예제 #6
0
 def test_parse_empty_terminal_command(self):
     i = UserEvent(text='!  ')
     self.assertEqual(i.vim_command, '!')
     self.assertEqual(i.vim_command_spacer, '  ')
     self.assertEqual(i.vim_command_parameter, '')
     self.assertEqual(i.terminal_command, '')
     self.assertEqual(i.terminal_command_spacer, '')
     self.assertEqual(i.terminal_command_parameter, '')
예제 #7
0
 def test_parse_vim_command_with_number_parameter_without_separation(self):
     i = UserEvent(text='b2')
     self.assertEqual(i.vim_command, 'b')
     self.assertEqual(i.vim_command_spacer, '')
     self.assertEqual(i.vim_command_parameter, '2')
     self.assertEqual(i.terminal_command, '')
     self.assertEqual(i.terminal_command_spacer, '')
     self.assertEqual(i.terminal_command_parameter, '')
예제 #8
0
 def test_parse_terminal_command_with_parameter(self):
     i = UserEvent(text='!  git   add')
     self.assertEqual(i.vim_command, '!')
     self.assertEqual(i.vim_command_spacer, '  ')
     self.assertEqual(i.vim_command_parameter, 'git   add')
     self.assertEqual(i.terminal_command, 'git')
     self.assertEqual(i.terminal_command_spacer, '   ')
     self.assertEqual(i.terminal_command_parameter, 'add')
예제 #9
0
 def test_parse_vim_command_with_number_parameter(self):
     i = UserEvent(text='buffer  23')
     self.assertEqual(i.vim_command, 'buffer')
     self.assertEqual(i.vim_command_spacer, '  ')
     self.assertEqual(i.vim_command_parameter, '23')
     self.assertEqual(i.terminal_command, '')
     self.assertEqual(i.terminal_command_spacer, '')
     self.assertEqual(i.terminal_command_parameter, '')
예제 #10
0
파일: reading.py 프로젝트: pedrosans/pocoy
	def show_completions(self):

		if configurations.is_auto_hint():
			self.completion.search_for(UserEvent(text=self.view.get_command()))
		else:
			self.completion.clean()

		if self.completion.assisting:
			self.view.offer(self.completion.options, self.completion.index, self.completion.should_auto_assist())
		else:
			self.view.clean_completions()
예제 #11
0
def keyboard_listener(key: Key, x_key_event, multiplier=1):
    if not key.function:
        return

    user_event = UserEvent(time=x_key_event.time,
                           parameters=key.parameters,
                           keyval=x_key_event.keyval,
                           keymod=x_key_event.keymod)

    if hasattr(key.function,
               'skip_event_processing') and key.function.skip_event_processing:
        key.function(user_event)
        return

    _execute_inside_main_loop(key.function, user_event, multiplier)
예제 #12
0
 def test_parse_vim_command(self):
     i = UserEvent(text='buffers')
     self.assertEqual(i.vim_command, 'buffers')
     self.assertTrue('' == i.vim_command_spacer == i.vim_command_parameter)
     self.assertTrue('' is i.terminal_command is i.terminal_command_spacer
                     is i.terminal_command_parameter)
예제 #13
0
파일: service.py 프로젝트: pedrosans/pocoy
 def test_calls_function(self):
     service.call(self.foo, UserEvent())
     self.foo.assert_called()
예제 #14
0
 def test_parse_colon_spacer(self):
     i = UserEvent(text='  buffers')
     self.assertEqual(i.colon_spacer, '  ')
     self.assertEqual(i.vim_command, 'buffers')
예제 #15
0
파일: service.py 프로젝트: pedrosans/pocoy
 def test_dont_end_long_conversation(self):
     service.reading.is_transient = lambda: False
     service.call(self.foo, UserEvent())
     service.reading.end.assert_not_called()
예제 #16
0
	def test_mount_name_plus_partial_match(self):
		self.completion.search_for(UserEvent(text='bar o'))
		self.completion.index = 0
		self.assertEqual(self.completion.mount_input(), 'bar foobar')
예제 #17
0
	def test_dont_query_vim_command_if_bang(self):
		command_input = UserEvent(text='!foo')
		self.completion.search_for(command_input)
		names.completions_for.assert_not_called()
예제 #18
0
	def test_query_vim_commands_if_name_completions_is_empty(self):
		c_in = UserEvent(text='bd')
		self.completion.search_for(c_in)
		names.completions_for.assert_called_once_with(c_in)
예제 #19
0
	def test_dont_query_vim_commands_if_input_with_parameter_not_separated(self):
		self.completion.search_for(UserEvent(text='b4'))
		names.completions_for.assert_not_called()
예제 #20
0
파일: service.py 프로젝트: pedrosans/pocoy
 def test_is_pre_processed(self):
     service.call(self.foo, UserEvent())
     service.reading.make_transient.assert_called()
예제 #21
0
 def test_parse_empty_input(self):
     i = UserEvent(text='')
     self.assertEqual(i.colon_spacer, '')
     self.assertEqual(i.vim_command, '')
예제 #22
0
	def test_mount_spaces(self):
		self.completion.search_for(UserEvent(text='  !   foo'))
		self.completion.cycle(1)
		self.assertEqual('  !   foobar', self.completion.mount_input())
예제 #23
0
파일: service.py 프로젝트: pedrosans/pocoy
 def test_end_conversation(self):
     service.call(self.foo, UserEvent())
     service.reading.end.assert_called()
예제 #24
0
	def test_mount_bang_plus_match(self):
		self.completion.search_for(UserEvent(text='!foo'))
		self.completion.index = 0
		self.assertEqual(self.completion.mount_input(), '!foobar')
예제 #25
0
파일: terminal.py 프로젝트: pedrosans/pocoy
	def test_autocomplete_parameters(self):
		terminal.query_command_parameters = lambda x: ['bar']
		self.assertEqual(
			['bar'],
			terminal.complete(UserEvent(text='!foo ')))