Пример #1
1
    def __init__(self, contents = None,
                 title = None, draggable = True,
                 width = 500,
                 modal = False,
                 **kwargs):
        Fixed.__init__(self, **kwargs)
        self.interactive, self.mouse_cursor = True, False

        #: whether the dialog is modal or not. in case of modality won't be able
        #: to click on other interface elements while dialog is being displayed
        self.modal = modal

        #: dialog content - message and such like
        self.contents = contents

        #: container for description and buttons
        # setting it interactive and filling extents so that they can't be clicked through
        self.box = VBox(contents, interactive=True, mouse_cursor = False)
        def fill_blank():
            self.box.graphics.rectangle(0, 0, self.box.width, self.box.height)
            self.box.graphics.new_path()
        self.box.do_render = fill_blank

        #: the main container box that contains title and contents
        components = []
        self.title_label = None
        if title:
            self.title_label = self.title_class(title)
            components.append(self.title_label)
        components.append(self.box)

        self.main_box = self.dialog_box_class(components, interactive=draggable, draggable=draggable, width=width, padding=0)

        self.connect_child(self.main_box, "on-drag", self.on_drag)
        self._dragged = False

        self.add_child(self.main_box)

        #: fill color for the background when the dialog is modal
        self.background_fill = "#fff"

        #: opacity of the background fill when the dialog is modal
        self.background_opacity = .5

        #: initial centered position as a tuple in lieu of scale_x, scale_y
        self.pre_dragged_absolute_position = None
Пример #2
0
 def __setattr__(self, name, val):
     if name in ("label", "markup") and hasattr(self, "_caption"):
         setattr(self._caption, name, val)
     else:
         VBox.__setattr__(self, name, val)
         if name == "expanded" and hasattr(self, "_caption"):
             self._caption.expanded = val
Пример #3
0
 def __setattr__(self, name, val):
     if name in ("label", "markup") and hasattr(self, "_caption"):
         setattr(self._caption, name, val)
     else:
         VBox.__setattr__(self, name, val)
         if name == "expanded" and hasattr(self, "_caption"):
             self._caption.expanded = val
Пример #4
0
    def __init__(self, label = "", contents = [], expand = False, spacing = 0, expanded = False, **kwargs):
        VBox.__init__(self, expand=expand, spacing=spacing, **kwargs)
        self.expanded = expanded
        self._caption = self.caption_class(label, x_align=0, expanded = self.expanded, expand=False)
        self.connect_child(self._caption, "on-click", self.on_caption_mouse_down)

        self.container = ScrollArea(scroll_vertical=False, scroll_horizontal=False, visible=False, border=0)
        self.add_child(self._caption, self.container)
        self.add_child(*contents)
Пример #5
0
    def __init__(self,
                 contents=None,
                 title=None,
                 draggable=True,
                 width=500,
                 modal=False,
                 **kwargs):
        Fixed.__init__(self, **kwargs)
        self.interactive, self.mouse_cursor = True, False

        #: whether the dialog is modal or not. in case of modality won't be able
        #: to click on other interface elements while dialog is being displayed
        self.modal = modal

        #: dialog content - message and such like
        self.contents = contents

        #: container for description and buttons
        # setting it interactive and filling extents so that they can't be clicked through
        self.box = VBox(contents, interactive=True, mouse_cursor=False)

        def fill_blank():
            self.box.graphics.rectangle(0, 0, self.box.width, self.box.height)
            self.box.graphics.new_path()

        self.box.do_render = fill_blank

        #: the main container box that contains title and contents
        components = []
        self.title_label = None
        if title:
            self.title_label = self.title_class(title)
            components.append(self.title_label)
        components.append(self.box)

        self.main_box = self.dialog_box_class(components,
                                              interactive=draggable,
                                              draggable=draggable,
                                              width=width,
                                              padding=0)

        self.connect_child(self.main_box, "on-drag", self.on_drag)
        self._dragged = False

        self.add_child(self.main_box)

        #: fill color for the background when the dialog is modal
        self.background_fill = "#fff"

        #: opacity of the background fill when the dialog is modal
        self.background_opacity = .5

        #: initial centered position as a tuple in lieu of scale_x, scale_y
        self.pre_dragged_absolute_position = None
Пример #6
0
    def __setattr__(self, name, val):
        # forward useful attributes to the list view
        if name in ("rows", "renderers", "select_on_drag", "spacing", "row_height", "current_row", "_hover_row"):
            setattr(self.list_view, name, val)
            return

        if self.__dict__.get(name, "hamster_no_value_really") == val:
            return
        VBox.__setattr__(self, name, val)

        if name == "scroll_border":
            self.scrollbox.border = val
        elif name == "headers":
            self._update_headers()
Пример #7
0
    def __setattr__(self, name, val):
        # forward useful attributes to the list view
        if name in ("rows", "renderers", "select_on_drag", "spacing",
                    "row_height", "current_row", "_hover_row"):
            setattr(self.list_view, name, val)
            return

        if self.__dict__.get(name, 'hamster_no_value_really') == val:
            return
        VBox.__setattr__(self, name, val)

        if name == "scroll_border":
            self.scrollbox.border = val
        elif name == "headers":
            self._update_headers()
Пример #8
0
    def __init__(self,
                 title,
                 message,
                 affirmative_label,
                 decline_label="Cancel",
                 width=500,
                 modal=False):
        Dialog.__init__(self, title=title, width=width, modal=modal)

        scrollbox = ScrollArea(Label(markup=message,
                                     padding=5,
                                     overflow=pango.WrapMode.WORD),
                               scroll_horizontal=False,
                               border=0,
                               margin=2,
                               margin_right=3,
                               height=150)

        affirmative = Button(affirmative_label, id="affirmative_button")
        affirmative.connect("on-click", self._on_button_click)
        decline = Button(decline_label, id="decline_button")
        decline.connect("on-click", self._on_button_click)

        self.box.contents = VBox([
            scrollbox,
            HBox([HBox(), decline, affirmative], expand=False, padding=10)
        ])
Пример #9
0
    def __init__(self, pages = [], spacing = 0, animation_duration = None,
                 easing_function = Easing.Quad.ease_out, **kwargs):
        VBox.__init__(self, spacing=spacing, **kwargs)

        #: currently selected page
        self.current_page = None

        self.reclick_to_close = True

        #: duration of the sliding animation. Defaults to scene's settings.
        #: Set 0 to disable
        self.animation_duration = animation_duration

        #: Tweening method to use for the animation
        self.easing_function = easing_function

        if pages:
            self.add_child(*pages)
Пример #10
0
    def __init__(self,
                 rows=[],
                 renderers=None,
                 headers=None,
                 select_on_drag=False,
                 spacing=0,
                 scroll_border=1,
                 row_height=None,
                 fixed_headers=None,
                 **kwargs):
        VBox.__init__(self, **kwargs)

        self.list_view = self.class_list_view(rows=rows)
        self.list_view.connect("on-render", self._on_list_render)

        for event in ("on-select", "on-change", "on-mouse-down", "on-mouse-up",
                      "on-click"):
            self.list_view.connect(event, self._forward_event, event)

        if renderers is not None:
            self.renderers = renderers
        self.select_on_drag = select_on_drag
        self.spacing = spacing
        self.row_height = row_height

        self.header_container = self.class_headers_container()
        self.headers = headers

        if fixed_headers is not None:
            self.fixed_headers = fixed_headers

        self.scrollbox = self.class_scroll_area(border=scroll_border)

        if self.fixed_headers:
            self.scrollbox.add_child(self.list_view)
            self.add_child(self.header_container, self.scrollbox)
        else:
            self.scrollbox.add_child(
                VBox([self.header_container, self.list_view], spacing=0))
            self.add_child(self.scrollbox)
Пример #11
0
    def __init__(
        self,
        rows=[],
        renderers=None,
        headers=None,
        select_on_drag=False,
        spacing=0,
        scroll_border=1,
        row_height=None,
        fixed_headers=None,
        **kwargs
    ):
        VBox.__init__(self, **kwargs)

        self.list_view = self.class_list_view(rows=rows)
        self.list_view.connect("on-render", self._on_list_render)

        for event in ("on-select", "on-change", "on-mouse-down", "on-mouse-up", "on-click"):
            self.list_view.connect(event, self._forward_event, event)

        if renderers is not None:
            self.renderers = renderers
        self.select_on_drag = select_on_drag
        self.spacing = spacing
        self.row_height = row_height

        self.header_container = self.class_headers_container()
        self.headers = headers

        if fixed_headers is not None:
            self.fixed_headers = fixed_headers

        self.scrollbox = self.class_scroll_area(border=scroll_border)

        if self.fixed_headers:
            self.scrollbox.add_child(self.list_view)
            self.add_child(self.header_container, self.scrollbox)
        else:
            self.scrollbox.add_child(VBox([self.header_container, self.list_view], spacing=0))
            self.add_child(self.scrollbox)
Пример #12
0
    def __init__(self,
                 pages=[],
                 spacing=0,
                 animation_duration=None,
                 easing_function=Easing.Quad.ease_out,
                 **kwargs):
        VBox.__init__(self, spacing=spacing, **kwargs)

        #: currently selected page
        self.current_page = None

        self.reclick_to_close = True

        #: duration of the sliding animation. Defaults to scene's settings.
        #: Set 0 to disable
        self.animation_duration = animation_duration

        #: Tweening method to use for the animation
        self.easing_function = easing_function

        if pages:
            self.add_child(*pages)
Пример #13
0
    def __init__(self,
                 label="",
                 contents=[],
                 expand=False,
                 spacing=0,
                 expanded=False,
                 **kwargs):
        VBox.__init__(self, expand=expand, spacing=spacing, **kwargs)
        self.expanded = expanded
        self._caption = self.caption_class(label,
                                           x_align=0,
                                           expanded=self.expanded,
                                           expand=False)
        self.connect_child(self._caption, "on-click",
                           self.on_caption_mouse_down)

        self.container = ScrollArea(scroll_vertical=False,
                                    scroll_horizontal=False,
                                    visible=False,
                                    border=0)
        self.add_child(self._caption, self.container)
        self.add_child(*contents)
Пример #14
0
 def resize_children(self):
     self.scrollbox.alloc_w = self.width
     self.scrollbox.resize_children()
     self.scrollbox.viewport.resize_children()
     VBox.resize_children(self)
Пример #15
0
class Dialog(Fixed):
    """An in-window message box

    **Signals**

        **on-close** *(sprite, pressed_button)*
        - fired when the window is closed. returns back the label of the button that triggered closing
    """
    __gsignals__ = {
        "on-close": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)),
    }

    title_class = DialogTitle
    dialog_box_class = DialogBox

    def __init__(self, contents = None,
                 title = None, draggable = True,
                 width = 500,
                 modal = False,
                 **kwargs):
        Fixed.__init__(self, **kwargs)
        self.interactive, self.mouse_cursor = True, False

        #: whether the dialog is modal or not. in case of modality won't be able
        #: to click on other interface elements while dialog is being displayed
        self.modal = modal

        #: dialog content - message and such like
        self.contents = contents

        #: container for description and buttons
        # setting it interactive and filling extents so that they can't be clicked through
        self.box = VBox(contents, interactive=True, mouse_cursor = False)
        def fill_blank():
            self.box.graphics.rectangle(0, 0, self.box.width, self.box.height)
            self.box.graphics.new_path()
        self.box.do_render = fill_blank

        #: the main container box that contains title and contents
        components = []
        self.title_label = None
        if title:
            self.title_label = self.title_class(title)
            components.append(self.title_label)
        components.append(self.box)

        self.main_box = self.dialog_box_class(components, interactive=draggable, draggable=draggable, width=width, padding=0)

        self.connect_child(self.main_box, "on-drag", self.on_drag)
        self._dragged = False

        self.add_child(self.main_box)

        #: fill color for the background when the dialog is modal
        self.background_fill = "#fff"

        #: opacity of the background fill when the dialog is modal
        self.background_opacity = .5

        #: initial centered position as a tuple in lieu of scale_x, scale_y
        self.pre_dragged_absolute_position = None


    def on_drag(self, sprite, event):
        self.main_box.x = max(min(self.main_box.x, self.width - 10), -self.main_box.width + 10 )
        self.main_box.y = max(min(self.main_box.y, self.height - 10), -self.main_box.height + 10 )
        self._dragged = True


    def __setattr__(self, name, val):
        if name in ("width",) and hasattr(self, "main_box"):
            self.main_box.__setattr__(name, val)
        else:
            Fixed.__setattr__(self, name, val)

        if name == "contents" and hasattr(self, "box"):
            self.box.add_child(val)

    def show(self, scene):
        """show the dialog"""
        scene.add_child(self)

    def resize_children(self):
        if not self._dragged:
            if not self.pre_dragged_absolute_position:
                self.main_box.x = (self.width - self.main_box.width) * self.x_align
                self.main_box.y = (self.height - self.main_box.height) * self.y_align
            else:
                #put it right where we want it
                self.main_box.x = self.pre_dragged_absolute_position[0] - (self.main_box.width * 0.5)
                self.main_box.y = self.pre_dragged_absolute_position[1] - (self.main_box.height * 0.5)
                #but ensure it is in bounds, cause if it ain't you could be in a world of modal pain
                self.on_drag( None, None )
        else:
            self.on_drag(self.main_box, None)

    def close(self, label = ""):
        self.emit("on-close", label)
        scene = self.get_scene()
        if scene:
            scene.remove_child(self)


    def do_render(self):
        if self.modal:
            self.graphics.rectangle(0, 0, self.width + 1, self.height + 1)
            self.graphics.fill(self.background_fill, self.background_opacity)
        else:
            self.graphics.clear()
Пример #16
0
 def __init__(self, contents=None, spacing = 0, **kwargs):
     VBox.__init__(self, contents=contents, spacing=spacing, **kwargs)
Пример #17
0
    def add_child(self, *pages):
        VBox.add_child(self, *pages)

        for page in pages:
            self.connect_child(page, "on-caption-mouse-down",
                               self.on_caption_mouse_down)
Пример #18
0
 def __init__(self, contents=None, spacing=0, **kwargs):
     VBox.__init__(self, contents=contents, spacing=spacing, **kwargs)
Пример #19
0
 def add_child(self, *sprites):
     for sprite in sprites:
         if sprite in (self._caption, self.container):
             VBox.add_child(self, sprite)
         else:
             self.container.add_child(sprite)
Пример #20
0
class Dialog(Fixed):
    """An in-window message box

    **Signals**

        **on-close** *(sprite, pressed_button)*
        - fired when the window is closed. returns back the label of the button that triggered closing
    """
    __gsignals__ = {
        "on-close": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                     (gobject.TYPE_PYOBJECT, )),
    }

    title_class = DialogTitle
    dialog_box_class = DialogBox

    def __init__(self,
                 contents=None,
                 title=None,
                 draggable=True,
                 width=500,
                 modal=False,
                 **kwargs):
        Fixed.__init__(self, **kwargs)
        self.interactive, self.mouse_cursor = True, False

        #: whether the dialog is modal or not. in case of modality won't be able
        #: to click on other interface elements while dialog is being displayed
        self.modal = modal

        #: dialog content - message and such like
        self.contents = contents

        #: container for description and buttons
        # setting it interactive and filling extents so that they can't be clicked through
        self.box = VBox(contents, interactive=True, mouse_cursor=False)

        def fill_blank():
            self.box.graphics.rectangle(0, 0, self.box.width, self.box.height)
            self.box.graphics.new_path()

        self.box.do_render = fill_blank

        #: the main container box that contains title and contents
        components = []
        self.title_label = None
        if title:
            self.title_label = self.title_class(title)
            components.append(self.title_label)
        components.append(self.box)

        self.main_box = self.dialog_box_class(components,
                                              interactive=draggable,
                                              draggable=draggable,
                                              width=width,
                                              padding=0)

        self.connect_child(self.main_box, "on-drag", self.on_drag)
        self._dragged = False

        self.add_child(self.main_box)

        #: fill color for the background when the dialog is modal
        self.background_fill = "#fff"

        #: opacity of the background fill when the dialog is modal
        self.background_opacity = .5

        #: initial centered position as a tuple in lieu of scale_x, scale_y
        self.pre_dragged_absolute_position = None

    def on_drag(self, sprite, event):
        self.main_box.x = max(min(self.main_box.x, self.width - 10),
                              -self.main_box.width + 10)
        self.main_box.y = max(min(self.main_box.y, self.height - 10),
                              -self.main_box.height + 10)
        self._dragged = True

    def __setattr__(self, name, val):
        if name in ("width", ) and hasattr(self, "main_box"):
            self.main_box.__setattr__(name, val)
        else:
            Fixed.__setattr__(self, name, val)

        if name == "contents" and hasattr(self, "box"):
            self.box.add_child(val)

    def show(self, scene):
        """show the dialog"""
        scene.add_child(self)

    def resize_children(self):
        if not self._dragged:
            if not self.pre_dragged_absolute_position:
                self.main_box.x = (self.width -
                                   self.main_box.width) * self.x_align
                self.main_box.y = (self.height -
                                   self.main_box.height) * self.y_align
            else:
                #put it right where we want it
                self.main_box.x = self.pre_dragged_absolute_position[0] - (
                    self.main_box.width * 0.5)
                self.main_box.y = self.pre_dragged_absolute_position[1] - (
                    self.main_box.height * 0.5)
                #but ensure it is in bounds, cause if it ain't you could be in a world of modal pain
                self.on_drag(None, None)
        else:
            self.on_drag(self.main_box, None)

    def close(self, label=""):
        self.emit("on-close", label)
        scene = self.get_scene()
        if scene:
            scene.remove_child(self)

    def do_render(self):
        if self.modal:
            self.graphics.rectangle(0, 0, self.width + 1, self.height + 1)
            self.graphics.fill(self.background_fill, self.background_opacity)
        else:
            self.graphics.clear()
Пример #21
0
 def add_child(self, *sprites):
     for sprite in sprites:
         if sprite in (self._caption, self.container):
             VBox.add_child(self, sprite)
         else:
             self.container.add_child(sprite)
Пример #22
0
 def resize_children(self):
     self.scrollbox.alloc_w = self.width
     self.scrollbox.resize_children()
     self.scrollbox.viewport.resize_children()
     VBox.resize_children(self)
Пример #23
0
    def add_child(self, *pages):
        VBox.add_child(self, *pages)

        for page in pages:
            self.connect_child(page, "on-caption-mouse-down", self.on_caption_mouse_down)