Ejemplo n.º 1
0
 def __init__(self, initialValue="", target="", method="POST"):
     Widget.__init__(self);
     self.id = "rte"+hash(self)
     fck = createFCK("fck"+self.id)
     fck.Height = "600px"
     self.setElement(DOM.createForm())
     DOM.setAttribute(self.element, "method", "POST")
     DOM.setAttribute(self.element, "target", target)
     JS("""
     var rte = this;
     this.element.onsubmit = function() {
         $wnd.setTimeout(function() { rte.onSave.call(rte) }, 0);
         return false;
     }
     """)
     self.setID(self.id)
     self.addStyleName("gwt-RichTextEditor")
     fck.Value = initialValue
     fck.BasePath = "fckeditor/"
     fck.Config.CustomConfigurationsPath = "../../fckconfig.js"
     fck.pyjsObject = self
     self.loaded = False
     self.saveListeners = []
     self.pendingHTML = None
     html = fck.CreateHtml()
     #console.log("fck html = %s", html)
     html = html
     DOM.setInnerHTML(self.getElement(), html)
Ejemplo n.º 2
0
    def __init__(self,
                 path=None,
                 slice_left=0,
                 slice_right=0,
                 slice_top=0,
                 slice_bottom=0,
                 fill=False,
                 **kwargs):
        Widget.__init__(self, fill=fill, **kwargs)

        #: path to the image file
        self.path = path
        self.image_data, self.image_w, self.image_h = None, None, None

        if path:
            self.image_data = cairo.ImageSurface.create_from_png(self.path)
            self.image_w, self.image_h = self.image_data.get_width(
            ), self.image_data.get_height()

        self.min_width, self.min_height = self.min_width or self.image_w, self.min_height or self.image_h

        #: pixels from left that should not be scaled upon image scale
        self.slice_left = slice_left

        #: pixels from right that should not be scaled upon image scale
        self.slice_right = slice_right

        #: pixels from top that should not be scaled upon image scale
        self.slice_top = slice_top

        #: pixels from bottom that should not be scaled upon image scale
        self.slice_bottom = slice_bottom

        self._slices = []
        self._slice()
Ejemplo n.º 3
0
    def __init__(self, path = None, slice_left=0, slice_right=0, slice_top=0, slice_bottom=0, fill = False, **kwargs):
        Widget.__init__(self, fill = fill, **kwargs)

        #: path to the image file
        self.path = path
        self.image_data, self.image_w, self.image_h = None, None, None

        if path:
            self.image_data = cairo.ImageSurface.create_from_png(self.path)
            self.image_w, self.image_h = self.image_data.get_width(), self.image_data.get_height()

        self.min_width, self.min_height = self.min_width or self.image_w, self.min_height or self.image_h

        #: pixels from left that should not be scaled upon image scale
        self.slice_left = slice_left

        #: pixels from right that should not be scaled upon image scale
        self.slice_right = slice_right

        #: pixels from top that should not be scaled upon image scale
        self.slice_top = slice_top

        #: pixels from bottom that should not be scaled upon image scale
        self.slice_bottom = slice_bottom

        self._slices = []
        self._slice()
Ejemplo n.º 4
0
    def __setattr__(self, name, val):
        new_rows = False
        if name == "rows":
            if isinstance(val, TreeModel) == False:
                val = TreeModel(val)

            if getattr(self, "rows", None):
                for listener in getattr(self, "_data_change_listeners", []):
                    self.rows.disconnect(listener)
            if getattr(self, "rows", None):
                new_rows = True
            self.queue_resize()

        row_changed = name == "current_row" and val != self.__dict__.get(
            name, 'hamster_no_value_really')
        Widget.__setattr__(self, name, val)

        if new_rows:
            self._on_row_deleted(self.rows)

        if row_changed:
            self.emit("on-change", val if val else None)

        if name == "rows":
            changed = self.rows.connect("row-changed", self._on_row_changed)
            deleted = self.rows.connect("row-deleted", self._on_row_deleted)
            inserted = self.rows.connect("row-inserted", self._on_row_inserted)
            self._data_change_listeners = [changed, deleted, inserted]
        elif name == "padding":
            for renderer in self.renderers:
                renderer.padding = val
        elif name == "current_row" and val:
            self.scroll_to_row(val)
Ejemplo n.º 5
0
    def __init__(self):

        self.__current_page = 0
        self.__pages = []

        data = open(os.path.join(_PATH, "tour_C.dat")).read()
        self.__parse_tour(data)

        Configurator.__init__(self)

        self.__tour_box = Widget()

        # toolbar elements
        btn_toc = ToolbarButton(theme.mb_btn_toc_1)
        btn_toc.connect_clicked(self.__on_btn_toc)

        btn_previous = ToolbarButton(theme.mb_btn_previous_1)
        btn_previous.connect_clicked(self.__on_btn_previous)

        btn_next = ToolbarButton(theme.mb_btn_next_1)
        btn_next.connect_clicked(self.__on_btn_next)

        # toolbar
        self.__toolbar = Toolbar()
        self.__toolbar.set_toolbar(btn_previous, btn_toc, btn_next)

        # arrangement
        self.__arr = Arrangement()
        self.__arr.connect_resized(self.__update_layout)
        self.__arr.add(self.__tour_box, "content")
        self.__arr.add(self.__toolbar, "toolbar")
        self.add(self.__arr)
Ejemplo n.º 6
0
    def PaneWithLabelframe(cls,
                           master,
                           f_name,
                           s_name,
                           orient=Tkconstants.HORIZONTAL):
        '''Sample usage:
            from com.ui import ROOT    
            (frame1, frame2) = Components.PaneWithLabelframe(ROOT, "frame1", "frame2")[1:]
            Window.widg = Widget.Button(frame1,text = "button1")
            Window.Pack()
            
            Window.widg = Widget.Button(frame2,text = "button2")
            Window.Pack()
            ROOT.mainloop()
        '''
        p = Widget.Panedwindow(master, orient=orient)
        l1 = Widget.Labelframe(master, text=f_name)
        l2 = Widget.Labelframe(master, text=s_name)
        p.add(l1)
        p.add(l2)
        Window.widg = p
        Window.Pack(side="top",
                    fill=Tkconstants.BOTH,
                    expand=Tkconstants.YES,
                    pady=2,
                    padx=2)

        return (p, l1, l2)
Ejemplo n.º 7
0
    def __setattr__(self, name, val):
        new_rows = False
        if name == "rows":
            if isinstance(val, TreeModel) == False:
                val = TreeModel(val)

            if getattr(self, "rows", None):
                for listener in getattr(self, "_data_change_listeners", []):
                    self.rows.disconnect(listener)
            if getattr(self, "rows", None):
                new_rows = True
            self.queue_resize()

        row_changed = name == "current_row" and val != self.__dict__.get(name, "hamster_no_value_really")
        Widget.__setattr__(self, name, val)

        if new_rows:
            self._on_row_deleted(self.rows)

        if row_changed:
            self.emit("on-change", val if val else None)

        if name == "rows":
            changed = self.rows.connect("row-changed", self._on_row_changed)
            deleted = self.rows.connect("row-deleted", self._on_row_deleted)
            inserted = self.rows.connect("row-inserted", self._on_row_inserted)
            self._data_change_listeners = [changed, deleted, inserted]
        elif name == "padding":
            for renderer in self.renderers:
                renderer.padding = val
        elif name == "current_row" and val:
            self.scroll_to_row(val)
Ejemplo n.º 8
0
    def __init__(self, title, label_ok="OK", label_cancel="Cancel"):

        self.__inputs = []
        self.__return_code = self.RETURN_CANCEL

        # list of value retrieving functions
        self.__retrievers = []

        Window.__init__(self, Window.TYPE_DIALOG)
        self.set_flag(windowflags.EXCLUSIVE, True)
        self.connect_closed(self.__on_close, self.RETURN_CANCEL)
        self.set_title(title)

        self.__box = Widget()
        self.add(self.__box)

        self.__button_ok = Button(label_ok)
        self.__button_ok.connect_clicked(self.__on_close, self.RETURN_OK)
        self.__box.add(self.__button_ok)

        if (not platforms.MAEMO5):
            self.__button_cancel = Button(label_cancel)
            self.__button_cancel.connect_clicked(self.__on_close,
                                                 self.RETURN_CANCEL)
            self.__box.add(self.__button_cancel)

        self.__vbox = VBox()
        self.__box.add(self.__vbox)
Ejemplo n.º 9
0
    def __init__(self, value, label=None, **kwargs):
        Widget.__init__(self, **kwargs)

        #: value
        self.value = value

        #: label
        self.label = label
Ejemplo n.º 10
0
    def __init__(self,
                 horizontal=False,
                 thickness=None,
                 size=0,
                 offset=0,
                 **kwargs):
        Box.__init__(self, **kwargs)
        self.interactive, self.cursor = True, False

        self.spacing = 0

        self.thickness = thickness if thickness else self.thickness

        #: whether the scroll bar is vertical or horizontal
        self.orient_horizontal = horizontal

        #: width of the bar in pixels
        self.size = size

        #: scroll position in range 0..1
        self.offset = offset

        if horizontal:
            self.expand_vert = False
            self.min_height = thickness
        else:
            self.expand = False
            self.min_width = thickness

        #: slider container
        self.slider_zone = Widget()

        #: slider widget
        self.slider = ScrollBarSlider()
        self.slider_zone.add_child(self.slider)

        #: the scroll up button
        self.up = ScrollBarButton(
            direction="left" if self.orient_horizontal else "up")

        #: the scroll down button
        self.down = ScrollBarButton(
            direction="right" if self.orient_horizontal else "down")

        self.add_child(self.up, self.slider_zone, self.down)

        self._timeout = None

        for button in (self.up, self.down):
            self.connect_child(button, "on-mouse-down",
                               self.on_scrollbutton_pressed)
            self.connect_child(button, "on-mouse-up",
                               self.on_scrollbutton_released)
            self.connect_child(button, "on-mouse-out",
                               self.on_scrollbutton_released)

        self.connect_child(self.slider, "on-drag", self.on_slider_drag)
        self.connect("on-click", self.on_click)
Ejemplo n.º 11
0
 def draw (self, screen, pos = (0, 0), draw_bg = True):
     Widget.draw(self, screen, pos, draw_bg)
     for c in self.cons:
         c.draw_base(screen, pos)
     for p in self.people:
         p.draw(screen, pos)
     for c in self.cons:
         c.draw_pos(screen, pos)
     if self._sel_area is not None:
         img_pos, img = self._sel_area
         screen.blit(img, sum_pos(pos, img_pos))
     return True
Ejemplo n.º 12
0
    def ListWithScrollbar(cls, master):
        '''Sample usage:
            from com.ui import ROOT    
            frame1 = Widget.Labelframe(ROOT,text = "sssss")
            frame1.rowconfigure(0,weight =1, minsize = 0)
            frame1.columnconfigure(0,weight =1, minsize = 0)
            Window.widg = frame1
            Window.Pack(side = "top", fill="both", expand="yes", padx = "0.2c")
                
            (l,x,y) = Components.ListWithScrollbar(frame1)
            elems = ["Don't speculate, measure", "Waste not, want not", "Early to bed and early to rise makes a man healthy, wealthy, and wise", "Ask not what your country can do for you, ask what you can do for your country", "I shall return", "NOT", "A picture is worth a thousand words", "User interfaces are hard to build", "Thou shalt not steal", "A penny for your thoughts", "Fool me once, shame on you;  fool me twice, shame on me", "Every cloud has a silver lining", "Where there's smoke there's fire", "It takes one to know one", "Curiosity killed the cat", "Take this job and shove it", "Up a creek without a paddle", "I'm mad as hell and I'm not going to take it any more", "An apple a day keeps the doctor away", "Don't look a gift horse in the mouth", "Measure twice, cut once"]
            l.insert(0,*elems)
            ROOT.mainloop()
        '''
        f = TkFont()
        lb = Widget.Listbox(master,
                            width=60,
                            height=24,
                            font=f.font,
                            setgrid=1)
        s_x = Widget.Scrollbar(master,
                               orient=Tkconstants.HORIZONTAL,
                               command=lb.xview)
        s_y = Widget.Scrollbar(master,
                               orient=Tkconstants.VERTICAL,
                               command=lb.yview)

        Window.widg = s_y
        Window.Pack(side="right", fill="y")

        Window.widg = s_x
        Window.Pack(side="bottom", fill="x")

        Window.widg = lb
        Window.Config(xscrollcommand=s_x.set, yscrollcommand=s_y.set)
        Window.Pack(side="top", fill="both", expand="yes")

        #         lb = Widget.Listbox(master, width = 20, height = 10, setgrid = 1)
        #         s_x = Widget.Scrollbar(master,orient = Tkconstants.HORIZONTAL, command = lb.xview)
        #         s_y = Widget.Scrollbar(master,orient = Tkconstants.VERTICAL, command = lb.yview)
        #
        #         Window.widg = lb
        #         Window.Config(xscrollcommand = s_x.set, yscrollcommand = s_y.set)
        #         Window.Grid(row =0, column = 0, rowspan = 1, columnspan = 1, sticky = Tkconstants.NSEW)
        #
        #         Window.widg = s_y
        #         Window.Grid(row =0, column = 1, rowspan = 1, columnspan = 1, sticky = Tkconstants.NSEW)
        #
        #         Window.widg = s_x
        #         Window.Grid(row =1, column = 0, rowspan = 1, columnspan = 1, sticky = Tkconstants.NSEW)

        return (lb, s_x, s_y)
Ejemplo n.º 13
0
    def __setattr__(self, name, val):
        Widget.__setattr__(self, name, val)
        if self.__dict__.get(name, "hamster_graphics_no_value_really") == val:
            return

        # reslice when params change
        if name in ("slice_left", "slice_top", "slice_right", "slice_bottom") and hasattr(self, "_slices"):
            self._slice()

        if name == "path" and val and hasattr(self, "image_data"):
            self.image_data = cairo.ImageSurface.create_from_png(val)
            self.image_w, self.image_h = self.image_data.get_width(), self.image_data.get_height()
            self._slice()
Ejemplo n.º 14
0
    def __setattr__(self, name, val):
        Widget.__setattr__(self, name, val)
        if self.__dict__.get(name, "hamster_graphics_no_value_really") == val:
            return

        # reslice when params change
        if name in ("slice_left", "slice_top", "slice_right",
                    "slice_bottom") and hasattr(self, "_slices"):
            self._slice()

        if name == "path" and val and hasattr(self, "image_data"):
            self.image_data = cairo.ImageSurface.create_from_png(val)
            self.image_w, self.image_h = self.image_data.get_width(
            ), self.image_data.get_height()
            self._slice()
Ejemplo n.º 15
0
 def __init__(self):
 
     self.__buffer = None
     
     self.__title = ""
     self.__info = "- no media loaded -"
     self.__cover = theme.mb_logo
     
     self.__prepared_file = None
     
     
     Component.__init__(self)
     Widget.__init__(self)
     
     self.connect_clicked(self.__on_click)
Ejemplo n.º 16
0
    def __setattr__(self, name, val):
        if self.__dict__.get(name, "hamster_graphics_no_value_really") == val:
            return

        Widget.__setattr__(self, name, val)
        if name == 'contents':
            if val:
                if isinstance(val, graphics.Sprite):
                    val = [val]
                self.add_child(*val)
            if self.sprites and self.sprites != val:
                self.remove_child(*list(set(self.sprites) ^ set(val or [])))

        if name in ("alloc_w", "alloc_h") and val:
            self.__dict__['_cached_w'], self.__dict__['_cached_h'] = None, None
            self._children_resize_queued = True
Ejemplo n.º 17
0
    def on_resize(self, size, final):
        Widget.on_resize(self, size, final)

        dx, dy = size * (1.0 / self._cols, 1.0 / self._rows)

        x = 0.0
        y = 0.0
        for n, widget in enumerate(self.get_children()):
            widget.pos.x = (n % self._cols) * dx
            widget.pos.y = (n / self._cols) * dy
            widget.pos.z = 0.0

            widget.size.x = dx
            widget.size.y = dy

            widget.on_resize(widget.size, final)
Ejemplo n.º 18
0
    def __setattr__(self, name, val):
        if self.__dict__.get(name, "hamster_graphics_no_value_really") == val:
            return

        Widget.__setattr__(self, name, val)
        if name == 'contents':
            if val:
                if isinstance(val, graphics.Sprite):
                    val = [val]
                self.add_child(*val)
            if self.sprites and self.sprites != val:
                self.remove_child(*list(set(self.sprites) ^ set(val or [])))

        if name in ("alloc_w", "alloc_h") and val:
            self.__dict__['_cached_w'], self.__dict__['_cached_h'] = None, None
            self._children_resize_queued = True
Ejemplo n.º 19
0
    def on_resize(self, size, final):
        Widget.on_resize(self, size, final)
        
        dx, dy = size * (1.0/self._cols, 1.0/self._rows)

        x = 0.0
        y = 0.0
        for n, widget in enumerate(self.get_children()):
            widget.pos.x = (n%self._cols) * dx
            widget.pos.y = (n/self._cols) * dy
            widget.pos.z = 0.0
            
            widget.size.x = dx
            widget.size.y = dy

            widget.on_resize(widget.size, final)
Ejemplo n.º 20
0
    def __init__(self,
                 rows=[],
                 renderers=None,
                 select_on_drag=False,
                 spacing=0,
                 row_height=None,
                 **kwargs):
        Widget.__init__(self, **kwargs)
        self.interactive, self.can_focus = True, True
        self.mouse_cursor = False

        #: should an item be select upon drag motion. By default select happens
        #: only when clicking
        self.select_on_drag = select_on_drag

        #: the list of text strings available for selection
        self.rows = rows

        #: row height in pixels. if specified, will be using that instead of
        #: asking cell renderers. defaults to None.
        self.row_height = row_height

        self._search_string = ""
        self._search_timeout = None

        self._row_pos = None  # cache of row positions

        self._hover_row = None

        #: currently selected item
        self.current_row = None

        if renderers is not None:
            self.renderers = renderers
        else:
            self.renderers = [renderer() for renderer in self.renderers]

        self.connect("on-mouse-move", self.__on_mouse_move)
        self.connect("on-mouse-down", self.__on_mouse_down)
        self.connect("on-mouse-out", self.__on_mouse_out)

        self.connect("on-mouse-scroll", self.on_mouse_scroll)
        self.connect("on-double-click", self.on_doubleclick)
        self.connect("on-key-press", self.__on_key_press)

        self.connect("on-render", self.__on_render)
Ejemplo n.º 21
0
    def LabelWithEntryAndButton(cls, master, grid_tree):
        '''Sample usage
            from com.ui import ROOT    
            frame1 = Widget.Labelframe(ROOT,text = "YYYY")
            Window.widg = frame1        
            Window.Pack(side = "top", fill="both", expand="yes", padx = "0.2c")
            
            grid_tree = [
                        [(u"用户名:", u"登录")],
                        [(u"密码:", ""),(u"验证码:", "")], 
                    ]
            widgets = Components.LabelWithEntryAndButton(frame1, grid_tree)
            widgets[0][1].insert("end","hi handsome boy.")    
            ROOT.mainloop()
        '''
        result = []
        rows = len(grid_tree)
        for row in range(rows):
            result.append([])
            column = -1

            groups = grid_tree[row]
            for lable_name, button_name in groups:
                column = column + 1
                label = Widget.Label(master, text=lable_name)
                result[row].append(label)
                Window.widg = label
                Window.Grid(row, column, "w")

                column = column + 1
                entry = Widget.Entry(master)
                result[row].append(entry)
                Window.widg = entry
                Window.Grid(row, column, "ew")

                if button_name:
                    column = column + 1
                    button = Widget.Button(master, text=button_name)
                    result[row].append(button)
                    Window.widg = button
                    Window.Grid(row, column, "e")
        return result
Ejemplo n.º 22
0
    def TextWithScrollbar(cls, master):
        '''Sample usage:
            from com.ui import ROOT    
            frame1 = Widget.Labelframe(ROOT,text = "XXXX")
            Window.widg = frame1        
            Window.Pack(side = "top", fill="both", expand="yes", padx = "0.2c")
            
            (t,x,y) = Components.TextWithScrollbar(frame1)    
            t.insert("end","0.ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\n")
            t.insert("end","1.sdf\n")    
            ROOT.mainloop()
        '''
        f = TkFont()
        # wrap -->设置当一行文本的长度超过width选项设置的宽度时,是否换行; "none"不自动换行, "char"按字符自动换行, "word"按单词自动换行
        # undo -->设置文本 是否可以 撤销 和 恢复; 默认值是  0 或者 False,表示没有开启
        tx = Widget.Text(master,
                         width=60,
                         height=24,
                         font=f.font,
                         wrap="word",
                         setgrid=1,
                         undo=True,
                         background="white")
        s_x = Widget.Scrollbar(master,
                               orient=Tkconstants.HORIZONTAL,
                               command=tx.xview)
        s_y = Widget.Scrollbar(master,
                               orient=Tkconstants.VERTICAL,
                               command=tx.yview)

        Window.widg = s_y
        Window.Pack(side="right", fill="y")

        Window.widg = s_x
        Window.Pack(side="bottom", fill="x")

        Window.widg = tx
        Window.Config(xscrollcommand=s_x.set, yscrollcommand=s_y.set)
        Window.Pack(side="top", fill="both", expand="yes")

        return (tx, s_x, s_y)
Ejemplo n.º 23
0
    def __init__(self, rows=[], renderers=None, select_on_drag=False, spacing=0, row_height=None, **kwargs):
        Widget.__init__(self, **kwargs)
        self.interactive, self.can_focus = True, True
        self.mouse_cursor = False

        #: should an item be select upon drag motion. By default select happens
        #: only when clicking
        self.select_on_drag = select_on_drag

        #: the list of text strings available for selection
        self.rows = rows

        #: row height in pixels. if specified, will be using that instead of
        #: asking cell renderers. defaults to None.
        self.row_height = row_height

        self._search_string = ""
        self._search_timeout = None

        self._row_pos = None  # cache of row positions

        self._hover_row = None

        #: currently selected item
        self.current_row = None

        if renderers is not None:
            self.renderers = renderers
        else:
            self.renderers = [renderer() for renderer in self.renderers]

        self.connect("on-mouse-move", self.__on_mouse_move)
        self.connect("on-mouse-down", self.__on_mouse_down)
        self.connect("on-mouse-out", self.__on_mouse_out)

        self.connect("on-mouse-scroll", self.on_mouse_scroll)
        self.connect("on-double-click", self.on_doubleclick)
        self.connect("on-key-press", self.__on_key_press)

        self.connect("on-render", self.__on_render)
Ejemplo n.º 24
0
    def __init__(self, horizontal = False, thickness = None, size = 0, offset = 0, **kwargs):
        Box.__init__(self, **kwargs)
        self.interactive, self.cursor = True, False

        self.spacing = 0

        self.thickness = thickness if thickness else self.thickness

        #: whether the scroll bar is vertical or horizontal
        self.orient_horizontal = horizontal

        #: width of the bar in pixels
        self.size = size

        #: scroll position in range 0..1
        self.offset = offset

        if horizontal:
            self.expand_vert = False
            self.min_height = thickness
        else:
            self.expand = False
            self.min_width = thickness

        #: slider container
        self.slider_zone = Widget()

        #: slider widget
        self.slider = ScrollBarSlider()
        self.slider_zone.add_child(self.slider)

        #: the scroll up button
        self.up = ScrollBarButton(direction="left" if self.orient_horizontal else "up")

        #: the scroll down button
        self.down = ScrollBarButton(direction="right" if self.orient_horizontal else "down")

        self.add_child(self.up, self.slider_zone, self.down)

        self._timeout = None

        for button in (self.up, self.down):
            self.connect_child(button, "on-mouse-down", self.on_scrollbutton_pressed)
            self.connect_child(button, "on-mouse-up", self.on_scrollbutton_released)
            self.connect_child(button, "on-mouse-out", self.on_scrollbutton_released)

        self.connect_child(self.slider, "on-drag", self.on_slider_drag)
        self.connect("on-click", self.on_click)
Ejemplo n.º 25
0
    def __init__(self, window):
        Texture.__init__(self)
        pyglet.event.EventDispatcher.__init__(self)
        self.window = window
        self.dragging = False
        self.grid = grid = Grid(cols={1:self.mapping_width}, rows=40)
        
        
        text1 = Text('Hi')
        text2 = Text('World')
        checkbox = Checkbox('Toggle', 'non')
        
        g = Graph(100, 100, 0, 0)
        
        dial = Dial(100, '30%')
        dial.value = 0.30
        vdial = VDial(100)
        vdial.value = 0.30
        r1 = Row([text1, text2, checkbox, dial, g, vdial])

        self.col = Column()
        self.col.append(r1)
        for i in range(3):
            for j in range(3):
                pass
                self.grid[i,j] = Button('Grid Button'+str(i+j))
        r2 = Row([self.grid])
        self.col.append(r2)
        self.col.x = 20
        self.col.width = 400
        self.col.height = 300
        self.scrollable = Scrollable(self.col, 300)
        self.scrollable = Column()
        self.widget = Widget('My Dialog', self.scrollable)
        close = Close()
        close.x = self.widget.width - close.width - 15
        close.y = self.widget.height - close.height - 15
        close.on_click = self.on_close
        
        self.children = [self.widget, close]#, self.resizer]
        
        self.width = self.widget.width
        self.height = self.widget.height
        self._layout()
Ejemplo n.º 26
0
    def RadioWithLabelframe(cls, master, texts=[], values=[], command=None):
        '''Sample usage:
            from ui import ROOT    
            frame1 = Widget.Labelframe(ROOT,text = "XXXX")
            Window.widg = frame1        
            Window.Pack(side = "left", fill="both", expand="no", padx = "0.2c")
                    
            frame2 = None
            def test(a):
                print a
                if frame2:
                    frame2.config(text = var.get())
                    t.delete("1.0","end")
                    t.insert("end",var.get())
                
            var,rds = Components.RadioWithLabelframe(frame1, texts = [1,2,3,4,5], values = [1,2,3,4,5], command = lambda: test("if command has parameter; please use lambda.like this"))
            
            frame2 = Widget.Labelframe(ROOT,text = "YYYY")        
            Window.widg = frame2
            Window.Pack(side = "left", fill="both", expand="yes", padx = "0.2c")
            (t,x,y) = Components.TextWithScrollbar(frame2)
                    
            ROOT.mainloop()
        '''
        radios = []
        var = Tkinter.StringVar()
        radio_items = dict(zip(texts, values))
        for text, value in radio_items.items():
            Window.widg = Widget.Radiobutton(master, variable=var)
            Window.Config(text=text, value=value)
            if command:
                Window.Config(command=command)
            Window.Pack(side="top", fill="x", expand="yes", pady=2, anchor="w")
            radios.append(Window.widg)

        if radios:
            return var, radios
Ejemplo n.º 27
0
 def remove_child(self, *sprites):
     Widget.remove_child(self, *sprites)
     self.queue_resize()
Ejemplo n.º 28
0
class ScrollBar(Box):
    """A scroll bar.

    **Signals**:

    **on-scroll** *(sprite, current_normalized_position)*
    - fired after scrolling.
    """
    __gsignals__ = {
        "on-scroll": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)),
        "on-scroll-step": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)),
        "on-scroll-page": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)),
    }

    #: thickness of the bar in pixels
    thickness = 20

    def __init__(self, horizontal = False, thickness = None, size = 0, offset = 0, **kwargs):
        Box.__init__(self, **kwargs)
        self.interactive, self.cursor = True, False

        self.spacing = 0

        self.thickness = thickness if thickness else self.thickness

        #: whether the scroll bar is vertical or horizontal
        self.orient_horizontal = horizontal

        #: width of the bar in pixels
        self.size = size

        #: scroll position in range 0..1
        self.offset = offset

        if horizontal:
            self.expand_vert = False
            self.min_height = thickness
        else:
            self.expand = False
            self.min_width = thickness

        #: slider container
        self.slider_zone = Widget()

        #: slider widget
        self.slider = ScrollBarSlider()
        self.slider_zone.add_child(self.slider)

        #: the scroll up button
        self.up = ScrollBarButton(direction="left" if self.orient_horizontal else "up")

        #: the scroll down button
        self.down = ScrollBarButton(direction="right" if self.orient_horizontal else "down")

        self.add_child(self.up, self.slider_zone, self.down)

        self._timeout = None

        for button in (self.up, self.down):
            self.connect_child(button, "on-mouse-down", self.on_scrollbutton_pressed)
            self.connect_child(button, "on-mouse-up", self.on_scrollbutton_released)
            self.connect_child(button, "on-mouse-out", self.on_scrollbutton_released)

        self.connect_child(self.slider, "on-drag", self.on_slider_drag)
        self.connect("on-click", self.on_click)


    def get_min_size(self):
        return self.thickness, self.thickness

    def resize_children(self):
        Box.resize_children(self)
        self._size_slider()


    def _size_slider(self):
        if self.orient_horizontal:
            self.slider.alloc_h = self.slider_zone.alloc_h
            size = max(self.slider_zone.width * self.size, self.slider_zone.height)
            if self.slider_zone.width < self.slider_zone.height:
                size = self.slider_zone.width
            self.slider.width = round(size)
        else:
            self.slider.alloc_w = self.slider_zone.alloc_w
            size = max(self.slider_zone.height * self.size, self.slider_zone.width)
            if self.slider_zone.height < self.slider_zone.width:
                size = self.slider_zone.height
            self.slider.height = round(size)
        self._position_slider()


    def __setattr__(self, name, val):
        if self.__dict__.get(name, "hamster_graphics_no_value_really") == val:
            return

        Box.__setattr__(self, name, val)

        if name == "orient_horizontal" and hasattr(self, "up"):
            self.up.direction="left" if val else "up"
            self.down.direction="right" if val else "down"
        elif name == "size" and hasattr(self, "slider"):
            self._size_slider()
        elif name == "offset" and hasattr(self, "slider_zone"):
            self._position_slider()

    def _position_slider(self):
        if self.orient_horizontal:
            size = max(self.slider_zone.width - self.slider.width, 1)
            self.slider.x = size * self.offset
        else:
            size = max(self.slider_zone.height - self.slider.height, 1)
            self.slider.y = size * self.offset


    def on_slider_drag(self, slider, event):
        if self.orient_horizontal:
            size = max(self.slider_zone.width - self.slider.width, 0)
            self.slider.y = 0
            self.slider.x = int(max(min(self.slider.x, size), 0))
            self.__dict__['offset'] = self.slider.x / size if size > 0 else 0
        else:
            size = max(self.slider_zone.height - self.slider.height, 0)
            self.slider.x = 0
            self.slider.y = int(max(min(self.slider.y, size), 0))
            self.__dict__['offset'] = self.slider.y / size if size > 0 else 0


        self.emit("on-scroll", self.offset)


    def on_scrollbutton_pressed(self, button, event = None):
        if self._timeout: return  #something's going on already

        # scroll right away and set a timeout to come again after 50 milisecs
        self._emit_scroll(button)
        self._timeout = gobject.timeout_add(100, self._emit_scroll, button)

    def on_scrollbutton_released(self, button, event = None):
        if self._timeout:
            gobject.source_remove(self._timeout)
            self._timeout = None

    def _emit_scroll(self, button):
        direction = -1 if button == self.up else 1
        self.emit("on-scroll-step", direction)
        return True

    def on_click(self, sprite, event):
        direction = -1 if event.y < self.slider.y else 1
        self.emit("on-scroll-page", direction)


    def do_render(self):
        self.graphics.rectangle(0, 0, self.width, self.height)
        if self.enabled:
            self.graphics.fill("#D6D4D2")
        else:
            self.graphics.fill("#eee")
Ejemplo n.º 29
0
	def on_resize(self, size, final):
		self._icon.on_resize(size, final)
		Widget.on_resize(self, size, final)
Ejemplo n.º 30
0
class ScrollBar(Box):
    """A scroll bar.

    **Signals**:

    **on-scroll** *(sprite, current_normalized_position)*
    - fired after scrolling.
    """
    __gsignals__ = {
        "on-scroll": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                      (gobject.TYPE_PYOBJECT, )),
        "on-scroll-step": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                           (gobject.TYPE_PYOBJECT, )),
        "on-scroll-page": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                           (gobject.TYPE_PYOBJECT, )),
    }

    #: thickness of the bar in pixels
    thickness = 20

    def __init__(self,
                 horizontal=False,
                 thickness=None,
                 size=0,
                 offset=0,
                 **kwargs):
        Box.__init__(self, **kwargs)
        self.interactive, self.cursor = True, False

        self.spacing = 0

        self.thickness = thickness if thickness else self.thickness

        #: whether the scroll bar is vertical or horizontal
        self.orient_horizontal = horizontal

        #: width of the bar in pixels
        self.size = size

        #: scroll position in range 0..1
        self.offset = offset

        if horizontal:
            self.expand_vert = False
            self.min_height = thickness
        else:
            self.expand = False
            self.min_width = thickness

        #: slider container
        self.slider_zone = Widget()

        #: slider widget
        self.slider = ScrollBarSlider()
        self.slider_zone.add_child(self.slider)

        #: the scroll up button
        self.up = ScrollBarButton(
            direction="left" if self.orient_horizontal else "up")

        #: the scroll down button
        self.down = ScrollBarButton(
            direction="right" if self.orient_horizontal else "down")

        self.add_child(self.up, self.slider_zone, self.down)

        self._timeout = None

        for button in (self.up, self.down):
            self.connect_child(button, "on-mouse-down",
                               self.on_scrollbutton_pressed)
            self.connect_child(button, "on-mouse-up",
                               self.on_scrollbutton_released)
            self.connect_child(button, "on-mouse-out",
                               self.on_scrollbutton_released)

        self.connect_child(self.slider, "on-drag", self.on_slider_drag)
        self.connect("on-click", self.on_click)

    def get_min_size(self):
        return self.thickness, self.thickness

    def resize_children(self):
        Box.resize_children(self)
        self._size_slider()

    def _size_slider(self):
        if self.orient_horizontal:
            self.slider.alloc_h = self.slider_zone.alloc_h
            size = max(self.slider_zone.width * self.size,
                       self.slider_zone.height)
            if self.slider_zone.width < self.slider_zone.height:
                size = self.slider_zone.width
            self.slider.width = round(size)
        else:
            self.slider.alloc_w = self.slider_zone.alloc_w
            size = max(self.slider_zone.height * self.size,
                       self.slider_zone.width)
            if self.slider_zone.height < self.slider_zone.width:
                size = self.slider_zone.height
            self.slider.height = round(size)
        self._position_slider()

    def __setattr__(self, name, val):
        if self.__dict__.get(name, "hamster_graphics_no_value_really") == val:
            return

        Box.__setattr__(self, name, val)

        if name == "orient_horizontal" and hasattr(self, "up"):
            self.up.direction = "left" if val else "up"
            self.down.direction = "right" if val else "down"
        elif name == "size" and hasattr(self, "slider"):
            self._size_slider()
        elif name == "offset" and hasattr(self, "slider_zone"):
            self._position_slider()

    def _position_slider(self):
        if self.orient_horizontal:
            size = max(self.slider_zone.width - self.slider.width, 1)
            self.slider.x = size * self.offset
        else:
            size = max(self.slider_zone.height - self.slider.height, 1)
            self.slider.y = size * self.offset

    def on_slider_drag(self, slider, event):
        if self.orient_horizontal:
            size = max(self.slider_zone.width - self.slider.width, 0)
            self.slider.y = 0
            self.slider.x = int(max(min(self.slider.x, size), 0))
            self.__dict__['offset'] = self.slider.x / size if size > 0 else 0
        else:
            size = max(self.slider_zone.height - self.slider.height, 0)
            self.slider.x = 0
            self.slider.y = int(max(min(self.slider.y, size), 0))
            self.__dict__['offset'] = self.slider.y / size if size > 0 else 0

        self.emit("on-scroll", self.offset)

    def on_scrollbutton_pressed(self, button, event=None):
        if self._timeout: return  #something's going on already

        # scroll right away and set a timeout to come again after 50 milisecs
        self._emit_scroll(button)
        self._timeout = gobject.timeout_add(100, self._emit_scroll, button)

    def on_scrollbutton_released(self, button, event=None):
        if self._timeout:
            gobject.source_remove(self._timeout)
            self._timeout = None

    def _emit_scroll(self, button):
        direction = -1 if button == self.up else 1
        self.emit("on-scroll-step", direction)
        return True

    def on_click(self, sprite, event):
        direction = -1 if event.y < self.slider.y else 1
        self.emit("on-scroll-page", direction)

    def do_render(self):
        self.graphics.rectangle(0, 0, self.width, self.height)
        if self.enabled:
            self.graphics.fill("#D6D4D2")
        else:
            self.graphics.fill("#eee")
Ejemplo n.º 31
0
    def __init__(self, editable=False, **kwargs):
        Widget.__init__(self, **kwargs)
        self.editable = editable

        self._target = None
        self._cell = None
Ejemplo n.º 32
0
class InputDialog(Window):
    def __init__(self, title, label_ok="OK", label_cancel="Cancel"):

        self.__inputs = []
        self.__return_code = self.RETURN_CANCEL

        # list of value retrieving functions
        self.__retrievers = []

        Window.__init__(self, Window.TYPE_DIALOG)
        self.set_flag(windowflags.EXCLUSIVE, True)
        self.connect_closed(self.__on_close, self.RETURN_CANCEL)
        self.set_title(title)

        self.__box = Widget()
        self.add(self.__box)

        self.__button_ok = Button(label_ok)
        self.__button_ok.connect_clicked(self.__on_close, self.RETURN_OK)
        self.__box.add(self.__button_ok)

        if (not platforms.MAEMO5):
            self.__button_cancel = Button(label_cancel)
            self.__button_cancel.connect_clicked(self.__on_close,
                                                 self.RETURN_CANCEL)
            self.__box.add(self.__button_cancel)

        self.__vbox = VBox()
        self.__box.add(self.__vbox)

    def __on_close(self, return_code):

        self.__return_code = return_code
        self.set_visible(False)

    def render_this(self):

        Window.render_this(self)

        x, y = self.__box.get_screen_pos()
        w, h = self.__box.get_size()
        screen = self.__box.get_screen()

        screen.fill_area(x, y, w, h, theme.color_mb_background)

        if (not platforms.MAEMO5):
            self.__vbox.set_geometry(4, 4, w - 8, h - 78)
            self.__button_ok.set_geometry(w - 260, h - 60, 120, 60)
            self.__button_cancel.set_geometry(w - 130, h - 60, 120, 60)

        else:
            self.__vbox.set_geometry(6, 5, w - 165 - 12, h - 5)
            self.__button_ok.set_geometry(w - 120, h - 80, 100, 60)

    def add_input(self, label, default):

        vbox = VBox()
        vbox.set_spacing(12)
        vbox.set_valign(vbox.VALIGN_CENTER)
        self.__vbox.add(vbox, True)

        lbl = Label(label, theme.font_mb_plain, theme.color_mb_text)
        vbox.add(lbl, True)

        entry = TextInput()
        vbox.add(entry, True)

        self.__retrievers.append(lambda: entry.get_text())

    def add_range(self, label, min_value, max_value, preset):
        def update_label(v):
            value = min_value + v * total
            lbl.set_text(label + " %d" % value)

        vbox = VBox()
        vbox.set_spacing(12)
        vbox.set_valign(vbox.VALIGN_CENTER)
        self.__vbox.add(vbox, True)

        total = max_value - min_value

        lbl = Label(label + " %d" % preset, theme.font_mb_plain,
                    theme.color_mb_text)
        vbox.add(lbl, True)

        slider = HSlider(theme.mb_slider_gauge)
        slider.connect_value_changed(update_label)
        slider.set_value((preset - min_value) / float(total))
        vbox.add(slider, True)

        self.__retrievers.append(lambda: min_value + slider.get_value() *
                                 (max_value - min_value))

    def get_values(self):

        return [r() for r in self.__retrievers]

    def run(self):

        w = gtk.gdk.screen_width()
        h = min(gtk.gdk.screen_height() - 120, len(self.__retrievers) * 120)

        if (not platforms.MAEMO5):
            w -= 80
            h += 70
        self.set_window_size(w, h)
        Window.run(self)

        return self.__return_code
Ejemplo n.º 33
0
 def __init__(self, width=1, **kwargs):
     Widget.__init__(self, **kwargs)
     self.width = width
     self.draggable = True
Ejemplo n.º 34
0
	def __init__(self, position=Vector3(0,0,0), size=Vector2i(1,1), *widgets):
		Container.__init__(self, children=widgets)
		Widget.__init__(self, position, size)
Ejemplo n.º 35
0
    def __init__(self, contents = None, **kwargs):
        Widget.__init__(self, **kwargs)

        #: contents of the container - either a widget or a list of widgets
        self.contents = contents
        self._cached_w, self._cached_h = None, None
Ejemplo n.º 36
0
 def _Widget__on_render(self, sprite):
     if self._children_resize_queued:
         self.resize_children()
         self.__dict__['_children_resize_queued'] = False
     Widget._Widget__on_render(self, sprite)
Ejemplo n.º 37
0
 def __init__(self, width=1, **kwargs):
     Widget.__init__(self, **kwargs)
     self.width = width
     self.draggable = True
Ejemplo n.º 38
0
	def __init__(self, filename):
		Widget.__init__(self)
		
		self._filename = resources.realpath(filename)
		(self._texture, real_size) = self.load_texture(self._filename)
Ejemplo n.º 39
0
 def _add(self, *sprites):
     Widget._add(self, *sprites)
     self.queue_resize()
Ejemplo n.º 40
0
 def _add(self, *sprites):
     Widget._add(self, *sprites)
     self.queue_resize()
Ejemplo n.º 41
0
 def remove_child(self, *sprites):
     Widget.remove_child(self, *sprites)
     self.queue_resize()
Ejemplo n.º 42
0
    def __init__(self, editable=False, **kwargs):
        Widget.__init__(self, **kwargs)
        self.editable = editable

        self._target = None
        self._cell = None
Ejemplo n.º 43
0
 def queue_resize(self):
     self.__dict__['_cached_w'], self.__dict__['_cached_h'] = None, None
     Widget.queue_resize(self)
Ejemplo n.º 44
0
class Dialog(Texture, pyglet.event.EventDispatcher):
    mapping_width = 400
    def __init__(self, window):
        Texture.__init__(self)
        pyglet.event.EventDispatcher.__init__(self)
        self.window = window
        self.dragging = False
        self.grid = grid = Grid(cols={1:self.mapping_width}, rows=40)
        
        
        text1 = Text('Hi')
        text2 = Text('World')
        checkbox = Checkbox('Toggle', 'non')
        
        g = Graph(100, 100, 0, 0)
        
        dial = Dial(100, '30%')
        dial.value = 0.30
        vdial = VDial(100)
        vdial.value = 0.30
        r1 = Row([text1, text2, checkbox, dial, g, vdial])

        self.col = Column()
        self.col.append(r1)
        for i in range(3):
            for j in range(3):
                pass
                self.grid[i,j] = Button('Grid Button'+str(i+j))
        r2 = Row([self.grid])
        self.col.append(r2)
        self.col.x = 20
        self.col.width = 400
        self.col.height = 300
        self.scrollable = Scrollable(self.col, 300)
        self.scrollable = Column()
        self.widget = Widget('My Dialog', self.scrollable)
        close = Close()
        close.x = self.widget.width - close.width - 15
        close.y = self.widget.height - close.height - 15
        close.on_click = self.on_close
        
        self.children = [self.widget, close]#, self.resizer]
        
        self.width = self.widget.width
        self.height = self.widget.height
        self._layout()

    def on_press(self, abs, rel):
        if rel in self:
            self.dragging = True

    def on_release(self, abs, rel):
        if self.dragging:
            abs = self.window_pos
            pos = abs + self.dim/2
            self.window.set_mouse_position(int(pos.x), int(pos.y))
            self.window.set_mouse_visible(True)
            self.dragging = False
            self.on_enter()
        self.widget.on_release(abs, rel)
            
    def on_drag(self, delta):
        if not self.widget.on_drag(delta) and self.dragging:
            self.pos += delta
            return True
    
    def resize(self, delta):
        self.widget.width += delta.x
        self.widget.height += delta.y
        self.scrollable.layout
        self._layout()

    def write_something(self):
        print 'Something'
        
    def on_close(self):
        self.write_something()
        self.dispatch_event('on_widget_close', self)

    def on_key_press(self, symbol, modifiers):
        if symbol == pyglet.window.key.ESCAPE:
            self.on_close()
            return True
Ejemplo n.º 45
0
    def _draw(self, context, opacity=1, *args, **kwargs):

        self.get_visible_range()

        col_widths = self._get_col_widths()
        width = self.width

        row_height = self.get_row_height()

        g = graphics.Graphics(context)

        x, y = 0, 0
        Widget._draw(self, context, opacity, *args, **kwargs)
        editor = None

        # suboptimal workaround for case when the list is packed in a vbox and then in a scrollbox
        # TODO - generalize and sniff out the actual crop area
        if (
            self.parent
            and self.parent.parent
            and self.parent.parent
            and isinstance(self.parent.parent.parent, ScrollArea)
        ):
            scrollbox = self.parent.parent
            list_y = self.y + self.parent.y
        else:
            list_y = self.y
            scrollbox = self.parent

        g.rectangle(0, 0, scrollbox.width, scrollbox.height)
        g.clip()

        for row_idx in range(*self.get_visible_range()):
            y = row_idx * row_height
            row = self.rows[row_idx]

            state = "normal"
            if row == self.current_row:
                state = "current"
            elif row == self._hover_row:
                state = "highlight"

            context.save()
            context.translate(x, y + self.y)
            context.rectangle(0, 0, width, row_height)

            self.paint_row_background(g, row_idx, state, self.enabled)
            context.clip()

            col_x = 0
            for i, (data, renderer, col_width) in enumerate(zip(row, self.renderers, col_widths)):
                renderer.set_data(data)
                renderer.render(context, col_width, row_height, row[i], state, self.enabled)
                renderer.restore_data()
                context.translate(col_width, 0)

                # TODO - put some place else
                if renderer._cell and hasattr(renderer, "_editor") and renderer._cell["col"] == i:
                    renderer._editor.x, renderer._editor.alloc_w = col_x, col_width - 1
                    editor = renderer._editor

                col_x += col_width

            context.restore()

        if editor:
            # repaint editor as it is stepped all over
            context.save()
            context.translate(0, self.y)
            editor._draw(context, parent_matrix=self.get_matrix())
            context.restore()
Ejemplo n.º 46
0
    def _draw(self, context, opacity=1, *args, **kwargs):

        self.get_visible_range()

        col_widths = self._get_col_widths()
        width = self.width

        row_height = self.get_row_height()

        g = graphics.Graphics(context)

        x, y = 0, 0
        Widget._draw(self, context, opacity, *args, **kwargs)
        editor = None

        # suboptimal workaround for case when the list is packed in a vbox and then in a scrollbox
        # TODO - generalize and sniff out the actual crop area
        if self.parent and self.parent.parent and self.parent.parent and isinstance(
                self.parent.parent.parent, ScrollArea):
            scrollbox = self.parent.parent
            list_y = self.y + self.parent.y
        else:
            list_y = self.y
            scrollbox = self.parent

        g.rectangle(0, 0, scrollbox.width, scrollbox.height)
        g.clip()

        for row_idx in range(*self.get_visible_range()):
            y = row_idx * row_height
            row = self.rows[row_idx]

            state = "normal"
            if row == self.current_row:
                state = "current"
            elif row == self._hover_row:
                state = "highlight"

            context.save()
            context.translate(x, y + self.y)
            context.rectangle(0, 0, width, row_height)

            self.paint_row_background(g, row_idx, state, self.enabled)
            context.clip()

            col_x = 0
            for i, (data, renderer, col_width) in enumerate(
                    zip(row, self.renderers, col_widths)):
                renderer.set_data(data)
                renderer.render(context, col_width, row_height, row[i], state,
                                self.enabled)
                renderer.restore_data()
                context.translate(col_width, 0)

                # TODO - put some place else
                if renderer._cell and hasattr(
                        renderer, "_editor") and renderer._cell['col'] == i:
                    renderer._editor.x, renderer._editor.alloc_w = col_x, col_width - 1
                    editor = renderer._editor

                col_x += col_width

            context.restore()

        if editor:
            # repaint editor as it is stepped all over
            context.save()
            context.translate(0, self.y)
            editor._draw(context, parent_matrix=self.get_matrix())
            context.restore()
Ejemplo n.º 47
0
 def __init__(self, columns, rows, *widgets):
     Container.__init__(self, children=widgets)
     Widget.__init__(self)
     self._cols = int(columns)
     self._rows = int(rows)
Ejemplo n.º 48
0
 def __setattr__(self, name, val):
     Widget.__setattr__(self, name, val)
     if name.startswith("padding") and hasattr(self, "label"):
         setattr(self.label, name, val)
Ejemplo n.º 49
0
    def __init__(self, contents=None, **kwargs):
        Widget.__init__(self, **kwargs)

        #: contents of the container - either a widget or a list of widgets
        self.contents = contents
        self._cached_w, self._cached_h = None, None
Ejemplo n.º 50
0
 def __setattr__(self, name, val):
     Widget.__setattr__(self, name, val)
     if name.startswith("padding") and hasattr(self, "label"):
         setattr(self.label, name, val)
Ejemplo n.º 51
0
	def __init__(self, icon, callback=None, *args, **kwargs):
		Widget.__init__(self, *args, **kwargs)
		self._icon = icon
		self._icon.pos = self.pos
		self._callback = callback or (lambda *args: None)
Ejemplo n.º 52
0
 def _Widget__on_render(self, sprite):
     if self._children_resize_queued:
         self.resize_children()
         self.__dict__['_children_resize_queued'] = False
     Widget._Widget__on_render(self, sprite)
Ejemplo n.º 53
0
    def __init__ (self, level, size, selected):
        Widget.__init__(self, size)
        self.level = level
        self.selected = selected
        self.selecting = None
        self._sel_area = None
        self._actions = []
        self._news = []
        self.areas = areas = {}
        w, h = self.size
        # generate areas
        names = sample(conf.AREAS, conf.NUM_AREAS)
        n_rows = int(ceil(len(names) ** .5))
        n_per_row = float(len(names)) / n_rows
        done_f = done = 0
        dy = ir(h / float(n_rows))
        y = dy / 2
        for j in xrange(n_rows):
            done_f += n_per_row
            n_this_row = int(done_f) - done
            dx = ir(w / float(n_this_row))
            x = dx / 2
            for i in xrange(n_this_row):
                areas[names[done + i]] = (x, y)
                x += dx
            done += n_this_row
            y += dy
        # generate people
        self.people = ps = []
        dists = {}
        self.dists = used_dists = {}
        b = conf.WMAP_BORDER
        x0 = y0 = b
        x1 = w - b
        y1 = h - b
        nearest = 2 * conf.PERSON_RADIUS + conf.PERSON_NEAREST
        for i in range(conf.NUM_PEOPLE):
            while True:
                x, y = randint(x0, x1), randint(y0, y1)
                this_dists = {}
                for p in ps:
                    ox, oy = p.pos
                    dist = ((ox - x) * (ox - x) + (oy - y) * (oy - y)) ** .5
                    if dist < nearest:
                        break
                    this_dists[p] = dist
                else:
                    new_p = Person(level, self, (x, y))
                    for p, dist in this_dists.iteritems():
                        dists[frozenset((new_p, p))] = dist
                    ps.append(new_p)
                    break
        # compute all remaining distances
        for p1 in ps:
            for p2 in ps:
                if p1 is not p2:
                    key = frozenset((p1, p2))
                    if key not in dists:
                        x1, y1 = p1.pos
                        x2, y2 = p2.pos
                        dists[key] = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** .5

        def add_con (p1, p2):
            # need to add dist to self.dists before creating Connection
            key = frozenset((p1, p2))
            used_dists[key] = dists[key]
            # choose method types
            this_methods = set()
            for i in xrange(ir(max(1, n_methods()))):
                this_methods.add(weighted_rand(methods))
            # create connection and add to stores
            c = Connection(level, (p1, p2), this_methods)
            self.cons.append(c)
            p1.cons.append(c)
            p2.cons.append(c)
            g1 = groups[p1]
            g2 = groups[p2]
            # merge groups
            g1.update(g2)
            for p, g in groups.iteritems():
                if g is g2:
                    groups[p] = g1

        # generate connections
        methods = dict((method, data['freq'])
                       for method, data in conf.METHODS.iteritems())
        n_methods = conf.METHODS_PER_CON
        self.cons = []
        # and group by whether connected
        groups = dict((p, set((p,))) for p in ps)
        n_cons = conf.CONS_PER_PERSON
        max_cons = conf.MAX_CONS_PER_PERSON
        # give everyone connections biased towards people near them
        for p in ps:
            # distances have a non-zero minimum
            others = dict((other, 1. / dists[frozenset((p, other))] ** \
                                       conf.SHORT_CONNECTION_BIAS)
                          for other in ps if other is not p)
            for c in p.cons:
                del others[c.other(p)]
            targets = []
            this_n_cons = ir(max(1, min(max_cons, min(len(others), n_cons()))))
            for i in xrange(this_n_cons - len(p.cons)):
                other = weighted_rand(others)
                targets.append(other)
                del others[other]
            for other in targets:
                add_con(p, other)
        # reduce to one group by adding extra connections
        frozen_groups = set(frozenset(g) for g in groups.itervalues())
        while len(frozen_groups) > 1:
            i = iter(frozen_groups)
            g1 = next(i)
            g2 = next(i)
            dist, p1, p2 = min(min((dists[frozenset((p1, p2))], p1, p2)
                                   for p2 in g2 if p2 is not p1) for p1 in g1)
            add_con(p1, p2)
            frozen_groups = set(frozenset(g) for g in groups.itervalues())

        # give some people full names
        ps = ps[:min(conf.NUM_FULL_NAMES, len(ps))]
        for p, name in zip(ps, sample(conf.FULL_NAMES, len(ps))):
            p.name = name
        # let someone know
        self.n_know = 0
        ps[0].recieve()
Ejemplo n.º 54
0
 def queue_resize(self):
     self.__dict__['_cached_w'], self.__dict__['_cached_h'] = None, None
     Widget.queue_resize(self)
Ejemplo n.º 55
0
	def on_resize(self, size, final):
		Widget.on_resize(self, size, final)
		if final and self._filename[-4:] == '.svg':
			self._texture,_ = self._rasterize_svg(self._filename)
Ejemplo n.º 56
0
 def __init__(self, spacing=None, **kwargs):
     Widget.__init__(self)
     if spacing:
         self.spacing = spacing
     self.menu = None