Beispiel #1
0
    def createWindow(self, parent, **kwargs):
        self.win = wx.Panel(parent, style=wx.NO_BORDER | wx.TAB_TRAVERSAL)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        prompt = wx.StaticText(self.win, -1, _(self.label))
        sizer.Add(prompt, 0, wx.CENTER)
        self.text = TextCtrlAutoComplete(self.win,
                                         choices=[],
                                         size=(-1, -1),
                                         style=wx.TE_PROCESS_ENTER
                                         | wx.TE_PROCESS_TAB)
        sizer.Add(self.text, 1, wx.EXPAND)
        self.win.SetSizer(sizer)

        self.win.Bind(wx.EVT_SET_FOCUS, self.OnFocus)

        if 'highlight_initial' in kwargs:
            self.highlight_initial = kwargs['highlight_initial']
        else:
            self.highlight_initial = False

        if self.initial is not None:
            self.text.ChangeValue(self.initial)
            self.text.SetChoices(self.complete(self.initial))
        self.text.SetEntryCallback(self.setDynamicChoices)
        #self.text.SetInsertionPointEnd()

        # FIXME: Using the EVT_SET_FOCUS doesn't seem to work to set the cursor
        # to the end of the text.  It doesn't seem to get called at all, so
        # the only way to do it appears to be to co-opt the Panel's SetFocus
        # method
        self.win.saveSetFocus = self.win.SetFocus
        self.win.SetFocus = self.SetFocus
Beispiel #2
0
    def createWindow(self, parent, **kwargs):
        self.win = wx.Panel(parent, style=wx.NO_BORDER | wx.TAB_TRAVERSAL)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        prompt = wx.StaticText(self.win, -1, _(self.label))
        sizer.Add(prompt, 0, wx.CENTER)
        self.text = TextCtrlAutoComplete(
            self.win, choices=[], size=(-1, -1), style=wx.TE_PROCESS_ENTER | wx.TE_PROCESS_TAB
        )
        sizer.Add(self.text, 1, wx.EXPAND)
        self.win.SetSizer(sizer)

        self.win.Bind(wx.EVT_SET_FOCUS, self.OnFocus)

        if "highlight_initial" in kwargs:
            self.highlight_initial = kwargs["highlight_initial"]
        else:
            self.highlight_initial = False

        if self.initial is not None:
            self.text.ChangeValue(self.initial)
            self.text.SetChoices(self.complete(self.initial))
        self.text.SetEntryCallback(self.setDynamicChoices)
        # self.text.SetInsertionPointEnd()

        # FIXME: Using the EVT_SET_FOCUS doesn't seem to work to set the cursor
        # to the end of the text.  It doesn't seem to get called at all, so
        # the only way to do it appears to be to co-opt the Panel's SetFocus
        # method
        self.win.saveSetFocus = self.win.SetFocus
        self.win.SetFocus = self.SetFocus
Beispiel #3
0
class CompletionMinibuffer(TextMinibuffer):
    """Base class for a minibuffer based on the TextCtrlAutoComplete
    widget from the wxpython list.

    This class doesn't implement the complete method, leaving its
    implementation to subclasses.
    
    Most of the time completion minibuffers will want to extend the
    initial value when the use types something, but in case you want the
    initial buffer to be selected so that a keystroke replaces it, the
    'highlight_initial' kwarg can be passed to the constructor (which in turn
    passes it to createWindow).
    """

    def createWindow(self, parent, **kwargs):
        self.win = wx.Panel(parent, style=wx.NO_BORDER | wx.TAB_TRAVERSAL)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        prompt = wx.StaticText(self.win, -1, _(self.label))
        sizer.Add(prompt, 0, wx.CENTER)
        self.text = TextCtrlAutoComplete(
            self.win, choices=[], size=(-1, -1), style=wx.TE_PROCESS_ENTER | wx.TE_PROCESS_TAB
        )
        sizer.Add(self.text, 1, wx.EXPAND)
        self.win.SetSizer(sizer)

        self.win.Bind(wx.EVT_SET_FOCUS, self.OnFocus)

        if "highlight_initial" in kwargs:
            self.highlight_initial = kwargs["highlight_initial"]
        else:
            self.highlight_initial = False

        if self.initial is not None:
            self.text.ChangeValue(self.initial)
            self.text.SetChoices(self.complete(self.initial))
        self.text.SetEntryCallback(self.setDynamicChoices)
        # self.text.SetInsertionPointEnd()

        # FIXME: Using the EVT_SET_FOCUS doesn't seem to work to set the cursor
        # to the end of the text.  It doesn't seem to get called at all, so
        # the only way to do it appears to be to co-opt the Panel's SetFocus
        # method
        self.win.saveSetFocus = self.win.SetFocus
        self.win.SetFocus = self.SetFocus

    def SetFocus(self):
        # dprint(self)
        self.win.saveSetFocus()
        self.OnFocus(None)

    def OnFocus(self, evt):
        # dprint()
        if self.highlight_initial and self.text.GetValue() == self.initial:
            self.text.SetSelection(-1, -1)
        else:
            self.text.SetInsertionPointEnd()

    def complete(self, text):
        raise NotImplementedError

    def setDynamicChoices(self):
        ctrl = self.text
        text = ctrl.GetValue()
        current_choices = ctrl.GetChoices()
        choices = self.complete(text)
        self.dprint(choices)
        if choices != current_choices:
            ctrl.SetChoices(choices)

    def getRawTextValue(self):
        """Get either the value from the dropdown list if it is selected, or the
        value from the text control.
        """
        self.text._setValueFromSelected()
        return self.text.GetValue()
Beispiel #4
0
class CompletionMinibuffer(TextMinibuffer):
    """Base class for a minibuffer based on the TextCtrlAutoComplete
    widget from the wxpython list.

    This class doesn't implement the complete method, leaving its
    implementation to subclasses.
    
    Most of the time completion minibuffers will want to extend the
    initial value when the use types something, but in case you want the
    initial buffer to be selected so that a keystroke replaces it, the
    'highlight_initial' kwarg can be passed to the constructor (which in turn
    passes it to createWindow).
    """
    def createWindow(self, parent, **kwargs):
        self.win = wx.Panel(parent, style=wx.NO_BORDER | wx.TAB_TRAVERSAL)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        prompt = wx.StaticText(self.win, -1, _(self.label))
        sizer.Add(prompt, 0, wx.CENTER)
        self.text = TextCtrlAutoComplete(self.win,
                                         choices=[],
                                         size=(-1, -1),
                                         style=wx.TE_PROCESS_ENTER
                                         | wx.TE_PROCESS_TAB)
        sizer.Add(self.text, 1, wx.EXPAND)
        self.win.SetSizer(sizer)

        self.win.Bind(wx.EVT_SET_FOCUS, self.OnFocus)

        if 'highlight_initial' in kwargs:
            self.highlight_initial = kwargs['highlight_initial']
        else:
            self.highlight_initial = False

        if self.initial is not None:
            self.text.ChangeValue(self.initial)
            self.text.SetChoices(self.complete(self.initial))
        self.text.SetEntryCallback(self.setDynamicChoices)
        #self.text.SetInsertionPointEnd()

        # FIXME: Using the EVT_SET_FOCUS doesn't seem to work to set the cursor
        # to the end of the text.  It doesn't seem to get called at all, so
        # the only way to do it appears to be to co-opt the Panel's SetFocus
        # method
        self.win.saveSetFocus = self.win.SetFocus
        self.win.SetFocus = self.SetFocus

    def SetFocus(self):
        #dprint(self)
        self.win.saveSetFocus()
        self.OnFocus(None)

    def OnFocus(self, evt):
        #dprint()
        if self.highlight_initial and self.text.GetValue() == self.initial:
            self.text.SetSelection(-1, -1)
        else:
            self.text.SetInsertionPointEnd()

    def complete(self, text):
        raise NotImplementedError

    def setDynamicChoices(self):
        ctrl = self.text
        text = ctrl.GetValue()
        current_choices = ctrl.GetChoices()
        choices = self.complete(text)
        self.dprint(choices)
        if choices != current_choices:
            ctrl.SetChoices(choices)

    def getRawTextValue(self):
        """Get either the value from the dropdown list if it is selected, or the
        value from the text control.
        """
        self.text._setValueFromSelected()
        return self.text.GetValue()