primitivus group chat & misc
primitivus: new widget: SurroundedText (text with a character repeated around it) primitivus: new decorator LabelLine (like lineBox, but with a label on the top line) wix & primitivus & quick_app: group chat method move to quick_chat wix: when new message, window is not raised anymore, but RequestUserAttention is called instead
This commit is contained in:
parent
a21a658c33
commit
dbb3520a4f
1 changed files with 113 additions and 31 deletions
|
|
@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
"""
|
||||
|
||||
import urwid
|
||||
from urwid.escape import utf8decode
|
||||
|
||||
class Password(urwid.Edit):
|
||||
|
||||
|
|
@ -59,7 +60,28 @@ class AdvancedEdit(urwid.Edit):
|
|||
return super(AdvancedEdit, self).keypress(size, key)
|
||||
|
||||
|
||||
class SurroundedText(urwid.FlowWidget):
|
||||
|
||||
def __init__(self,text,car=utf8decode('─')):
|
||||
self.text=text
|
||||
self.car=car
|
||||
|
||||
def rows(self,size,focus=False):
|
||||
return self.display_widget(size, focus).rows(size, focus)
|
||||
|
||||
def render(self, size, focus=False):
|
||||
return self.display_widget(size, focus).render(size, focus)
|
||||
|
||||
def display_widget(self, size, focus):
|
||||
(maxcol,) = size
|
||||
middle = (maxcol-len(self.text))/2
|
||||
render_text = middle * self.car + self.text + (maxcol - len(self.text) - middle) * self.car
|
||||
return urwid.Text(render_text)
|
||||
|
||||
|
||||
|
||||
class SelectableText(urwid.FlowWidget):
|
||||
"""Text which can be selected with space"""
|
||||
signals = ['change']
|
||||
|
||||
def __init__(self, text, align='left'):
|
||||
|
|
@ -255,9 +277,11 @@ class List(urwid.FlowWidget):
|
|||
|
||||
def displayWidget(self, size, focus):
|
||||
list_size = sum([wid.rows(size, focus) for wid in self.genericList.content])
|
||||
height = min(list_size,self.max_height)
|
||||
height = min(list_size,self.max_height) or 1
|
||||
return urwid.BoxAdapter(self.genericList, height)
|
||||
|
||||
## DIALOGS ##
|
||||
|
||||
class GenericDialog(urwid.WidgetWrap):
|
||||
|
||||
def __init__(self, widgets_lst, title, style=[], **kwargs):
|
||||
|
|
@ -286,9 +310,9 @@ class GenericDialog(urwid.WidgetWrap):
|
|||
|
||||
class InputDialog(GenericDialog):
|
||||
|
||||
def __init__(self, title, instrucions, style=['OK/CANCEL'], **kwargs):
|
||||
def __init__(self, title, instrucions, style=['OK/CANCEL'], default_txt = '', **kwargs):
|
||||
instr_wid = urwid.Text(instrucions+':')
|
||||
edit_box = urwid.Edit()
|
||||
edit_box = urwid.Edit(edit_text=default_txt)
|
||||
GenericDialog.__init__(self, [instr_wid,edit_box], title, style, ok_value=edit_box, **kwargs)
|
||||
|
||||
class ConfirmDialog(GenericDialog):
|
||||
|
|
@ -301,6 +325,8 @@ class Alert(GenericDialog):
|
|||
def __init__(self, title, message, style=['OK'], **kwargs):
|
||||
GenericDialog.__init__(self, [urwid.Text(message, 'center')], title, style, ok_value=None, **kwargs)
|
||||
|
||||
## CONTAINERS ##
|
||||
|
||||
class FocusFrame(urwid.Frame):
|
||||
"""Frame which manage "tab" key"""
|
||||
|
||||
|
|
@ -316,3 +342,12 @@ class FocusFrame(urwid.Frame):
|
|||
self.set_focus(focus_name)
|
||||
|
||||
return urwid.Frame.keypress(self, size, key)
|
||||
|
||||
## DECORATORS ##
|
||||
class LabelLine(urwid.LineBox):
|
||||
|
||||
def __init__(self, original_widget, label_widget):
|
||||
urwid.LineBox.__init__(self, original_widget)
|
||||
top_columns = self._w.widget_list[0]
|
||||
top_columns.widget_list[1] = label_widget
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue