Exemplo n.º 1
0
    def __init__(self,
                 parent,
                 value='',
                 autosize=True,
                 formatOptions=None,
                 multiFormat=True,
                 showFormattingBar=True,
                 rtl=False,
                 skin=None,
                 entercallback=None,
                 validator=wx.DefaultValidator,
                 formatpref=None):

        FormattedInput.__init__(self,
                                parent,
                                value=value,
                                autosize=autosize,
                                formatOptions=formatOptions,
                                multiFormat=multiFormat,
                                showFormattingBar=showFormattingBar,
                                rtl=rtl,
                                skin=skin,
                                validator=validator)

        self.formatpref = formatpref
        if formatpref is not None:
            self.LoadStyle(formatpref)  #'messaging.default_style'
Exemplo n.º 2
0
    def __init__(
        self,
        parent,
        value='',
        autosize=True,
        formatOptions=None,
        multiFormat=True,
        showFormattingBar=True,
        rtl=False,
        skin=None,
        entercallback=None,
        validator=wx.DefaultValidator,
    ):

        FormattedInput.__init__(self,
                                parent,
                                value=value,
                                autosize=autosize,
                                formatOptions=formatOptions,
                                multiFormat=multiFormat,
                                showFormattingBar=showFormattingBar,
                                rtl=rtl,
                                skin=skin,
                                validator=validator)

        self.LoadStyle('messaging.default_style')

        self.entercallback = entercallback

        self.tc.Bind(wx.EVT_KEY_DOWN, self.OnEnterKey)

        self.sendbutton = None
        if self.showSendButton:
            self.CreateSendButton()
Exemplo n.º 3
0
    def __init__(self,
                 parent,
                 value     = '',
                 autosize = True,
                 formatOptions = None,
                 multiFormat = True,
                 showFormattingBar = True,
                 rtl = False,
                 skin = None,
                 entercallback = None,
                 validator = wx.DefaultValidator,
                 formatpref = None):


        FormattedInput.__init__(self,
                                parent,
                                value = value,
                                autosize = autosize,
                                formatOptions = formatOptions,
                                multiFormat = multiFormat,
                                showFormattingBar = showFormattingBar,
                                rtl = rtl,
                                skin = skin,
                                validator = validator)

        self.formatpref = formatpref
        if formatpref is not None:
            self.LoadStyle(formatpref) #'messaging.default_style'
Exemplo n.º 4
0
    def __init__(self,
                 parent,
                 value     = '',
                 autosize = True,
                 formatOptions = None,
                 multiFormat = True,
                 showFormattingBar = True,
                 rtl = False,
                 skin = None,
                 entercallback = None,
                 validator = wx.DefaultValidator,):


        FormattedInput.__init__(self,
                                parent,
                                value = value,
                                autosize = autosize,
                                formatOptions = formatOptions,
                                multiFormat = multiFormat,
                                showFormattingBar = showFormattingBar,
                                rtl = rtl,
                                skin = skin,
                                validator = validator)

        self.LoadStyle('messaging.default_style')

        self.entercallback = entercallback


        self.tc.Bind(wx.EVT_KEY_DOWN, self.OnEnterKey)

        self.sendbutton = None
        if self.showSendButton:
            self.CreateSendButton()
Exemplo n.º 5
0
def NewInput():
    f = wx.Frame(None)

    f.Sizer = wx.BoxSizer(wx.VERTICAL)

    font = FontFromFacename('Arial')
    font.SetPointSize(10)
    #    fo = {'default': False,
    #          'italic': True}
    textattr = wx.TextAttr(wx.BLACK, wx.WHITE, font)  #@UndefinedVariable

    i = FormattedInput(f, multiFormat=True)  #, formatOptions = fo)

    def OnExpandEvent(event):
        height = (i.fbar.Size.height
                  if i.FormattingBarIsShown() else 0) + i.tc.MinSize.height

        i.MinSize = wx.Size(-1, height)
        f.Fit()

    i.Bind(EVT_ETC_LAYOUT_NEEDED, OnExpandEvent)

    f.Sizer.Add(i, 0, wx.EXPAND)

    f.Show()
    f.Fit()
Exemplo n.º 6
0
    def construct(self, is_exception, status_message = None):

        if not is_exception:
            self.title_label = wx.StaticText(self, -1, _('&Title:'))
            self.title = t   = wx.TextCtrl(self, -1, '', size=(340,-1), validator=LengthLimit(255))
            t.Bind(wx.EVT_TEXT, lambda e: setattr(self, 'title_edited',
                                                  bool(self.title.Value)))

        self.status_label = wx.StaticText(self, -1, _('&State:'))

        curstatus = self.status_message.status if self.status_message is not None else None
        choices = get_state_choices(curstatus, is_exception)

        self.status = StatusChoice(self, choices)
        self.status.SetStatus('Away')

        self.message_label = wx.StaticText(self, -1, _('&Status message:'))

        self.message_panel = OutlinePanel(self)

        self.message = FormattedInput(self.message_panel, multiFormat = False,
                                      autosize = False,
                                      format = getattr(status_message, 'format', None) or StyleFromPref('messaging.default_style'),
                                      skin = 'AppDefaults.FormattingBar',
                                      validator= LengthLimit(10240),
                                      )
        self.message_panel.AddControl(self.message, 1, wx.EXPAND)

        self.message.SetMinSize(status_message_size)

        if not is_exception:
            self.message.tc.Bind(wx.EVT_TEXT, self.on_message_text)

            msg = self.status_message

            self.exceptionspanel = StatusExceptionPanel(self)
            self.exceptions = StatusExceptionList(self.exceptionspanel, self, status_message.exceptions if status_message else {})
            self.exceptionspanel.SetExceptionList(self.exceptions)

            hasexcs = msg is not None and msg.use_exceptions
            self.exceptionspanel.Show(hasexcs)

            chk = self.diffcheck = wx.CheckBox(self, -1, _('&Use a different status for some accounts'))
            chk.Value = hasexcs
            chk.Bind(wx.EVT_CHECKBOX, lambda e: self.show_exceptions(not self.exceptionspanel.IsShown()))

        s = self.save = wx.Button(self, wx.ID_SAVE, _('&Set') if self.save_checkbox else _('&Save'))
        s.SetDefault()
        s.Bind(wx.EVT_BUTTON, self.on_save)

        c = self.cancel = wx.Button(self, wx.ID_CANCEL, _('&Cancel'))
        c.Bind(wx.EVT_BUTTON, self.on_cancel)

        # Save checkbox
        if self.save_checkbox:
            self.save_check = wx.CheckBox(self, -1, _('Save for &later'))
Exemplo n.º 7
0
class StatusPanel(wx.Panel):
    '''
    Fields for entering a status message, which include:

    - a title
    - a message
    - optional exceptions for each account
    '''

    def __init__(self, parent, status_message = None, is_exception = False, save_checkbox = False):
        wx.Panel.__init__(self, parent)

        self.save_checkbox = save_checkbox        # True if this dialog needs a "Save" checkbox
        self.is_exception = is_exception          # Is this status dialog editing an exception?
        self.status_message = status_message      # the current status object
        self.title_edited = False                 # has the title text control been edited yet?

        self.construct(is_exception, status_message)
        if status_message is not None:
            self.populate_controls(status_message)
        self.layout(is_exception)

        self.Fit()

    def info(self):
        # Allows all text fields in this dialog to be optional.
        #
        # If "title" isn't specified but message is, then title becomes
        # the first line of message.
        #
        # If message is blank and title is not, message becomes title.
        #
        # If both are blank, both become the status.
        #
        status = self.status.db_val

        if not self.is_exception:
            title = self.title.Value
            if not title or title.isspace():
                title = None

        message = self.message.Value
        if not message or message.isspace(): message = None

        if not self.is_exception:
            if title is None:
                title = message.split('\n')[0] if message is not None else status
        else:
            title = None

        if message is None:
            message = title if title is not None else _(status)

        s = Storage(message = message,
                    status = status,
                    format  = self.message.Format)

        if not self.is_exception:
            # while editing exceptions, there isn't a title.
            s.title = title
            s.exceptions = self.exceptions.Exceptions if self.diffcheck.IsChecked() else {}

        from pprint import pformat
        log.info(pformat(dict(s)))

        return s

    def show_exceptions(self, show = True):
        'Shows or hides the exceptions list at the bottom of the dialog.'

        with self.Frozen():
            if self.exceptionspanel.Show(show):
                self.Top.FitInScreen()

    def on_message_text(self, e):
        e.Skip()
        if not self.title_edited:
            # the ChangeValue function does not emit EVT_TEXT

            # skip leading whitespace
            msg = self.message.Value.lstrip()

            # find all text up to the first newline
            newline = msg.find('\n')
            if newline == -1: newline = len(msg)

            self.title.ChangeValue( msg[:newline] )

    def populate_controls(self, status_message = None):
        for key in ('title', 'message'):
            if hasattr(self, key):
                getattr(self, key).Value = getattr(status_message, key)

        # Online, Away, Out to Luncg, etc...
        self.status.SetStatus(status_message.status)


    def construct(self, is_exception, status_message = None):

        if not is_exception:
            self.title_label = wx.StaticText(self, -1, _('&Title:'))
            self.title = t   = wx.TextCtrl(self, -1, '', size=(340,-1), validator=LengthLimit(255))
            t.Bind(wx.EVT_TEXT, lambda e: setattr(self, 'title_edited',
                                                  bool(self.title.Value)))

        self.status_label = wx.StaticText(self, -1, _('&State:'))

        curstatus = self.status_message.status if self.status_message is not None else None
        choices = get_state_choices(curstatus, is_exception)

        self.status = StatusChoice(self, choices)
        self.status.SetStatus('Away')

        self.message_label = wx.StaticText(self, -1, _('&Status message:'))

        self.message_panel = OutlinePanel(self)

        self.message = FormattedInput(self.message_panel, multiFormat = False,
                                      autosize = False,
                                      format = getattr(status_message, 'format', None) or StyleFromPref('messaging.default_style'),
                                      skin = 'AppDefaults.FormattingBar',
                                      validator= LengthLimit(10240),
                                      )
        self.message_panel.AddControl(self.message, 1, wx.EXPAND)

        self.message.SetMinSize(status_message_size)

        if not is_exception:
            self.message.tc.Bind(wx.EVT_TEXT, self.on_message_text)

            msg = self.status_message

            self.exceptionspanel = StatusExceptionPanel(self)
            self.exceptions = StatusExceptionList(self.exceptionspanel, self, status_message.exceptions if status_message else {})
            self.exceptionspanel.SetExceptionList(self.exceptions)

            hasexcs = msg is not None and msg.use_exceptions
            self.exceptionspanel.Show(hasexcs)

            chk = self.diffcheck = wx.CheckBox(self, -1, _('&Use a different status for some accounts'))
            chk.Value = hasexcs
            chk.Bind(wx.EVT_CHECKBOX, lambda e: self.show_exceptions(not self.exceptionspanel.IsShown()))

        s = self.save = wx.Button(self, wx.ID_SAVE, _('&Set') if self.save_checkbox else _('&Save'))
        s.SetDefault()
        s.Bind(wx.EVT_BUTTON, self.on_save)

        c = self.cancel = wx.Button(self, wx.ID_CANCEL, _('&Cancel'))
        c.Bind(wx.EVT_BUTTON, self.on_cancel)

        # Save checkbox
        if self.save_checkbox:
            self.save_check = wx.CheckBox(self, -1, _('Save for &later'))

    def layout(self, is_exception):
        self.Sizer = sz = BoxSizer(wx.VERTICAL)

        # The upper two fields: title text field and state combo box
        inner = wx.FlexGridSizer(2, 2, 6, 6)

        if not is_exception:
            inner.AddMany([ (self.title_label, 0, wx.ALIGN_CENTER_VERTICAL),
                            (self.title) ])
        inner.AddMany([ (self.status_label, 0, wx.ALIGN_CENTER_VERTICAL),
                        (self.status) ])
        inner.AddGrowableCol(1, 1)
        sz.Add(inner, 0, wx.EXPAND | wx.ALL, 8)

        # The label for the message, and the big text area itself
        sz.Add(self.message_label, 0, EXPAND | ALL,            8)
        h = wx.BoxSizer(wx.HORIZONTAL)
        h.Add((1,status_message_size[1]))
        h.Add(self.message_panel,       1, EXPAND)
        sz.Add(h, 1, EXPAND | RIGHT | LEFT, 15)
        #sz.Add(self.message)

        sz.AddSpacer(3)

        # Save For Later
        if self.save_checkbox: sz.Add(self.save_check, 0, EXPAND | TOP | LEFT, 8)

        if not is_exception:
            # The checkbox to expand the dialog
            sz.Add(self.diffcheck,  0, EXPAND | ALL, 8)

            # Status exceptions
            sz.Add(self.exceptionspanel, 0, EXPAND | RIGHT | LEFT | BOTTOM, 8)

        # Save/Cancel
        sz.Add(build_button_sizer(save=self.save, cancel=self.cancel), 0, EXPAND | BOTTOM | RIGHT | LEFT, 4)

    def on_cancel(self,e):
        self.Parent.Cancel()

    def on_save(self, e):
        self.Parent.Save()

    @property
    def SaveForLater(self):
        return hasattr(self, 'save_check') and self.save_check.IsChecked()