예제 #1
0
    def __init__(self):
        self.app = Application()
        # Set app size.
        self.app.set_default_size(APP_WIDTH, APP_HEIGHT)
        self.app.set_icon(app_theme.get_pixbuf("logo.ico"))
        self.app.set_skin_preview(app_theme.get_pixbuf("frame.png"))
        # Add app titlebar.
        self.app.add_titlebar(["theme", "max", "min", "close"],
                              app_theme.get_pixbuf("logo.png"),
                              "Assembly-IDE v 1.0",
                              " ",
                              add_separator=True)

        self.vbox_ali = gtk.Alignment()
        self.vbox_ali.set(1, 1, 1, 1)
        self.vbox_ali.set_padding(6, 2, 2, 2)
        self.vbox = gtk.VBox()
        self.vbox_ali.add(self.vbox)

        self.init_root_menu()

        self.init_top_toolbar()

        self.code_edit = CodeEdit()
        self.code_edit_file = self.code_edit.file_path

        self.complie_show_list = ComplieShowList()
        self.code_edit.connect("codeedit-changed-file-name",
                               self.modify_code_edit_file_name)

        self.vbox.pack_start(self.top_toolbar_ali, False, False)
        self.vbox.pack_start(self.code_edit, True, True)
        self.vbox.pack_start(self.complie_show_list, False, False)
        self.app.main_box.pack_start(self.vbox_ali, True, True)
        self.app.window.show_all()
예제 #2
0
    def __init__ (self):            
        self.app = Application()
        # Set app size.
        self.app.set_default_size(APP_WIDTH, APP_HEIGHT)
        self.app.set_icon(app_theme.get_pixbuf("logo.ico"))
        self.app.set_skin_preview(app_theme.get_pixbuf("frame.png"))        
        # Add app titlebar.
        self.app.add_titlebar(["theme", "max", "min", "close"],
                              app_theme.get_pixbuf("logo.png"),
                              "Assembly-IDE v 1.0", " ", add_separator = True)

        self.vbox_ali = gtk.Alignment()
        self.vbox_ali.set(1, 1, 1, 1)
        self.vbox_ali.set_padding(6, 2, 2, 2)
        self.vbox = gtk.VBox()
        self.vbox_ali.add(self.vbox)
        
        self.init_root_menu()
        
        self.init_top_toolbar()
        
        self.code_edit = CodeEdit()
        self.code_edit_file = self.code_edit.file_path
        
        self.complie_show_list = ComplieShowList()
        self.code_edit.connect("codeedit-changed-file-name", self.modify_code_edit_file_name)
        
        self.vbox.pack_start(self.top_toolbar_ali, False, False)
        self.vbox.pack_start(self.code_edit, True,True)
        self.vbox.pack_start(self.complie_show_list, False, False)
        self.app.main_box.pack_start(self.vbox_ali, True, True)
        self.app.window.show_all()
예제 #3
0
 def __init__(self):        
     '''application.'''
     self.app = Application(False)
     # application set.
     self.app.set_default_size(800, 500)
     # self.app.window.resize
     self.app.set_icon(app_theme.get_pixbuf("icon.ico"))
     self.app.set_skin_preview(app_theme.get_pixbuf("frame.png"))
     # set titlebar.
     self.app.add_titlebar(["theme", "menu", "max", "min", "close"],
                           app_theme.get_pixbuf("logo.png"),
                           _("Deepin Media Player"), " ", 
                           add_separator = False)
     #
     self.main_ali = gtk.Alignment()
     self.main_vbox = gtk.VBox()
     self.main_ali.add(self.main_vbox)
     self.main_ali.set(0, 0, 1.0, 1.0)
     self.main_ali.set_padding(0, 2, 2, 2)
     '''movie screen. 电影播放屏幕.'''
     # 播放屏幕和播放列表的HBOX.
     self.screen_and_play_list_hbox = gtk.HBox() 
     self.screen_frame = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
     self.screen = gtk.DrawingArea()
     self.screen_frame.add(self.screen)
     #
     self.play_list = gtk.Button("播放列表")
     #
     self.screen_and_play_list_hbox.pack_start(self.screen_frame, True, True)
     self.screen_and_play_list_hbox.pack_start(self.play_list, False, False)
     #
     self.main_vbox.pack_start(self.screen_and_play_list_hbox, True, True)
     #
     self.app.main_box.pack_start(self.main_ali, True, True)
예제 #4
0
    def __init__(self, session_bus):
        dbus.service.Object.__init__(self, session_bus, DSC_UPDATE_MANAGER_PATH)

        self.in_update_list = False
        self.in_upgrade_packages = False
        self.upgrade_pkg_infos = []

        self.application = Application()
        self.application.set_default_size(400, 250)
        self.application.add_titlebar(
                button_mask=['min', 'close'],
                app_name='Software Update Manager',
                )

        self.application.window.set_title("Software Update Manager")
        self.application.set_icon(get_common_image('update.png'))


        # Init page box.
        self.page_box = gtk.VBox()
        
        # Init page align.
        self.page_align = gtk.Alignment()
        self.page_align.set(0.5, 0.5, 1, 1)
        self.page_align.set_padding(0, 0, 2, 2)
        
        self.page_align.add(self.page_box)
        self.application.main_box.pack_start(self.page_align, True, True)
        
        # Init status bar.
        self.statusbar = Statusbar(28)
        status_box = gtk.HBox()

        self.statusbar.status_box.pack_start(status_box, True, True)
        self.application.main_box.pack_start(self.statusbar, False, False)

        self.background = BackgroundBox()
        self.background.draw_mask = self.draw_mask
        self.page_box.pack_start(self.background)

        self.upgrade_button = Button('更新软件')
        self.upgrade_button.set_sensitive(False)

        button_box = gtk.HBox()
        button_box.pack_start(self.upgrade_button, False, False)

        button_box_align = gtk.Alignment(0.5, 0.5, 0, 0)
        button_box_align.set_padding(3, 8, 4, 4)
        button_box_align.add(button_box)

        self.statusbar.status_item_box.pack_start(button_box_align)

        self.update_info_label = Label("初始化...")
        self.update_info_label_align = create_align((0.5, 0.5, 0, 0))
        self.update_info_label_align.add(self.update_info_label)
        
        self.upgrade_button.connect('clicked', self.upgrade_packages)
    def __init__(self, 
                 app_support_colormap=True, 
                 resizable=True,
                 window_type=gtk.WINDOW_TOPLEVEL,
                 destroy_func=None,
                 always_at_center=True,
                 max_callback=None,
                 ):
        '''
        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.
        Application.__init__(
                self,
                app_support_colormap,
                resizable,
                window_type,
                destroy_func,
                always_at_center
                )

        ''' Initialize 
        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

        self.init()
        '''

        if max_callback:
            self.max_callback = max_callback
        else:
            self.max_callback = lambda w:self.window.toggle_max_window()

        self.skin_preview_pixbuf = None
예제 #6
0
 def __init__(self):        
     '''application.'''
     self.__init_values()
     self.app = Application(False)
     # application set.
     app_w, app_h = 890, 590
     min_app_w, min_app_h = 480, 300
     self.app.set_default_size(min_app_w, min_app_h)
     self.app.window.set_default_size(app_w, app_h)
     # self.app.window.resize
     self.app.set_icon(app_theme.get_pixbuf("icon.ico"))
     self.app.set_skin_preview(app_theme.get_pixbuf("frame.png"))
     # set titlebar.
     self.app.add_titlebar(["theme", "menu", "max", "min", "close"],
                           app_theme.get_pixbuf("logo.png"),
                           _("Deepin Media Player"), " ", 
                           add_separator = False)
     #
     self.play_menus = PlayMenus()
     # 设置主题菜单.
     self.app.set_menu_callback(lambda button: self.play_menus.show_theme_menu(button))
     #
     self.main_ali = gtk.Alignment()
     self.main_vbox = gtk.VBox()
     self.main_ali.add(self.main_vbox)
     self.main_ali.set(0, 0, 1.0, 1.0)
     self.main_ali.set_padding(0, 2, 2, 2)
     '''movie screen. 电影播放屏幕.'''
     # 播放屏幕和播放列表的HBOX.
     self.play_list_view = PlayListView()
     self.screen_paned = Paned()
     self.screen_paned.paint_bottom_window = self.__paint_bottom_toolbar_background
     self.screen_frame = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
     self.screen = gtk.DrawingArea()
     self.screen_frame.add(self.screen)
     self.top_toolbar = ToolBar()
     self.bottom_toolbar = BottomToolBar()
     # BUG: 当显示上部工具条的时候,画面抖动.
     self.screen_paned.add_top_widget(self.top_toolbar.hbox_hframe)
     self.screen_paned.add_bottom_widget(self.bottom_toolbar.vbox)
     #
     self.screen_frame_event = self.screen_paned
     self.screen_paned.screen = self.screen
     #
     self.screen_paned.add1(self.screen_frame)
     self.screen_paned.add2(self.play_list_view.play_list_vbox)
     #
     self.play_control_panel = BottomToolBar(False)
     #
     self.main_vbox.pack_start(self.screen_paned, True, True)
     self.main_vbox.pack_start(self.play_control_panel.vbox, False, False)
     #
     self.app.main_box.pack_start(self.main_ali, True, True)
예제 #7
0
class WorkListApp(gobject.GObject):
	def __init__(self):
		gobject.GObject.__init__(self)
		
		self.app = Application(False)
		self.app.window.set_size_request(500, 300)
		# Add app titlebar.
		self.app.add_titlebar(["theme", "menu", "max", "min", "close"],
								None, "WorkList for Deepin", " ", 
								add_separator = True)        
		self.app.set_icon(app_theme.get_pixbuf('icon/worklist.png'))
		self.app.set_skin_preview(app_theme.get_pixbuf('frame.png'))

		self.win = self.app.window
		self.win.set_resizable(False)
		self.app.run()
    def __init__(
        self,
        app_support_colormap=True,
        resizable=True,
        window_type=gtk.WINDOW_TOPLEVEL,
        destroy_func=None,
        always_at_center=True,
        max_callback=None,
    ):
        '''
        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.
        Application.__init__(self, app_support_colormap, resizable,
                             window_type, destroy_func, always_at_center)
        ''' Initialize 
        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

        self.init()
        '''

        if max_callback:
            self.max_callback = max_callback
        else:
            self.max_callback = lambda w: self.window.toggle_max_window()

        self.skin_preview_pixbuf = None
예제 #9
0
class GUI(object):
    '''Media Player GUI kernel code.核心界面代码'''
    def __init__(self):
        '''application.'''
        self.__init_values()
        self.app = Application(False)
        # application set.
        app_w, app_h = 800, 570  # 初始化宽,高.
        min_app_w, min_app_h = 480, 300  # 防止超过,界面布局被破坏.
        self.app.set_default_size(min_app_w, min_app_h)
        self.app.window.set_default_size(app_w, app_h)
        # self.app.window.resize
        image_dir = os.path.join(get_parent_dir(__file__, 2), "image")
        self.app.set_icon(os.path.join(image_dir, "icon.ico"))
        self.app.set_skin_preview(
            os.path.join(os.path.join(image_dir, "frame.png")))
        # set titlebar.
        self.app.add_titlebar(
            ["theme", "menu", "max", "min", "close"],
            os.path.join(os.path.join(image_dir, "logo.png")),
            _("DPlayer"),
            " ",
            add_separator=False,
        )
        self.app.titlebar.set_size_request(-1, 30)

        #
        self.play_menus = PlayMenus()
        # 设置主题菜单.
        self.app.set_menu_callback(
            lambda button: self.play_menus.show_theme_menu(button))
        #
        self.main_ali = gtk.Alignment()
        self.main_vbox = gtk.VBox()
        self.main_ali.add(self.main_vbox)
        self.main_ali.set(0, 0, 1.0, 1.0)
        self.main_ali.set_padding(0, 2, 2, 2)
        #
        self.mid_combo_event = gtk.EventBox()
        self.mid_combo_event.connect("expose-event",
                                     self.mid_combo_event_expose_event)
        self.screen_mid_combo = ScreenMidCombo()
        self.mid_combo_event.set_visible_window(True)
        self.mid_combo_event.add(self.screen_mid_combo)
        '''movie screen. 电影播放屏幕.'''
        # 播放屏幕和播放列表的HBOX.
        self.play_list_view = PlayListView()
        self.screen_paned = Paned()
        self.screen_paned.paint_bottom_window = self.__paint_bottom_toolbar_background
        self.screen_frame = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
        self.screen = gtk.DrawingArea()
        self.screen_frame.add(self.screen)
        self.top_toolbar = ToolBar()
        self.bottom_toolbar = BottomToolBar()
        # BUG: 当显示上部工具条的时候,画面抖动.
        self.screen_paned.add_top_widget(self.top_toolbar.hbox_hframe)
        self.screen_paned.add_bottom_widget(self.bottom_toolbar.vbox)
        #self.screen_paned.add_mid_widget(self.screen_mid_combo)
        self.screen_paned.add_mid_widget(self.mid_combo_event)
        #
        self.screen_frame_event = self.screen_paned
        self.screen_paned.screen = self.screen
        #
        self.screen_paned.add1(self.screen_frame)
        self.screen_paned.add2(self.play_list_view.play_list_vbox)
        #
        self.play_control_panel = BottomToolBar(False)
        #
        self.main_vbox.pack_start(self.screen_paned, True, True)
        self.main_vbox.pack_start(self.play_control_panel.vbox, False, False)
        #
        self.app.main_box.pack_start(self.main_ali, True, True)

    def __init_values(self):
        self.child2_show_check = False  # True 显示 False 隐藏

    ################################################################################
    ##
    def __paint_bottom_toolbar_background(self, e):
        # 将皮肤的图片画在bottom toolbar上,作为背景.
        cr = e.window.cairo_create()
        bottom_size = e.window.get_size()
        # draw background.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(("#ebebeb", 0.1)))
        cr.rectangle(0, 0, bottom_size[0], bottom_size[1])
        cr.fill()
        # draw background pixbuf.
        pixbuf = skin_config.background_pixbuf
        app_h = self.app.window.allocation.height
        app_w = self.app.window.allocation.width
        bottom_h = bottom_size[1]
        # 当图片的高度小雨窗口高度的时候,只拿出图片的最尾巴.
        if pixbuf.get_height() > app_h + bottom_h:
            h = app_h
        else:
            h = pixbuf.get_height() - bottom_h
        # 当图片小于窗口宽度的时候,拉伸图片.
        if pixbuf.get_width() < app_w:
            pixbuf = pixbuf.scale_simple(app_w, pixbuf.get_width(),
                                         gtk.gdk.INTERP_BILINEAR)

        draw_pixbuf(cr, pixbuf, 0, -(h))

    def not_in_system_widget(self):
        # 判断handle toolbar 是否显示出来了.
        return (not self.screen_paned.show_check
                and not self.screen_paned.top_win_show_check
                and not self.screen_paned.bottom_win_show_check)

    def set_paned_handle(self, event):
        if self.screen_paned.show_check and (0 <= event.x <= 7):
            if self.screen_paned.get_move_width() == 0:  # child2 隐藏和显示.
                self.play_control_panel.play_list_btn.button.set_active(True)
            else:
                self.play_control_panel.play_list_btn.button.set_active(False)

    def close_right_child2(self):
        self.screen_paned.set_jmp_end()  # 关闭右侧控件(播放列表..).

    def open_right_child2(self):
        self.screen_paned.set_jmp_start()  # 打开右侧控件 (播放列表...).

    def hide_handle(self):
        self.screen_paned.set_visible_handle(False)

    def show_handle(self):
        self.screen_paned.set_visible_handle(True)

    def show_play_control_paned(self):
        self.main_vbox.pack_start(self.play_control_panel.vbox, False, False)

    def hide_play_control_paned(self):
        self.main_vbox.remove(self.play_control_panel.vbox)

    def show_tooltip_text(self, text, sec=1500):
        self.screen_paned.show_tooltip_text(text, sec)

    def notify_msgbox(self, title, msg, icon_path=get_system_tooptil_icon()):
        try:
            pynotify.init("deepi-media-player")
            msg = pynotify.Notification(title, msg, icon_path)
            if icon_path:
                msg.set_hint_string("image-path", icon_path)
            msg.show()
        except Exception, e:
            print "message[error]:", e
예제 #10
0
    ops, args = getopt.getopt(sys.argv[1:], '')
    module_name = ""

    if len(args):
        module_name = args[0]

    # Check unique.
    if is_exists(APP_DBUS_NAME, APP_OBJECT_NAME, module_name):
        sys.exit()

    # WARING: only use once in one process
    DBusGMainLoop(set_as_default=True)

    # Init application.
    application = Application(resizable=False)
    application.window.connect("focus-out-event", application_focus_changed_cb,
                               "o")
    application.window.connect("focus-in-event", application_focus_changed_cb,
                               "i")

    # Set application default size.
    application.window.set_geometry_hints(
        None,
        WINDOW_WIDTH,
        WINDOW_HEIGHT,
        WINDOW_WIDTH,
        WINDOW_HEIGHT,
    )
    image_dir = os.path.join(get_parent_dir(__file__, 2), "image")
예제 #11
0
    align.set(0.5, 0.5, 0.0, 0.0)
    align.add(gtk.Button(name))
    
    return (name, align)

if __name__ == "__main__":
    # Build DBus name.
    app_dbus_name = "com.deepin.demo"
    app_object_name = "/com/deepin/demo"
    
    # Check unique.
    if is_exists(app_dbus_name, app_object_name):
        sys.exit()
    
    # Init application.
    application = Application()
    
    # Startup unique service, must after application code.
    app_bus_name = dbus.service.BusName(app_dbus_name, bus=dbus.SessionBus())
    UniqueService(app_bus_name, app_dbus_name, app_object_name, application.raise_to_top)
    
    # Set application default size.
    application.set_default_size(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT)
    
    # Set application icon.
    application.set_icon(app_theme.get_pixbuf("icon.ico"))
    
    # Set application preview pixbuf.
    application.set_skin_preview(app_theme.get_pixbuf("frame.png"))
    
    # Add titlebar.
예제 #12
0
class AssemblyIDE(object):
    def __init__ (self):            
        self.app = Application()
        # Set app size.
        self.app.set_default_size(APP_WIDTH, APP_HEIGHT)
        self.app.set_icon(app_theme.get_pixbuf("logo.ico"))
        self.app.set_skin_preview(app_theme.get_pixbuf("frame.png"))        
        # Add app titlebar.
        self.app.add_titlebar(["theme", "max", "min", "close"],
                              app_theme.get_pixbuf("logo.png"),
                              "Assembly-IDE v 1.0", " ", add_separator = True)

        self.vbox_ali = gtk.Alignment()
        self.vbox_ali.set(1, 1, 1, 1)
        self.vbox_ali.set_padding(6, 2, 2, 2)
        self.vbox = gtk.VBox()
        self.vbox_ali.add(self.vbox)
        
        self.init_root_menu()
        
        self.init_top_toolbar()
        
        self.code_edit = CodeEdit()
        self.code_edit_file = self.code_edit.file_path
        
        self.complie_show_list = ComplieShowList()
        self.code_edit.connect("codeedit-changed-file-name", self.modify_code_edit_file_name)
        
        self.vbox.pack_start(self.top_toolbar_ali, False, False)
        self.vbox.pack_start(self.code_edit, True,True)
        self.vbox.pack_start(self.complie_show_list, False, False)
        self.app.main_box.pack_start(self.vbox_ali, True, True)
        self.app.window.show_all()
        
    def init_root_menu(self):        
        # Init file menu.
        file_menu = Menu(
            [(None, "新建", lambda : self.code_edit.clear()), # 清空代码编辑器.
             (None, "打开", lambda : self.open_file_dialog_window()),
             (None),
             (None, "我的程序...", None),
             (None),
             (None, "保存", lambda : self.code_edit.save()),
             (None, "另存为", None),
             (None),
             (None, "退出", lambda :gtk.main_quit())
             ]
            )
        # Init edit menu.
        edit_menu = Menu(
            [(None, "剪切", None),
             (None, "复制", None),             
             (None, "粘帖", None),
             (None, "全选", None),
             (None),
             (None, "注释", lambda : self.notes_line()),
             (None, "取消注释", lambda : self.notes_line()),
             (None),
             (None, "撤销", None),
             (None, "恢复", None),
             (None),
             (None, "查找", None),
             (None, "替换", None),
             (None, "定位到行", None)
             ]
            )
        # Init run menu.
        run_menu = Menu(
            [(None, "编译成目标文件", None),
             (None, "生成可执行文件", None),
             (None, "生成动态链接库文件", None),
             (None, "运行", None),
             (None, "多模块链接", None),
             (None, "调试", None),
             (None, "运行LINUX控制台程序", None)
             ]
            )
        # Init tool menu.
        tool_menu = Menu(
            [(None, "选项", None),
             (None, "计算器", lambda :open_gcalctool())
             ]
            )
        # Init help menu.
        help_menu = Menu(
            [(None, "帮助主题", None),
             (None, "关于", None),             
             ]
            )

        # Init root menu.
        self.root_menu = Menu(
            [(None, "文件", file_menu),
             (None, "编辑", edit_menu),
             (None, "运行", run_menu),
             (None, "工具", tool_menu),
             (None, "帮助", help_menu),
             ],
            True
            )
        
    def init_top_toolbar(self):        
        self.top_toolbar_ali = gtk.Alignment()
        self.top_toolbar_ali.set(0, 0, 0, 0)
        self.top_toolbar_ali.set_padding(0, 0, 5, 0)
        self.top_toolbar = ToolBar()
        self.top_toolbar_ali.add(self.top_toolbar)
        
        
        self.bin_btn = gtk.Button("生成bin")
        self.link_btn = gtk.Button("链接")
        self.run_btn = gtk.Button("运行")        
        self.gcalctool_btn = gtk.Button("计算器")
        
        self.top_toolbar.insert(0, Button("菜单", self.root_menu))
        self.top_toolbar.insert(1, None)
        self.top_toolbar.insert(2, self.bin_btn)
        self.top_toolbar.insert(3, self.link_btn)
        self.top_toolbar.insert(4, self.run_btn)
        self.top_toolbar.insert(5, None)
        self.top_toolbar.insert(6, self.gcalctool_btn)
        
        
        self.bin_btn.connect("clicked", self.bin_btn_clicked)
        self.link_btn.connect("clicked", self.link_btn_clicked)
        self.run_btn.connect("clicked", self.run_btn_clicked)
        self.gcalctool_btn.connect("clicked", self.gcalctool_btn_clicked)
        
    def bin_btn_clicked(self, widget):
        pass
    
    def link_btn_clicked(self, widget):
        self.link_function()    
        
    def link_function(self):    
        self.complie_show_list.clear_text()
        self.code_edit.save()
        temp_path = os.path.split(self.code_edit_file)
        link_file_name = os.path.splitext(temp_path[1])[0] + ".o"
        self.link_file_path = os.path.join(temp_path[0], link_file_name) 
        self.complie_show_list.add_text(input_link(self.code_edit_file, self.link_file_path))
        
    def run_btn_clicked(self, widget):
        self.link_function()
        if os.path.exists(self.link_file_path):
            temp_path = os.path.split(self.link_file_path)
            run_file_name = os.path.splitext(temp_path[1])[0] + ".out"
            self.run_file_path = os.path.join(temp_path[0], run_file_name) 
            print "run_btn_clicked:", self.run_file_path
            run_bool = input_elf(self.link_file_path, self.run_file_path)
            if run_bool == "True":
                self.complie_show_list.add_text("编译完成!!")
                self.complie_show_list.add_text(run_elf(self.run_file_path))
            else:    
                print run_bool
        
    def gcalctool_btn_clicked(self, widget):
        open_gcalctool()
        
    def open_file_dialog_window(self):    
        open_file_path = show_open_file_dialog_window()
        if open_file_path:
            self.code_edit.read(open_file_path)
            
    def notes_line(self):        
        self.code_edit.cursor_start_insert_ch()
        
    def modify_code_edit_file_name(self, CodeEdit, file_name):    
        self.code_edit_file = file_name
예제 #13
0
def open_file_dlg_click_ok(filename):
    print "opened %s" % filename


if __name__ == "__main__":
    # Build DBus name.
    app_dbus_name = "com.deepin.demo"
    app_object_name = "/com/deepin/demo"

    # Check unique.
    if is_exists(app_dbus_name, app_object_name):
        sys.exit()

    # Init application.
    application = Application()

    # Startup unique service, must after application code.
    app_bus_name = dbus.service.BusName(app_dbus_name, bus=dbus.SessionBus())
    UniqueService(app_bus_name, app_dbus_name, app_object_name,
                  application.raise_to_top)

    # Set application default size.
    application.set_default_size(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT)

    # Set application icon.
    application.set_icon(os.path.join(get_current_dir(__file__), "icon.ico"))

    # Set application preview pixbuf.
    application.set_skin_preview(
        os.path.join(get_current_dir(__file__), "frame.png"))
예제 #14
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from dtk.ui.application import Application
from dtk.ui.browser_client import BrowserClient
from dtk.ui.constant import DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT
from dtk.ui.frame import HorizontalFrame
from dtk.ui.theme import ui_theme

if __name__ == "__main__":
    # Init application.
    application = Application("browser_demo")

    # Set application default size.
    application.set_default_size(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT)

    # Set application icon.
    application.set_icon(ui_theme.get_pixbuf("icon.ico"))

    # Add titlebar.
    application.add_titlebar(["theme", "menu", "max", "min", "close"],
                             ui_theme.get_pixbuf("title.png"), "深度图形库",
                             "/home/andy/deepin-ui/browser_demo.py")

    # Add browser.
    horizontal_frame = HorizontalFrame()
    browser_client = BrowserClient(
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from dtk.ui.init_skin import init_theme
init_theme()
from dtk.ui.application import Application
from dtk.ui.button import ToggleButton
from dtk.ui.theme import ui_theme
from dtk.ui.dialog import ConfirmDialog
import gtk

if __name__ == "__main__":
    application = Application()
    application.set_default_size(600, 450)
    application.add_titlebar(title="ToggleButton example!")
    
    toggle_button = ToggleButton(
        inactive_normal_dpixbuf=ui_theme.get_pixbuf("switchbutton/off.png"),
        active_normal_dpixbuf=ui_theme.get_pixbuf("switchbutton/on.png"),
        button_label="This is toggle button",
        padding_x=5,
        )
    toggle_button.connect(
        "toggled", 
        lambda w: ConfirmDialog(
            "反馈对话框",
            "按钮开启" if w.get_active() else "按钮关闭",
            ).show_all())
    
    toggle_button_align = gtk.Alignment()
    toggle_button_align.set(0.5, 0.5, 0, 0)
예제 #16
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from dtk.ui.application import Application
from dtk.ui.browser_client import BrowserClient
from dtk.ui.constant import DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT
from dtk.ui.frame import HorizontalFrame
from dtk.ui.theme import ui_theme

if __name__ == "__main__":
    # Init application.
    application = Application("browser_demo")
    
    # Set application default size.
    application.set_default_size(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT)
    
    # Set application icon.
    application.set_icon(ui_theme.get_pixbuf("icon.ico"))
    
    # Add titlebar.
    application.add_titlebar(
        ["theme", "menu", "max", "min", "close"], 
        ui_theme.get_pixbuf("title.png"), 
        "深度图形库",
        "/home/andy/deepin-ui/browser_demo.py")
    
    # Add browser.
예제 #17
0
    def __init__(self):
        gobject.GObject.__init__(self)
        image_dir = os.path.join(get_parent_dir(__file__, 3), "image")
        application = Application("DMuisc", resizable=False)
        application.close_callback = self.prompt_quit
        application.set_icon(os.path.join(image_dir, "logo.ico"))
        application.set_skin_preview(os.path.join(image_dir, "frame.png"))
        application.add_titlebar(
            ["theme", "menu", "min", "close"],
            os.path.join(image_dir, "logo1.png"),
            _("DMusic")
            )
        application.titlebar.menu_button.connect("button-press-event", self.menu_button_press)        
        application.titlebar.connect("button-press-event", self.right_click_cb)
        
        # Window mode change.
        self.revert_toggle_button = self.create_revert_button()
        self.revert_toggle_button.connect("toggled", self.change_view) 

        application.titlebar.button_box.pack_start(self.revert_toggle_button)
        application.titlebar.button_box.reorder_child(self.revert_toggle_button, 1)
        self.window = application.window
        self.window.is_disable_window_maximized = self.is_disable_window_maximized
        utils.set_main_window(self)
        
        self.plugins = plugins.PluginsManager(self, False)        
        self.browser_manager = BrowserMananger()        
        self.tray_icon = TrayIcon(self)        
        self.lyrics_display = LyricsModule()
        self.list_manager = ListManager()
        self.simple_header_bar = SimpleHeadbar()
        self.preference_dialog = PreferenceDialog()
        self.equalizer_win = EqualizerWindow()
        self.mmkeys = MMKeys()
        self.audiocd = AudioCDSource()
        self.playlist_ui = playlist_ui

        self.mini_window = MiniWindow()
        
        self.window.add_move_event(self.simple_header_bar)

        bottom_box = gtk.HBox()
        self.browser_align = gtk.Alignment()
        self.browser_align.set_padding(0, 0, 0, 0)
        self.browser_align.set(0.5, 0.5, 1, 1)
        
        list_manager_align = gtk.Alignment()
        list_manager_align.set_padding(0, 0, 0, 0)
        list_manager_align.set(1, 1, 1, 1)
        list_manager_align.add(self.list_manager)
        
        self.browser_align.add(self.browser_manager)
        bottom_box.pack_start(list_manager_align, False, False)        
        bottom_box.pack_start(self.browser_align, True, True)
        self.browser_align.set_no_show_all(True)
        
        main_box = gtk.VBox()
        self.header_box = gtk.VBox()
        self.header_box.add(self.simple_header_bar)
        main_box.pack_start(self.header_box, False)
        main_box.pack_start(bottom_box, True)
        
        self.link_box = gtk.HBox()
        self.link_box.pack_start(create_right_align(), True, True)
        self.link_box.pack_start(LinkButton(_("Join us"), "http://www.linuxdeepin.com/joinus/job"), False, False)
        
        status_box = gtk.HBox(spacing=5)
        status_box.pack_start(jobs_manager)
        status_box.pack_start(self.link_box, padding=5)
        
        status_bar = gtk.EventBox()
        status_bar.set_visible_window(False)
        status_bar.set_size_request(-1, 22)
        status_bar.add(status_box)
        
        application.main_box.pack_start(main_box)        
        application.main_box.pack_start(status_bar, False, True)
        
        # if config.get("globalkey", "enable", "false") == "true":
            # global_hotkeys.start_bind()
        
        if config.get("setting", "window_mode") == "simple":
            self.revert_toggle_button.set_active(False)
        else:    
            self.revert_toggle_button.set_active(True)
                
        self.change_view(self.revert_toggle_button)    
            
        if config.get("window", "x") == "-1":
            self.window.set_position(gtk.WIN_POS_CENTER)
        else:    
            self.window.move(int(config.get("window","x")),int(config.get("window","y")))
            
        # try:    
        #     self.window.resize(int(config.get("window","width")),int(config.get("window","height")))
        # except:    
        #     pass
        
        # window_state = config.get("window", "state")
        # if window_state == "maximized":
        #     self.window.maximize()
        # elif window_state == "normal":    
        #     self.window.unmaximize()
        
        self.window.connect("delete-event", self.quit)
        self.window.connect("configure-event", self.on_configure_event)
        self.window.connect("destroy", self.quit)
        
        Dispatcher.connect("quit",self.force_quit)
        Dispatcher.connect("show-main-menu", self.show_instance_menu)
        Dispatcher.connect("show-setting", lambda w : self.preference_dialog.show_all())
        Dispatcher.connect("show-desktop-page", lambda w: self.preference_dialog.show_desktop_lyrics_page())
        Dispatcher.connect("show-scroll-page", lambda w: self.preference_dialog.show_scroll_lyrics_page())
        Dispatcher.connect("show-job", self.hide_link_box)
        Dispatcher.connect("hide-job", self.show_link_box)
        
        gobject.idle_add(self.ready)
예제 #18
0
app_theme = init_skin(
    "deepin-ui-demo", 
    "1.0",
    "01",
    os.path.join(get_parent_dir(__file__), "skin"),
    os.path.join(get_parent_dir(__file__), "app_theme"),
    )

from dtk.ui.application import Application
from dtk.ui.treeview import TreeView, TextItem
from dtk.ui.constant import DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT
import gtk

if __name__ == "__main__":
    # Init application.
    application = Application()

    # Set application default size.
    application.set_default_size(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT)

    # Set application icon.
    application.set_icon(os.path.join(get_current_dir(__file__), "icon.ico"))
    
    # Set application preview pixbuf.
    application.set_skin_preview(os.path.join(get_current_dir(__file__), "frame.png"))
    
    # Add titlebar.
    application.add_titlebar(
        ["theme", "max", "min", "close"], 
        os.path.join(get_current_dir(__file__), "logo.png"), 
        "TreeView demo",
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from dtk.ui.init_skin import init_theme
init_theme()
from dtk.ui.application import Application

application = Application()
application.set_default_size(600, 450)
application.add_titlebar(title="Hello world!")
application.run()
예제 #20
0
 def __init__(self):
     """application."""
     self.__init_values()
     self.app = Application(False)
     # application set.
     app_w, app_h = 800, 570  # 初始化宽,高.
     min_app_w, min_app_h = 480, 300  # 防止超过,界面布局被破坏.
     self.app.set_default_size(min_app_w, min_app_h)
     self.app.window.set_default_size(app_w, app_h)
     # self.app.window.resize
     image_dir = os.path.join(get_parent_dir(__file__, 2), "image")
     self.app.set_icon(os.path.join(image_dir, "icon.ico"))
     self.app.set_skin_preview(os.path.join(os.path.join(image_dir, "frame.png")))
     # set titlebar.
     self.app.add_titlebar(["theme", "menu", "max", "min", "close"],
                           os.path.join(os.path.join(image_dir, "logo.png")),
                           _("DPlayer"), " ",
                           add_separator=False)
     #
     self.play_menus = PlayMenus()
     # 设置主题菜单.
     self.app.set_menu_callback(lambda button: self.play_menus.show_theme_menu(button))
     #
     self.main_ali = gtk.Alignment()
     self.main_vbox = gtk.VBox()
     self.main_ali.add(self.main_vbox)
     self.main_ali.set(0, 0, 1.0, 1.0)
     self.main_ali.set_padding(0, 2, 2, 2)
     #
     self.mid_combo_event = gtk.EventBox()
     self.mid_combo_event.connect("expose-event", self.mid_combo_event_expose_event)
     self.screen_mid_combo = ScreenMidCombo()
     self.mid_combo_event.set_visible_window(True)
     self.mid_combo_event.add(self.screen_mid_combo)
     # movie screen. 电影播放屏幕.
     # 播放屏幕和播放列表的HBOX.
     self.play_list_view = PlayListView()
     self.screen_paned = Paned()
     self.screen_paned.paint_bottom_window = self.__paint_bottom_toolbar_background
     self.screen_frame = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
     self.screen = gtk.DrawingArea()
     self.screen_frame.add(self.screen)
     self.top_toolbar = ToolBar()
     self.bottom_toolbar = BottomToolBar()
     # BUG: 当显示上部工具条的时候,画面抖动.
     self.screen_paned.add_top_widget(self.top_toolbar.hbox_hframe)
     self.screen_paned.add_bottom_widget(self.bottom_toolbar.vbox)
     #self.screen_paned.add_mid_widget(self.screen_mid_combo)
     self.screen_paned.add_mid_widget(self.mid_combo_event)
     #
     self.screen_frame_event = self.screen_paned
     self.screen_paned.screen = self.screen
     #
     self.screen_paned.add1(self.screen_frame)
     self.screen_paned.add2(self.play_list_view.play_list_vbox)
     #
     self.play_control_panel = BottomToolBar(False)
     #
     self.main_vbox.pack_start(self.screen_paned, True, True)
     self.main_vbox.pack_start(self.play_control_panel.vbox, False, False)
     #
     self.app.main_box.pack_start(self.main_ali, True, True)
예제 #21
0
class GUI(object):
    """Media Player GUI kernel code.核心界面代码"""

    def __init__(self):
        """application."""
        self.__init_values()
        self.app = Application(False)
        # application set.
        app_w, app_h = 800, 570  # 初始化宽,高.
        min_app_w, min_app_h = 480, 300  # 防止超过,界面布局被破坏.
        self.app.set_default_size(min_app_w, min_app_h)
        self.app.window.set_default_size(app_w, app_h)
        # self.app.window.resize
        image_dir = os.path.join(get_parent_dir(__file__, 2), "image")
        self.app.set_icon(os.path.join(image_dir, "icon.ico"))
        self.app.set_skin_preview(os.path.join(os.path.join(image_dir, "frame.png")))
        # set titlebar.
        self.app.add_titlebar(["theme", "menu", "max", "min", "close"],
                              os.path.join(os.path.join(image_dir, "logo.png")),
                              _("DPlayer"), " ",
                              add_separator=False)
        #
        self.play_menus = PlayMenus()
        # 设置主题菜单.
        self.app.set_menu_callback(lambda button: self.play_menus.show_theme_menu(button))
        #
        self.main_ali = gtk.Alignment()
        self.main_vbox = gtk.VBox()
        self.main_ali.add(self.main_vbox)
        self.main_ali.set(0, 0, 1.0, 1.0)
        self.main_ali.set_padding(0, 2, 2, 2)
        #
        self.mid_combo_event = gtk.EventBox()
        self.mid_combo_event.connect("expose-event", self.mid_combo_event_expose_event)
        self.screen_mid_combo = ScreenMidCombo()
        self.mid_combo_event.set_visible_window(True)
        self.mid_combo_event.add(self.screen_mid_combo)
        # movie screen. 电影播放屏幕.
        # 播放屏幕和播放列表的HBOX.
        self.play_list_view = PlayListView()
        self.screen_paned = Paned()
        self.screen_paned.paint_bottom_window = self.__paint_bottom_toolbar_background
        self.screen_frame = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
        self.screen = gtk.DrawingArea()
        self.screen_frame.add(self.screen)
        self.top_toolbar = ToolBar()
        self.bottom_toolbar = BottomToolBar()
        # BUG: 当显示上部工具条的时候,画面抖动.
        self.screen_paned.add_top_widget(self.top_toolbar.hbox_hframe)
        self.screen_paned.add_bottom_widget(self.bottom_toolbar.vbox)
        #self.screen_paned.add_mid_widget(self.screen_mid_combo)
        self.screen_paned.add_mid_widget(self.mid_combo_event)
        #
        self.screen_frame_event = self.screen_paned
        self.screen_paned.screen = self.screen
        #
        self.screen_paned.add1(self.screen_frame)
        self.screen_paned.add2(self.play_list_view.play_list_vbox)
        #
        self.play_control_panel = BottomToolBar(False)
        #
        self.main_vbox.pack_start(self.screen_paned, True, True)
        self.main_vbox.pack_start(self.play_control_panel.vbox, False, False)
        #
        self.app.main_box.pack_start(self.main_ali, True, True)

    def __init_values(self):
        self.child2_show_check = False  # True 显示 False 隐藏

    ################################################################################
    ##
    def __paint_bottom_toolbar_background(self, e):
        # 将皮肤的图片画在bottom toolbar上,作为背景.
        cr = e.window.cairo_create()
        bottom_size = e.window.get_size()
        # draw background.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(("#ebebeb", 0.1)))
        cr.rectangle(0, 0, bottom_size[0], bottom_size[1])
        cr.fill()
        # draw background pixbuf.
        pixbuf = skin_config.background_pixbuf
        app_h = self.app.window.allocation.height
        app_w = self.app.window.allocation.width
        bottom_h = bottom_size[1]
        # 当图片的高度小雨窗口高度的时候,只拿出图片的最尾巴.
        if pixbuf.get_height() > app_h + bottom_h:
            h = app_h
        else:
            h = pixbuf.get_height() - bottom_h
            # 当图片小于窗口宽度的时候,拉伸图片.
        if pixbuf.get_width() < app_w:
            pixbuf = pixbuf.scale_simple(app_w,
                                         pixbuf.get_width(),
                                         gtk.gdk.INTERP_BILINEAR)

        draw_pixbuf(cr,
                    pixbuf,
                    0,
                    -h)

    def not_in_system_widget(self):
        # 判断handle toolbar 是否显示出来了.
        return (not self.screen_paned.show_check and
                not self.screen_paned.top_win_show_check and
                not self.screen_paned.bottom_win_show_check)

    def set_paned_handle(self, event):
        if self.screen_paned.show_check and (0 <= event.x <= 7):
            if self.screen_paned.get_move_width() == 0:  # child2 隐藏和显示.
                self.play_control_panel.play_list_btn.button.set_active(True)
            else:
                self.play_control_panel.play_list_btn.button.set_active(False)

    def close_right_child2(self):
        self.screen_paned.set_jmp_end()  # 关闭右侧控件(播放列表..).

    def open_right_child2(self):
        self.screen_paned.set_jmp_start()  # 打开右侧控件 (播放列表...).

    def hide_handle(self):
        self.screen_paned.set_visible_handle(False)

    def show_handle(self):
        self.screen_paned.set_visible_handle(True)

    def show_play_control_paned(self):
        self.main_vbox.pack_start(self.play_control_panel.vbox, False, False)

    def hide_play_control_paned(self):
        self.main_vbox.remove(self.play_control_panel.vbox)

    def show_tooltip_text(self, text, sec=1500):
        self.screen_paned.show_tooltip_text(text, sec)

    def notify_msgbox(self, title, msg, icon_path=get_system_tooptil_icon()):
        try:
            pynotify.init("deepi-media-player")
            msg = pynotify.Notification(title, msg, icon_path)
            if icon_path:
                msg.set_hint_string("image-path", icon_path)
            msg.show()
        except Exception, e:
            print "message[error]:", e
예제 #22
0
from dtk.ui.frame import HorizontalFrame, VerticalFrame
from dtk.ui.mplayer_view import MplayerView
from dtk.ui.statusbar import Statusbar
'''
FIXME: ImportError: No module named dragbar
dragbar木有了?
'''
from dtk.ui.dragbar import Dragbar

def show_video(widget, xid):
    '''Show video.'''
    run_command("mplayer -fs -wid %s %s" % (xid, "/data/Video/Manatee.avi"))
    
if __name__ == "__main__":
    # Init application.
    application = Application("demo", False)

    # Set application default size.
    application.set_default_size(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT)
    
    # Set application icon.
    application.set_icon(ui_theme.get_pixbuf("icon.ico"))
    
    # Add titlebar.
    application.add_titlebar(
        ["theme", "menu", "max", "min", "close"], 
        ui_theme.get_pixbuf("title.png"), 
        "电影播放器",
        "深度Linux视频演示")
    
    # Add mplayer view.
예제 #23
0
app_theme = init_skin(
    "deepin-ui-demo", 
    "1.0",
    "01",
    os.path.join(get_parent_dir(__file__), "skin"),
    os.path.join(get_parent_dir(__file__), "app_theme"),
    )

from dtk.ui.application import Application
from dtk.ui.dragable_tab import TabBox
from dtk.ui.constant import DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT
import gtk

if __name__ == "__main__":
    # Init application.
    application = Application()

    # Set application default size.
    application.set_default_size(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT)

    # Set application icon.
    application.set_icon(os.path.join(get_current_dir(__file__), "icon.ico"))
    
    # Set application preview pixbuf.
    application.set_skin_preview(os.path.join(get_current_dir(__file__), "frame.png"))
    
    # Add titlebar.
    application.add_titlebar(
        ["theme", "max", "min", "close"], 
        os.path.join(get_current_dir(__file__), "logo.png"), 
        "Tab demo",
예제 #24
0
    "1.0",
    "01",
    os.path.join(get_parent_dir(__file__), "skin"),
    os.path.join(get_parent_dir(__file__), "app_theme"),
    )

from dtk.ui.application import Application
from dtk.ui.new_treeview import TreeView
from dtk.ui.constant import DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT
from dtk.ui.file_treeview import (get_dir_items, sort_by_name, sort_by_size,
                                  sort_by_type, sort_by_mtime)
import gtk

if __name__ == "__main__":
    # Init application.
    application = Application()

    # Set application default size.
    application.set_default_size(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT)

    # Set application icon.
    application.set_icon(app_theme.get_pixbuf("icon.ico"))
    
    # Set application preview pixbuf.
    application.set_skin_preview(app_theme.get_pixbuf("frame.png"))
    
    # Add titlebar.
    application.add_titlebar(
        ["theme", "max", "min", "close"], 
        app_theme.get_pixbuf("logo.png"), 
        "TreeView demo",
예제 #25
0
    def init_ui(self):
        self.loginfo("Init ui")
        # Init application.
        self.application = Application(
            resizable=False,
            destroy_func=self.application_close_window,
            )
        self.application.set_default_size(888, 634)
        self.application.set_skin_preview(utils.get_common_image("frame.png"))
        self.application.set_icon(utils.get_common_image("logo48.png"))
        self.application.add_titlebar(
                ["theme", "menu", "min", "close"],
                show_title=False
                )
        self.application.window.set_title(_("Deepin Store"))
        self.application.window.connect("delete-event", self.application_close_window)

        # Init page box.
        self.page_box = gtk.VBox()

        # Init page switcher.
        self.page_switcher = HSlider(200)
        self.page_switcher.append_page(self.page_box)
        self.page_switcher.set_to_page(self.page_box)

        # Init page align.
        self.page_align = gtk.Alignment()
        self.page_align.set(0.5, 0.5, 1, 1)
        self.page_align.set_padding(0, 0, 2, 2)

        # Append page to switcher.
        self.paned_box = PanedBox(24)
        self.paned_box.add_content_widget(self.page_switcher)
        self.bottom_tip_bar = BottomTipBar()
        self.bottom_tip_bar.close_button.connect('clicked', lambda w: self.paned_box.bottom_window.hide())
        self.paned_box.add_bottom_widget(self.bottom_tip_bar)
        self.page_align.add(self.paned_box)
        self.application.main_box.pack_start(self.page_align, True, True)

        # Init status bar.
        self.statusbar = Statusbar(24)
        status_box = gtk.HBox()
        self.message_box = gtk.HBox()

        self.message_label = Label("", enable_gaussian=True)
        label_align = gtk.Alignment()
        label_align.set(0.0, 0.5, 0, 0)
        label_align.set_padding(0, 0, 10, 0)
        label_align.add(self.message_label)
        self.message_box.pack_start(label_align)

        join_us_button = LinkButton(_("Join us"), "http://www.linuxdeepin.com/joinus/job")
        join_us_button_align = gtk.Alignment()
        join_us_button_align.set(0.5, 0.5, 0, 0)
        join_us_button_align.set_padding(0, 3, 0, 10)
        join_us_button_align.add(join_us_button)
        status_box.pack_start(self.message_box, True, True)
        status_box.pack_start(join_us_button_align, False, False)
        self.statusbar.status_box.pack_start(status_box, True, True)
        self.application.main_box.pack_start(self.statusbar, False, False)

        # Init navigatebar.
        self.detail_page = None
        self.home_page = None
        self.upgrade_page = None
        self.uninstall_page = None
        self.install_page = None

        self.navigatebar = Navigatebar(
                [
                (DynamicPixbuf(utils.get_common_image("navigatebar/nav_home.png")), _("Home"), self.show_home_page),
                (DynamicPixbuf(utils.get_common_image("navigatebar/nav_update.png")), _("Upgrade"), self.show_upgrade_page),
                (DynamicPixbuf(utils.get_common_image("navigatebar/nav_uninstall.png")), _("Uninstall"), self.show_uninstall_page),
                (DynamicPixbuf(utils.get_common_image("navigatebar/nav_download.png")), _("Installation"), self.show_install_page),
                ],
                font_size = 11,
                padding_x = 2,
                padding_y = 2,
                vertical=False,
                item_hover_pixbuf=DynamicPixbuf(utils.get_common_image("navigatebar/nav_hover.png")),
                item_press_pixbuf=DynamicPixbuf(utils.get_common_image("navigatebar/nav_press.png")),
                )
        self.navigatebar.set_size_request(-1, 56)
        self.navigatebar_align = gtk.Alignment(0, 0, 1, 1)
        self.navigatebar_align.set_padding(0, 0, 4, 0)
        self.navigatebar_align.add(self.navigatebar)
        self.application.titlebar.set_size_request(-1, 56)
        self.application.titlebar.left_box.pack_start(self.navigatebar_align, True, True)
        self.application.window.add_move_event(self.navigatebar)

        # Init menu.
        if LANGUAGE == 'en_US':
            menu_min_width = 185
        else:
            menu_min_width = 150
        menu = Menu(
            [
             (None, _("Refresh package lists"), lambda:global_event.emit('start-update-list')),
             (None, _("Open download directory"), self.open_download_directory),
             (None, _("Clear up cached packages"), self.clean_download_cache),
             (None, _("View new features"), lambda : self.show_wizard_win()),
             (self.get_pixbuf_group("menu", "setting"), _("Preferences"), self.show_preference_dialog),
             (self.get_pixbuf_group("menu", "close"), _("Quit"), self.exit),
             ],
            is_root_menu=True,
            menu_min_width=menu_min_width,
            )
        self.application.set_menu_callback(
            lambda button:
                menu.show(
                get_widget_root_coordinate(button, WIDGET_POS_BOTTOM_LEFT),
                (button.get_allocation().width, 0)))

        self.preference_dialog = DscPreferenceDialog()

        if hasattr(self, 'recommend_status'):
            self.init_home_page(self.recommend_status)
        else:
            self.init_home_page()
예제 #26
0
class UpdateManager(dbus.service.Object):
    def __init__(self, session_bus):
        dbus.service.Object.__init__(self, session_bus, DSC_UPDATE_MANAGER_PATH)

        self.in_update_list = False
        self.in_upgrade_packages = False
        self.upgrade_pkg_infos = []

        self.application = Application()
        self.application.set_default_size(400, 250)
        self.application.add_titlebar(
                button_mask=['min', 'close'],
                app_name='Software Update Manager',
                )

        self.application.window.set_title("Software Update Manager")
        self.application.set_icon(get_common_image('update.png'))


        # Init page box.
        self.page_box = gtk.VBox()
        
        # Init page align.
        self.page_align = gtk.Alignment()
        self.page_align.set(0.5, 0.5, 1, 1)
        self.page_align.set_padding(0, 0, 2, 2)
        
        self.page_align.add(self.page_box)
        self.application.main_box.pack_start(self.page_align, True, True)
        
        # Init status bar.
        self.statusbar = Statusbar(28)
        status_box = gtk.HBox()

        self.statusbar.status_box.pack_start(status_box, True, True)
        self.application.main_box.pack_start(self.statusbar, False, False)

        self.background = BackgroundBox()
        self.background.draw_mask = self.draw_mask
        self.page_box.pack_start(self.background)

        self.upgrade_button = Button('更新软件')
        self.upgrade_button.set_sensitive(False)

        button_box = gtk.HBox()
        button_box.pack_start(self.upgrade_button, False, False)

        button_box_align = gtk.Alignment(0.5, 0.5, 0, 0)
        button_box_align.set_padding(3, 8, 4, 4)
        button_box_align.add(button_box)

        self.statusbar.status_item_box.pack_start(button_box_align)

        self.update_info_label = Label("初始化...")
        self.update_info_label_align = create_align((0.5, 0.5, 0, 0))
        self.update_info_label_align.add(self.update_info_label)
        
        self.upgrade_button.connect('clicked', self.upgrade_packages)


    def draw_mask(self, cr, x, y, w, h):
        sidebar_color = ui_theme.get_color("menu_select_font").get_color()
        draw_vlinear(cr, x, y, w, h,
                     [(0, (sidebar_color, 0.9)),
                      (1, (sidebar_color, 0.9)),]
                     )

    def start_dsc_backend(self):
        self.system_bus = dbus.SystemBus()
        bus_object = self.system_bus.get_object(DSC_SERVICE_NAME, DSC_SERVICE_PATH)
        self.bus_interface = dbus.Interface(bus_object, DSC_SERVICE_NAME)
        self.system_bus.add_signal_receiver(
                self.backend_signal_receiver, 
                signal_name="update_signal", 
                dbus_interface=DSC_SERVICE_NAME, 
                path=DSC_SERVICE_PATH)

    def backend_signal_receiver(self, messages):
        for message in messages:
            (signal_type, action_content) = message
            
            if signal_type == "update-list-update":
                self.in_update_list = True
                message_str = "正在检查更新,请稍等...(%s%%)" % int(float(action_content[0]))
                self.update_info_label.set_text(message_str)
                self.upgrade_button.set_sensitive(False)
            elif signal_type == 'update-list-finish':
                message_str = "正在检查更新,请稍等..."
                self.update_info_label.set_text(message_str)
                self.in_update_list = False

                self.bus_interface.request_upgrade_pkgs(
                        reply_handler=self.render_upgrade_info, 
                        error_handler=lambda e:handle_dbus_error("request_upgrade_pkgs", e))
            elif signal_type == 'update-list-failed':
                message_str = '检查更新失败!'
                self.update_info_label.set_text(message_str)

            elif signal_type == 'upgrade-commit-update':
                pkg_names, action_type, percent, status = action_content
                message_str = "[%s%%]%s" % (percent, status)
                self.update_info_label.set_text(message_str)
                self.upgrade_button.set_sensitive(False)
                self.in_upgrade_packages = True

            elif signal_type == 'upgrade-commit-finish':
                self.in_upgrade_packages = False
                message_str = '软件更新完成!'
                self.update_info_label.set_text(message_str)

    def upgrade_packages(self, widget):
        if self.in_update_list:
            print 'Check update, please wait...'
        elif self.in_upgrade_packages:
            print 'Upgrade packages, please wait...'
        else:
            self.upgrade_button.set_sensitive(False)
            self.in_upgrade_packages = True
            all_upgrade_pkgs = []
            for info in self.upgrade_pkg_infos:
                all_upgrade_pkgs.append(str(eval(info)[0]))
            self.bus_interface.upgrade_pkgs_with_new_policy(
                    all_upgrade_pkgs,
                    reply_handler=lambda :handle_dbus_reply("upgrade_pkgs_with_new_policy"), 
                    error_handler=lambda e:handle_dbus_error("upgrade_pkgs_with_new_policy", e),
                    )

    def render_upgrade_info(self, pkg_infos):
        self.upgrade_pkg_infos = pkg_infos
        if len(pkg_infos) > 0:
            msg_str = '您的系统有%s个更新!' % (len(pkg_infos),)
            self.upgrade_button.set_sensitive(True)
        else:
            msg_str = '您的系统已经最新状态了~'
            self.upgrade_button.set_sensitive(False)

        self.update_info_label.set_text(msg_str)
        self.application.window.show_all()

    def run(self):
        self.start_dsc_backend()
        container_remove_all(self.background)
        self.background.pack_start(self.update_info_label_align)

        gtk.timeout_add(1000, lambda:self.bus_interface.start_update_list(
                reply_handler=lambda :handle_dbus_reply("start_update_list"),
                error_handler=lambda e:handle_dbus_error("start_update_list", e)))

        self.application.run()
        self.bus_interface.request_quit(
                reply_handler=lambda :handle_dbus_reply("request_quit"), 
                error_handler=lambda e:handle_dbus_error("request_quit", e))

    def quit(self):
        gtk.main_quit()

    @dbus.service.method(DSC_UPDATE_MANAGER_NAME, in_signature="", out_signature="")    
    def hello(self):
        self.application.window.present()
예제 #27
0
    def init_ui(self):
        self.application = Application()
        self.application.set_default_size(1000, 660)
        self.application.set_skin_preview(get_common_image("frame.png"))
        self.application.set_icon(get_common_image("logo48.png"))
        self.application.add_titlebar(
                ["theme", "menu", "max","min", "close"],
                show_title=False
                )
        self.application.window.set_title(_("Deepin Games"))

        # Init page box.
        self.page_box = gtk.VBox()
        self.page_box.connect('expose-event', self.page_box_render)
        
        # Init page align.
        self.page_align = gtk.Alignment()
        self.page_align.set(0.5, 0.5, 1, 1)
        self.page_align.set_padding(0, 0, 2, 2)
        
        # Append page to switcher.
        self.paned_box = PanedBox(24)
        self.paned_box.add_content_widget(self.page_box)
        self.bottom_tip_bar = BottomTipBar()
        self.bottom_tip_bar.close_button.connect('clicked', lambda w: self.paned_box.bottom_window.hide())
        self.paned_box.add_bottom_widget(self.bottom_tip_bar)

        self.page_align.add(self.paned_box)
        self.application.main_box.pack_start(self.page_align, True, True)
        
        # Init status bar.
        self.statusbar = Statusbar(30)
        status_box = gtk.HBox()

        self.statusbar.status_box.pack_start(status_box, True, True)
        self.application.main_box.pack_start(self.statusbar, False, False)

        self.webview = WebView(COOKIE_FILE)
        webkit.set_web_database_directory_path(CACHE_DIR)
        web_settings = self.webview.get_settings()
        web_settings.set_property("enable-page-cache", True)
        web_settings.set_property("enable-offline-web-application-cache", True)
        #web_settings.set_property("enable-file-access-from-file-uris", True)
        web_settings.set_property("enable-xss-auditor", False)
        web_settings.set_property('enable-universal-access-from-file-uris', True)
        web_settings.set_property("enable-default-context-menu", False)
        self.webview.set_settings(web_settings)
        #self.webview.enable_inspector()
        self.webview.connect('new-window-policy-decision-requested', self.navigation_policy_decision_requested_cb)
        #self.webview.connect('notify::load-status', self.webview_load_status_handler)
        self.webview.connect('notify::title', self.webview_title_changed_handler)
        self.webview.connect('script-alert', self.webview_script_alert_handler)
        self.webview.connect('window-object-cleared', self.webview_window_object_cleared)
        #self.webview.connect('load-progress-changed', self.load_progress)
        
        self.home_url = urllib.basejoin(GAME_CENTER_SERVER_ADDRESS, 'game/?hl=%s' % LANGUAGE)
        self.network_failed_box = NetworkConnectFailed(self.check_network_connection)
        self.check_network_connection()
        #self.page_box.add(self.network_failed_box)

        self.navigatebar = Navigatebar(
                [
                (None, _("Home"), self.show_home_page),
                (None, _("Topics"), self.show_subject_page),
                (None, _("My Games"), self.show_mygame_page),
                ],
                font_size = 11,
                padding_x = 5,
                padding_y = 16,
                vertical=False,
                item_normal_pixbuf=DynamicPixbuf(get_common_image('top/nav_normal.png')),
                item_hover_pixbuf=DynamicPixbuf(get_common_image('top/nav_hover.png')),
                item_press_pixbuf=DynamicPixbuf(get_common_image('top/nav_press.png')),
                )
        self.navigatebar.set_size_request(-1, 56)
        self.navigatebar_align = gtk.Alignment(0, 0, 1, 1)
        self.navigatebar_align.set_padding(0, 0, 4, 0)
        self.navigatebar_align.add(self.navigatebar)
        self.application.titlebar.set_size_request(-1, 56)
        self.application.titlebar.left_box.pack_start(self.navigatebar_align, True, True)
        self.application.window.add_move_event(self.navigatebar)

        self.about_dialog = AboutDialog(_('About us'))
        self.about_dialog.set_transient_for(self.application.window)

        # Init menu.
        #if LANGUAGE == 'en_US':
            #menu_min_width = 185
        #else:
            #menu_min_width = 150

        menu = Menu(
            [
             (None, _("Clear all cached data"), self.clean_download_cache),
             (None, _("See what's new"), lambda : self.show_wizard_win()),
             (None, _("About us"), self.show_about_dialog),
             (None, _("Quit"), lambda: gtk.main_quit()),
             ],
            is_root_menu=True,
            #menu_min_width=menu_min_width,
            )
        self.application.set_menu_callback(
            lambda button:
                menu.show(
                get_widget_root_coordinate(button, WIDGET_POS_BOTTOM_LEFT),
                (button.get_allocation().width, 0)))
        
        self.no_favorite_html_path = os.path.join(static_dir, "error-no-favorite.html")
        self.no_recent_html_path = os.path.join(static_dir, "error-no-recent.html")
        self.mygame_frame_path = os.path.join(static_dir, "mygame-frame.html")
        self.gallery_html_path = os.path.join(static_dir, 'game-mygame.html')

        skin_config.connect('theme-changed', self.theme_changed_handler)
        global_event.register_event('show-message', self.update_message)
예제 #28
0
    ops, args = getopt.getopt(sys.argv[1:], '')
    module_name = ""

    if len(args):
        module_name = args[0]

    # Check unique.
    if is_exists(APP_DBUS_NAME, APP_OBJECT_NAME, module_name):
        sys.exit()

    # WARING: only use once in one process
    DBusGMainLoop(set_as_default=True)

    # Init application.
    application = Application(resizable=False)
    application.window.connect("focus-out-event", application_focus_changed_cb, "o")
    application.window.connect("focus-in-event", application_focus_changed_cb, "i")

    # Set application default size.
    application.window.set_geometry_hints(
        None,
        WINDOW_WIDTH, WINDOW_HEIGHT,
        WINDOW_WIDTH, WINDOW_HEIGHT,
        )
    image_dir = os.path.join(get_parent_dir(__file__, 2), "image")

    # Set application icon.
    application.set_icon(os.path.join(image_dir, "icon.png"))

    # Set application preview pixbuf.
예제 #29
0
    def __init__(self):
        '''application.'''
        self.__init_values()
        self.app = Application(False)
        # application set.
        app_w, app_h = 800, 570  # 初始化宽,高.
        min_app_w, min_app_h = 480, 300  # 防止超过,界面布局被破坏.
        self.app.set_default_size(min_app_w, min_app_h)
        self.app.window.set_default_size(app_w, app_h)
        # self.app.window.resize
        image_dir = os.path.join(get_parent_dir(__file__, 2), "image")
        self.app.set_icon(os.path.join(image_dir, "icon.ico"))
        self.app.set_skin_preview(
            os.path.join(os.path.join(image_dir, "frame.png")))
        # set titlebar.
        self.app.add_titlebar(
            ["theme", "menu", "max", "min", "close"],
            os.path.join(os.path.join(image_dir, "logo.png")),
            _("DPlayer"),
            " ",
            add_separator=False,
        )
        self.app.titlebar.set_size_request(-1, 30)

        #
        self.play_menus = PlayMenus()
        # 设置主题菜单.
        self.app.set_menu_callback(
            lambda button: self.play_menus.show_theme_menu(button))
        #
        self.main_ali = gtk.Alignment()
        self.main_vbox = gtk.VBox()
        self.main_ali.add(self.main_vbox)
        self.main_ali.set(0, 0, 1.0, 1.0)
        self.main_ali.set_padding(0, 2, 2, 2)
        #
        self.mid_combo_event = gtk.EventBox()
        self.mid_combo_event.connect("expose-event",
                                     self.mid_combo_event_expose_event)
        self.screen_mid_combo = ScreenMidCombo()
        self.mid_combo_event.set_visible_window(True)
        self.mid_combo_event.add(self.screen_mid_combo)
        '''movie screen. 电影播放屏幕.'''
        # 播放屏幕和播放列表的HBOX.
        self.play_list_view = PlayListView()
        self.screen_paned = Paned()
        self.screen_paned.paint_bottom_window = self.__paint_bottom_toolbar_background
        self.screen_frame = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
        self.screen = gtk.DrawingArea()
        self.screen_frame.add(self.screen)
        self.top_toolbar = ToolBar()
        self.bottom_toolbar = BottomToolBar()
        # BUG: 当显示上部工具条的时候,画面抖动.
        self.screen_paned.add_top_widget(self.top_toolbar.hbox_hframe)
        self.screen_paned.add_bottom_widget(self.bottom_toolbar.vbox)
        #self.screen_paned.add_mid_widget(self.screen_mid_combo)
        self.screen_paned.add_mid_widget(self.mid_combo_event)
        #
        self.screen_frame_event = self.screen_paned
        self.screen_paned.screen = self.screen
        #
        self.screen_paned.add1(self.screen_frame)
        self.screen_paned.add2(self.play_list_view.play_list_vbox)
        #
        self.play_control_panel = BottomToolBar(False)
        #
        self.main_vbox.pack_start(self.screen_paned, True, True)
        self.main_vbox.pack_start(self.play_control_panel.vbox, False, False)
        #
        self.app.main_box.pack_start(self.main_ali, True, True)
예제 #30
0
from dtk.ui.statusbar import Statusbar
'''
FIXME: ImportError: No module named dragbar
dragbar木有了?
'''
from dtk.ui.dragbar import Dragbar


def show_video(widget, xid):
    '''Show video.'''
    run_command("mplayer -fs -wid %s %s" % (xid, "/data/Video/Manatee.avi"))


if __name__ == "__main__":
    # Init application.
    application = Application("demo", False)

    # Set application default size.
    application.set_default_size(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT)

    # Set application icon.
    application.set_icon(ui_theme.get_pixbuf("icon.ico"))

    # Add titlebar.
    application.add_titlebar(["theme", "menu", "max", "min", "close"],
                             ui_theme.get_pixbuf("title.png"), "电影播放器",
                             "深度Linux视频演示")

    # Add mplayer view.
    mplayer_view = MplayerView()
    mplayer_view.connect("get-xid", show_video)
예제 #31
0
class AssemblyIDE(object):
    def __init__(self):
        self.app = Application()
        # Set app size.
        self.app.set_default_size(APP_WIDTH, APP_HEIGHT)
        self.app.set_icon(app_theme.get_pixbuf("logo.ico"))
        self.app.set_skin_preview(app_theme.get_pixbuf("frame.png"))
        # Add app titlebar.
        self.app.add_titlebar(["theme", "max", "min", "close"],
                              app_theme.get_pixbuf("logo.png"),
                              "Assembly-IDE v 1.0",
                              " ",
                              add_separator=True)

        self.vbox_ali = gtk.Alignment()
        self.vbox_ali.set(1, 1, 1, 1)
        self.vbox_ali.set_padding(6, 2, 2, 2)
        self.vbox = gtk.VBox()
        self.vbox_ali.add(self.vbox)

        self.init_root_menu()

        self.init_top_toolbar()

        self.code_edit = CodeEdit()
        self.code_edit_file = self.code_edit.file_path

        self.complie_show_list = ComplieShowList()
        self.code_edit.connect("codeedit-changed-file-name",
                               self.modify_code_edit_file_name)

        self.vbox.pack_start(self.top_toolbar_ali, False, False)
        self.vbox.pack_start(self.code_edit, True, True)
        self.vbox.pack_start(self.complie_show_list, False, False)
        self.app.main_box.pack_start(self.vbox_ali, True, True)
        self.app.window.show_all()

    def init_root_menu(self):
        # Init file menu.
        file_menu = Menu([
            (None, "新建", lambda: self.code_edit.clear()),  # 清空代码编辑器.
            (None, "打开", lambda: self.open_file_dialog_window()),
            (None),
            (None, "我的程序...", None),
            (None),
            (None, "保存", lambda: self.code_edit.save()),
            (None, "另存为", None),
            (None),
            (None, "退出", lambda: gtk.main_quit())
        ])
        # Init edit menu.
        edit_menu = Menu([(None, "剪切", None), (None, "复制", None),
                          (None, "粘帖", None), (None, "全选", None), (None),
                          (None, "注释", lambda: self.notes_line()),
                          (None, "取消注释", lambda: self.notes_line()), (None),
                          (None, "撤销", None), (None, "恢复", None), (None),
                          (None, "查找", None), (None, "替换", None),
                          (None, "定位到行", None)])
        # Init run menu.
        run_menu = Menu([(None, "编译成目标文件", None), (None, "生成可执行文件", None),
                         (None, "生成动态链接库文件", None), (None, "运行", None),
                         (None, "多模块链接", None), (None, "调试", None),
                         (None, "运行LINUX控制台程序", None)])
        # Init tool menu.
        tool_menu = Menu([(None, "选项", None),
                          (None, "计算器", lambda: open_gcalctool())])
        # Init help menu.
        help_menu = Menu([
            (None, "帮助主题", None),
            (None, "关于", None),
        ])

        # Init root menu.
        self.root_menu = Menu([
            (None, "文件", file_menu),
            (None, "编辑", edit_menu),
            (None, "运行", run_menu),
            (None, "工具", tool_menu),
            (None, "帮助", help_menu),
        ], True)

    def init_top_toolbar(self):
        self.top_toolbar_ali = gtk.Alignment()
        self.top_toolbar_ali.set(0, 0, 0, 0)
        self.top_toolbar_ali.set_padding(0, 0, 5, 0)
        self.top_toolbar = ToolBar()
        self.top_toolbar_ali.add(self.top_toolbar)

        self.bin_btn = gtk.Button("生成bin")
        self.link_btn = gtk.Button("链接")
        self.run_btn = gtk.Button("运行")
        self.gcalctool_btn = gtk.Button("计算器")

        self.top_toolbar.insert(0, Button("菜单", self.root_menu))
        self.top_toolbar.insert(1, None)
        self.top_toolbar.insert(2, self.bin_btn)
        self.top_toolbar.insert(3, self.link_btn)
        self.top_toolbar.insert(4, self.run_btn)
        self.top_toolbar.insert(5, None)
        self.top_toolbar.insert(6, self.gcalctool_btn)

        self.bin_btn.connect("clicked", self.bin_btn_clicked)
        self.link_btn.connect("clicked", self.link_btn_clicked)
        self.run_btn.connect("clicked", self.run_btn_clicked)
        self.gcalctool_btn.connect("clicked", self.gcalctool_btn_clicked)

    def bin_btn_clicked(self, widget):
        pass

    def link_btn_clicked(self, widget):
        self.link_function()

    def link_function(self):
        self.complie_show_list.clear_text()
        self.code_edit.save()
        temp_path = os.path.split(self.code_edit_file)
        link_file_name = os.path.splitext(temp_path[1])[0] + ".o"
        self.link_file_path = os.path.join(temp_path[0], link_file_name)
        self.complie_show_list.add_text(
            input_link(self.code_edit_file, self.link_file_path))

    def run_btn_clicked(self, widget):
        self.link_function()
        if os.path.exists(self.link_file_path):
            temp_path = os.path.split(self.link_file_path)
            run_file_name = os.path.splitext(temp_path[1])[0] + ".out"
            self.run_file_path = os.path.join(temp_path[0], run_file_name)
            print "run_btn_clicked:", self.run_file_path
            run_bool = input_elf(self.link_file_path, self.run_file_path)
            if run_bool == "True":
                self.complie_show_list.add_text("编译完成!!")
                self.complie_show_list.add_text(run_elf(self.run_file_path))
            else:
                print run_bool

    def gcalctool_btn_clicked(self, widget):
        open_gcalctool()

    def open_file_dialog_window(self):
        open_file_path = show_open_file_dialog_window()
        if open_file_path:
            self.code_edit.read(open_file_path)

    def notes_line(self):
        self.code_edit.cursor_start_insert_ch()

    def modify_code_edit_file_name(self, CodeEdit, file_name):
        self.code_edit_file = file_name
예제 #32
0
    def __init__(self):
        gobject.GObject.__init__(self)
        image_dir = os.path.join(get_parent_dir(__file__, 3), "image")
        application = Application("DMuisc", resizable=False)
        application.close_callback = self.prompt_quit
        application.set_icon(os.path.join(image_dir, "logo.ico"))
        application.set_skin_preview(os.path.join(image_dir, "frame.png"))
        application.add_titlebar(["theme", "menu", "min", "close"],
                                 os.path.join(image_dir, "logo1.png"),
                                 _("DMusic"))
        application.titlebar.menu_button.connect("button-press-event",
                                                 self.menu_button_press)
        application.titlebar.connect("button-press-event", self.right_click_cb)

        # Window mode change.
        self.revert_toggle_button = self.create_revert_button()
        self.revert_toggle_button.connect("toggled", self.change_view)

        application.titlebar.button_box.pack_start(self.revert_toggle_button)
        application.titlebar.button_box.reorder_child(
            self.revert_toggle_button, 1)
        self.window = application.window
        self.window.is_disable_window_maximized = self.is_disable_window_maximized
        utils.set_main_window(self)

        self.plugins = plugins.PluginsManager(self, False)
        self.browser_manager = BrowserMananger()
        self.tray_icon = TrayIcon(self)
        self.lyrics_display = LyricsModule()
        self.list_manager = ListManager()
        self.simple_header_bar = SimpleHeadbar()
        self.preference_dialog = PreferenceDialog()
        self.equalizer_win = EqualizerWindow()
        self.mmkeys = MMKeys()
        self.audiocd = AudioCDSource()
        self.playlist_ui = playlist_ui

        self.mini_window = MiniWindow()

        self.window.add_move_event(self.simple_header_bar)

        bottom_box = gtk.HBox()
        self.browser_align = gtk.Alignment()
        self.browser_align.set_padding(0, 0, 0, 0)
        self.browser_align.set(0.5, 0.5, 1, 1)

        list_manager_align = gtk.Alignment()
        list_manager_align.set_padding(0, 0, 0, 0)
        list_manager_align.set(1, 1, 1, 1)
        list_manager_align.add(self.list_manager)

        self.browser_align.add(self.browser_manager)
        bottom_box.pack_start(list_manager_align, False, False)
        bottom_box.pack_start(self.browser_align, True, True)
        self.browser_align.set_no_show_all(True)

        main_box = gtk.VBox()
        self.header_box = gtk.VBox()
        self.header_box.add(self.simple_header_bar)
        main_box.pack_start(self.header_box, False)
        main_box.pack_start(bottom_box, True)

        self.link_box = gtk.HBox()
        self.link_box.pack_start(create_right_align(), True, True)
        self.link_box.pack_start(
            LinkButton(_("Join us"), "http://www.linuxdeepin.com/joinus/job"),
            False, False)

        status_box = gtk.HBox(spacing=5)
        status_box.pack_start(jobs_manager)
        status_box.pack_start(self.link_box, padding=5)

        status_bar = gtk.EventBox()
        status_bar.set_visible_window(False)
        status_bar.set_size_request(-1, 22)
        status_bar.add(status_box)

        application.main_box.pack_start(main_box)
        application.main_box.pack_start(status_bar, False, True)

        # if config.get("globalkey", "enable", "false") == "true":
        # global_hotkeys.start_bind()

        if config.get("setting", "window_mode") == "simple":
            self.revert_toggle_button.set_active(False)
        else:
            self.revert_toggle_button.set_active(True)

        self.change_view(self.revert_toggle_button)

        if config.get("window", "x") == "-1":
            self.window.set_position(gtk.WIN_POS_CENTER)
        else:
            self.window.move(int(config.get("window", "x")),
                             int(config.get("window", "y")))

        # try:
        #     self.window.resize(int(config.get("window","width")),int(config.get("window","height")))
        # except:
        #     pass

        # window_state = config.get("window", "state")
        # if window_state == "maximized":
        #     self.window.maximize()
        # elif window_state == "normal":
        #     self.window.unmaximize()

        self.window.connect("delete-event", self.quit)
        self.window.connect("configure-event", self.on_configure_event)
        self.window.connect("destroy", self.quit)

        Dispatcher.connect("quit", self.force_quit)
        Dispatcher.connect("show-main-menu", self.show_instance_menu)
        Dispatcher.connect("show-setting",
                           lambda w: self.preference_dialog.show_all())
        Dispatcher.connect(
            "show-desktop-page",
            lambda w: self.preference_dialog.show_desktop_lyrics_page())
        Dispatcher.connect(
            "show-scroll-page",
            lambda w: self.preference_dialog.show_scroll_lyrics_page())
        Dispatcher.connect("show-job", self.hide_link_box)
        Dispatcher.connect("hide-job", self.show_link_box)

        gobject.idle_add(self.ready)
예제 #33
0
class GameCenterApp(dbus.service.Object):

    def __init__(self, session_bus):
        dbus.service.Object.__init__(self, session_bus, GAME_CENTER_DBUS_PATH)
        self.conf_db = get_config_file("conf.db")
        self.in_wizard_showing = False

        self.init_ui()

    def init_ui(self):
        self.application = Application()
        self.application.set_default_size(1000, 660)
        self.application.set_skin_preview(get_common_image("frame.png"))
        self.application.set_icon(get_common_image("logo48.png"))
        self.application.add_titlebar(
                ["theme", "menu", "max","min", "close"],
                show_title=False
                )
        self.application.window.set_title(_("Deepin Games"))

        # Init page box.
        self.page_box = gtk.VBox()
        self.page_box.connect('expose-event', self.page_box_render)
        
        # Init page align.
        self.page_align = gtk.Alignment()
        self.page_align.set(0.5, 0.5, 1, 1)
        self.page_align.set_padding(0, 0, 2, 2)
        
        # Append page to switcher.
        self.paned_box = PanedBox(24)
        self.paned_box.add_content_widget(self.page_box)
        self.bottom_tip_bar = BottomTipBar()
        self.bottom_tip_bar.close_button.connect('clicked', lambda w: self.paned_box.bottom_window.hide())
        self.paned_box.add_bottom_widget(self.bottom_tip_bar)

        self.page_align.add(self.paned_box)
        self.application.main_box.pack_start(self.page_align, True, True)
        
        # Init status bar.
        self.statusbar = Statusbar(30)
        status_box = gtk.HBox()

        self.statusbar.status_box.pack_start(status_box, True, True)
        self.application.main_box.pack_start(self.statusbar, False, False)

        self.webview = WebView(COOKIE_FILE)
        webkit.set_web_database_directory_path(CACHE_DIR)
        web_settings = self.webview.get_settings()
        web_settings.set_property("enable-page-cache", True)
        web_settings.set_property("enable-offline-web-application-cache", True)
        #web_settings.set_property("enable-file-access-from-file-uris", True)
        web_settings.set_property("enable-xss-auditor", False)
        web_settings.set_property('enable-universal-access-from-file-uris', True)
        web_settings.set_property("enable-default-context-menu", False)
        self.webview.set_settings(web_settings)
        #self.webview.enable_inspector()
        self.webview.connect('new-window-policy-decision-requested', self.navigation_policy_decision_requested_cb)
        #self.webview.connect('notify::load-status', self.webview_load_status_handler)
        self.webview.connect('notify::title', self.webview_title_changed_handler)
        self.webview.connect('script-alert', self.webview_script_alert_handler)
        self.webview.connect('window-object-cleared', self.webview_window_object_cleared)
        #self.webview.connect('load-progress-changed', self.load_progress)
        
        self.home_url = urllib.basejoin(GAME_CENTER_SERVER_ADDRESS, 'game/?hl=%s' % LANGUAGE)
        self.network_failed_box = NetworkConnectFailed(self.check_network_connection)
        self.check_network_connection()
        #self.page_box.add(self.network_failed_box)

        self.navigatebar = Navigatebar(
                [
                (None, _("Home"), self.show_home_page),
                (None, _("Topics"), self.show_subject_page),
                (None, _("My Games"), self.show_mygame_page),
                ],
                font_size = 11,
                padding_x = 5,
                padding_y = 16,
                vertical=False,
                item_normal_pixbuf=DynamicPixbuf(get_common_image('top/nav_normal.png')),
                item_hover_pixbuf=DynamicPixbuf(get_common_image('top/nav_hover.png')),
                item_press_pixbuf=DynamicPixbuf(get_common_image('top/nav_press.png')),
                )
        self.navigatebar.set_size_request(-1, 56)
        self.navigatebar_align = gtk.Alignment(0, 0, 1, 1)
        self.navigatebar_align.set_padding(0, 0, 4, 0)
        self.navigatebar_align.add(self.navigatebar)
        self.application.titlebar.set_size_request(-1, 56)
        self.application.titlebar.left_box.pack_start(self.navigatebar_align, True, True)
        self.application.window.add_move_event(self.navigatebar)

        self.about_dialog = AboutDialog(_('About us'))
        self.about_dialog.set_transient_for(self.application.window)

        # Init menu.
        #if LANGUAGE == 'en_US':
            #menu_min_width = 185
        #else:
            #menu_min_width = 150

        menu = Menu(
            [
             (None, _("Clear all cached data"), self.clean_download_cache),
             (None, _("See what's new"), lambda : self.show_wizard_win()),
             (None, _("About us"), self.show_about_dialog),
             (None, _("Quit"), lambda: gtk.main_quit()),
             ],
            is_root_menu=True,
            #menu_min_width=menu_min_width,
            )
        self.application.set_menu_callback(
            lambda button:
                menu.show(
                get_widget_root_coordinate(button, WIDGET_POS_BOTTOM_LEFT),
                (button.get_allocation().width, 0)))
        
        self.no_favorite_html_path = os.path.join(static_dir, "error-no-favorite.html")
        self.no_recent_html_path = os.path.join(static_dir, "error-no-recent.html")
        self.mygame_frame_path = os.path.join(static_dir, "mygame-frame.html")
        self.gallery_html_path = os.path.join(static_dir, 'game-mygame.html')

        skin_config.connect('theme-changed', self.theme_changed_handler)
        global_event.register_event('show-message', self.update_message)

    def page_box_render(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.get_allocation()
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(*rect)
        cr.fill()

    def check_network_connection(self):
        if is_network_connected():
            self.network_connected_flag = True
            self.webview.load_uri(self.home_url)
            self.switch_page_view(self.webview)
        else:    
            self.network_connected_flag = False
            self.switch_page_view(self.network_failed_box)
    
    def switch_page_view(self, box):
        container_remove_all(self.page_box)
        self.page_box.add(box)

    def load_progress(self, webview, progress):
        print progress

    def webview_window_object_cleared(self, webview, frame, context, window_object):
        ctx = jswebkit.JSContext(frame.get_global_context())
        window = ctx.EvaluateScript("window")
        window.css_color = skin_config.theme_name
        location = window.location.href
        parse_result = urlparse.urlparse(location)

        frame.get_web_view().execute_script('var global_l18n_str = %s' % json.dumps({
                'my_favorites': _('My favorites'),
                'my_recent': _('My recents'),
                },
                encoding='UTF-8',
                ensure_ascii=False,
                ))
        frame.get_web_view().execute_script('var global_language = %s' %
                json.dumps(LANGUAGE, encoding='UTF-8', ensure_ascii=False))

        if parse_result.path == self.no_favorite_html_path or parse_result.path == self.no_recent_html_path:
            window.css_language = LANGUAGE

    def update_message(self, message, hide_timeout=0):
        if not self.paned_box.bottom_window.is_visible():
            self.paned_box.bottom_window.show()
        if isinstance(message, list) and len(message) == 3:
            self.bottom_tip_bar.update_info(*message)
        else:
            self.bottom_tip_bar.update_info(message)
        if hide_timeout != 0:
            gtk.timeout_add(hide_timeout, lambda:self.paned_box.bottom_window.hide())
    
    def ready_show(self):    
        if not utils.is_wizard_showed():
            self.in_wizard_showing = True
            self.show_wizard_win(True, callback=self.wizard_callback)
            utils.set_wizard_showed()
        else:    
            self.application.window.show_all()
        gtk.main()

    def show_wizard_win(self, show_button=False, callback=None):    

        self.wizard_win = Wizard(
            [get_common_locale_image('wizard', '%s.png' % i) for i in range(3)],
            (
                get_common_image('wizard/dot_normal.png'), 
                get_common_image('wizard/dot_active.png'),
            ),
            (
                get_common_locale_image('wizard', 'start_normal.png'), 
                get_common_locale_image('wizard', 'start_press.png'), 
            ),
            show_button,
            callback
            )
        self.wizard_win.show_all()
        
    def wizard_callback(self):
        self.in_wizard_showing = False
        self.application.window.show_all()
        gtk.timeout_add(200, self.application.raise_to_top)

    def clean_download_cache(self):
        info = {
                'file_num':0,
                'total_size':0
                }
        downloads_dir = os.path.join(CACHE_DIR, 'downloads')
        appids =  os.listdir(downloads_dir)
        for appid in appids:
            files = os.listdir(os.path.join(downloads_dir, appid))
            for f in files:
                if f.endswith('.swf'):
                    swf_path = os.path.join(downloads_dir, appid, f)
                    info['file_num'] += 1
                    info['total_size'] += os.path.getsize(swf_path)
                    os.remove(os.path.join(downloads_dir, appid, f))
        
        if info['file_num']:
            cache_cleaned_message = _('%s files are deleted and %s disk space is freed.') % (
                    info['file_num'], utils.get_human_size(info['total_size']))
        else:
            cache_cleaned_message = _('Your game cache is empty.')
        global_event.emit('show-message', cache_cleaned_message, 5000)

    def show_about_dialog(self):
        self.about_dialog.show_all()

    def theme_changed_handler(self, widget, name):
        self.webview.execute_script('change_color_theme(%s)' %
            json.dumps(name, encoding="UTF-8", ensure_ascii=False))
        self.webview.execute_script('$("#game-gallery").get(0).contentWindow.change_color_theme(%s)' %
            json.dumps(name, encoding="UTF-8", ensure_ascii=False))
        self.webview.execute_script('alert("scroll_top://" + $($("#game-gallery").get(0).contentWindow.document.body).scrollTop())')

    def send_event(self, data=0):
        press_event = gtk.gdk.Event(gtk.gdk.BUTTON_PRESS)
        press_event.window = self.webview.window
        press_event.x = 1062.0
        press_event.y = 35.0 + int(data) + 20.0
        press_event.button = 1

        release_event = gtk.gdk.Event(gtk.gdk.BUTTON_RELEASE)
        release_event.window = self.webview.window
        release_event.x = 1062.0
        release_event.y = 35.0 + int(data) + 20.0
        release_event.button = 1

        self.webview.event(press_event)
        self.webview.event(release_event)
        self.webview.window.invalidate_rect(self.webview.allocation, True)

    def webview_message_handler(self, info):
        info = info.split('://')
        if len(info) == 2:
            order, data = info

            if order == 'play':
                self.show_play(data)

            elif order == 'star':
                self.toggle_favorite(data)

            elif order == 'local':
                if data == 'recent':
                    self.show_recent_page()
                elif data == 'star':
                    self.show_favorite_page()

            elif order == 'document_ready' and data == 'game_gallery':
                self.document_ready()
                
            elif order == 'onload' and data == 'game_gallery':
                gtk.timeout_add(200, self.fresh_favotite_status)

            elif order == 'onload' and data == 'local_game_gallery':
                self.webview.execute_script('$("#game-gallery").get(0).contentWindow.set_right_menu()')
                gtk.timeout_add(200, self.fresh_favotite_status)

            elif order == 'onload' and data == 'main_frame':
                gtk.timeout_add(200, self.show_favorite_page)

            elif order == 'onload' and data == 'footer':
                self.webview.execute_script('if(infos){append_data_to_gallery(infos);}')

            elif order == 'favorite':
                record_info.record_favorite(data, self.conf_db)
                FetchInfo(data).start()
                favorite_animation(self.application.window)

            elif order == 'unfavorite':
                record_info.remove_favorite(data, self.conf_db)

            elif order == 'local_action':
                info = data.split('-')
                if len(info) == 2:
                    action_type= info[0]
                    appid = info[1]
                    if action_type == 'favorite':
                        record_info.remove_favorite(appid, self.conf_db)
                        utils.ThreadMethod(utils.send_analytics, ('unfavorite', appid)).start()
                        #var favorite_url = 'http://' + location.host + '/game/analytics/?type=unfavorite&appid=' + id;
                        self.webview.execute_script('if(infos){infos_remove(%s);}else{gallery_change(%s);}' % (
                                json.dumps(appid, encoding="UTF-8", ensure_ascii=False),
                                json.dumps(self.no_favorite_html_path, encoding="UTF-8", ensure_ascii=False),
                                ))
                    elif action_type == 'recent':
                        record_info.remove_recent_play(appid, self.conf_db)
                        self.webview.execute_script('if(infos){infos_remove(%s);}else{gallery_change(%s);}' % (
                                json.dumps(appid, encoding="UTF-8", ensure_ascii=False),
                                json.dumps(self.no_recent_html_path, encoding="UTF-8", ensure_ascii=False),
                                ))

            elif order == 'scroll_top':
                self.send_event(data)

    def navigation_policy_decision_requested_cb(self, web_view, frame, request, navigation_action, policy_decision):
        uri = request.get_uri()
        if uri.startswith('http://') or uri.startswith('https://'):
            return False
        else:
            self.webview_message_handler(uri)
            return True

    def webview_script_alert_handler(self, widget, frame, uri, data=None):
        self.webview_message_handler(uri)
        return True

    def webview_title_changed_handler(self, webview, data=None):
        title = webview.get_title()
        if title:
            self.webview_message_handler(title)

    def fresh_favotite_status(self):
        if os.path.exists(self.conf_db):
            data = utils.load_db(self.conf_db)
            if data.get('favorite'):
                for id in data['favorite']:
                    self.webview.execute_script("change_favorite_status(%s, 'ilike')" %
                        json.dumps(id, encoding="UTF-8", ensure_ascii=False))

    def webview_load_status_handler(self, widget=None, status=None):
        load_status = widget.get_load_status()
        if load_status == webkit.LOAD_FINISHED:
            self.webview.execute_script("$('#game-gallery').contents().find('#grid span span').removeClass('ilike')")
            self.webview.execute_script("$('#game-gallery').contents().find('#grid span span').addClass('like')")

    def document_ready(self):
        self.webview.execute_script("$('#game-gallery').contents().find('#grid span span').removeClass('ilike')")
        self.webview.execute_script("$('#game-gallery').contents().find('#grid span span').addClass('like')")

    def show_play(self, data):
        data = data.split(',')
        player_path = os.path.join(get_parent_dir(__file__), 'deepin-game-center.py')
        order = ['python2', player_path]
        order.append('-p')
        order.append(','.join(data))
        try:
            self.p = subprocess.Popen(order, stderr=subprocess.STDOUT, shell=False)
        except OSError:    
            order[0] = 'python'
            self.p = subprocess.Popen(order, stderr=subprocess.STDOUT, shell=False)


    #def mute_handler(self, widget, data=None):
        #active = widget.get_active()
        #current_sink = pypulse.get_fallback_sink_index()
        #if current_sink is not None:
            #pypulse.PULSE.set_output_mute(current_sink, active)

    def print_info(self, info_type, info):
        if info:
            print info_type, info

    def toggle_favorite(self, data):
        print "toggle favorite"

    def show_home_page(self):
        self.webview.load_uri(self.home_url)

    def show_subject_page(self):
        self.subject_url = urllib.basejoin(GAME_CENTER_SERVER_ADDRESS, 'game/subjects/?hl=%s' % LANGUAGE)
        self.webview.load_uri(self.subject_url)

    def show_mygame_page(self):
        self.webview.open('file://' + self.mygame_frame_path)
        
    def show_favorite_page(self):
        downloads_dir = os.path.join(CACHE_DIR, 'downloads')
        if os.path.exists(self.conf_db):
            data = utils.load_db(self.conf_db)
            if data.get('favorite'):
                infos = []
                favorite_list = data['favorite']
                for id in favorite_list:
                    try:
                        info_js_path = os.path.join(downloads_dir, str(id), 'info.json')
                        info = json.load(open(info_js_path))
                        info['index_pic_url'] = os.path.join(downloads_dir, str(id), info['index_pic_url'].split('/')[-1])
                        #info['swf_game'] = os.path.join(downloads_dir, str(id), info['swf_game'].split('/')[-1])
                        info['swf_game'] = urlparse.urlparse(info['swf_game']).path[1:]
                        info['type'] = 'favorite'
                        infos.append(info)
                    except Exception, e:
                        print "Load favorite page error:", e
                if infos:
                    self.webview.execute_script('var infos=%s' % 
                            json.dumps(infos, encoding="UTF-8", ensure_ascii=False))
                    self.webview.execute_script("gallery_change(%s)" %
                            json.dumps(self.gallery_html_path, encoding="UTF-8", ensure_ascii=False))
                    return

        self.webview.execute_script("gallery_change(%s)" %
                json.dumps(self.no_favorite_html_path, encoding="UTF-8", ensure_ascii=False))
import os
from deepin_utils.file import get_parent_dir, get_current_dir
app_theme = init_skin(
    "deepin-ui",
    "1.0",
    "default",
    os.path.join(get_parent_dir(__file__, 2), "skin"),
    os.path.join(get_current_dir(__file__), "app_theme"),
)
from dtk.ui.application import Application
from dtk.ui.button import ImageButton
from dtk.ui.dialog import ConfirmDialog
import gtk

if __name__ == "__main__":
    application = Application()
    application.set_default_size(600, 450)
    application.add_titlebar(title="ImageButton example!")

    image_button = ImageButton(
        normal_dpixbuf=app_theme.get_pixbuf("action/play_normal.png"),
        hover_dpixbuf=app_theme.get_pixbuf("action/play_hover.png"),
        press_dpixbuf=app_theme.get_pixbuf("action/play_press.png"),
        insensitive_dpixbuf=None,
        scale_x=False,
        content=None,
    )
    image_button.connect(
        "clicked", lambda w: ConfirmDialog(
            title="反馈对忽框",
            message="点击播放按钮",
예제 #35
0
class DeepinSoftwareCenter(dbus.service.Object, Logger):
    '''
    class docs
    '''

    pages = ['home', 'upgrade', 'uninstall', 'install']

    def __init__(self, session_bus, arguments):
        '''
        init docs
        '''
        dbus.service.Object.__init__(self, session_bus, DSC_FRONTEND_PATH)
        Logger.__init__(self)

        self.simulate = "--simulate" in arguments

        global debug_flag
        debug_flag = "--debug" in arguments
        self.in_wizard_showing = False
        self.init_hide = False

    def exit(self):
        gtk.main_quit()

    def open_download_directory(self):
        run_command("xdg-open %s" % get_software_download_dir())

    def switch_page(self, page):
        switch_page(self.page_switcher, self.page_box, page, self.detail_page)

    def show_home_page(self):
        if self.detail_page and self.home_page:
            self.switch_page(self.home_page)

    def show_upgrade_page(self):
        if self.detail_page and self.upgrade_page:
            self.switch_page(self.upgrade_page)

    def show_uninstall_page(self):
        if self.detail_page and self.uninstall_page:
            self.switch_page(self.uninstall_page)

    def show_install_page(self):
        if self.detail_page and self.install_page:
            self.switch_page(self.install_page)

    @dbus.service.method(DSC_FRONTEND_NAME, in_signature="s", out_signature="")
    def show_page(self, key):
        try:
            index = self.pages.index(key)
            if index != self.navigatebar.get_index():
                method = "show_%s_page" % key
                getattr(self, method)()
                self.navigatebar.set_index(index)
        except:
            print "Unknow page:", key

    def init_ui(self):
        self.loginfo("Init ui")
        # Init application.
        self.application = Application(
            resizable=False,
            destroy_func=self.application_close_window,
            )
        self.application.set_default_size(888, 634)
        self.application.set_skin_preview(utils.get_common_image("frame.png"))
        self.application.set_icon(utils.get_common_image("logo48.png"))
        self.application.add_titlebar(
                ["theme", "menu", "min", "close"],
                show_title=False
                )
        self.application.window.set_title(_("Deepin Store"))
        self.application.window.connect("delete-event", self.application_close_window)

        # Init page box.
        self.page_box = gtk.VBox()

        # Init page switcher.
        self.page_switcher = HSlider(200)
        self.page_switcher.append_page(self.page_box)
        self.page_switcher.set_to_page(self.page_box)

        # Init page align.
        self.page_align = gtk.Alignment()
        self.page_align.set(0.5, 0.5, 1, 1)
        self.page_align.set_padding(0, 0, 2, 2)

        # Append page to switcher.
        self.paned_box = PanedBox(24)
        self.paned_box.add_content_widget(self.page_switcher)
        self.bottom_tip_bar = BottomTipBar()
        self.bottom_tip_bar.close_button.connect('clicked', lambda w: self.paned_box.bottom_window.hide())
        self.paned_box.add_bottom_widget(self.bottom_tip_bar)
        self.page_align.add(self.paned_box)
        self.application.main_box.pack_start(self.page_align, True, True)

        # Init status bar.
        self.statusbar = Statusbar(24)
        status_box = gtk.HBox()
        self.message_box = gtk.HBox()

        self.message_label = Label("", enable_gaussian=True)
        label_align = gtk.Alignment()
        label_align.set(0.0, 0.5, 0, 0)
        label_align.set_padding(0, 0, 10, 0)
        label_align.add(self.message_label)
        self.message_box.pack_start(label_align)

        join_us_button = LinkButton(_("Join us"), "http://www.linuxdeepin.com/joinus/job")
        join_us_button_align = gtk.Alignment()
        join_us_button_align.set(0.5, 0.5, 0, 0)
        join_us_button_align.set_padding(0, 3, 0, 10)
        join_us_button_align.add(join_us_button)
        status_box.pack_start(self.message_box, True, True)
        status_box.pack_start(join_us_button_align, False, False)
        self.statusbar.status_box.pack_start(status_box, True, True)
        self.application.main_box.pack_start(self.statusbar, False, False)

        # Init navigatebar.
        self.detail_page = None
        self.home_page = None
        self.upgrade_page = None
        self.uninstall_page = None
        self.install_page = None

        self.navigatebar = Navigatebar(
                [
                (DynamicPixbuf(utils.get_common_image("navigatebar/nav_home.png")), _("Home"), self.show_home_page),
                (DynamicPixbuf(utils.get_common_image("navigatebar/nav_update.png")), _("Upgrade"), self.show_upgrade_page),
                (DynamicPixbuf(utils.get_common_image("navigatebar/nav_uninstall.png")), _("Uninstall"), self.show_uninstall_page),
                (DynamicPixbuf(utils.get_common_image("navigatebar/nav_download.png")), _("Installation"), self.show_install_page),
                ],
                font_size = 11,
                padding_x = 2,
                padding_y = 2,
                vertical=False,
                item_hover_pixbuf=DynamicPixbuf(utils.get_common_image("navigatebar/nav_hover.png")),
                item_press_pixbuf=DynamicPixbuf(utils.get_common_image("navigatebar/nav_press.png")),
                )
        self.navigatebar.set_size_request(-1, 56)
        self.navigatebar_align = gtk.Alignment(0, 0, 1, 1)
        self.navigatebar_align.set_padding(0, 0, 4, 0)
        self.navigatebar_align.add(self.navigatebar)
        self.application.titlebar.set_size_request(-1, 56)
        self.application.titlebar.left_box.pack_start(self.navigatebar_align, True, True)
        self.application.window.add_move_event(self.navigatebar)

        # Init menu.
        if LANGUAGE == 'en_US':
            menu_min_width = 185
        else:
            menu_min_width = 150
        menu = Menu(
            [
             (None, _("Refresh package lists"), lambda:global_event.emit('start-update-list')),
             (None, _("Open download directory"), self.open_download_directory),
             (None, _("Clear up cached packages"), self.clean_download_cache),
             (None, _("View new features"), lambda : self.show_wizard_win()),
             (self.get_pixbuf_group("menu", "setting"), _("Preferences"), self.show_preference_dialog),
             (self.get_pixbuf_group("menu", "close"), _("Quit"), self.exit),
             ],
            is_root_menu=True,
            menu_min_width=menu_min_width,
            )
        self.application.set_menu_callback(
            lambda button:
                menu.show(
                get_widget_root_coordinate(button, WIDGET_POS_BOTTOM_LEFT),
                (button.get_allocation().width, 0)))

        self.preference_dialog = DscPreferenceDialog()

        if hasattr(self, 'recommend_status'):
            self.init_home_page(self.recommend_status)
        else:
            self.init_home_page()

    def get_pixbuf_group(self, folder, name):
        return (app_theme.get_pixbuf("%s/%s_normal.png" % (folder, name)),
                app_theme.get_pixbuf("%s/%s_hover.png" % (folder, name)),
                app_theme.get_pixbuf("%s/%s_disable.png" % (folder, name)),
                )

    def application_close_window(self, widget=None, event=None):
        self.application.window.hide_all()
        gtk.main_quit()

        return True

    def upgrade_finish_action(self, pkg_info_list):
        return
        """
        if len(pkg_info_list) > 0:
            # Delete items from treeview.
            upgraded_items = []

            for (pkg_name, marked_delete, marked_install, marked_upgrade) in pkg_info_list:
                for item in self.upgrade_page.upgrade_treeview.visible_items:
                    if item.pkg_name == pkg_name:
                        upgraded_items.append(item)
                        break

            print upgraded_items
            self.upgrade_page.upgrade_treeview.delete_items(upgraded_items)
            print len(self.upgrade_page.upgrade_treeview.visible_items)
        """

    def show_preference_dialog(self):
        self.preference_dialog.show_all()

    def ready_show(self):
        if utils.is_first_started():
            utils.set_first_started()
            self.in_wizard_showing = True
            self.show_wizard_win(True, callback=self.wizard_callback)
            self.init_ui()
        else:
            self.init_ui()
            if not self.init_hide:
                self.application.window.show_all()
        #self.paned_box.bottom_window.set_composited(True)

    def show_wizard_win(self, show_button=False, callback=None):
        program_dir = get_parent_dir(__file__, 2)
        wizard_dir = os.path.join(program_dir, 'wizard', LANGUAGE)
        if not os.path.exists(wizard_dir):
            wizard_dir = os.path.join(program_dir, 'wizard', 'en_US')
        wizard_root_dir = os.path.dirname(wizard_dir)

        self.wizard = Wizard(
            [os.path.join(wizard_dir, "%d.png" % i) for i in range(3)],
            (os.path.join(wizard_root_dir, "dot_normal.png"),
             os.path.join(wizard_root_dir, "dot_active.png"),
             ),
            (os.path.join(wizard_dir, "start_normal.png"),
             os.path.join(wizard_dir, "start_press.png"),
             ),
            show_button,
            callback
            )
        self.wizard.set_icon(utils.get_common_image_pixbuf("logo48.png"))
        if not self.init_hide:
            self.wizard.show_all()

    def wizard_callback(self):
        self.in_wizard_showing = False
        self.application.window.show_all()
        gtk.timeout_add(200, self.application.raise_to_top)

    def init_home_page(self, recommend_status="publish"):

        # Init DBus.
        self.system_bus = dbus.SystemBus()
        bus_object = self.system_bus.get_object(DSC_SERVICE_NAME, DSC_SERVICE_PATH)
        self.bus_interface = dbus.Interface(bus_object, DSC_SERVICE_NAME)
        # Say hello to backend.
        #self.bus_interface.say_hello(self.simulate)
        self.set_software_download_dir()
        self.inhibit_obj = InhibitObject()

        self.loginfo("Init data manager")

        # Init data manager.
        self.data_manager = DataManager(self.bus_interface, debug_flag)

        # Init packages status
        self.packages_status = {}

        # Init home page.
        self.home_page = HomePage(self.data_manager, recommend_status)

        # Init switch page.
        self.switch_page(self.home_page)

        self.in_update_list = False

        self.init_backend()

    def init_backend(self):

        # Init detail view.
        self.detail_page = DetailPage(self.data_manager)

        self.page_switcher.append_page(self.detail_page)

        log("Init pages.")

        self.loginfo("Init pages")
        self.upgrade_page = UpgradePage(self.bus_interface, self.data_manager, self.preference_dialog)
        self.uninstall_page = UninstallPage(self.bus_interface, self.data_manager)
        self.install_page = InstallPage(self.bus_interface, self.data_manager)


        log("Handle global event.")

        # Handle global event.
        global_event.register_event("install-pkg", lambda pkg_names: install_pkg(
            self.bus_interface, self.install_page, pkg_names, self.application.window))
        global_event.register_event("upgrade-pkg", self.upgrade_pkgs)
        global_event.register_event("uninstall-pkg", lambda pkg_name, purge_flag: self.uninstall_pkg(pkg_name, purge_flag))
        global_event.register_event("stop-download-pkg", self.bus_interface.stop_download_pkg)
        global_event.register_event("switch-to-detail-page", lambda pkg_name : switch_to_detail_page(self.page_switcher, self.detail_page, pkg_name))
        global_event.register_event("switch-from-detail-page", lambda : switch_from_detail_page(self.page_switcher, self.detail_page, self.page_box))
        global_event.register_event("remove-wait-action", self.bus_interface.RemoveWaitMissions)
        global_event.register_event("remove-wait-download", self.bus_interface.remove_wait_downloads)
        global_event.register_event("request-clear-action-pages", request_clear_action_pages)
        global_event.register_event("request-stop-install-actions", request_stop_install_actions)
        global_event.register_event("request-clear-failed-action", request_clear_failed_action)
        global_event.register_event("update-upgrade-notify-number", lambda number: update_navigatebar_number(self.navigatebar, 1, number))
        global_event.register_event("update-install-notify-number", lambda number: update_navigatebar_number(self.navigatebar, 3, number))
        global_event.register_event("jump-to-category",
                                    lambda first_category_name, second_category_name:
                                    jump_to_category(self.page_switcher,
                                                     self.page_box,
                                                     self.home_page,
                                                     self.detail_page,
                                                     first_category_name,
                                                     second_category_name))
        global_event.register_event("grade-pkg", lambda pkg, star: grade_pkg(self.application.window, pkg, star))
        global_event.register_event("set-cursor", lambda cursor: set_cursor(self.application.window, cursor))
        global_event.register_event("show-message", self.update_status_bar_message)
        global_event.register_event("start-pkg", lambda alias_name, desktop_infos, offset: start_pkg(
            alias_name, desktop_infos, offset, self.application.window))
        global_event.register_event("show-pkg-name-tooltip", lambda pkg_name: show_tooltip(self.application.window, pkg_name))
        global_event.register_event("hide-pkg-name-tooltip", lambda :tool_tip.hide())
        global_event.register_event("update-current-status-pkg-page", update_current_status_pkg_page)
        global_event.register_event('start-change-mirror', self.change_mirror_action)
        global_event.register_event('download-directory-changed', self.set_software_download_dir)
        global_event.register_event('vote-send-success', lambda p: vote_send_success_callback(p, self.application.window))
        global_event.register_event('vote-send-failed', lambda p: vote_send_failed_callback(p, self.application.window))
        global_event.register_event('max-download-number-changed', self.init_download_manager)
        global_event.register_event('update-list-finish', self.update_list_finish)
        global_event.register_event('start-update-list', self.update_list_handler)
        global_event.register_event("upgrade-finish-action", self.upgrade_finish_action)
        global_event.register_event("upload-error-log", self.exec_upload_error_log)

        self.bus_interface.connect_to_signal(
                signal_name="update_signal",
                handler_function=lambda messages: message_handler(messages,
                                         self.bus_interface,
                                         self.upgrade_page,
                                         self.uninstall_page,
                                         self.install_page,
                                         self.home_page,
                                         self.inhibit_obj,
                                         ),
                )
        glib.timeout_add(1000, lambda : clear_action_pages(self.bus_interface, self.upgrade_page, self.uninstall_page, self.install_page))
        glib.timeout_add(1000, lambda : clear_install_stop_list(self.install_page))
        glib.timeout_add(1000, lambda : clear_failed_action(self.install_page, self.upgrade_page))

        #self.init_download_manager()

        #self.request_update_list()
        self.upgrade_page.fetch_upgrade_info(utils.get_backend_running())

    def change_mirror_action(self, mirror):
        repo_urls = mirror.get_repo_urls()
        self.bus_interface.change_source_list(
            repo_urls,
            reply_handler=lambda :self.handle_mirror_change_reply(mirror),
            error_handler=lambda e:handle_dbus_error("change_source_list", e)
            )

    def exec_upload_error_log(self):
        SendErrorLog().start()

    @dbus.service.method(DSC_FRONTEND_NAME, in_signature="sb", out_signature="")
    def uninstall_pkg(self, pkg_name, purge_flag):
        self.bus_interface.uninstall_pkg(pkg_name, purge_flag,
                reply_handler=lambda :handle_dbus_reply("uninstall_pkg"),
                error_handler=lambda e:handle_dbus_error("uninstall_pkg", e))
        SendUninstallCount(pkg_name).start()

        self.install_page.delete_item_match_pkgname(pkg_name)

    def init_download_manager(self, v=5):
        self.bus_interface.init_download_manager(
                v,
                reply_handler=lambda :self.init_download_manager_handler(),
                error_handler=lambda e:handle_dbus_error("init_download_manager", e))

    def init_download_manager_handler(self):
        self.dbus_request_status()
        self.loginfo("Init download manager")

    def dbus_request_status(self):
        self.bus_interface.request_status(
                reply_handler=lambda reply: request_status_reply_hander(reply, self.install_page, self.upgrade_page, self.uninstall_page),
                error_handler=lambda e:handle_dbus_error("request_status", e),
                )

    def set_software_download_dir(self):
        self.bus_interface.set_download_dir(
                get_software_download_dir(),
                reply_handler=lambda :handle_dbus_reply("set_download_dir"),
                error_handler=lambda e:handle_dbus_error("set_download_dir", e))

    def update_list_handler(self):
        self.show_page("upgrade")
        if not self.in_update_list:
            self.request_update_list()
            global_event.emit('show-updating-view')

    def update_list_finish(self):
        try:
            self.hide_dialog('update_list_dialog')
        except:
            pass
        self.in_update_list = False
        self.data_manager.init_cache_soft_db()

    def hide_dialog(self, name):
        getattr(self, name).hide_all()

    def show_dialog(self, name):
        getattr(self, name).show_all()

    def handle_mirror_change_reply(self, mirror):
        global_event.emit("mirror-backend-changed", mirror)

    def update_status_bar_message(self, message, hide_timeout=0):
        if not self.paned_box.bottom_window.is_visible():
            self.paned_box.bottom_window.show()
        if isinstance(message, list) and len(message) == 4:
            self.bottom_tip_bar.update_info(message[0], message[2], message[3])
            self.bottom_tip_bar.update_end_info(message[1])
        elif isinstance(message, list) and len(message) == 3:
            self.bottom_tip_bar.update_info(*message)
            self.bottom_tip_bar.update_end_info("")
        elif isinstance(message, list) and len(message) == 2:
            self.bottom_tip_bar.update_info(message[0])
            self.bottom_tip_bar.update_end_info(message[1])
        else:
            self.bottom_tip_bar.update_info(message)
            self.bottom_tip_bar.update_end_info("")
        if hide_timeout != 0:
            gtk.timeout_add(hide_timeout, lambda:self.paned_box.bottom_window.hide())

    def request_update_list(self):
        self.in_update_list = True
        self.bus_interface.start_update_list(
                reply_handler=lambda :handle_dbus_reply("start_update_list"),
                error_handler=lambda e:handle_dbus_error("start_update_list", e),)

    def upgrade_pkgs(self, pkg_names):
        self.bus_interface.upgrade_pkgs_with_new_policy(
                pkg_names,
                reply_handler=lambda :handle_dbus_reply("upgrade_pkgs"),
                error_handler=lambda e:handle_dbus_error("upgrade_pkgs", e))
        return False

    def clean_download_cache(self):
        self.bus_interface.clean_download_cache(
                reply_handler=self.clean_download_cache_reply,
                error_handler=lambda e:handle_dbus_error("clean_download_cache", e),
                )

    def clean_download_cache_reply(obj, result):
        num, size = result
        if num != 0:
            message = _("You have cleared up %s packages and saved %s of space.") % (num, bit_to_human_str(size))
        else:
            message = _("Your system cache is empty.")
        global_event.emit("show-message", message, 5000)

    def run(self):
        self.ready_show()
        gtk.main()

        # Send exit request to backend when frontend exit.
        self.bus_interface.request_quit(
                reply_handler=lambda :handle_dbus_reply("request_quit"),
                error_handler=lambda e:handle_dbus_error("request_quit", e))

        # Remove id from config file.
        data_exit()
        self.loginfo('Data id removed')

    @dbus.service.method(DSC_FRONTEND_NAME, in_signature="", out_signature="")
    def request_exit(self):
        self.exit()
        self.bus_interface.request_quit(
                reply_handler=lambda :handle_dbus_reply("request_quit"),
                error_handler=lambda e:handle_dbus_error("request_quit", e))
        data_exit()
        self.loginfo('Data id removed')

    @dbus.service.method(DSC_FRONTEND_NAME, in_signature="as", out_signature="")
    def install_pkgs(self, pkg_names):
        for pkg_name in pkg_names:
            self.install_page.download_wait(pkg_name)
        create_thread(lambda : self.bus_interface.install_pkg(
                                    pkg_names,
                                    reply_handler=lambda :handle_dbus_reply("install_pkg"),
                                    error_handler=lambda e:handle_dbus_error("install_pkg", e))).start()
        for pkg_name in pkg_names:
            SendDownloadCount(pkg_name).start()

    @dbus.service.method(DSC_FRONTEND_NAME, in_signature="", out_signature="")
    def raise_to_top(self):
        if not self.in_wizard_showing:
            self.application.window.show_all()
            self.application.raise_to_top()
        else:
            self.wizard.present()

    @dbus.service.signal(DSC_FRONTEND_NAME)
    def update_signal(self, message):
        pass