示例#1
0
class InlineArgumentDefaultDialog(RefactoringDialog):

    def __init__(self, context):
        resource = context.get_active_editor().get_file()
        editor = context.get_active_editor().get_editor()
        self.project = context.get_core().get_open_project()
        super(InlineArgumentDefaultDialog, self).__init__(
            context, 'Inline Argument Default')
        self.signature = rope.refactor.change_signature.ChangeSignature(
            context.project, resource, editor.get_current_offset())
        self.definition_info = self.signature.get_definition_info()

    def _get_changes(self):
        selected = self.param_list.get_active_entry()
        index = _get_parameter_index(self.definition_info, selected.name)
        return self.signature.inline_default(index)

    def _get_dialog_frame(self):
        frame = Tkinter.Frame(self.toplevel)
        label = Tkinter.Label(frame, text='Change Method Signature :')
        label.grid(row=0, column=0)
        self.param_list = EnhancedList(
            frame, _ParameterListHandle(self.definition_info),
            "Choose which to inline:")
        for pair in self.definition_info.args_with_defaults:
            if pair[1] is not None:
                self.param_list.add_entry(_Parameter(pair[0]))
        frame.grid()
        frame.focus_set()
        return frame
 def test_enhanced_inserting_clearing(self):
     handle = SampleListHandle()
     enhanced_list = EnhancedList(self.parent, handle)
     enhanced_list.add_entry(1)
     enhanced_list.add_entry(2)
     self.assertEquals(2, enhanced_list.list.size())
     enhanced_list.clear()
     self.assertEquals(0, enhanced_list.list.size())
def _show_annotations(context, name, items):
    toplevel = Tkinter.Toplevel()
    toplevel.title('%s List' % name)
    enhanced_list = EnhancedList(
        toplevel, _AnnotationListHandle(toplevel, context.get_core()),
        title='%ss' % name)
    for item in items:
        enhanced_list.add_entry(item)
    def close(event):
        toplevel.destroy()
    enhanced_list.list.focus_set()
 def __call__(self, context):
     editor = context.get_active_editor().get_editor()
     source = editor.get_text()
     offset = editor.get_current_offset()
     maxfixes = context.core.get_prefs().get('codeassist_maxfixes', 1)
     result = rope.contrib.codeassist.code_assist(
         context.project, source, offset, context.resource, maxfixes=maxfixes)
     proposals = rope.contrib.codeassist.sorted_proposals(result)
     expression = rope.contrib.codeassist.starting_expression(source, offset)
     proposals.extend(self._get_templates(context, expression))
     start_offset = rope.contrib.codeassist.starting_offset(source, offset)
     toplevel = Tkinter.Toplevel()
     toplevel.title('Code Assist Proposals')
     handle = _CompletionListHandle(editor, toplevel, start_offset)
     enhanced_list = EnhancedList(
         toplevel, handle, title='Code Assist Proposals',
         height=9, width=30, single_keys=False)
     for proposal in proposals:
         enhanced_list.add_entry(proposal)
     start_index = editor.text.index('0.0 +%dc' % start_offset)
     initial_cursor_position = str(editor.text.index(Tkinter.INSERT))
     def key_pressed(event):
         import string
         if len(event.char) == 1 and (event.char.isalnum() or
                                      event.char in string.punctuation):
             editor.text.insert(Tkinter.INSERT, event.char)
         elif event.keysym == 'space':
             editor.text.insert(Tkinter.INSERT, ' ')
         elif event.keysym == 'BackSpace':
             editor.text.delete(Tkinter.INSERT + '-1c')
         elif editor.text.compare(initial_cursor_position, '>', Tkinter.INSERT):
             toplevel.destroy()
             return
         else:
             return
         new_name = editor.text.get(start_index, Tkinter.INSERT)
         enhanced_list.clear()
         for proposal in proposals:
             if proposal.name.startswith(new_name):
                 enhanced_list.add_entry(proposal)
     enhanced_list.list.focus_set()
     enhanced_list.list.bind('<Any-KeyPress>', key_pressed)
     enhanced_list.list.bind('<Control-g>', lambda event: handle.canceled())
     toplevel.grab_set()
示例#5
0
 def _get_dialog_frame(self):
     frame = Tkinter.Frame(self.toplevel)
     label = Tkinter.Label(frame, text='Change Method Signature :')
     label.grid(row=0, column=0)
     self.param_list = EnhancedList(
         frame, _ParameterListHandle(self.definition_info),
         "Choose which to inline:")
     for pair in self.definition_info.args_with_defaults:
         if pair[1] is not None:
             self.param_list.add_entry(_Parameter(pair[0]))
     frame.grid()
     frame.focus_set()
     return frame
def find_occurrences(context):
    resource = context.resource
    offset = context.editor.get_current_offset()
    def calculate(handle):
        return rope.contrib.codeassist.find_occurrences(
            context.project, resource, offset,
            unsure=True, task_handle=handle)
    result = StoppableTaskRunner(calculate, title='Finding Occurrences')()
    enhanced_list = None
    def focus_set():
        enhanced_list.list.focus_set()
    toplevel = Tkinter.Toplevel()
    toplevel.title('Code Assist Proposals')
    enhanced_list = EnhancedList(
        toplevel, _OccurrenceListHandle(toplevel, context.get_core(),
                                        focus_set),
        title='Occurrences')
    for occurrence in result:
        enhanced_list.add_entry(occurrence)
    def close(event):
        toplevel.destroy()
    toplevel.bind('<Escape>', close)
    toplevel.bind('<Control-g>', close)
    enhanced_list.list.focus_set()
 def test_enhanced_list_to_string(self):
     handle = SampleListHandle()
     enhanced_list = EnhancedList(self.parent, handle)
     enhanced_list.add_entry(1)
     self.assertEquals('element 1', enhanced_list.list.get(0))