예제 #1
0
    def add_titlebar(self,
                     button_mask=["theme", "menu", "max", "min", "close"],
                     icon_dpixbuf=None, app_name=None, title=None, add_separator=False, show_title=True):
        """
        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_dpixbuf: The icon pixbuf of type dtk.ui.theme.DynamicPixbuf. By default, it is None.
        @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.
        """
        # Init titlebar.
        self.titlebar = Titlebar(button_mask, icon_dpixbuf, app_name, title, add_separator, show_title=show_title)
        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", lambda w: self.window.toggle_max_window())
        if "close" in button_mask:
            self.titlebar.close_button.connect("clicked", self.close_callback)
        self.window.add_toggle_event(self.titlebar)
        self.window.add_move_event(self.titlebar)

        # Show titlebar.
        self.show_titlebar()
예제 #2
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
    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)
예제 #4
0
파일: dialog.py 프로젝트: netphi/deepin-ui
    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):
        '''Dialog box.'''
        Window.__init__(self, resizable)
        self.default_width = default_width
        self.default_height = default_height
        self.mask_type = mask_type
        
        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 close_callback:
            self.titlebar.close_button.connect("clicked", lambda w: close_callback())
            self.connect("destroy", lambda w: close_callback())
        else:
            self.titlebar.close_button.connect("clicked", lambda w: self.destroy())
            self.connect("destroy", lambda w: self.destroy())
        
        self.draw_mask = self.get_mask_func(self, 1, 1, 0, 1)
예제 #5
0
    def add_titlebar(self,
                     button_mask=["theme", "menu", "max", "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,
                     ):
        '''
        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", lambda w: self.window.toggle_max_window())
        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_motion_move_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)
예제 #6
0
class Application(object):
    """
    This is the base class of every program based on deepin-ui.
    Every program should realize it.
    """
    def __init__(self, app_support_colormap=True):
        """
        Initialize the Application class.
        
        @param app_support_colormap: Set False if your program don't allow manipulate colormap, such as mplayer, otherwise you should keep this option as True.
        """
        # Init.
        self.app_support_colormap = app_support_colormap
        self.close_callback = self.close_window

        # Start application.
        self.init()

    def init(self):
        """
        This do the remain initialize step.
        
        It Initializes the window and some important signal such as "destroy".
        """
        # Init gdk threads, the integrant method for multi-thread GUI application.
        gtk.gdk.threads_init()
        
        # Load customize rc style before any other.
        gtk.rc_parse_string("style 'my_style' {\n    GtkPaned::handle-size = %s\n }\nwidget '*' style 'my_style'" % (PANED_HANDLE_SIZE))

        # Init status.
        self.menu_button_callback = None

        # Init window.
        if self.app_support_colormap:
            self.window = Window(True)
        else:
            self.window = MplayerWindow(True)
        self.window.set_position(gtk.WIN_POS_CENTER)
        self.window.connect("destroy", self.destroy)
        
        # Init main box.
        self.main_box = self.window.window_frame

        # Add titlebar box.
        self.titlebar = None
        self.titlebar_box = gtk.HBox()
        self.main_box.pack_start(self.titlebar_box, False)

    def add_titlebar(self,
                     button_mask=["theme", "menu", "max", "min", "close"],
                     icon_dpixbuf=None, app_name=None, title=None, add_separator=False, show_title=True):
        """
        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_dpixbuf: The icon pixbuf of type dtk.ui.theme.DynamicPixbuf. By default, it is None.
        @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.
        """
        # Init titlebar.
        self.titlebar = Titlebar(button_mask, icon_dpixbuf, app_name, title, add_separator, show_title=show_title)
        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", lambda w: self.window.toggle_max_window())
        if "close" in button_mask:
            self.titlebar.close_button.connect("clicked", self.close_callback)
        self.window.add_toggle_event(self.titlebar)
        self.window.add_move_event(self.titlebar)

        # Show titlebar.
        self.show_titlebar()
        
    def close_window(self, widget):
        """
        Close the window when the close button is clicked.

        @param widget: A widget of Gtk.Widget. Passed by gtk.
        """
        self.window.close_window()

    def show_titlebar(self):
        """
        Show title bar of the window. 

        By default, it is invoked at the last step of add_titlebar.
        """
        if self.titlebar_box.get_children() == [] and self.titlebar != None:
            self.titlebar_box.add(self.titlebar)

    def hide_titlebar(self):
        """
        Hide the title bar.
        """
        container_remove_all(self.titlebar_box)

    @post_gui
    def raise_to_top(self):
        """
        Raise the window to the top of the window stack.
        """
        self.window.present()

    def set_title(self, title):
        """
        Set the application title.
        
        @param title: The title string of the application.
        """
        self.titlebar.change_title(title)

    def set_default_size(self, default_width, default_height):
        """
        Set the default size of the window.
        
        @param default_width: Default width in pixels of the application, once set, application don't allow smaller than width.
        @param default_height: Default height in pixels of the application, once set, application don't allow smaller than height.
        """
        self.window.set_default_size(default_width, default_height)
        self.window.set_geometry_hints(
            None,
            default_width,       # minimum width
            default_height       # minimum height
            -1, -1, -1, -1, -1, -1, -1, -1
            )
        
        # Pass application size to skin config.
        skin_config.set_application_window_size(default_width, default_height)

    def set_icon(self, icon_dpixbuf):
        """
        Set the icon of the application. 

        This icon is used by the window manager or the dock.
        
        @param icon_dpixbuf: The icon pixbuf of dtk.ui.theme.DynamicPixbuf.
        """
        gtk.window_set_default_icon(icon_dpixbuf.get_pixbuf())

    def destroy(self, widget, data=None):
        """
        Destroy the window and quit the program.
        
        @param widget: Not used.
        @param data: Not used.
        """
        gtk.main_quit()

    def run(self):
        """
        Show the window and start the mainloop.
        
        You must use this function at last of program, otherwise program will run in loop too early that all code after application.run won't execute until program exit.
        """
        # Show window.
        self.window.show_window()

        # Run main loop.
        gtk.main()

    def set_skin_preview(self, preview_pixbuf):
        """
        Set the skin preview of the application.
        
        @note: The size of preview_pixbuf must be proportional to the size of program, otherwise adjust skin will got wrong coordinate.
        
        @param preview_pixbuf: A pixbuf of type dtk.ui.theme.DynamicPixbuf.
        """
        self.skin_preview_pixbuf = preview_pixbuf
        
    def theme_callback(self, widget):
        """
        Invoked when the theme button is clicked.
        
        @param widget: Not used.
        @return: Always return False
        """
        skin_window = SkinWindow(self.skin_preview_pixbuf)
        skin_window.show_all()
        skin_window.connect("show", lambda w: place_center(self.window, w))

        return False

    def menu_callback(self, widget):
        """
        Invoked when the menu button is clicked.
        
        @param widget: Not used.
        @return: Always return False
        """
        if self.menu_button_callback:
            self.menu_button_callback(widget)

        return False

    def set_menu_callback(self, callback):
        """
        Set the menu_button_callback function.
        
        @param callback: A function which is invoked when the menu button is clicked.
        """
        self.menu_button_callback = callback
예제 #7
0
class Application(object):
    '''
    This is the base class of every program based on deepin-ui.
    Every program should realize it.
    '''

    def __init__(self,
                 app_support_colormap=True,
                 resizable=True,
                 window_type=gtk.WINDOW_TOPLEVEL,
                 destroy_func=None,
                 always_at_center=True,
                 ):
        '''
        Initialize the Application class.

        @param app_support_colormap: Set False if your program don't allow manipulate colormap,
        such as mplayer, otherwise you should keep this option as True.
        @param resizable: Set this option with False if you want window's size fixed, default is True.
        '''
        # Init.
        self.app_support_colormap = app_support_colormap
        self.resizable = resizable
        self.window_type = window_type
        self.close_callback = self.close_window
        self.skin_preview_pixbuf = None
        self.destroy_func = destroy_func
        self.always_at_center = always_at_center

        # Start application.
        self.init()

    def init(self):
        '''
        This do the remain initialize step.

        It Initializes the window and some important signal such as "destroy".
        '''
        # Init gdk threads, the integrant method for multi-thread GUI application.
        gtk.gdk.threads_init()

        # Init status.
        self.menu_button_callback = None

        # Init window.
        if self.app_support_colormap:
            self.window = Window(True, window_type=self.window_type)
        else:
            self.window = MplayerWindow(True, window_type=self.window_type)
        self.window.set_resizable(self.resizable)

        if self.always_at_center:
            self.window.set_position(gtk.WIN_POS_CENTER)

        if hasattr(self, "destroy_func") and self.destroy_func:
            self.window.connect("destroy", lambda w: self.destroy_func)
        else:
            self.window.connect("destroy", self.destroy)

        # Init main box.
        self.main_box = self.window.window_frame

        # Add titlebar box.
        self.titlebar = None
        self.titlebar_box = gtk.HBox()
        self.main_box.pack_start(self.titlebar_box, False)

    def add_titlebar(self,
                     button_mask=["theme", "menu", "max", "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,
                     ):
        '''
        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", lambda w: self.window.toggle_max_window())
        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_motion_move_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)

    def close_window(self, widget):
        '''
        Close the window when the close button is clicked.

        @param widget: A widget of Gtk.Widget. Passed by gtk.
        '''
        if hasattr(self, "destroy_func") and self.destroy_func:
            self.destroy_func()
        else:
            self.window.close_window()

    def show_titlebar(self):
        '''
        Show title bar of the window.

        By default, it is invoked at the last step of add_titlebar.
        '''
        if self.titlebar_box.get_children() == [] and self.titlebar != None:
            self.titlebar_box.add(self.titlebar)

    def hide_titlebar(self):
        '''
        Hide the title bar.
        '''
        container_remove_all(self.titlebar_box)

    @post_gui
    def raise_to_top(self):
        '''
        Raise the window to the top of the window stack.
        '''
        self.window.present()

    def set_title(self, title):
        '''
        Set the application title.

        @param title: The title string of the application.
        '''
        self.titlebar.change_title(title)

    def set_default_size(self, default_width, default_height):
        '''
        Set the default size of the window.

        @param default_width: Default width in pixels of the application, once set, application don't allow smaller than width.
        @param default_height: Default height in pixels of the application, once set, application don't allow smaller than height.
        '''
        self.window.set_default_size(default_width, default_height)
        if self.resizable:
            self.window.set_geometry_hints(
                None,
                default_width,       # minimum width
                default_height       # minimum height
                -1, -1, -1, -1, -1, -1, -1, -1
                )
        else:
            self.window.set_geometry_hints(
                None,
                default_width,       # minimum width
                default_height,       # minimum height
                default_width,
                default_height,
                -1, -1, -1, -1, -1, -1
                )

        # Pass application size to skin config.
        skin_config.set_application_window_size(default_width, default_height)

    def set_icon(self, icon_path):
        '''
        Set the icon of the application.

        This icon is used by the window manager or the dock.

        @param icon_path: The path of application icon.
        '''
        gtk.window_set_default_icon(gtk.gdk.pixbuf_new_from_file(icon_path))

    def destroy(self, widget, data=None):
        '''
        Destroy the window and quit the program.

        This function just call gtk.main_quit .

        @param widget: Not used.
        @param data: Not used.
        '''
        gtk.main_quit()

    def run(self):
        '''
        Show the window and start the mainloop.

        You must use this function at last of program,
        otherwise program will run in loop too early that all code after application.run won't execute until program exit.
        '''
        # Show window.
        self.window.show_window()

        # Run main loop.
        gtk.main()

    def set_skin_preview(self, preview_image_path):
        '''
        Set the skin preview of the application.

        @note: The size of preview_pixbuf must be proportional to the size of program, otherwise adjust skin will got wrong coordinate.

        @param preview_image_path: A path of skin preview image.
        '''
        self.skin_preview_pixbuf = gtk.gdk.pixbuf_new_from_file(preview_image_path)

    def theme_callback(self, widget):
        '''
        Invoked when the theme button is clicked.

        @param widget: Not used.
        @return: Always return False
        '''
        skin_window = SkinWindow(self.skin_preview_pixbuf)
        skin_window.show_all()
        place_center(self.window, skin_window)

        return False

    def menu_callback(self, widget):
        '''
        Invoked when the menu button is clicked.

        @param widget: Not used.
        @return: Always return False
        '''
        if self.menu_button_callback:
            self.menu_button_callback(widget)

        return False

    def set_menu_callback(self, callback):
        '''
        Set the menu_button_callback function.

        @param callback: A function which is invoked when the menu button is clicked,
        this callback just accept one argument, argument is gtk.widget.
        '''
        self.menu_button_callback = callback
예제 #8
0
class Application(object):
    '''
    This is the base class of every program based on deepin-ui.
    Every program should realize it.
    '''
    def __init__(
        self,
        app_support_colormap=True,
        resizable=True,
        window_type=gtk.WINDOW_TOPLEVEL,
        destroy_func=None,
        always_at_center=True,
    ):
        '''
        Initialize the Application class.

        @param app_support_colormap: Set False if your program don't allow manipulate colormap,
        such as mplayer, otherwise you should keep this option as True.
        @param resizable: Set this option with False if you want window's size fixed, default is True.
        '''
        # Init.
        self.app_support_colormap = app_support_colormap
        self.resizable = resizable
        self.window_type = window_type
        self.close_callback = self.close_window
        self.skin_preview_pixbuf = None
        self.destroy_func = destroy_func
        self.always_at_center = always_at_center

        # Start application.
        self.init()

    def init(self):
        '''
        This do the remain initialize step.

        It Initializes the window and some important signal such as "destroy".
        '''
        # Init gdk threads, the integrant method for multi-thread GUI application.
        gtk.gdk.threads_init()

        # Init status.
        self.menu_button_callback = None

        # Init window.
        if self.app_support_colormap:
            self.window = Window(True, window_type=self.window_type)
        else:
            self.window = MplayerWindow(True, window_type=self.window_type)
        self.window.set_resizable(self.resizable)

        if self.always_at_center:
            self.window.set_position(gtk.WIN_POS_CENTER)

        if hasattr(self, "destroy_func") and self.destroy_func:
            self.window.connect("destroy", lambda w: self.destroy_func)
        else:
            self.window.connect("destroy", self.destroy)

        # Init main box.
        self.main_box = self.window.window_frame

        # Add titlebar box.
        self.titlebar = None
        self.titlebar_box = gtk.HBox()
        self.main_box.pack_start(self.titlebar_box, False)

    def add_titlebar(
        self,
        button_mask=["theme", "menu", "max", "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,
    ):
        '''
        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", lambda w: self.window.toggle_max_window())
        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_motion_move_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)

    def close_window(self, widget):
        '''
        Close the window when the close button is clicked.

        @param widget: A widget of Gtk.Widget. Passed by gtk.
        '''
        if hasattr(self, "destroy_func") and self.destroy_func:
            self.destroy_func()
        else:
            self.window.close_window()

    def show_titlebar(self):
        '''
        Show title bar of the window.

        By default, it is invoked at the last step of add_titlebar.
        '''
        if self.titlebar_box.get_children() == [] and self.titlebar != None:
            self.titlebar_box.add(self.titlebar)

    def hide_titlebar(self):
        '''
        Hide the title bar.
        '''
        container_remove_all(self.titlebar_box)

    @post_gui
    def raise_to_top(self):
        '''
        Raise the window to the top of the window stack.
        '''
        self.window.present()

    def set_title(self, title):
        '''
        Set the application title.

        @param title: The title string of the application.
        '''
        self.titlebar.change_title(title)

    def set_default_size(self, default_width, default_height):
        '''
        Set the default size of the window.

        @param default_width: Default width in pixels of the application, once set, application don't allow smaller than width.
        @param default_height: Default height in pixels of the application, once set, application don't allow smaller than height.
        '''
        self.window.set_default_size(default_width, default_height)
        if self.resizable:
            self.window.set_geometry_hints(
                None,
                default_width,  # minimum width
                default_height  # minimum height
                - 1,
                -1,
                -1,
                -1,
                -1,
                -1,
                -1,
                -1)
        else:
            self.window.set_geometry_hints(
                None,
                default_width,  # minimum width
                default_height,  # minimum height
                default_width,
                default_height,
                -1,
                -1,
                -1,
                -1,
                -1,
                -1)

        # Pass application size to skin config.
        skin_config.set_application_window_size(default_width, default_height)

    def set_icon(self, icon_path):
        '''
        Set the icon of the application.

        This icon is used by the window manager or the dock.

        @param icon_path: The path of application icon.
        '''
        gtk.window_set_default_icon(gtk.gdk.pixbuf_new_from_file(icon_path))

    def destroy(self, widget, data=None):
        '''
        Destroy the window and quit the program.

        This function just call gtk.main_quit .

        @param widget: Not used.
        @param data: Not used.
        '''
        gtk.main_quit()

    def run(self):
        '''
        Show the window and start the mainloop.

        You must use this function at last of program,
        otherwise program will run in loop too early that all code after application.run won't execute until program exit.
        '''
        # Show window.
        self.window.show_window()

        # Run main loop.
        gtk.main()

    def set_skin_preview(self, preview_image_path):
        '''
        Set the skin preview of the application.

        @note: The size of preview_pixbuf must be proportional to the size of program, otherwise adjust skin will got wrong coordinate.

        @param preview_image_path: A path of skin preview image.
        '''
        self.skin_preview_pixbuf = gtk.gdk.pixbuf_new_from_file(
            preview_image_path)

    def theme_callback(self, widget):
        '''
        Invoked when the theme button is clicked.

        @param widget: Not used.
        @return: Always return False
        '''
        skin_window = SkinWindow(self.skin_preview_pixbuf)
        skin_window.show_all()
        place_center(self.window, skin_window)

        return False

    def menu_callback(self, widget):
        '''
        Invoked when the menu button is clicked.

        @param widget: Not used.
        @return: Always return False
        '''
        if self.menu_button_callback:
            self.menu_button_callback(widget)

        return False

    def set_menu_callback(self, callback):
        '''
        Set the menu_button_callback function.

        @param callback: A function which is invoked when the menu button is clicked,
        this callback just accept one argument, argument is gtk.widget.
        '''
        self.menu_button_callback = callback
예제 #9
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):
        '''
        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, resizable)
        self.default_width = default_width
        self.default_height = default_height
        self.mask_type = mask_type
        
        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 close_callback:
            self.titlebar.close_button.connect("clicked", lambda w: close_callback())
            self.connect("destroy", lambda w: close_callback())
            self.connect("delete-event", lambda w, e: 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)
예제 #10
0
class DialogBox(Window):
    '''
    Dialog box to standard dialog layout and ui detail.
    
    If you want build a dialog, you should use this standard.
    
    @undocumented: draw_mask_single_page
    @undocumented: draw_mask_glass_page
    @undocumented: draw_mask_multiple_page
    @undocumented: draw_mask_tab_page
    '''
	
    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):
        '''
        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, resizable)
        self.default_width = default_width
        self.default_height = default_height
        self.mask_type = mask_type
        
        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 close_callback:
            self.titlebar.close_button.connect("clicked", lambda w: close_callback())
            self.connect("destroy", lambda w: close_callback())
            self.connect("delete-event", lambda w, e: 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)
        
    def get_mask_func(self, widget, padding_left=0, padding_right=0, padding_top=0, padding_bottom=0):
        '''
        Get mask function to render background, you can use this function to return \"render function\" to draw your ui to keep same style.

        @param widget: DialogBox widget.
        @param padding_left: Padding at left side. 
        @param padding_right: Padding at right side. 
        @param padding_top: Padding at top side. 
        @param padding_bottom: Padding at bottom side. 
        '''
        if self.mask_type == DIALOG_MASK_SINGLE_PAGE:
            return lambda cr, x, y, w, h: draw_mask(
                widget, x + padding_left, 
                y + padding_top, 
                w - padding_left - padding_right, 
                h - padding_top - padding_bottom,
                self.draw_mask_single_page)
        elif self.mask_type == DIALOG_MASK_GLASS_PAGE:
            return lambda cr, x, y, w, h: draw_mask(
                widget, x + padding_left, 
                y + padding_top, 
                w - padding_left - padding_right, 
                h - padding_top - padding_bottom,
                self.draw_mask_glass_page)
        elif self.mask_type == DIALOG_MASK_MULTIPLE_PAGE:
            return lambda cr, x, y, w, h: draw_mask(
                widget, x + padding_left, 
                y + padding_top, 
                w - padding_left - padding_right, 
                h - padding_top - padding_bottom,
                self.draw_mask_multiple_page)
        elif self.mask_type == DIALOG_MASK_TAB_PAGE:
            return lambda cr, x, y, w, h: draw_mask(
                widget, x + padding_left, 
                y + padding_top, 
                w - padding_left - padding_right, 
                h - padding_top - padding_bottom,
                self.draw_mask_tab_page)
        else:
            return lambda cr, x, y, w, h: draw_mask(
                widget, x + padding_left, 
                y + padding_top, 
                w - padding_left - padding_right, 
                h - padding_top - padding_bottom,
                draw_blank_mask)
        
    def draw_mask_single_page(self, cr, x, y, w, h):
        '''
        Internal render function for DIALOG_MASK_SINGLE_PAGE type.
        
        @param cr: Cairo context.
        @param x: X coordinate of draw area.
        @param y: Y coordinate of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        '''
        top_height = 70
        
        draw_vlinear(
            cr, x, y, w, top_height,
            ui_theme.get_shadow_color("mask_single_page_top").get_color_info(),
            )
        
        draw_vlinear(
            cr, x, y + top_height, w, h - top_height,
            ui_theme.get_shadow_color("mask_single_page_bottom").get_color_info(),
            )

    def draw_mask_glass_page(self, cr, x, y, w, h):
        '''
        Internal render function for DIALOG_MASK_GLASS_PAGE type.
        
        @param cr: Cairo context.
        @param x: X coordinate of draw area.
        @param y: Y coordinate of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        '''
        top_height = 70
        
        draw_vlinear(
            cr, x, y, w, top_height,
            ui_theme.get_shadow_color("mask_glass_page_top").get_color_info(),
            )
        
        draw_vlinear(
            cr, x, y + top_height, w, h - top_height,
            ui_theme.get_shadow_color("mask_glass_page_bottom").get_color_info(),
            )
        
    def draw_mask_multiple_page(self, cr, x, y, w, h):
        '''
        Internal render function for DIALOG_MASK_MULTIPLE_PAGE type.
        
        @param cr: Cairo context.
        @param x: X coordinate of draw area.
        @param y: Y coordinate of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        '''
        titlebar_height = self.titlebar.get_allocation().height
        button_box_height = self.right_button_box.get_allocation().height
        dominant_color = skin_config.dominant_color
        
        draw_vlinear(
            cr, x, y + titlebar_height, w, h - titlebar_height,
            ui_theme.get_shadow_color("mask_single_page_bottom").get_color_info(),
            )
        
        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            [(0, (dominant_color, 1.0)),
             (1, (dominant_color, 1.0))])

        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            ui_theme.get_shadow_color("mask_multiple_page").get_color_info(),
            )

    def draw_mask_tab_page(self, cr, x, y, w, h):
        '''
        Internal render function for DIALOG_MASK_TAB_PAGE type.
        
        @param cr: Cairo context.
        @param x: X coordinate of draw area.
        @param y: Y coordinate of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        '''
        button_box_height = self.right_button_box.get_allocation().height
        dominant_color = skin_config.dominant_color
        
        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            [(0, (dominant_color, 1.0)),
             (1, (dominant_color, 1.0))])

        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            ui_theme.get_shadow_color("mask_multiple_page").get_color_info(),
            )
        
    def place_center(self, window=None):
        '''
        Place dialog at center place.
        
        @param window: Place dialog at screen center place if window is None, otherwise place center place of given window.
        '''
        if window == None:
            self.set_position(gtk.WIN_POS_CENTER)
        else:
            place_center(self, window)
예제 #11
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)
예제 #12
0
class DialogBox(Window):
    '''
    Dialog box to standard dialog layout and ui detail.

    If you want build a dialog, you should use this standard.

    @undocumented: draw_mask_single_page
    @undocumented: draw_mask_glass_page
    @undocumented: draw_mask_multiple_page
    @undocumented: draw_mask_tab_page
    '''

    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)

    def key_press_dialog_box(self, widget, event):
        key_name = get_keyevent_name(event)
        if self.keymap.has_key(key_name):
            self.keymap[key_name]()

            return True
        else:
            return False

    def close(self):
        if self.close_callback:
            self.close_callback()
        else:
            self.destroy()

    def get_mask_func(self, widget, padding_left=0, padding_right=0, padding_top=0, padding_bottom=0):
        '''
        Get mask function to render background, you can use this function to return \"render function\" to draw your ui to keep same style.

        @param widget: DialogBox widget.
        @param padding_left: Padding at left side.
        @param padding_right: Padding at right side.
        @param padding_top: Padding at top side.
        @param padding_bottom: Padding at bottom side.
        '''
        if self.mask_type == DIALOG_MASK_SINGLE_PAGE:
            return lambda cr, x, y, w, h: draw_mask(
                widget, x + padding_left,
                y + padding_top,
                w - padding_left - padding_right,
                h - padding_top - padding_bottom,
                self.draw_mask_single_page)
        elif self.mask_type == DIALOG_MASK_GLASS_PAGE:
            return lambda cr, x, y, w, h: draw_mask(
                widget, x + padding_left,
                y + padding_top,
                w - padding_left - padding_right,
                h - padding_top - padding_bottom,
                self.draw_mask_glass_page)
        elif self.mask_type == DIALOG_MASK_MULTIPLE_PAGE:
            return lambda cr, x, y, w, h: draw_mask(
                widget, x + padding_left,
                y + padding_top,
                w - padding_left - padding_right,
                h - padding_top - padding_bottom,
                self.draw_mask_multiple_page)
        elif self.mask_type == DIALOG_MASK_TAB_PAGE:
            return lambda cr, x, y, w, h: draw_mask(
                widget, x + padding_left,
                y + padding_top,
                w - padding_left - padding_right,
                h - padding_top - padding_bottom,
                self.draw_mask_tab_page)
        else:
            return lambda cr, x, y, w, h: draw_mask(
                widget, x + padding_left,
                y + padding_top,
                w - padding_left - padding_right,
                h - padding_top - padding_bottom,
                draw_blank_mask)

    def draw_mask_single_page(self, cr, x, y, w, h):
        '''
        Internal render function for DIALOG_MASK_SINGLE_PAGE type.

        @param cr: Cairo context.
        @param x: X coordinate of draw area.
        @param y: Y coordinate of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        '''
        top_height = 70

        draw_vlinear(
            cr, x, y, w, top_height,
            ui_theme.get_shadow_color("mask_single_page_top").get_color_info(),
            )

        draw_vlinear(
            cr, x, y + top_height, w, h - top_height,
            ui_theme.get_shadow_color("mask_single_page_bottom").get_color_info(),
            )

    def draw_mask_glass_page(self, cr, x, y, w, h):
        '''
        Internal render function for DIALOG_MASK_GLASS_PAGE type.

        @param cr: Cairo context.
        @param x: X coordinate of draw area.
        @param y: Y coordinate of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        '''
        top_height = 70

        draw_vlinear(
            cr, x, y, w, top_height,
            ui_theme.get_shadow_color("mask_glass_page_top").get_color_info(),
            )

        draw_vlinear(
            cr, x, y + top_height, w, h - top_height,
            ui_theme.get_shadow_color("mask_glass_page_bottom").get_color_info(),
            )

    def draw_mask_multiple_page(self, cr, x, y, w, h):
        '''
        Internal render function for DIALOG_MASK_MULTIPLE_PAGE type.

        @param cr: Cairo context.
        @param x: X coordinate of draw area.
        @param y: Y coordinate of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        '''
        titlebar_height = self.titlebar.get_allocation().height
        button_box_height = self.right_button_box.get_allocation().height
        dominant_color = skin_config.dominant_color

        draw_vlinear(
            cr, x, y + titlebar_height, w, h - titlebar_height,
            ui_theme.get_shadow_color("mask_single_page_bottom").get_color_info(),
            )

        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            [(0, (dominant_color, 1.0)),
             (1, (dominant_color, 1.0))])

        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            ui_theme.get_shadow_color("mask_multiple_page").get_color_info(),
            )

    def draw_mask_tab_page(self, cr, x, y, w, h):
        '''
        Internal render function for DIALOG_MASK_TAB_PAGE type.

        @param cr: Cairo context.
        @param x: X coordinate of draw area.
        @param y: Y coordinate of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        '''
        button_box_height = self.right_button_box.get_allocation().height
        dominant_color = skin_config.dominant_color

        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            [(0, (dominant_color, 1.0)),
             (1, (dominant_color, 1.0))])

        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            ui_theme.get_shadow_color("mask_multiple_page").get_color_info(),
            )

    def place_center(self, window=None):
        '''
        Place dialog at center place.

        @param window: Place dialog at screen center place if window is None, otherwise place center place of given window.
        '''
        if window == None:
            self.set_position(gtk.WIN_POS_CENTER)
        else:
            place_center(self, window)
예제 #13
0
파일: dialog.py 프로젝트: netphi/deepin-ui
class DialogBox(Window):
    '''Dialog box.'''
	
    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):
        '''Dialog box.'''
        Window.__init__(self, resizable)
        self.default_width = default_width
        self.default_height = default_height
        self.mask_type = mask_type
        
        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 close_callback:
            self.titlebar.close_button.connect("clicked", lambda w: close_callback())
            self.connect("destroy", lambda w: close_callback())
        else:
            self.titlebar.close_button.connect("clicked", lambda w: self.destroy())
            self.connect("destroy", lambda w: self.destroy())
        
        self.draw_mask = self.get_mask_func(self, 1, 1, 0, 1)
        
    def get_mask_func(self, widget, padding_left=0, padding_right=0, padding_top=0, padding_bottom=0):
        '''Get mask function.'''
        if self.mask_type == DIALOG_MASK_SINGLE_PAGE:
            return lambda cr, x, y, w, h: draw_mask(
                widget, x + padding_left, 
                y + padding_top, 
                w - padding_left - padding_right, 
                h - padding_top - padding_bottom,
                self.draw_mask_single_page)
        elif self.mask_type == DIALOG_MASK_GLASS_PAGE:
            return lambda cr, x, y, w, h: draw_mask(
                widget, x + padding_left, 
                y + padding_top, 
                w - padding_left - padding_right, 
                h - padding_top - padding_bottom,
                self.draw_mask_glass_page)
        elif self.mask_type == DIALOG_MASK_MULTIPLE_PAGE:
            return lambda cr, x, y, w, h: draw_mask(
                widget, x + padding_left, 
                y + padding_top, 
                w - padding_left - padding_right, 
                h - padding_top - padding_bottom,
                self.draw_mask_multiple_page)
        elif self.mask_type == DIALOG_MASK_TAB_PAGE:
            return lambda cr, x, y, w, h: draw_mask(
                widget, x + padding_left, 
                y + padding_top, 
                w - padding_left - padding_right, 
                h - padding_top - padding_bottom,
                self.draw_mask_tab_page)
        else:
            return lambda cr, x, y, w, h: draw_mask(
                widget, x + padding_left, 
                y + padding_top, 
                w - padding_left - padding_right, 
                h - padding_top - padding_bottom,
                draw_blank_mask)
        
    def draw_mask_single_page(self, cr, x, y, w, h):
        '''Draw make for single page type.'''
        top_height = 70
        
        draw_vlinear(
            cr, x, y, w, top_height,
            ui_theme.get_shadow_color("mask_single_page_top").get_color_info(),
            )
        
        draw_vlinear(
            cr, x, y + top_height, w, h - top_height,
            ui_theme.get_shadow_color("mask_single_page_bottom").get_color_info(),
            )

    def draw_mask_glass_page(self, cr, x, y, w, h):
        '''Draw make for glass page type.'''
        top_height = 70
        
        draw_vlinear(
            cr, x, y, w, top_height,
            ui_theme.get_shadow_color("mask_glass_page_top").get_color_info(),
            )
        
        draw_vlinear(
            cr, x, y + top_height, w, h - top_height,
            ui_theme.get_shadow_color("mask_glass_page_bottom").get_color_info(),
            )
        
    def draw_mask_multiple_page(self, cr, x, y, w, h):
        '''Draw make for multiple page type.'''
        titlebar_height = self.titlebar.get_allocation().height
        button_box_height = self.right_button_box.get_allocation().height
        dominant_color = skin_config.dominant_color
        
        draw_vlinear(
            cr, x, y + titlebar_height, w, h - titlebar_height,
            ui_theme.get_shadow_color("mask_single_page_bottom").get_color_info(),
            )
        
        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            [(0, (dominant_color, 1.0)),
             (1, (dominant_color, 1.0))])

        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            ui_theme.get_shadow_color("mask_multiple_page").get_color_info(),
            )

    def draw_mask_tab_page(self, cr, x, y, w, h):
        '''Draw make for tab page type.'''
        button_box_height = self.right_button_box.get_allocation().height
        dominant_color = skin_config.dominant_color
        
        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            [(0, (dominant_color, 1.0)),
             (1, (dominant_color, 1.0))])

        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            ui_theme.get_shadow_color("mask_multiple_page").get_color_info(),
            )