Ejemplo n.º 1
0
    def create_top_titlebar(
        self,
        button_mask=['min', "close"],
        icon_path=None,
        app_name=None,
        title=None,
        add_separator=False,
        show_title=True,
        enable_gaussian=True,
        name_size=DEFAULT_FONT_SIZE,
        title_size=DEFAULT_FONT_SIZE,
    ):
        titlebar = Titlebar(
            button_mask,
            icon_path,
            app_name,
            title,
            add_separator,
            show_title=show_title,
            enable_gaussian=enable_gaussian,
            name_size=name_size,
            title_size=title_size,
        )
        if "min" in button_mask:
            titlebar.min_button.connect("clicked",
                                        lambda w: self.window.min_window())
        if "close" in button_mask:
            titlebar.close_button.connect("clicked", self.quit)

        return titlebar
Ejemplo n.º 2
0
    def add_titlebar(
        self,
        button_mask=["theme", "menu", 'min', "max", "close"],
        icon_path=None,
        app_name=None,
        title=None,
        add_separator=False,
        show_title=True,
        enable_gaussian=True,
        name_size=DEFAULT_FONT_SIZE,
        title_size=DEFAULT_FONT_SIZE,
    ):
        '''
        Add titlebar to the application.
        
        Connect click signal of the standard button to default callback.
        
        @param button_mask: A list of string, each of which stands for a standard button on top right of the window. By default, it's ["theme", "menu", "max", "min", "close"].
        @param icon_path: The path of icon image.
        @param app_name: The name string of the application, which will be displayed just next to the icon_dpixbuf. By default, it is None.
        @param title: The title string of the window, which will be displayed on the center of the titlebar. By default, it is None.
        @param add_separator: If True, add a line between the titlebar and the body of the window. By default, it's False.
        @param show_title: If False, the titlebar will not be displayed. By default, it's True.
        @param enable_gaussian: Set it as False if don't want gaussian application title. By default, it's True.
        @param name_size: The size of name, default is DEFAULT_FONT_SIZE.
        @param title_size: The size of title, default is DEFAULT_FONT_SIZE.
        '''
        # Init titlebar.
        self.titlebar = Titlebar(
            button_mask,
            icon_path,
            app_name,
            title,
            add_separator,
            show_title=show_title,
            enable_gaussian=enable_gaussian,
            name_size=name_size,
            title_size=title_size,
        )
        if "theme" in button_mask:
            self.titlebar.theme_button.connect("clicked", self.theme_callback)
        if "menu" in button_mask:
            self.titlebar.menu_button.connect("clicked", self.menu_callback)
        if "min" in button_mask:
            self.titlebar.min_button.connect(
                "clicked", lambda w: self.window.min_window())
        if "max" in button_mask:
            self.titlebar.max_button.connect("clicked", self.max_callback)
        if "close" in button_mask:
            self.titlebar.close_button.connect("clicked", self.close_callback)
        if self.resizable:
            self.window.add_toggle_event(self.titlebar)
        self.window.add_move_event(self.titlebar)

        # Show titlebar.
        self.show_titlebar()

        if app_name != None:
            self.window.set_title(app_name)
Ejemplo n.º 3
0
    def __init__(self,
                 title,
                 default_width=None,
                 default_height=None,
                 mask_type=None,
                 close_callback=None,
                 modal=True,
                 window_hint=gtk.gdk.WINDOW_TYPE_HINT_DIALOG,
                 window_pos=None,
                 skip_taskbar_hint=True,
                 resizable=False,
                 window_type=gtk.WINDOW_TOPLEVEL,
                 ):
        '''
        Initialize DialogBox class.

        @param title: Dialog title.
        @param default_width: Width of dialog, default is None.
        @param default_height: Height of dialog, default is None.
        @param mask_type: Background mask type, it allow use below type:
         - DIALOG_MASK_SINGLE_PAGE      single mask style, use in single page that background mask include dialog button area.
         - DIALOG_MASK_GLASS_PAGE       glass mask style, similar DIALOG_MASK_SINGLE_PAGE but with different color.
         - DIALOG_MASK_MULTIPLE_PAGE    multiple mask style, use in multiple page that background mask not include dialog button area.
         - DIALOG_MASK_TAB_PAGE         tab mask style, use in preference page that background mask not include button area.
        @param close_callback: The callback that will call when close dialog box, callback don't need input argument.
        @param modal: If modal is True the window becomes modal. Modal windows prevent interaction with other windows in the same application.
        @param window_hint: Sets the window type hint, default is gtk.gdk.WINDOW_TYPE_HINT_DIALOG, it allow use below value:
         - gtk.gdk.WINDOW_TYPE_HINT_NORMAL                          A normal toplevel window.
         - gtk.gdk.WINDOW_TYPE_HINT_DIALOG                          A dialog window.
         - gtk.gdk.WINDOW_TYPE_HINT_MENU                            A window used to implement a menu.
         - gtk.gdk.WINDOW_TYPE_HINT_TOOLBAR                         A window used to implement a toolbar.
         - gtk.gdk.WINDOW_TYPE_HINT_SPLASHSCREEN                    A window used to implement a splash screen
         - gtk.gdk.WINDOW_TYPE_HINT_UTILITY
         - gtk.gdk.WINDOW_TYPE_HINT_DOCK                            A window used to implement a docking bar.
         - gtk.gdk.WINDOW_TYPE_HINT_DESKTOP                         A window used to implement a desktop.
         - gtk.gdk.WINDOW_TYPE_HINT_DROPDOWN_MENU                   A menu that belongs to a menubar.
         - gtk.gdk.WINDOW_TYPE_HINT_POPUP_MENU                      A menu that does not belong to a menubar, e.g. a context menu.
         - gtk.gdk.WINDOW_TYPE_HINT_TOOLTIP                         A tooltip.
         - gtk.gdk.WINDOW_TYPE_HINT_NOTIFICATION                    A notification - typically a "bubble" that belongs to a status icon.
         - gtk.gdk.WINDOW_TYPE_HINT_COMBO                           A popup from a combo box.
         - gtk.gdk.WINDOW_TYPE_HINT_DND                             A window that is used to implement a DND cursor.
        @param window_pos: The window position of window, it can use below value:
         - gtk.WIN_POS_NONE                      No influence is made on placement.
         - gtk.WIN_POS_CENTER                    Windows should be placed in the center of the screen.
         - gtk.WIN_POS_MOUSE                     Windows should be placed at the current mouse position.
         - gtk.WIN_POS_CENTER_ALWAYS             Keep window centered as it changes size, etc.
         - gtk.WIN_POS_CENTER_ON_PARENT          Center the window on its transient parent (see the gtk.Window.set_transient_for()) method.
        @param skip_taskbar_hint: Set True to make desktop environment not to display the window in the task bar, default is True.
        @param resizable: Whether allowed user resizable dialog, default is False.
        '''
        Window.__init__(
            self,
            enable_resize=resizable,
            window_type=window_type,
            )
        self.default_width = default_width
        self.default_height = default_height
        self.mask_type = mask_type
        self.close_callback = close_callback

        if window_pos:
            self.set_position(window_pos)
        self.set_modal(modal)                                # grab focus to avoid build too many skin window
        if window_hint:
            self.set_type_hint(window_hint)
        self.set_skip_taskbar_hint(skip_taskbar_hint) # skip taskbar
        if self.default_width != None and self.default_height != None:
            self.set_default_size(self.default_width, self.default_height)

            if not resizable:
                self.set_geometry_hints(None, self.default_width, self.default_height, -1, -1, -1, -1, -1, -1, -1, -1)

        self.padding_left = 2
        self.padding_right = 2

        self.titlebar = Titlebar(
            ["close"],
            None,
            title)
        self.add_move_event(self.titlebar)
        self.body_box = gtk.VBox()
        self.body_align = gtk.Alignment()
        self.body_align.set(0.5, 0.5, 1, 1)
        self.body_align.set_padding(0, 0, self.padding_left, self.padding_right)
        self.body_align.add(self.body_box)
        self.button_box = gtk.HBox()
        self.left_button_box = DialogLeftButtonBox()
        self.right_button_box = DialogRightButtonBox()

        self.button_box.pack_start(self.left_button_box, True, True)
        self.button_box.pack_start(self.right_button_box, True, True)

        self.window_frame.pack_start(self.titlebar, False, False)
        self.window_frame.pack_start(self.body_align, True, True)
        self.window_frame.pack_start(self.button_box, False, False)

        if self.close_callback:
            self.titlebar.close_button.connect("clicked", lambda w: self.close_callback())
            self.connect("destroy", lambda w: self.close_callback())
            self.connect("delete-event", lambda w, e: self.close_callback())
        else:
            self.titlebar.close_button.connect("clicked", lambda w: self.destroy())
            self.connect("destroy", lambda w: self.destroy())
            self.connect("delete-event", lambda w, e: self.destroy())

        self.draw_mask = self.get_mask_func(self, 1, 1, 0, 1)

        self.keymap = {
            "Escape" : self.close,
            }

        self.connect("key-press-event", self.key_press_dialog_box)