Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, parent):
self.parent = parent
self._edit = ExtendedEdit('', parent.active)
urwid.connect_signal(self._edit, 'change',
lambda edit, text: self.filter(text))
self._walker = urwid.SimpleFocusListWalker([self._edit])
walker = urwid.BoxAdapter(
urwid.ListBox(self._walker), height=self.parent.win_len - 1)
self._pile = NPile([self._edit, walker], outermost=True)
self.filter('')
self.focus_on(self.parent.active)
fill = urwid.Filler(self._pile, 'top')
urwid.WidgetWrap.__init__(self, urwid.AttrMap(fill, 'popupbg'))
def _delete_till_end_of_line(self):
"""delete till end of line before cursor"""
text = self.get_edit_text()
f_text = delete_till_end_of_line(text[self.edit_pos:])
self.set_edit_text(text[:self.edit_pos] + f_text)
def _goto_beginning_of_line(self):
text = self.get_edit_text()
self.set_edit_pos(goto_beginning_of_line(text[:self.edit_pos]))
def _goto_end_of_line(self):
text = self.get_edit_text()
self.set_edit_pos(goto_end_of_line(text[self.edit_pos:]) + self.edit_pos)
class EnterEdit(ExtendedEdit):
"""Edit class that emits signal `enter` if user tries to edit"""
signals = ['enter']
def keypress(self, size, key):
if key not in ['up', 'down', 'left', 'right', 'tab', 'shift tab']:
self._emit('enter')
return
else:
return super().keypress(size, key)
class DateTimeWidget(ExtendedEdit):
def __init__(self, dateformat, on_date_change=lambda x: None, **kwargs):
self.dateformat = dateformat
self.on_date_change = on_date_change
def __init__(self, this_func, abort_func, event):
lines = []
lines.append(urwid.Text('Export event as ICS file'))
lines.append(urwid.Text(''))
export_location = ExtendedEdit(
caption='Location: ', edit_text="~/%s.ics" % event.summary.strip())
lines.append(export_location)
lines.append(urwid.Divider(' '))
lines.append(
urwid.Button('Save', on_press=this_func, user_data=export_location)
)
content = NPile(lines)
urwid.WidgetWrap.__init__(self, urwid.LineBox(content))
def __init__(self, alarm, delete_handler):
duration, description = alarm
if duration.total_seconds() > 0:
direction = 'after'
else:
direction = 'before'
duration = -1 * duration
self.duration = DurationWidget(duration)
self.description = ExtendedEdit(edit_text=description)
self.direction = Choice(
['before', 'after'], active=direction, overlay_width=10)
self.columns = NColumns([
(2, urwid.Text(' ')),
(21, self.duration),
(14, urwid.Padding(self.direction, right=1)),
self.description,
(10, urwid.Button('Delete', on_press=delete_handler, user_data=self)),
])
urwid.WidgetWrap.__init__(self, self.columns)
self.set_edit_pos(goto_end_of_line(text[self.edit_pos:]) + self.edit_pos)
class EnterEdit(ExtendedEdit):
"""Edit class that emits signal `enter` if user tries to edit"""
signals = ['enter']
def keypress(self, size, key):
if key not in ['up', 'down', 'left', 'right', 'tab', 'shift tab']:
self._emit('enter')
return
else:
return super().keypress(size, key)
class DateTimeWidget(ExtendedEdit):
def __init__(self, dateformat, on_date_change=lambda x: None, **kwargs):
self.dateformat = dateformat
self.on_date_change = on_date_change
super().__init__(wrap='any', **kwargs)
def keypress(self, size, key):
if key == 'ctrl x':
self.decrease()
return None
elif key == 'ctrl a':
self.increase()
return None
if (
key in ['up', 'down', 'tab', 'shift tab'] or
self._abort_confirmed = False
self.description = event.description
self.location = event.location
self.categories = event.categories
self.startendeditor = StartEndEditor(
event.start_local, event.end_local, self._conf,
self.start_datechange, self.end_datechange,
)
# TODO make sure recurrence rules cannot be edited if we only
# edit one instance (or this and future) (once we support that)
self.recurrenceeditor = RecurrenceEditor(
self.event.recurobject, self._conf, event.start_local,
)
self.summary = urwid.AttrMap(ExtendedEdit(
caption=('', 'Title: '), edit_text=event.summary), 'edit'
)
divider = urwid.Divider(' ')
def decorate_choice(c):
return ('calendar ' + c['name'], c['name'])
self.calendar_chooser = Choice(
[self.collection._calendars[c] for c in self.collection.writable_names],
self.collection._calendars[self.event.calendar],
decorate_choice
)
self.description = urwid.AttrMap(
ExtendedEdit(
caption=('', 'Description: '),
self.summary = urwid.AttrMap(ExtendedEdit(
caption=('', 'Title: '), edit_text=event.summary), 'edit'
)
divider = urwid.Divider(' ')
def decorate_choice(c):
return ('calendar ' + c['name'], c['name'])
self.calendar_chooser = Choice(
[self.collection._calendars[c] for c in self.collection.writable_names],
self.collection._calendars[self.event.calendar],
decorate_choice
)
self.description = urwid.AttrMap(
ExtendedEdit(
caption=('', 'Description: '),
edit_text=self.description,
multiline=True
),
'edit'
)
self.location = urwid.AttrMap(ExtendedEdit(
caption=('', 'Location: '), edit_text=self.location), 'edit'
)
self.categories = urwid.AttrMap(ExtendedEdit(
caption=('', 'Categories: '), edit_text=self.categories), 'edit'
)
self.alarms = AlarmsEditor(self.event)
self.pile = NListBox(urwid.SimpleFocusListWalker([
self.summary,
urwid.Columns([(12, self.calendar_chooser)]),
def keypress(self, size, key):
if key == 'ctrl w':
self._delete_word()
elif key == 'ctrl u':
self._delete_till_beginning_of_line()
elif key == 'ctrl k':
self._delete_till_end_of_line()
elif key == 'ctrl a':
self._goto_beginning_of_line()
elif key == 'ctrl e':
self._goto_end_of_line()
else:
return super(ExtendedEdit, self).keypress(size, key)
def __init__(self, search_func, abort_func):
class Search(Edit):
def keypress(self, size, key):
if key == 'enter':
search_func(self.text)
else:
return super().keypress(size, key)
search_field = Search('')
def this_func(_):
search_func(search_field.text)
lines = []
lines.append(urwid.Text('Please enter a search term (Escape cancels):'))
lines.append(search_field)
buttons = NColumns([urwid.Button('Search', on_press=this_func),
def __init__(self, search_func, abort_func):
class Search(Edit):
def keypress(self, size, key):
if key == 'enter':
search_func(self.text)
else:
return super().keypress(size, key)
search_field = Search('')
def this_func(_):
search_func(search_field.text)
lines = []
lines.append(urwid.Text('Please enter a search term (Escape cancels):'))
lines.append(search_field)
buttons = NColumns([urwid.Button('Search', on_press=this_func),