~adamblackburn/wicd/1.6.2.1

« back to all changes in this revision

Viewing changes to curses/curses_misc.py

  • Committer: Adam Blackburn
  • Date: 2009-08-26 03:24:45 UTC
  • Revision ID: compwiz18@gmail.com-20090826032445-gcx1kqyj2d1fmhpd
reverted to revision 436 (1.6.2)

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    dialog = TextDialog(message,6,40,('important',"ERROR"))
34
34
    return dialog.run(ui,parent)
35
35
 
 
36
# My savior.  :-)
 
37
# Although I could have made this myself pretty easily, just want to give credit
 
38
# where it's due.
 
39
# http://excess.org/urwid/browser/contrib/trunk/rbreu_filechooser.py
36
40
class SelText(urwid.Text):
37
41
    """A selectable text widget. See urwid.Text."""
38
42
 
204
208
            ])
205
209
        if not firstrun:
206
210
            self.frame.set_body(self.pile)
207
 
            self._w = self.frame
208
 
            self._invalidate()
 
211
            self.set_w(self.frame)
209
212
 
210
213
    def selectable(self):
211
214
        return True
250
253
# I based this off of the code found here:
251
254
# http://excess.org/urwid/browser/contrib/trunk/rbreu_menus.py
252
255
# This is a hack/kludge.  It isn't without quirks, but it more or less works.
253
 
# We need to wait for changes in urwid's Canvas API before we can actually
 
256
# We need to wait for changes in urwid's Canvas controls before we can actually
254
257
# make a real ComboBox.
255
258
class ComboBox(urwid.WidgetWrap):
256
259
    """A ComboBox of text objects"""
330
333
        str,trash =  self.label.get_text()
331
334
 
332
335
        self.overlay = None
 
336
        #w,sensitive=True,attrs=('editbx','editnfc'),focus_attr='editfc')
333
337
        self.cbox  = DynWrap(SelText(self.DOWN_ARROW),attrs=attrs,focus_attr=focus_attr)
334
 
        # Unicode will kill me sooner or later.
 
338
        # Unicode will kill me sooner or later.  ^_^
335
339
        if label != '':
336
340
            w = urwid.Columns([('fixed',len(str),self.label),self.cbox],dividechars=1)
337
341
        else:
340
344
 
341
345
        # We need this to pick our keypresses
342
346
        self.use_enter = use_enter
343
 
 
 
347
        # The Focus
344
348
        self.focus = focus
345
349
 
 
350
        # The callback and friends
346
351
        self.callback = callback
347
352
        self.user_args = user_args
348
353
 
376
381
            self.overlay = self.ComboSpace(self.list,parent,ui,self.focus,
377
382
                    pos=(0,row))
378
383
 
379
 
        self._w = w
380
 
        self._invalidate()
 
384
        self.set_w(w)
381
385
        self.parent = parent
382
386
        self.ui = ui
383
387
        self.row = row
438
442
                       urwid.Divider()] )
439
443
       w = self.frame
440
444
       self.view = w
 
445
       
 
446
       # pad area around listbox
 
447
       #w = urwid.Padding(w, ('fixed left',2), ('fixed right',2))
 
448
       #w = urwid.Filler(w, ('fixed top',1), ('fixed bottom',1))
 
449
       #w = urwid.AttrWrap(w, 'body')
441
450
 
442
451
    # buttons: tuple of name,exitcode
443
452
    def add_buttons(self, buttons):
494
503
class TextDialog(Dialog2):
495
504
    def __init__(self, text, height, width, header=None,align='left'):
496
505
        l = [urwid.Text(text)]
 
506
        #for line in text:
 
507
        #    l.append( urwid.Text( line,align=align))
497
508
        body = urwid.ListBox(l)
498
509
        body = urwid.AttrWrap(body, 'body')
499
510
 
585
596
                   else:
586
597
                       key += part
587
598
            
 
599
            #theText = urwid.Text([(attrs[0],cmd[0]),(attrs[1],cmd[1])])
588
600
            if debug:
589
601
                callback = self.debugClick
590
602
                args = cmd[1]
596
608
                ('fixed',len(key)+1,urwid.Text((attrs[0],key+':')) ),
597
609
                              urwid.AttrWrap(urwid.Text(cmd[1]),attrs[1])],
598
610
                              callback,args)
 
611
            #if i != len(tuples)-1:
 
612
            #    textList.append(('fixed',maxlen,col))
 
613
            #else: # The last one
599
614
            textList.append(col)
600
615
            i+=1
601
616
        if debug:
610
625
    def mouse_event(self,size,event,button,x,y,focus):
611
626
        # Widgets are evenly long (as of current), so...
612
627
        return self._w.mouse_event(size,event,button,x,y,focus)
 
628
        """
 
629
        if self.debug:
 
630
            if x > size[0]-10:
 
631
                return
 
632
            widsize = (size[0]-10)/len(self.callbacks)
 
633
        else:
 
634
            widsize = size[0]/len(self.callbacks)
 
635
        widnum = x/widsize
 
636
        if self.debug:
 
637
            text = str(widnum)
 
638
            if self.callbacks[widnum] == None:
 
639
                text += " None"
 
640
            self.debug.set_text(text)
 
641
        elif self.callbacks[widnum] != None:
 
642
            self.callbacks[widnum]()
 
643
        """