def __init__(self):
     DialogBox.__init__(self, _("Task Manager"), 350, 450, DIALOG_MASK_SINGLE_PAGE,
                        modal=False, close_callback=self.hide_all)
     
     self.is_changed = False
     scrolled_window = ScrolledWindow(0, 0)
     scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
     
     scrolled_align = gtk.Alignment()
     scrolled_align.set(1, 1, 1, 1)
     scrolled_align.set_padding(10, 0, 0, 0)
     scrolled_align.add(scrolled_window)
     
     self.jobs_view = JobsView()
     self.jobs_view.draw_mask = self.get_mask_func(self.jobs_view)
     scrolled_window.add_child(self.jobs_view)
     
     pause_button = Button(_("Pause"))
     pause_button.connect("clicked", self.pause_job)
     stop_button = Button(_("Close"))
     stop_button.connect("clicked", lambda w: self.hide_all())
     
     self.body_box.add(scrolled_align)
     self.right_button_box.set_buttons([pause_button, stop_button])
     
     Dispatcher.connect("transfor-job", self.add_new_job)
Example #2
0
    def __init__(self, confirm_callback=None):
        DialogBox.__init__(self, 
                           title=_("Close"),
                           default_width=360,
                           default_height=145,
                           mask_type=DIALOG_MASK_SINGLE_PAGE,
                           )
        
        self.confirm_callback = confirm_callback
        radio_group = gtk.HBox(spacing=50)
        self.minimize_radio = RadioButton(_("Minimize to tray"))
        self.minimize_radio.set_active(True)
        self.quit_radio = RadioButton(_("Quit"))
        
        radio_group.pack_start(self.minimize_radio, False, True)
        radio_group.pack_start(self.quit_radio, False, True)
        self.remembar_button = CheckButton(_("Don't prompt again"))
        self.remembar_button.set_active(True)
        
        radio_group_align = gtk.Alignment()
        radio_group_align.set_padding(30, 0, 10, 0)
        radio_group_align.add(radio_group)
                
        confirm_button = Button(_("OK"))
        confirm_button.connect("clicked", self.on_confirm_button_clicked)

        cancel_button = Button(_("Cancel"))
        cancel_button.connect("clicked", self.on_cancel_button_clicked)        
        
        # Connect widgets.
        self.body_box.pack_start(radio_group_align, False, True)
        self.left_button_box.set_buttons([self.remembar_button,])
        self.right_button_box.set_buttons([confirm_button, cancel_button])
Example #3
0
    def __init__(self):
        DialogBox.__init__(self,
                           _("Task Manager"),
                           350,
                           450,
                           DIALOG_MASK_SINGLE_PAGE,
                           modal=False,
                           close_callback=self.hide_all)

        self.is_changed = False
        scrolled_window = ScrolledWindow(0, 0)
        scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)

        scrolled_align = gtk.Alignment()
        scrolled_align.set(1, 1, 1, 1)
        scrolled_align.set_padding(10, 0, 0, 0)
        scrolled_align.add(scrolled_window)

        self.jobs_view = JobsView()
        self.jobs_view.draw_mask = self.get_mask_func(self.jobs_view)
        scrolled_window.add_child(self.jobs_view)

        pause_button = Button(_("Pause"))
        pause_button.connect("clicked", self.pause_job)
        stop_button = Button(_("Close"))
        stop_button.connect("clicked", lambda w: self.hide_all())

        self.body_box.add(scrolled_align)
        self.right_button_box.set_buttons([pause_button, stop_button])

        Dispatcher.connect("transfor-job", self.add_new_job)
    def __init__(self, default_width=300, default_height=160, cancel_cb=None):
        DialogBox.__init__(self, "", default_width, default_height, self.DIALOG_MASK_SINGLE_PAGE)

        self.cancel_cb = cancel_cb

        self.message_align = gtk.Alignment()
        self.message_align.set(0, 0, 0, 0)
        self.message_align.set_padding(0, 0, 10, 0)
        self.message_label = Label("", label_width=300)
        self.message_align.add(self.message_label)
        self.progress_align = gtk.Alignment()
        self.progress_align.set(0, 0, 0, 0)
        self.progress_align.set_padding(20, 0, 10, 10)
        self.progress_bar = ProgressBar()
        self.progress_bar.set_size_request(default_width, -1)
        self.progress_align.add(self.progress_bar)
        self.percentage_align = gtk.Alignment()
        self.percentage_align.set(0, 0, 0, 0)
        self.percentage_align.set_padding(10, 0, 140, 0)
        self.percentage_label = Label("0%", label_width=300)
        self.percentage_label.set_size_request(default_width, -1)
        self.percentage_align.add(self.percentage_label)
        self.cancel_align = gtk.Alignment()
        self.cancel_align.set(0, 0, 0, 0)
        self.cancel_align.set_padding(20, 0, 200, 0)
        self.cancel_button = Button(_("Cancel"))
        self.cancel_button.set_size_request(70, WIDGET_HEIGHT)
        self.cancel_button.connect("clicked", self.__on_cancel_button_clicked)
        self.cancel_align.add(self.cancel_button)

        self.body_box.pack_start(self.message_align, False, False)
        self.body_box.pack_start(self.progress_align, False, False)
        self.body_box.pack_start(self.percentage_align, False, False)
        self.body_box.pack_start(self.cancel_align)
    def __init__(self, message, default_width=300, default_height=140, is_succeed=True):
        DialogBox.__init__(self, "", default_width, default_height, self.DIALOG_MASK_SINGLE_PAGE)

        self.hbox = gtk.HBox()
        self.image_align = gtk.Alignment()
        self.image_align.set(0, 0, 0, 0)
        self.image_align.set_padding(0, 0, 20, 0)
        self.image_box = ImageBox(app_theme.get_pixbuf("bluetooth/succeed.png"))
        if not is_succeed:
            self.image_box = ImageBox(app_theme.get_pixbuf("bluetooth/failed.png"))
        self.image_align.add(self.image_box)
        self.message_align = gtk.Alignment()
        self.message_align.set(0, 0, 0, 0)
        self.message_align.set_padding(20, 0, 10, 0)
        if not is_succeed:
            self.message_align.set_padding(0, 0, 10, 0)
        self.message_label = Label(message, wrap_width = 200)
        self.message_align.add(self.message_label)
        self.hbox.pack_start(self.image_align)
        self.hbox.pack_start(self.message_align)
        self.confirm_align = gtk.Alignment()
        self.confirm_align.set(0, 0, 0, 0)
        self.confirm_align.set_padding(20, 0, 200, 0)
        self.confirm_button = Button(_("Ok"))
        self.confirm_button.set_size_request(70, WIDGET_HEIGHT)
        self.confirm_button.connect("clicked", lambda widget : self.destroy())
        self.confirm_align.add(self.confirm_button)

        self.body_box.pack_start(self.hbox, False, False)
        self.body_box.pack_start(self.confirm_align, False, False)
    def __init__(self,
                 title,
                 message,
                 default_width=400,
                 default_height=220,
                 confirm_callback=None,
                 cancel_callback=None,
                 confirm_button_text="Yes",
                 cancel_button_text="No"):
        DialogBox.__init__(self, "", default_width, default_height, DIALOG_MASK_SINGLE_PAGE)
        self.confirm_callback = confirm_callback
        self.cancel_callback = cancel_callback

        self.title_align = gtk.Alignment()
        self.title_align.set(0, 0, 0, 0)
        self.title_align.set_padding(0, 0, FRAME_LEFT_PADDING, 8)
        self.title_label = Label(title, wrap_width=300)

        self.label_align = gtk.Alignment()
        self.label_align.set(0.5, 0.5, 0, 0)
        self.label_align.set_padding(0, 0, 8, 8)
        self.label = Label(message, text_x_align=ALIGN_MIDDLE, text_size=55)

        self.confirm_button = Button(confirm_button_text)
        self.cancel_button = Button(cancel_button_text)

        self.confirm_button.connect("clicked", lambda w: self.click_confirm_button())
        self.cancel_button.connect("clicked", lambda w: self.click_cancel_button())

        self.body_box.pack_start(self.title_align, False, False)
        self.title_align.add(self.title_label)
        self.body_box.pack_start(self.label_align, True, True)
        self.label_align.add(self.label)

        self.right_button_box.set_buttons([self.cancel_button, self.confirm_button])
 def __init__(self):
     DialogBox.__init__(self, _("Search"), 460, 300, DIALOG_MASK_SINGLE_PAGE,
                        modal=False, window_hint=None, close_callback=self.hide_all)
     title_label = Label(_("Title:"))
     self.title_entry = TextEntry("")
     self.title_entry.set_size(300, 25)
     self.search_button = Button(_("Search"))
     self.search_button.connect("clicked", self.search_song)
     
     control_box = gtk.HBox(spacing=5)
     control_box.pack_start(title_label, False, False)
     control_box.pack_start(self.title_entry, False, False)
     control_box.pack_start(self.search_button, False, False)
     
     scrolled_window = ScrolledWindow(0, 0)
     scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
     self.result_view = ListView()
     self.result_view.connect("double-click-item", self.double_click_cb)
     self.result_view.draw_mask = self.get_mask_func(self.result_view)
     self.result_view.add_titles([_("Title"), _("Artist"), _("Album"), _("Type"), _("Size")])
     scrolled_window.add_child(self.result_view)
     
     self.prompt_label = Label("")
     download_button = Button(_("Download"))
     download_button.connect("clicked", self.download_song)
     cancel_button = Button(_("Close"))
     cancel_button.connect("clicked", lambda w: self.hide_all())
     
     self.body_box.set_spacing(5)
     self.body_box.pack_start(control_box, False, False)
     self.body_box.pack_start(scrolled_window, True, True)
     self.left_button_box.set_buttons([self.prompt_label])
     self.right_button_box.set_buttons([download_button, cancel_button])
Example #8
0
    def __init__(
        self,
        title,
        message,
        default_width=330,
        default_height=145,
        confirm_callback=None,
        cancel_callback=None,
        cancel_first=True,
        message_text_size=9,
    ):
        '''
        Initialize ConfirmDialog class.

        @param title: Title for confirm dialog.
        @param message: Confirm message.
        @param default_width: Dialog width, default is 330 pixel.
        @param default_height: Dialog height, default is 145 pixel.
        @param confirm_callback: Callback when user click confirm button.
        @param cancel_callback: Callback when user click cancel button.
        @param cancel_first: Set as True if to make cancel button before confirm button, default is True.
        @param message_text_size: Text size of message, default is 11.
        '''
        # Init.
        DialogBox.__init__(self,
                           title,
                           default_width,
                           default_height,
                           DIALOG_MASK_SINGLE_PAGE,
                           close_callback=self.hide)
        self.confirm_callback = confirm_callback
        self.cancel_callback = cancel_callback

        self.label_align = gtk.Alignment()
        self.label_align.set(0.5, 0.5, 0, 0)
        self.label_align.set_padding(0, 0, 8, 8)
        self.label = Label(message,
                           text_x_align=ALIGN_MIDDLE,
                           text_size=message_text_size)

        self.confirm_button = Button(_("OK"))
        self.cancel_button = Button(_("Cancel"))

        self.confirm_button.connect("clicked",
                                    lambda w: self.click_confirm_button())
        self.cancel_button.connect("clicked",
                                   lambda w: self.click_cancel_button())

        # Connect widgets.
        self.body_box.pack_start(self.label_align, True, True)
        self.label_align.add(self.label)

        if cancel_first:
            self.right_button_box.set_buttons(
                [self.cancel_button, self.confirm_button])
        else:
            self.right_button_box.set_buttons(
                [self.confirm_button, self.cancel_button])
Example #9
0
 def __init__(self):
     DialogBox.__init__(
         self, _("Lyrics search"), 460, 300, DIALOG_MASK_MULTIPLE_PAGE, close_callback=self.hide_all, 
         modal=False, window_hint=None, skip_taskbar_hint=False, window_pos=gtk.WIN_POS_CENTER)
     
     self.artist_entry = InputEntry()
     self.artist_entry.set_size(130, 23)
     self.title_entry = InputEntry()
     self.title_entry.set_size(130, 23)
     artist_label = Label(_("Artist:"))
     title_label = Label(_("Title:"))
     right_align = gtk.Alignment()
     right_align.set(0, 0, 0, 1)
     
     self.search_button = Button(_("Search"))
     self.search_button.connect("clicked", self.search_lyric_cb)
     self.process_id = 0
     
     info_box = gtk.HBox(spacing=25)
     
     control_box = gtk.HBox(spacing=5)
     title_box = gtk.HBox(spacing=5)        
     title_box.pack_start(title_label, False, False)
     title_box.pack_start(self.title_entry)
     artist_box = gtk.HBox(spacing=5)
     artist_box.pack_start(artist_label, False, False)
     artist_box.pack_start(self.artist_entry)
     control_box.pack_start(title_box, False, False)
     control_box.pack_start(artist_box, False, False)
     
     info_box.pack_start(control_box, False, False)
     info_box.pack_start(self.search_button, False, False)
     
     sort_items = [ lambda items, reverse : self.sort_by_key(items, reverse, "title"),
                    lambda items, reverse : self.sort_by_key(items, reverse, "artist")]
     self.result_view = TreeView()
     self.result_view.set_expand_column(0)
     self.result_view.connect("double-click-item", self.double_click_cb)
     self.result_view.set_column_titles([_("Title"), _("Artist")], sort_items)
     self.result_view.draw_mask = self.draw_view_mask
     
     self.prompt_label = Label("")
     download_button = Button(_("Download"))
     download_button.connect("clicked", self.download_lyric_cb)
     cancel_button = Button(_("Close"))
     cancel_button.connect("clicked", lambda w: self.hide_all())
     
     info_box_align = gtk.Alignment()
     info_box_align.set_padding(5, 0, 5, 0)
     info_box_align.add(info_box)
     
     self.body_box.set_spacing(5)
     self.body_box.pack_start(info_box_align, False, False)
     self.body_box.pack_start(self.result_view, True, True)
     self.left_button_box.set_buttons([self.prompt_label])
     self.right_button_box.set_buttons([download_button, cancel_button])
     self.lrc_manager = LrcManager()
 def __init__(self):
     DialogBox.__init__(
         self, _("Lyrics search"), 460, 300, DIALOG_MASK_MULTIPLE_PAGE, close_callback=self.hide_all, 
         modal=False, window_hint=None, skip_taskbar_hint=False)
     self.artist_entry = InputEntry()
     self.artist_entry.set_size(130, 23)
     self.title_entry = InputEntry()
     self.title_entry.set_size(130, 23)
     artist_label = Label(_("Artist:"))
     title_label = Label(_("Title:"))
     right_align = gtk.Alignment()
     right_align.set(0, 0, 0, 1)
     
     search_button = Button(_("Search"))
     search_button.connect("clicked", self.search_lyric_cb)
     
     info_box = gtk.HBox(spacing=25)
     
     control_box = gtk.HBox(spacing=5)
     title_box = gtk.HBox(spacing=5)        
     title_box.pack_start(title_label, False, False)
     title_box.pack_start(self.title_entry)
     artist_box = gtk.HBox(spacing=5)
     artist_box.pack_start(artist_label, False, False)
     artist_box.pack_start(self.artist_entry)
     control_box.pack_start(title_box, False, False)
     control_box.pack_start(artist_box, False, False)
     
     info_box.pack_start(control_box, False, False)
     info_box.pack_start(search_button, False, False)
     
     scrolled_window = ScrolledWindow(0, 0)
     scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
     sort_items = [(lambda item: item.title, cmp), (lambda item: item.artist, cmp)]
     self.result_view = ListView(sort_items)
     self.result_view.connect("double-click-item", self.double_click_cb)
     self.result_view.add_titles([_("Title"), _("Artist")])
     self.result_view.draw_mask = self.get_mask_func(self.result_view)
     scrolled_window.add_child(self.result_view)
     
     self.prompt_label = Label("")
     download_button = Button(_("Download"))
     download_button.connect("clicked", self.download_lyric_cb)
     cancel_button = Button(_("Close"))
     cancel_button.connect("clicked", lambda w: self.hide_all())
     
     info_box_align = gtk.Alignment()
     info_box_align.set_padding(5, 0, 5, 0)
     info_box_align.add(info_box)
     
     self.body_box.set_spacing(5)
     self.body_box.pack_start(info_box_align, False, False)
     self.body_box.pack_start(scrolled_window, True, True)
     self.left_button_box.set_buttons([self.prompt_label])
     self.right_button_box.set_buttons([download_button, cancel_button])
     self.lrc_manager = LrcManager()
Example #11
0
    def __init__(self,
                 default_width=350,
                 default_height=160,
                 confirm_callback=None,
                 cancel_callback=None):
        '''
        Initialize InputDialog class.
        
        @param title: Input dialog title.
        @param init_text: Initialize input text.
        @param default_width: Width of dialog, default is 330 pixel.
        @param default_height: Height of dialog, default is 330 pixel.
        @param confirm_callback: Callback when user click confirm button, this callback accept one argument that return by user input text.
        @param cancel_callback: Callback when user click cancel button, this callback not need argument.
        '''
        # Init.
        DialogBox.__init__(self, _("Autostart app"), default_width,
                           default_height, DIALOG_MASK_SINGLE_PAGE)
        self.confirm_callback = confirm_callback
        self.cancel_callback = cancel_callback
        self.on_click = None

        self.confirm_button = Button(_("OK"))
        self.cancel_button = Button(_("Cancel"))

        self.confirm_button.connect("clicked",
                                    lambda w: self.click_confirm_button())
        self.cancel_button.connect("clicked",
                                   lambda w: self.click_cancel_button())
        self.connect(
            "destroy", self._close_callback
        )  #self.close_callback is None at this moment, so we use _close_callback
        # get system pixbuf
        icon_theme = gtk.IconTheme()
        icon_theme.set_custom_theme("Deepin")
        icon_info = None
        if icon_theme:
            icon_info = icon_theme.lookup_icon("folder-open", 16,
                                               gtk.ICON_LOOKUP_NO_SVG)

        self.icon_pixbuf = None
        if icon_info:
            self.icon_pixbuf = DynamicPixbuf(icon_info.get_filename())
        else:
            self.icon_pixbuf = app_theme.get_pixbuf("navigate/none-small.png")

        table = self.add_new_box()
        self.pack(self.body_box, [table])
        self.right_button_box.set_buttons(
            [self.cancel_button, self.confirm_button])

        self.connect("show", self.focus_input)
 def __init__(self):
     DialogBox.__init__(self, "登录", 645, 500, DIALOG_MASK_MULTIPLE_PAGE, 
                        close_callback=self.hide_all, modal=False,
                        window_hint=None, skip_taskbar_hint=False,
                        window_pos=gtk.WIN_POS_CENTER)
     
     self.url = "http://musicmini.baidu.com/app/mv/playMV.html"
     self.webview = BaseWebView("", enable_plugins=True)
     webview_align = gtk.Alignment()
     webview_align.set(1, 1, 1, 1)
     webview_align.set_padding(0, 0, 0, 2)
     webview_align.add(self.webview)
     self.body_box.pack_start(webview_align, False, True)
 def __init__(self):
     DialogBox.__init__(self, "MV", 980, 600, DIALOG_MASK_MULTIPLE_PAGE, 
                        close_callback=self.hide_all, modal=False,
                        window_hint=None, skip_taskbar_hint=False,
                        window_pos=gtk.WIN_POS_CENTER)
     
     self.url = "http://musicmini.baidu.com/app/mv/playMV.html"
     self.webview = BaseWebView("", enable_plugins=False)
     webview_align = gtk.Alignment()
     webview_align.set(1, 1, 1, 1)
     webview_align.set_padding(0, 0, 0, 2)
     webview_align.add(self.webview)
     self.body_box.pack_start(webview_align, False, True)
 def __init__(self):
     DialogBox.__init__(self, "登录", 326, 340, DIALOG_MASK_MULTIPLE_PAGE, 
                        close_callback=self.hide_all, modal=False,
                        window_hint=None, skip_taskbar_hint=False,
                        window_pos=gtk.WIN_POS_CENTER)
     
     self.set_keep_above(True)
     self.is_reload_flag = False
     self.webview = BaseWebView("http://musicmini.baidu.com/app/passport/passport_phoenix.html")
     webview_align = gtk.Alignment()
     webview_align.set(1, 1, 1, 1)
     webview_align.set_padding(0, 0, 0, 2)
     webview_align.add(self.webview)
     self.body_box.pack_start(webview_align, False, True)
    def __init__(self):
        DialogBox.__init__(self, "登录", 700, 700, DIALOG_MASK_MULTIPLE_PAGE,
                close_callback=self.hide_all, modal=False,
                window_hint=None, skip_taskbar_hint=False,
                window_pos=gtk.WIN_POS_CENTER)

        #self.set_keep_above(True)
        #self.is_reload_flag = False
        self.webview = BaseWebView("")
        webview_align = gtk.Alignment()
        webview_align.set(1, 1, 1, 1)
        webview_align.set_padding(0, 0, 0, 2)
        webview_align.add(self.webview)
        self.body_box.pack_start(webview_align, False, True)
 def __init__(self):
     DialogBox.__init__(self, 
                        _("Task Manager for format conversion"), 
                        FORM_WIDTH, FORM_HEIGHT, 
                        mask_type=DIALOG_MASK_SINGLE_PAGE, #DIALOG_MASK_MULTIPLE_PAGE,
                        close_callback=self.hide_all,
                        modal=True,
                        window_hint=gtk.gdk.WINDOW_TYPE_HINT_DIALOG,
                        window_pos=gtk.WIN_POS_CENTER,
                        resizable=False,
                        )
     self.init_widgets()
     # add widgets.
     self.body_box.pack_start(self.scrolled_window, False, False)
 def __init__(self):
     DialogBox.__init__(self, "登录", 326, 340, DIALOG_MASK_MULTIPLE_PAGE, 
                        close_callback=self.hide_all, modal=False,
                        window_hint=None, skip_taskbar_hint=False,
                        window_pos=gtk.WIN_POS_CENTER)
     
     self.set_keep_above(True)
     self.is_reload_flag = False
     self.webview = BaseWebView("http://musicmini.baidu.com/app/passport/passport_phoenix.html")
     webview_align = gtk.Alignment()
     webview_align.set(1, 1, 1, 1)
     webview_align.set_padding(0, 0, 0, 2)
     webview_align.add(self.webview)
     self.body_box.pack_start(webview_align, False, True)
Example #18
0
def resolve_accel_entry_conflict(origin_entry, conflict_entry, tmp_accel_buf):
    dialog = DialogBox(" ", 620, 150)
    dialog.window_frame.connect("expose-event", draw_widget_background)
    dialog.set_keep_above(True)
    dialog.set_modal(True)
    dialog.body_align.set_padding(15, 10, 10, 10)
    label1 = Label(
        _("The shortcut \"%s\" is already used for \"%s\"") %
        (tmp_accel_buf.get_accel_label(), conflict_entry.settings_description),
        enable_select=False,
        enable_double_click=False)
    label2 = Label(_(
        "If you reassign the shortcut to \"%s\", the \"%s\" shortcut will be disabled."
    ) % (origin_entry.settings_description,
         conflict_entry.settings_description),
                   enable_select=False,
                   enable_double_click=False)
    dialog.body_box.pack_start(label1)
    dialog.body_box.pack_start(label2)
    button_reassign = Button(_("Reassign"))
    button_cancel = Button(_("Cancel"))
    button_cancel.connect("clicked",
                          lambda b: origin_entry.reassign_cancel(dialog))
    button_reassign.connect(
        "clicked",
        lambda b: origin_entry.reassign(tmp_accel_buf, conflict_entry, dialog))
    dialog.right_button_box.set_buttons([button_cancel, button_reassign])
    dialog.show_all()
Example #19
0
 def __init__(self):
     DialogBox.__init__(self, 
                        _("Convert"), 
                        FORM_WIDTH, FORM_HEIGHT, 
                        mask_type=DIALOG_MASK_SINGLE_PAGE,
                        close_callback=self.hide_all,
                        modal=True,                           
                        window_hint=gtk.gdk.WINDOW_TYPE_HINT_DIALOG,
                        window_pos=gtk.WIN_POS_CENTER,
                        # skip_taskbar_hint=False,
                        resizable=False,
                        )                        
     # Init value.
     self.init_value()
     # Init all widgets.
     self.InitializeComponent()
    def __init__(self, url=None):
        DialogBox.__init__(self, "登录", 600, 385, DIALOG_MASK_MULTIPLE_PAGE,
                close_callback=self.hide_all, modal=False,
                window_hint=None, skip_taskbar_hint=False,
                window_pos=gtk.WIN_POS_CENTER)

        #self.set_keep_above(True)
        #self.is_reload_flag = False
        self.webview = BaseWebView(url)
        self.webview.connect("notify::load-status",
                self.handle_login_dialog_status)
        webview_align = gtk.Alignment()
        webview_align.set(1, 1, 1, 1)
        webview_align.set_padding(0, 0, 0, 2)
        webview_align.add(self.webview)
        self.body_box.pack_start(webview_align, False, True)
    def __init__(self, url=None):
        DialogBox.__init__(self, "登录", 600, 385, DIALOG_MASK_MULTIPLE_PAGE,
                close_callback=self.hide_all, modal=False,
                window_hint=None, skip_taskbar_hint=False,
                window_pos=gtk.WIN_POS_CENTER)

        #self.set_keep_above(True)
        #self.is_reload_flag = False
        self.webview = BaseWebView(url)
        self.webview.connect("notify::load-status",
                self.handle_login_dialog_status)
        webview_align = gtk.Alignment()
        webview_align.set(1, 1, 1, 1)
        webview_align.set_padding(0, 0, 0, 2)
        webview_align.add(self.webview)
        self.body_box.pack_start(webview_align, False, True)
 def __init__(self, 
              title, 
              message, 
              default_width=330,
              default_height=145,
              confirm_callback=None, 
              cancel_callback=None, 
              cancel_first=True, 
              message_text_size=11,
              window_type=gtk.WINDOW_TOPLEVEL,
              close_callback=None,
              text_wrap_width=330,
              text_x_align=ALIGN_START,
              ):
     DialogBox.__init__(
         self, title, default_width, default_height, DIALOG_MASK_SINGLE_PAGE,
         window_type=window_type,
         close_callback=close_callback,
         )
     self.confirm_callback = confirm_callback
     self.cancel_callback = cancel_callback
     
     self.label_align = gtk.Alignment()
     self.label_align.set(0.5, 0.5, 0, 0)
     self.label_align.set_padding(0, 0, 8, 8)
     self.label = Label(
         message, 
         text_x_align=text_x_align, 
         text_size=message_text_size,
         wrap_width=text_wrap_width,
         )
     
     self.confirm_button = Button(_("OK"))
     
     self.confirm_button.connect("clicked", lambda w: self.click_confirm_button())
     
     # Connect widgets.
     self.label_align.add(self.label)
     self.body_box.pack_start(self.label_align, True, True)
     
     self.right_button_box.set_buttons([self.confirm_button,])
         
     self.keymap = {
         "Return" : self.click_confirm_button,
         "Escape" : self.close,
         }    
 def __init__(self, 
              title, 
              message, 
              default_width=330,
              default_height=145,
              confirm_callback=None, 
              cancel_callback=None, 
              cancel_first=True, 
              message_text_size=9,
              ):
     '''
     Initialize ConfirmDialog class.
     
     @param title: Title for confirm dialog.
     @param message: Confirm message.
     @param default_width: Dialog width, default is 330 pixel.
     @param default_height: Dialog height, default is 145 pixel.
     @param confirm_callback: Callback when user click confirm button.
     @param cancel_callback: Callback when user click cancel button.
     @param cancel_first: Set as True if to make cancel button before confirm button, default is True.
     @param message_text_size: Text size of message, default is 11.
     '''
     # Init.
     DialogBox.__init__(self, title, default_width, default_height, DIALOG_MASK_SINGLE_PAGE, close_callback=self.hide)
     self.confirm_callback = confirm_callback
     self.cancel_callback = cancel_callback
     
     self.label_align = gtk.Alignment()
     self.label_align.set(0.5, 0.5, 0, 0)
     self.label_align.set_padding(0, 0, 8, 8)
     self.label = Label(message, text_x_align=ALIGN_MIDDLE, text_size=message_text_size)
     
     self.confirm_button = Button(_("OK"))
     self.cancel_button = Button(_("Cancel"))
     
     self.confirm_button.connect("clicked", lambda w: self.click_confirm_button())
     self.cancel_button.connect("clicked", lambda w: self.click_cancel_button())
     
     # Connect widgets.
     self.body_box.pack_start(self.label_align, True, True)
     self.label_align.add(self.label)
     
     if cancel_first:
         self.right_button_box.set_buttons([self.cancel_button, self.confirm_button])
     else:
         self.right_button_box.set_buttons([self.confirm_button, self.cancel_button])
 def __init__(self,
              default_width=350,
              default_height=160,
              confirm_callback=None, 
              cancel_callback=None):
     '''
     Initialize InputDialog class.
     
     @param title: Input dialog title.
     @param init_text: Initialize input text.
     @param default_width: Width of dialog, default is 330 pixel.
     @param default_height: Height of dialog, default is 330 pixel.
     @param confirm_callback: Callback when user click confirm button, this callback accept one argument that return by user input text.
     @param cancel_callback: Callback when user click cancel button, this callback not need argument.
     '''
     # Init.
     DialogBox.__init__(self, _("Autostart app"), default_width, default_height, DIALOG_MASK_SINGLE_PAGE)
     self.confirm_callback = confirm_callback
     self.cancel_callback = cancel_callback
     self.on_click = None
     
     self.confirm_button = Button(_("OK"))
     self.cancel_button = Button(_("Cancel"))
     
     self.confirm_button.connect("clicked", lambda w: self.click_confirm_button())
     self.cancel_button.connect("clicked", lambda w: self.click_cancel_button())
     self.connect("destroy", self._close_callback) #self.close_callback is None at this moment, so we use _close_callback
     # get system pixbuf
     icon_theme = gtk.IconTheme()
     icon_theme.set_custom_theme("Deepin")
     icon_info = None
     if icon_theme:
         icon_info = icon_theme.lookup_icon("folder-open", 16, gtk.ICON_LOOKUP_NO_SVG)
     
     
     self.icon_pixbuf = None
     if icon_info:
         self.icon_pixbuf = DynamicPixbuf(icon_info.get_filename())
     else:
         self.icon_pixbuf = app_theme.get_pixbuf("navigate/none-small.png")
     
     table = self.add_new_box() 
     self.pack(self.body_box, [table])
     self.right_button_box.set_buttons([self.cancel_button, self.confirm_button])
     
     self.connect("show", self.focus_input)
    def __init__(self, hide_callback=None):
        self.hide_callback = hide_callback
        self.dialog_width = 330
        DialogBox.__init__(
            self,
            title="",
            default_width=self.dialog_width,
            default_height=145,
            mask_type=0,
            close_callback=self.close_action,
            modal=True,
            window_hint=gtk.gdk.WINDOW_TYPE_HINT_DIALOG,
            window_pos=None,
            skip_taskbar_hint=True,
            resizable=False,
            window_type=gtk.WINDOW_TOPLEVEL,
        )

        self.waiting_animation = gtk.VBox()
        self.waiting_animation.set_size_request(36, 36)
        self.waiting_bg_pixbuf = utils.get_common_image_pixbuf(
            "waiting/waiting_bg.png")
        self.waiting_fg_pixbuf = utils.get_common_image_pixbuf(
            "waiting/waiting_fg.png")
        self.waiting_animation.connect("expose-event", self.expose_waiting)
        self.counter = 1
        self.factor = math.pi / 10
        gtk.timeout_add(50, self.on_timer)

        self.label = Label(
            _("Speed testing will finish only after one minute, please wait."),
            text_size=10,
            wrap_width=self.dialog_width - 36 - 60,
        )

        self.waiting_hbox = gtk.HBox()
        self.waiting_hbox.pack_start(self.waiting_animation, False, False)
        self.waiting_hbox.pack_start(self.label, False, False)

        self.center_align = gtk.Alignment()
        self.center_align.set(0.5, 0.5, 0, 0)
        self.center_align.set_padding(0, 0, 8, 8)
        self.body_box.add(self.center_align)

        global_event.register_event("mirror-test-finished", self.show_result)
Example #26
0
 def __init__(self):
     DialogBox.__init__(
         self,
         _("Convert"),
         FORM_WIDTH,
         FORM_HEIGHT,
         mask_type=DIALOG_MASK_SINGLE_PAGE,
         close_callback=self.hide_all,
         modal=True,
         window_hint=gtk.gdk.WINDOW_TYPE_HINT_DIALOG,
         window_pos=gtk.WIN_POS_CENTER,
         # skip_taskbar_hint=False,
         resizable=False,
     )
     # Init value.
     self.init_value()
     # Init all widgets.
     self.InitializeComponent()
 def __init__(self, songs=None):
     DialogBox.__init__(self, _("Converter"), 385, 200, DIALOG_MASK_SINGLE_PAGE,
                        modal=True)
     
     self.songs = songs or [Player.song]
     default_format = "MP3 (CBR)"
     default_index = FORMATS.keys().index(default_format)
     format_box, self.format_combo_box = self.create_combo_widget(_("Format"),
                                                             [(key, None) for key in FORMATS.keys()],
                                                             default_index)
     quality_box, self.quality_combo_box = self.create_combo_widget(_("Quality"),
                                                                    self.get_quality_items(default_format),
                                                                    self.get_quality_index(default_format),
                                                                    65)
     format_quality_box = gtk.HBox(spacing=68)
     format_quality_box.pack_start(format_box, False, False)
     format_quality_box.pack_start(quality_box, False, False)
     
     exists_box, self.exists_combo_box = self.create_combo_widget(_("Target file already exists"),
                                                             [(_("Ask"), True), (_("Cover"), False)],
                                                             0)
     
     start_button = Button(_("Start"))
     close_button = Button(_("Close"))
     self.add_check_button = CheckButton(_("Add to Playlist after finished"), padding_x=2)
     
     main_table = gtk.Table()
     main_table.set_row_spacings(10)
     main_table.attach(format_quality_box, 0, 2, 0, 1, yoptions=gtk.FILL)
     main_table.attach(set_widget_left(exists_box), 0, 2, 1, 2, yoptions=gtk.FILL)
     main_table.attach(self.create_output_box(), 0, 2, 2, 3, yoptions=gtk.FILL)
     main_table.attach(set_widget_left(self.add_check_button), 0, 2, 3, 4, yoptions=gtk.FILL)
     
     main_align = gtk.Alignment()
     main_align.set_padding(10, 10, 15, 10)
     main_align.add(main_table)
     
     # Connect signals.
     self.format_combo_box.connect("item-selected", self.reset_quality_items)
     start_button.connect("clicked", self.add_and_close)
     close_button.connect("clicked", lambda w: self.destroy())
     
     self.body_box.pack_start(main_align, False, True)
     self.right_button_box.set_buttons([start_button, close_button])
Example #28
0
 def __init__(self, songs=None):
     DialogBox.__init__(self, _("Convert"), 385, 200, DIALOG_MASK_SINGLE_PAGE,
                        modal=True)
     
     self.songs = songs or [Player.song]
     default_format = "MP3 (CBR)"
     default_index = FORMATS.keys().index(default_format)
     format_box, self.format_combo_box = self.create_combo_widget(_("Format"),
                                                             [(key, None) for key in FORMATS.keys()],
                                                             default_index)
     quality_box, self.quality_combo_box = self.create_combo_widget(_("Quality"),
                                                                    self.get_quality_items(default_format),
                                                                    self.get_quality_index(default_format),
                                                                    65)
     format_quality_box = gtk.HBox(spacing=68)
     format_quality_box.pack_start(format_box, False, False)
     format_quality_box.pack_start(quality_box, False, False)
     
     exists_box, self.exists_combo_box = self.create_combo_widget(_("Target file already exists"),
                                                             [(_("Ask"), True), (_("Cover"), False)],
                                                             0)
     
     start_button = Button(_("Start"))
     close_button = Button(_("Close"))
     self.add_check_button = CheckButton(_("Add to Playlist when finished"), padding_x=2)
     
     main_table = gtk.Table()
     main_table.set_row_spacings(10)
     main_table.attach(format_quality_box, 0, 2, 0, 1, yoptions=gtk.FILL)
     main_table.attach(set_widget_left(exists_box), 0, 2, 1, 2, yoptions=gtk.FILL)
     main_table.attach(self.create_output_box(), 0, 2, 2, 3, yoptions=gtk.FILL)
     main_table.attach(set_widget_left(self.add_check_button), 0, 2, 3, 4, yoptions=gtk.FILL)
     
     main_align = gtk.Alignment()
     main_align.set_padding(10, 10, 15, 10)
     main_align.add(main_table)
     
     # Connect signals.
     self.format_combo_box.connect("item-selected", self.reset_quality_items)
     start_button.connect("clicked", self.add_and_close)
     close_button.connect("clicked", lambda w: self.destroy())
     
     self.body_box.pack_start(main_align, False, True)
     self.right_button_box.set_buttons([start_button, close_button])
    def __init__(self, hide_callback=None):
        self.hide_callback = hide_callback
        self.dialog_width = 330
        DialogBox.__init__(
                self,
                title="",
                default_width=self.dialog_width,
                default_height=145,
                mask_type=0,
                close_callback=self.close_action,
                modal=True,
                window_hint=gtk.gdk.WINDOW_TYPE_HINT_DIALOG,
                window_pos=None,
                skip_taskbar_hint=True,
                resizable=False,
                window_type=gtk.WINDOW_TOPLEVEL,
                )

        self.waiting_animation = gtk.VBox()
        self.waiting_animation.set_size_request(36, 36)
        self.waiting_bg_pixbuf = utils.get_common_image_pixbuf("waiting/waiting_bg.png")
        self.waiting_fg_pixbuf = utils.get_common_image_pixbuf("waiting/waiting_fg.png")
        self.waiting_animation.connect("expose-event", self.expose_waiting)
        self.counter = 1
        self.factor = math.pi/10
        gtk.timeout_add(50, self.on_timer)

        self.label = Label(
            _("Speed testing will finish only after one minute, please wait."),
            text_size=10,
            wrap_width=self.dialog_width- 36 - 60,
            )

        self.waiting_hbox = gtk.HBox()
        self.waiting_hbox.pack_start(self.waiting_animation, False, False)
        self.waiting_hbox.pack_start(self.label, False, False)

        self.center_align = gtk.Alignment()
        self.center_align.set(0.5, 0.5, 0, 0)
        self.center_align.set_padding(0, 0, 8, 8)
        self.body_box.add(self.center_align)

        global_event.register_event("mirror-test-finished", self.show_result)
Example #30
0
    def __init__(self):
        DialogBox.__init__(self,
                           "登录",
                           700,
                           700,
                           DIALOG_MASK_MULTIPLE_PAGE,
                           close_callback=self.hide_all,
                           modal=False,
                           window_hint=None,
                           skip_taskbar_hint=False,
                           window_pos=gtk.WIN_POS_CENTER)

        #self.set_keep_above(True)
        #self.is_reload_flag = False
        self.webview = BaseWebView("")
        webview_align = gtk.Alignment()
        webview_align.set(1, 1, 1, 1)
        webview_align.set_padding(0, 0, 0, 2)
        webview_align.add(self.webview)
        self.body_box.pack_start(webview_align, False, True)
 def __init__(self):
     DialogBox.__init__(self, _("Open Url"),
             mask_type=DIALOG_MASK_MULTIPLE_PAGE,
             window_pos=gtk.WIN_POS_CENTER
             )
     self.hbox_ali = gtk.Alignment(0, 0, 1, 1)
     self.hbox_ali.set_padding(5, 5, 5, 5)
     self.hbox = gtk.HBox()
     self.hbox_ali.add(self.hbox)
     self.url_text = InputEntry()
     self.ok_btn = Button(_("Ok"))
     self.cancel_btn = Button(_("Cancel"))
     self.url_text.set_size(280, 25)
     self.hbox.pack_start(self.url_text, True, True)
     #self.hbox.pack_start(self.ok_btn, True, True, 5)
     self.right_button_box.set_buttons([self.ok_btn, self.cancel_btn])
     #
     self.body_box.pack_start(self.hbox_ali, True, True)
     #
     self.cancel_btn.connect("clicked", self.__cancel_btn_clicked_event)
def process_unmodifier_key(tmp_accel_buf):
    dialog = DialogBox(" ", 550, 150)
    dialog.window_frame.connect("expose-event", draw_widget_background)
    dialog.set_keep_above(True)
    dialog.set_modal(True)
    dialog.body_align.set_padding(15, 10, 10, 10)
    label1 = Label(_("The shortcut \"%s\" cannot be used because it will become impossible to type using this key.")% tmp_accel_buf.get_accel_label(), enable_select=False, enable_double_click=False)
    label2 = Label(_("Please try with a key such as Control, Alt or Shift at the same time."), enable_select=False, enable_double_click=False)
    dialog.body_box.pack_start(label1)
    dialog.body_box.pack_start(label2)
    button = Button(_("Cancel"))
    button.connect("clicked", lambda b: dialog.destroy())
    dialog.right_button_box.set_buttons([button])
    dialog.show_all()
    def __init__(self, title, info_message, cancel_callback=None):
        DialogBox.__init__(self, 
                title, 
                mask_type=DIALOG_MASK_SINGLE_PAGE, 
                close_callback=self.dialog_close_action)
        self.set_size_request(-1, -1)
        self.set_position(gtk.WIN_POS_CENTER_ON_PARENT)

        self.loading_widget = Loading() 
        loading_widget_align = gtk.Alignment()
        loading_widget_align.set(0.5, 0.5, 0, 0)
        loading_widget_align.set_padding(padding_top=0, padding_bottom=0, padding_left=0, padding_right=8)
        loading_widget_align.add(self.loading_widget)

        self.info_message_label = Label(info_message, enable_select=False, wrap_width=200, text_size=10)
        info_message_align = gtk.Alignment()
        info_message_align.set(0.5, 0.5, 0, 0)
        info_message_align.add(self.info_message_label)

        outer_align = gtk.Alignment()
        outer_align.set(0.5, 0.5, 0, 0)
        outer_align.set_padding(padding_top=10, padding_bottom=10, padding_left=25, padding_right=25)

        outer_hbox = gtk.HBox()
        outer_hbox.pack_start(loading_widget_align, False, False)
        outer_hbox.pack_start(info_message_align, False, False)
        outer_align.add(outer_hbox)

        self.close_button = Button(_("Cancel"))
        if cancel_callback:
            self.close_button.connect("clicked", cancel_callback)
        else:
            self.close_button.connect("clicked", lambda w: self.hide_all())

        self.body_box.pack_start(outer_align, False, False)
        self.right_button_box.set_buttons([self.close_button])
Example #34
0
def process_unmodifier_key(tmp_accel_buf):
    dialog = DialogBox(" ", 550, 150)
    dialog.window_frame.connect("expose-event", draw_widget_background)
    dialog.set_keep_above(True)
    dialog.set_modal(True)
    dialog.body_align.set_padding(15, 10, 10, 10)
    label1 = Label(_(
        "The shortcut \"%s\" cannot be used because it will become impossible to type using this key."
    ) % tmp_accel_buf.get_accel_label(),
                   enable_select=False,
                   enable_double_click=False)
    label2 = Label(_(
        "Please try with a key such as Control, Alt or Shift at the same time."
    ),
                   enable_select=False,
                   enable_double_click=False)
    dialog.body_box.pack_start(label1)
    dialog.body_box.pack_start(label2)
    button = Button(_("Cancel"))
    button.connect("clicked", lambda b: dialog.destroy())
    dialog.right_button_box.set_buttons([button])
    dialog.show_all()
def resolve_accel_entry_conflict(origin_entry, conflict_entry, tmp_accel_buf):
    dialog = DialogBox(" ", 620, 150)
    dialog.window_frame.connect("expose-event", draw_widget_background)
    dialog.set_keep_above(True)
    dialog.set_modal(True)
    dialog.body_align.set_padding(15, 10, 10, 10)
    label1 = Label(_("The shortcut \"%s\" is already used for \"%s\"")%
                   (tmp_accel_buf.get_accel_label(), conflict_entry.settings_description), enable_select=False, enable_double_click=False)
    label2 = Label(_("If you reassign the shortcut to \"%s\", the \"%s\" shortcut will be disabled.")%
                   (origin_entry.settings_description, conflict_entry.settings_description), enable_select=False, enable_double_click=False)
    dialog.body_box.pack_start(label1)
    dialog.body_box.pack_start(label2)
    button_reassign = Button(_("Reassign"))
    button_cancel = Button(_("Cancel"))
    button_cancel.connect("clicked", lambda b: origin_entry.reassign_cancel(dialog))
    button_reassign.connect("clicked", lambda b: origin_entry.reassign(tmp_accel_buf, conflict_entry, dialog))
    dialog.right_button_box.set_buttons([button_cancel, button_reassign])
    dialog.show_all()
Example #36
0
    def __init__(self, title, cancel_callback=None):
        DialogBox.__init__(self, 
                title, 
                mask_type=2, 
                close_callback=self.dialog_close_action)
        self.connect('delete-event', self.dialog_close_action)
        self.set_size_request(480, 350)
        self.set_position(gtk.WIN_POS_CENTER_ON_PARENT)

        main_box = gtk.VBox(spacing=15)
        logo_image = gtk.image_new_from_pixbuf(get_common_image_pixbuf('logo24.png'))
        logo_name = Label(_("Deepin Game"), text_size=10)
        logo_box = gtk.HBox(spacing=2)
        logo_box.pack_start(logo_image, False, False)
        logo_box.pack_start(logo_name, False, False)
        
        version_label = Label(_("Version: "))
        version_content = Label(PROGRAM_VERSION, DynamicColor('#4D5154'))
        info_box = gtk.HBox(spacing=5)
        info_box.pack_start(version_label, False, False)
        info_box.pack_start(version_content, False, False)
        
        title_box = gtk.HBox()
        title_box.pack_start(logo_box, False, False)
        align = gtk.Alignment()
        align.set(0, 0, 0, 1)
        title_box.pack_start(align, True, True)
        title_box.pack_start(info_box, False, False)
        
        describe = _("Deepin Game is designed by Deepin for Linux users. Here "
                "you will elaborately find good and safe games selected by "
                "professionals. Click and play the best games you have ever "
                "met. Deepin Game just for happiness!")
        
        describe_label = Label(describe, enable_select=False, wrap_width=430, text_size=10)
        main_box.pack_start(title_box, False, False)
        main_box.pack_start(create_separator_box(), False, True)
        main_box.pack_start(describe_label, False, False)

        links_table = gtk.Table(4, 2)

        links = [
                (_('Weibo: '), None, 'http://weibo.com/linuxdeepinnew'),
                (_('Forum: '), None, 'http://www.linuxdeepin.com/forum'),
                (_('Feedback: '), None, 'http://www.linuxdeepin.com/mantis'),
                (_('Game deliver: '), '*****@*****.**', 'mailto:[email protected]'),
                ]
        for (i, l) in enumerate(links):
            left_text = Label(l[0])
            left_text_align = self.create_right_align()
            left_text_align.add(left_text)
            right_link = LinkButton(text=l[1], link=l[2])
            links_table.attach(left_text_align, 0, 1, i, i+1, xoptions=gtk.FILL, xpadding=5, ypadding=4)
            links_table.attach(right_link, 1, 2, i, i+1, xoptions=gtk.FILL)
            #main_box.pack_start(self.create_link_box(l[0], l[1], l[2]), False, False)
        
        main_box.pack_start(links_table, False, False)
        main_align = gtk.Alignment()
        main_align.set_padding(20, 0, 20, 20)
        main_align.set(0, 0, 1, 1)
        main_align.add(main_box)
        self.body_box.pack_start(main_align)

        self.ok_button = Button(_('Close'))
        self.ok_button.connect('clicked', self.dialog_close_action)
        ok_button_align = gtk.Alignment(0.5, 0.5, 0, 0)
        ok_button_align.set_padding(9, 11, 0, 10)
        ok_button_align.add(self.ok_button)
        self.right_button_box.pack_start(ok_button_align, False, False)
Example #37
0
    def __init__(self, title, cancel_callback=None):
        DialogBox.__init__(self, 
                title, 
                mask_type=2, 
                close_callback=self.dialog_close_action)
        self.connect('delete-event', self.dialog_close_action)
        self.set_size_request(480, 350)
        self.set_position(gtk.WIN_POS_CENTER_ON_PARENT)

        main_box = gtk.VBox(spacing=15)
        logo_image = gtk.image_new_from_pixbuf(get_common_image_pixbuf('logo24.png'))
        logo_name = Label(_("Deepin Games"), text_size=10)
        logo_box = gtk.HBox(spacing=2)
        logo_box.pack_start(logo_image, False, False)
        logo_box.pack_start(logo_name, False, False)
        
        version_label = Label(_("Version: "))
        version_content = Label(PROGRAM_VERSION, DynamicColor('#4D5154'))
        info_box = gtk.HBox(spacing=5)
        info_box.pack_start(version_label, False, False)
        info_box.pack_start(version_content, False, False)
        
        title_box = gtk.HBox()
        title_box.pack_start(logo_box, False, False)
        align = gtk.Alignment()
        align.set(0, 0, 0, 1)
        title_box.pack_start(align, True, True)
        title_box.pack_start(info_box, False, False)
        
        describe = _("Deepin Games is designed by Linux Deepin for Linux users. Here you will find good and safe games elaborately selected by professionals. Click and play the best games you have ever met. Deepin Games - deeper into the world of game!")
        
        describe_label = Label(describe, enable_select=False, wrap_width=430, text_size=10)
        main_box.pack_start(title_box, False, False)
        main_box.pack_start(create_separator_box(), False, True)
        main_box.pack_start(describe_label, False, False)

        links_table = gtk.Table(4, 2)

        links = [
                (_('Weibo: '), None, 'http://weibo.com/linuxdeepinnew'),
                (_('Forum: '), None, 'http://www.linuxdeepin.com/forum'),
                (_('Feedback: '), None, 'http://www.linuxdeepin.com/mantis'),
                (_('Game deliver: '), '*****@*****.**', 'mailto:[email protected]'),
                ]
        for (i, l) in enumerate(links):
            left_text = Label(l[0])
            left_text_align = self.create_right_align()
            left_text_align.add(left_text)
            right_link = LinkButton(text=l[1], link=l[2])
            links_table.attach(left_text_align, 0, 1, i, i+1, xoptions=gtk.FILL, xpadding=5, ypadding=4)
            links_table.attach(right_link, 1, 2, i, i+1, xoptions=gtk.FILL)
            #main_box.pack_start(self.create_link_box(l[0], l[1], l[2]), False, False)
        
        main_box.pack_start(links_table, False, False)
        main_align = gtk.Alignment()
        main_align.set_padding(20, 0, 20, 20)
        main_align.set(0, 0, 1, 1)
        main_align.add(main_box)
        self.body_box.pack_start(main_align)

        self.ok_button = Button(_('Close'))
        self.ok_button.connect('clicked', self.dialog_close_action)
        ok_button_align = gtk.Alignment(0.5, 0.5, 0, 0)
        ok_button_align.set_padding(9, 11, 0, 10)
        ok_button_align.add(self.ok_button)
        self.right_button_box.pack_start(ok_button_align, False, False)
Example #38
0
class ShareToWeibo(object):
    '''share picture to weibo'''
    def __init__(self, filename=""):
        '''
        init share
        @param filename: the file to share
        '''
        self.upload_image = filename
        self.thumb_width = 188
        self.thumb_height = 168
        self.MAX_CHAR = 140
        #self.__text_frame_color = (0.76, 0.76, 0.76)
        self.__win_width = 602
        open(COOKIE_FILE,'wb').close()

        self.window = DialogBox(_("Share to social networks"), close_callback=gtk.main_quit)
        self.window.set_keep_above(True)
        self.window.set_size_request(self.__win_width+20, 288)
        self.window.set_resizable(False)
        #self.window.titlebar.connect("expose-event", self.__expose_top_and_bottome)
        #self.window.button_box.connect("expose-event", self.__expose_top_and_bottome)

        # create slider
        self.slider = HSlider()
        self.slider_list = []

        self.share_box = gtk.VBox(False)     # first page, input context
        self.web_box = gtk.VBox(False, 10)      # second page, login
        self.result_box = gtk.VBox(False, 10)   # third page, share result

        share_align = gtk.Alignment()
        share_align.set(0.5, 0.5, 0, 0)
        share_align.add(self.share_box)
        share_align.connect("expose-event", self.__slider_expose)

        # go back button
        web_left_button = ImageButton(
            app_theme.get_pixbuf("share/back_normal.png"),
            app_theme.get_pixbuf("share/back_hover.png"),
            app_theme.get_pixbuf("share/back_press.png"))
        web_left_button.connect("clicked", lambda w: self.set_slide_index(0))
        web_left_button.set_can_focus(False)
        utils.set_clickable_cursor(web_left_button)
        # show url entry
        self.web_url_entry = InputEntry()
        self.web_url_entry.set_editable(False)
        self.web_url_entry.set_size(555, 20)
        self.web_url_entry.entry.right_menu_visible_flag = False
        # alig url entry
        web_navigate_vbox = gtk.VBox(False)
        web_navigate_vbox.pack_start(self.web_url_entry)
        web_navigate_t_align = gtk.Alignment()
        web_navigate_t_align.set(0.0, 0.5, 0, 0)
        web_navigate_t_align.add(web_navigate_vbox)
        # pack back button and url entry
        web_navigate_box = gtk.HBox(False, 7)
        web_navigate_box.pack_start(web_left_button, False, False)
        web_navigate_box.pack_start(web_navigate_t_align)

        web_navigate_align = gtk.Alignment()
        web_navigate_align.set(0.5, 0.5, 0, 0)
        web_navigate_align.set_padding(4, 0, 11, 13)
        web_navigate_align.add(web_navigate_box)

        # create a webkit
        self.web_view = WebView(COOKIE_FILE)
        self.web_view.connect("notify::load-status", self.web_view_load_status)
        self.web_view.connect("load-error", self.web_view_load_error)
        self.web_scrolled_window = ScrolledWindow()
        self.web_scrolled_window.add(self.web_view)
        self.web_scrolled_window.set_size_request(590, 228)

        self.web_box.pack_start(web_navigate_align, False, False)
        self.web_box.pack_start(self.web_scrolled_window)
        #self.web_box.set_size_request(-1, 258)
        web_align = gtk.Alignment()
        web_align.set(0.5, 0.0, 0, 1)
        web_align.add(self.web_box)
        web_align.connect("expose-event", self.__slider_expose)

        res_align = gtk.Alignment()
        res_align.set(0.5, 0.5, 0, 0)
        res_align.add(self.result_box)
        res_align.connect("expose-event", self.__slider_expose)

        self.slider.set_to_page(share_align)
        self.slider_list.append(share_align)
        self.slider_list.append(web_align)
        self.slider_list.append(res_align)

        self.__weibo_list = []
        self.sina = weibo.Sina(self.web_view)
        self.qq = weibo.Tencent(self.web_view)
        self.__weibo_list.append(self.sina)
        self.__weibo_list.append(self.qq)
        if default_locale != 'zh_CN':
            self.twitter = weibo.Twitter(self.web_view)
            #self.__weibo_list.append(self.twitter)
        self.__current_weibo = None

        self.weibo_name_l18n = {
                'Sina': _("Sina"),
                'Tencent': _("Tencent"),
                'Twitter': _("Twitter"),
                }

        self.window.body_box.pack_start(self.slider, True, True)
        self.init_share_box()

    # webkit load-status, login success, go back
    def web_view_load_status(self, web, status):
        '''web_view notify load-status callback'''
        state = web.get_property("load-status")
        url = web.get_property('uri')
        if url:
            self.web_url_entry.set_editable(True)
            self.web_url_entry.set_text(url)
            self.web_url_entry.entry.move_to_start()
            self.web_url_entry.set_editable(False)
        if state == webkit.LOAD_FAILED:  # load failed
            print "load failed",
            print web.get_property('uri')

        elif state == webkit.LOAD_COMMITTED:
            if self.__current_weibo and self.__current_weibo.is_callback_url(url):
                web.stop_loading()  # if go to  callback url, stop loading
                # access token
                #print "load committed", url
                t = threading.Thread(target=self.weibo_login_thread)
                t.setDaemon(True)
                t.start()

    def web_view_load_error(self, web, fram, url, error, data=None):
        web.load_string(
            "<html><body><p><h1>%s</h1></p>%s</body></html>" % (
            _("Unable to load page"),
            _("Problem occurred while loading the URL '%s'") % (url)),
            "text/html", "UTF-8", "")
        print url
        return True

    # login or switch user
    def weibo_login(self, widget, weibo):
        '''weibo button clicked callback'''
        self.web_view.load_uri("about:blank")
        utils.set_cursor(widget)
        self.set_slide_index(1)
        self.__current_weibo = weibo
        t = threading.Thread(target=self.__current_weibo.request_oauth)
        t.setDaemon(True)
        t.start()

    def weibo_login_thread(self):
        '''in webkit login finish, get user info again'''
        self.__current_weibo.access_token()
        self.get_user_info_again()
        gtk.gdk.threads_enter()
        self.set_slide_index(0)
        gtk.gdk.threads_leave()

    def get_user_info_again(self):
        ''' login or switch user, and get user info again'''
        box = self.__current_weibo.get_box()
        #print "cuurent weibo:", self.__current_weibo.t_type
        gtk.gdk.threads_enter()
        children = box.get_children()
        for child in children:
            if child in self.__weibo_check_button_list:
                self.__weibo_check_button_list.remove(child)
            if child in self.__weibo_image_button_list:
                self.__weibo_image_button_list.remove(child)
            child.destroy()
        gtk.gdk.threads_leave()

        self.get_user_info(self.__current_weibo)

        gtk.gdk.threads_enter()
        box.show_all()
        gtk.gdk.threads_leave()

    def set_slide_index(self, index):
        '''
        set slide to index
        @param index: the index of widget in slider, an int num
        '''
        if index >= len(self.slider_list):
            return
        direct = "right"
        if index == 1 and self.window.button_box in self.window.window_frame.get_children():
            #self.slider.set_size_request(-1, 260)
            win = self.window
            if win.left_button_box in win.button_box.get_children():
                win.button_box.remove(win.left_button_box)
            if win.right_button_box in win.button_box.get_children():
                win.button_box.remove(win.right_button_box)
            tmp = gtk.HSeparator()
            tmp.set_size_request(-1, 1)
            tmp.show()
            win.button_box.pack_start(tmp)
            direct = "right"
            #if self.window.button_box in self.window.window_frame.get_children():
                #self.window.window_frame.remove(self.window.button_box)
        elif index == 0:
            #self.slider.set_size_request(-1, 223)
            win = self.window
            for each in win.button_box.get_children():
                each.destroy()
            if win.left_button_box not in win.button_box.get_children():
                win.button_box.pack_start(win.left_button_box)
            if win.right_button_box not in win.button_box.get_children():
                win.button_box.pack_start(win.right_button_box)
            direct = "left"
            #if self.window.button_box not in self.window.window_frame.get_children():
                #self.window.window_frame.pack_start(self.window.button_box, False, False)
        elif index == 2:
            self.window.left_button_box.set_buttons([])
            l = Label("  ")
            l.show()
            self.window.right_button_box.set_buttons([l])
            direct = "right"
            #self.slider.set_size_request(-1, 223)

        self.slider.slide_to_page(self.slider_list[index], direct)

    def weibo_check_toggle(self, button, weibo):
        '''weibo check button toggled callback. check the weibo to share'''
        if button.get_active():
            self.to_share_weibo[weibo] = 1
        else:
            self.to_share_weibo[weibo] = 0

    def create_ico_image(self, name):
        ''' create image from file'''
        pix1 = app_theme_get_dynamic_pixbuf('image/share/%s.png' % name).get_pixbuf()
        pix2 = app_theme_get_dynamic_pixbuf('image/share/%s_no.png' % name).get_pixbuf()
        return (pix1, pix2)

    def get_user_info(self, weibo):
        '''get weibo user info'''
        info = weibo.get_user_name()
        gtk.gdk.threads_enter()
        #self.get_user_error_text = ""
        weibo_hbox = weibo.get_box()
        hbox = gtk.HBox(False)
        vbox = gtk.VBox(False)
        weibo_hbox.pack_start(vbox, False, False)
        vbox.pack_start(hbox)
        #print weibo.t_type, info
        if info:
            self.is_get_user_info[weibo] = 1
            label = Label(text=info, label_width=70, enable_select=False)
            check = CheckButton()
            #check = gtk.CheckButton()
            check.connect("toggled", self.weibo_check_toggle, weibo)
            check.set_active(True)
            check_vbox = gtk.VBox(False)
            check_align = gtk.Alignment(0.5, 0.5, 0, 0)
            check_align.add(check_vbox)
            check_vbox.pack_start(check, False, False)
            button = ImageButton(
                app_theme.get_pixbuf("share/" + weibo.t_type + ".png"),
                app_theme.get_pixbuf("share/" + weibo.t_type + ".png"),
                app_theme.get_pixbuf("share/" + weibo.t_type + ".png"))
            utils.set_clickable_cursor(button)
            button.connect("enter-notify-event", self.show_tooltip, _("Click to switch user"))
            hbox.pack_start(check_align, False, False)
            hbox.pack_start(button, False, False, 5)
            hbox.pack_start(label, False, False)
        else:
            self.is_get_user_info[weibo] = 0
            check = CheckButton()
            #check = gtk.CheckButton()
            check.set_sensitive(False)
            check_vbox = gtk.VBox(False)
            check_align = gtk.Alignment(0.5, 0.5, 0, 0)
            check_align.add(check_vbox)
            check_vbox.pack_start(check, False, False)
            button = ImageButton(
                app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png"),
                app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png"),
                app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png"))
            utils.set_clickable_cursor(button)
            button.connect("enter-notify-event", self.show_tooltip, _("Click to login"))
            hbox.pack_start(check_align, False, False)
            hbox.pack_start(button, False, False, 5)
            # curl time out
            info_error = weibo.get_curl_error()
            if info_error:
                #self.get_user_error_text += "%s:%s." % (weibo.t_type, _(info_error))
                hbox.pack_start(
                    Label(text="(%s)" % _(info_error), label_width=70,enable_select=False,
                    text_color = ui_theme.get_color("category_item")), False, False)

        button.connect("clicked", self.weibo_login, weibo)
        self.__weibo_check_button_list.append(check)
        self.__weibo_image_button_list.append(button)
        gtk.gdk.threads_leave()
        return weibo_hbox

    def show_tooltip(self, widget, event, text):
        '''Create help tooltip.'''
        Tooltip.text(widget, text)

    def init_user_info_thread(self, button, text_view):
        '''get user name thread'''
        time.sleep(0.1)

        for weibo in self.__weibo_list:
            self.get_user_info(weibo)

        gtk.gdk.threads_enter()
        #self.share_box.set_sensitive(True)
        button.set_sensitive(True)
        text_view.set_editable(True)
        for weibo in self.__weibo_list:
            weibo.get_box().show_all()
            weibo.get_box().queue_draw()
        self.loading_label.destroy()
        gtk.gdk.threads_leave()

    # init share box, create share button, input
    def init_share_box(self):
        '''get weibo info, and create button'''
        self.to_share_weibo = {}
        self.to_share_weibo_res = {}
        self.deepin_info = {}
        self.is_get_user_info = {}
        self.__weibo_check_button_list = []
        self.__weibo_image_button_list = []

        # create Thumbnail
        if exists(self.upload_image):
            pixbuf = gtk.gdk.pixbuf_new_from_file(self.upload_image)
            pix_w = pixbuf.get_width()
            pix_h = pixbuf.get_height()
            if pix_w > pix_h:
                pix_s_w = self.thumb_width
                pix_s_h = int(pix_h / (float(pix_w) / self.thumb_width))
            else:
                pix_s_h = self.thumb_height
                pix_s_w = int(pix_w / (float(pix_h) / self.thumb_height))
            pixbuf = pixbuf.scale_simple(pix_s_w, pix_s_h, gtk.gdk.INTERP_TILES)
            thumb = gtk.image_new_from_pixbuf(pixbuf)
        else:
            thumb = gtk.Image()
        thumb.set_size_request(self.thumb_width, self.thumb_height)

        # weibo context input
        text_box = gtk.HBox(False, 2)
        text_vbox = gtk.VBox(False, 2)
        text_bg_vbox = gtk.VBox(False)
        text_bg_align = gtk.Alignment()
        text_bg_align.set(0.5, 0.5, 0, 0)
        text_bg_align.set_padding(5, 5, 16, 5)
        text_bg_align.connect("expose-event", self.text_view_bg_expose)
        text_scrolled_win = gtk.ScrolledWindow()
        text_scrolled_win.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
        text_scrolled_win.set_size_request(340, 157)

        text_view = gtk.TextView()
        text_view.set_left_margin(10)
        text_view.set_right_margin(10)
        text_view.set_pixels_above_lines(5)
        text_view.set_pixels_below_lines(5)
        text_view.set_wrap_mode(gtk.WRAP_WORD| gtk.WRAP_CHAR)
        text_view.connect("expose-event", self.text_view_expose)
        buf = text_view.get_buffer()
        text_scrolled_win.add(text_view)
        text_bg_vbox.pack_start(text_scrolled_win)
        text_bg_align.add(text_bg_vbox)

        text_align = gtk.Alignment()
        text_align.set(0.5, 0.5, 0, 0)
        text_align.set_padding(25, 30, 10, 10)

        text_box.pack_start(thumb, False, False, 10)
        text_box.pack_start(text_bg_align)
        text_vbox.pack_start(text_box, False, False, 10)

        text_align.add(text_vbox)
        #tmp_align = gtk.Alignment()
        #tmp_align.set(0.5, 0, 0, 1)
        #self.share_box.pack_start(tmp_align, False, False)
        self.share_box.pack_start(text_align, False, False)

        # dialog button box
        left_box = self.window.left_button_box
        right_box = self.window.right_button_box

        # input tip label
        self.input_num_label = Label("%d" % self.MAX_CHAR,
            text_size=16, text_x_align=pango.ALIGN_CENTER, label_width=50, enable_select=False)
        self.input_num_label.text_color = ui_theme.get_color("label_select_text")

        # login box
        #weibo_box = gtk.HBox(False, 1)
        #weibo_box.set_size_request(-1, 50)
        weibo_box_list = []
        self.loading_label = Label("%s..." % _("Loading"), text_size=12,
            label_width=70, enable_select=False)
        weibo_box_list.append(self.loading_label)

        for weibo in self.__weibo_list:
            box = gtk.HBox(False, 2)
            weibo.set_box(box)
            weibo_box_list.append(box)
        left_box.set_buttons(weibo_box_list)

        # share button
        button = Button(_("Share"))
        #button.set_size_request(75, 25)
        button.connect("clicked", self.share_button_clicked, text_view)
        buf.connect("changed", self.text_view_changed, button)  # check char num

        tmp_vbox = gtk.VBox(False)
        tmp_align = gtk.Alignment()
        tmp_align.set(0.5, 0.5, 0, 0)
        tmp_vbox.pack_start(button, False, False)
        #tmp_vbox.pack_start(tmp_align)
        tmp_align.add(tmp_vbox)
        right_box.set_buttons([self.input_num_label, tmp_align])

        # at first, set widget insensitive
        button.set_sensitive(False)
        text_view.set_editable(False)
        t = threading.Thread(target=self.init_user_info_thread, args=(button, text_view))
        t.setDaemon(True)
        t.start()

    # draw text view background
    def text_view_bg_expose(self, widget, event):
        '''draw text view bg'''
        cr = widget.window.cairo_create()
        rect = widget.allocation
        text_pixbuf = app_theme_get_dynamic_pixbuf('image/share/text_view.png').get_pixbuf()
        draw.draw_pixbuf(cr, text_pixbuf, rect.x, rect.y)

    # if text is empty, show tip info
    def text_view_expose(self, text_view, event):
        '''text_view expose'''
        buf = text_view.get_buffer()
        text = buf.get_text(*buf.get_bounds())

        if text == "" and text_view.get_editable() and not text_view.is_focus():
            win = text_view.get_window(gtk.TEXT_WINDOW_TEXT)
            cr = win.cairo_create()
            cr.move_to(10, 5)
            context = pangocairo.CairoContext(cr)
            layout = context.create_layout()
            layout.set_font_description(pango.FontDescription("Snas 10"))
            layout.set_alignment(pango.ALIGN_LEFT)
            layout.set_text(_("Please input text here"))
            cr.set_source_rgb(0.66, 0.66, 0.66)
            context.update_layout(layout)
            context.show_layout(layout)

    # show input char num
    def text_view_changed(self, buf, button):
        '''text_view changed callback'''
        count = buf.get_char_count()
        if count <= self.MAX_CHAR:
            #self.input_tip_label.set_text(_("left"))
            self.input_num_label.set_text("%d" % (self.MAX_CHAR - count))
            self.input_num_label.text_color = ui_theme.get_color("category_item")
            if not button.is_sensitive():
                button.set_sensitive(True)
        else:
            #self.input_tip_label.set_text(_("exceeds"))
            self.input_num_label.set_text("-%d" % (count - self.MAX_CHAR))
            self.input_num_label.text_color = ui_theme.get_color("category_item")
            if button.is_sensitive():
                button.set_sensitive(False)

    def show_confirm_dialog(self, title, content):
        d = ConfirmDialog(
                title,
                content,
                text_wrap_width=300,
                )
        d.show_all()
        d.set_transient_for(self.window)

    def share_button_clicked(self, button, text_view):
        '''share_button_clicked callback'''
        # file is not exist.
        if not exists(self.upload_image):
            self.show_confirm_dialog(
                    _("Error"),
                    _("Nonexistent picture"),
                    )
            return False
        has_share_web = False
        for weibo in self.to_share_weibo:
            if self.to_share_weibo[weibo]:
                has_share_web = True
                break
        # have no web selected
        if not has_share_web:
            self.show_confirm_dialog(
                    _("Error"),
                    _("Please choose at least one platform to share on"),
                    )
            return False
        # at first, set widget insensitive
        button.set_sensitive(False)
        text_view.set_editable(False)
        #self.window.left_button_box.set_sensitive(False)
        # set weibo checkbutton sensitive
        for check in self.__weibo_check_button_list:
            check.set_sensitive(False)
        # disconnect weibo ico button clicked function
        for img in self.__weibo_image_button_list:
            try:
                img.disconnect_by_func(self.weibo_login)
            except:
                pass
        button.set_label(_("Sharing"))
        t = threading.Thread(target=self.share_to_weibo_thread, args=(text_view, ))
        t.setDaemon(True)
        t.start()

    # upload image thread
    def share_to_weibo_thread(self, text_view):
        '''share in thread'''
        buf = text_view.get_buffer()
        text = buf.get_text(*buf.get_bounds())
        if text.strip() == "":
            text = _("from Deepin Game")
        # get deepin official info
        self.deepin_info[self.sina] = self.sina.get_deepin_info()
        self.deepin_info[self.qq] = self.qq.get_deepin_info()
        if default_locale != 'zh_CN':
            self.deepin_info[self.twitter] = self.twitter.get_deepin_info()
        # upload
        for weibo in self.to_share_weibo:
            if self.to_share_weibo[weibo]:
                self.to_share_weibo_res[weibo] = weibo.upload_image(self.upload_image, text)
        self.share_to_weibo_result()

    # show upload result
    @post_gui
    def share_to_weibo_result(self):
        '''result of share to weibo'''
        font_color = ui_theme.get_color("category_item")
        res_hbox = gtk.HBox(False)
        res_hbox.set_size_request(-1, 240)

        res_left_box = DialogLeftButtonBox()
        res_right_box = DialogRightButtonBox()

        res_left_box.button_align.set(0.5, 0.0, 0, 1)
        res_right_box.button_align.set(0.5, 0.0, 0, 1)
        res_left_box.button_align.set_padding(5, 9, 19, 0)
        res_right_box.button_align.set_padding(30, 0, 0, 0)

        res_left_box.set_size_request(405, -1)
        res_right_box.set_size_request(195, -1)

        res_hbox.pack_start(res_left_box)
        res_hbox.pack_start(
            VSeparator(app_theme.get_shadow_color("VSeparator").get_color_info(), 0, 0))
        res_hbox.pack_start(res_right_box)

        res_vbox = gtk.VBox(False)
        follow_vbox = gtk.VBox(False)

        tmp_img = gtk.Image()       # only use as a placeholder
        tmp_img.set_size_request(-1, 50)
        res_vbox.pack_start(tmp_img, False, False)

        follow_tip_hbox = gtk.HBox(False)
        img = gtk.image_new_from_icon_name("deepin-logo", 16)
        if img.get_pixel_size() == -1:
            img = gtk.image_new_from_file(app_theme.get_theme_file_path("image/share/deepin_logo.png"))
        follow_tip_hbox.pack_start(img, False, False, 5)
        follow_tip_hbox.pack_start(
            Label("%s %s" % (_("Follow"), "Linux Deepin"),
                text_color=app_theme_get_dynamic_color("#5f5f5f"),
                text_size=12, enable_select=False), False, False)
        follow_vbox.pack_start(follow_tip_hbox, False, False, 13)
        for weibo in self.to_share_weibo_res:
            vbox = gtk.VBox(False, 1)
            tip_box = gtk.HBox()
            error_box = gtk.HBox()
            vbox.pack_start(tip_box, False, False)
            vbox.pack_start(error_box, False, False)
            if self.to_share_weibo_res[weibo][0]:   # upload succeed
                img = gtk.image_new_from_file(app_theme.get_theme_file_path("image/share/share_succeed.png"))
                #link = LinkButton(_(weibo.t_type), text_size=13, self.to_share_weibo_res[weibo][1])
                link = Label(self.weibo_name_l18n[weibo.t_type], text_size=12,
                    text_color=ui_theme.get_color("link_text"))
                #, enable_gaussian=True, gaussian_radious=1, border_radious=0)
                link.add_events(gtk.gdk.BUTTON_PRESS_MASK)
                link.connect("enter-notify-event", lambda w, e: self.__draw_under_line(w))
                link.connect("leave-notify-event", lambda w, e: w.queue_draw())
                link.connect("button-press-event", self.goto_weibo_button_clicked, weibo)
                link_box = gtk.HBox(False)
                link_box.pack_start(link, False, False)
                utils.set_clickable_cursor(link)
                text = _("Share to")
                label = Label(text, text_size=12,
                    text_color=font_color, enable_select=False)
                text = _("Successful")
                label1 = Label(text, text_size=12,
                    text_color=font_color, enable_select=False)
                tip_box.pack_start(img, False, False, 15)
                tip_box.pack_start(label, False, False, 3)
                tip_box.pack_start(link_box, False, False, 3)
                tip_box.pack_start(label1, False, False)
                # only use as a placeholder
                img = gtk.Image()
                img.set_size_request(20, 1)
                error_box.pack_start(img, False, False, 16)
                tmp = Label(" ", text_size=9, label_width=200)
                tmp.set_size_request(200, 1)
                error_box.pack_start(tmp, False, False)
                #print text
            else:   # upload failed
                img = gtk.image_new_from_file(app_theme.get_theme_file_path("image/share/share_failed.png"))
                #text = "% %s %s." % (_(weibo.t_type), _("upload failed"))
                text = _("Share to")
                label1 = Label(text, text_size=12,
                    text_color=font_color, enable_select=False)
                label2 = Label(_(weibo.t_type), text_size=12,
                    text_color=font_color, enable_select=False)
                text = _("Failed")
                label3 = Label(text, text_size=12,
                    text_color=font_color, enable_select=False)
                if weibo.curl.error:
                    error = "(%s)" % _(weibo.curl.error)
                elif weibo.get_error_msg():
                    error = "(%s)" % _(weibo.get_error_msg())
                else:
                    error = "(%s)" % _("Unknown reason")
                #print "%s: %s" % (weibo.t_type, error)
                #print "%s: %s" % (weibo.t_type, weibo.get_error_msg())
                label = Label(text, text_size=12,
                    text_color=font_color, enable_select=False)
                tip_box.pack_start(img, False, False, 15)
                tip_box.pack_start(label1, False, False, 3)
                tip_box.pack_start(label2, False, False, 3)
                tip_box.pack_start(label3, False, False)
                img = gtk.Image()   # only use as a placeholder
                img.set_size_request(20, 20)
                error_box.pack_start(img, False, False, 16)
                error_box.pack_start(Label(error, text_size=9, label_width=200,
                    text_color=font_color, enable_select=False), False, False)
                #print text
            res_vbox.pack_start(vbox, False, False, 10)

        for weibo in self.deepin_info:
            box = gtk.HBox(False, 15)
            # followed
            img = gtk.image_new_from_pixbuf(app_theme.get_pixbuf("share/"+weibo.t_type+".png").get_pixbuf())
            box.pack_start(img, False, False)
            if self.deepin_info[weibo] is not None and self.deepin_info[weibo][3]:
                if not default_locale.startswith("zh_"):
                    button = gtk.image_new_from_pixbuf(
                        app_theme.get_pixbuf("share/followed_en.png").get_pixbuf())
                else:
                    button = gtk.image_new_from_pixbuf(
                        app_theme.get_pixbuf("share/followed.png").get_pixbuf())
            else:   # to follow
                if not default_locale.startswith("zh_"):
                    button = ImageButton(
                        app_theme.get_pixbuf("share/follow_normal_en.png"),
                        app_theme.get_pixbuf("share/follow_hover_en.png"),
                        app_theme.get_pixbuf("share/follow_press_en.png"))
                else:
                    button = ImageButton(
                        app_theme.get_pixbuf("share/follow_normal.png"),
                        app_theme.get_pixbuf("share/follow_hover.png"),
                        app_theme.get_pixbuf("share/follow_press.png"))
                button.connect("clicked", self.friendships_add_button_clicked, weibo, box)
            box.pack_start(button, False, False)
            align = gtk.Alignment()
            align.set(0.0, 0.5, 0, 0)
            align.set_padding(0, 0, 30, 0)
            align.add(box)
            follow_vbox.pack_start(align, False, False, 8)

        res_left_box.set_buttons([res_vbox])
        res_right_box.set_buttons([follow_vbox])

        self.result_box.pack_start(res_hbox, False, False)
        self.result_box.show_all()
        self.set_slide_index(2)

    def goto_weibo_button_clicked(self, widget, event, weibo):
        '''goto my weibo'''
        #print "goto weibo button clicked", weibo.t_type, "xdg-open %s" % self.to_share_weibo_res[weibo][1]
        if weibo in self.to_share_weibo_res:
            if self.to_share_weibo_res[weibo][1]:
                webbrowser.open(self.to_share_weibo_res[weibo][1])

    def friendships_add_button_clicked(self, widget, weibo, box):
        '''add friendships'''
        #self.result_box.set_sensitive(False)
        if not self.is_get_user_info[weibo]:
            utils.run_command("xdg-open %s" % weibo.index_url)
            return True

        widget.set_sensitive(False)
        t = threading.Thread(target=self.friendships_add_thread, args=(widget, weibo, box))
        t.setDaemon(True)
        t.start()

    def friendships_add_thread(self, button, weibo, box):
        '''add friendships'''
        if weibo.friendships_create() is not None:
            gtk.gdk.threads_enter()
            button.destroy()
            if not default_locale.startswith("zh_"):
                button = gtk.image_new_from_pixbuf(
                    app_theme.get_pixbuf("share/followed_en.png").get_pixbuf())
            else:
                button = gtk.image_new_from_pixbuf(
                    app_theme.get_pixbuf("share/followed.png").get_pixbuf())
            button.show()
            box.pack_start(button, False, False)
            #button.set_label("已关注")
            gtk.gdk.threads_leave()

    # show window
    def show(self):
        '''show'''
        self.window.show_window()

    # close widnow
    def quit(self, widget):
        ''' close '''
        gtk.main_quit()

    def __slider_expose(self, widget, event):
        ''' slider expose redraw'''
        cr = widget.window.cairo_create()
        rect = widget.allocation
        cr.set_source_rgba(1.0, 1.0, 1.0, 0.8)
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)
        cr.fill()

    def __expose_top_and_bottome(self, widget, event):
        '''titlebar or button_box expose'''
        cr = widget.window.cairo_create()
        rect = widget.allocation
        cr.set_source_rgb(0.89, 0.89, 0.89)
        cr.rectangle(rect.x+2, rect.y+2, rect.width-4, rect.height-4)
        cr.fill()

    def __draw_under_line(self, widget):
        '''draw under line'''
        cr = widget.window.cairo_create()
        with utils.cairo_disable_antialias(cr):
            x, y, w, h = widget.allocation
            # #1A70b1
            cr.set_source_rgba(0.1, 0.43, 0.69, 1.0)
            cr.set_line_width(1)
            cr.move_to(x, y+h-3)
            cr.line_to(x+w, y+h-3)
            cr.stroke()
Example #39
0
    def __init__(self, filename=""):
        '''
        init share
        @param filename: the file to share
        '''
        self.upload_image = filename
        self.thumb_width = 188
        self.thumb_height = 168
        self.MAX_CHAR = 140
        #self.__text_frame_color = (0.76, 0.76, 0.76)
        self.__win_width = 602
        open(COOKIE_FILE,'wb').close()

        self.window = DialogBox(_("Share to social networks"), close_callback=gtk.main_quit)
        self.window.set_keep_above(True)
        self.window.set_size_request(self.__win_width+20, 288)
        self.window.set_resizable(False)
        #self.window.titlebar.connect("expose-event", self.__expose_top_and_bottome)
        #self.window.button_box.connect("expose-event", self.__expose_top_and_bottome)

        # create slider
        self.slider = HSlider()
        self.slider_list = []

        self.share_box = gtk.VBox(False)     # first page, input context
        self.web_box = gtk.VBox(False, 10)      # second page, login
        self.result_box = gtk.VBox(False, 10)   # third page, share result

        share_align = gtk.Alignment()
        share_align.set(0.5, 0.5, 0, 0)
        share_align.add(self.share_box)
        share_align.connect("expose-event", self.__slider_expose)

        # go back button
        web_left_button = ImageButton(
            app_theme.get_pixbuf("share/back_normal.png"),
            app_theme.get_pixbuf("share/back_hover.png"),
            app_theme.get_pixbuf("share/back_press.png"))
        web_left_button.connect("clicked", lambda w: self.set_slide_index(0))
        web_left_button.set_can_focus(False)
        utils.set_clickable_cursor(web_left_button)
        # show url entry
        self.web_url_entry = InputEntry()
        self.web_url_entry.set_editable(False)
        self.web_url_entry.set_size(555, 20)
        self.web_url_entry.entry.right_menu_visible_flag = False
        # alig url entry
        web_navigate_vbox = gtk.VBox(False)
        web_navigate_vbox.pack_start(self.web_url_entry)
        web_navigate_t_align = gtk.Alignment()
        web_navigate_t_align.set(0.0, 0.5, 0, 0)
        web_navigate_t_align.add(web_navigate_vbox)
        # pack back button and url entry
        web_navigate_box = gtk.HBox(False, 7)
        web_navigate_box.pack_start(web_left_button, False, False)
        web_navigate_box.pack_start(web_navigate_t_align)

        web_navigate_align = gtk.Alignment()
        web_navigate_align.set(0.5, 0.5, 0, 0)
        web_navigate_align.set_padding(4, 0, 11, 13)
        web_navigate_align.add(web_navigate_box)

        # create a webkit
        self.web_view = WebView(COOKIE_FILE)
        self.web_view.connect("notify::load-status", self.web_view_load_status)
        self.web_view.connect("load-error", self.web_view_load_error)
        self.web_scrolled_window = ScrolledWindow()
        self.web_scrolled_window.add(self.web_view)
        self.web_scrolled_window.set_size_request(590, 228)

        self.web_box.pack_start(web_navigate_align, False, False)
        self.web_box.pack_start(self.web_scrolled_window)
        #self.web_box.set_size_request(-1, 258)
        web_align = gtk.Alignment()
        web_align.set(0.5, 0.0, 0, 1)
        web_align.add(self.web_box)
        web_align.connect("expose-event", self.__slider_expose)

        res_align = gtk.Alignment()
        res_align.set(0.5, 0.5, 0, 0)
        res_align.add(self.result_box)
        res_align.connect("expose-event", self.__slider_expose)

        self.slider.set_to_page(share_align)
        self.slider_list.append(share_align)
        self.slider_list.append(web_align)
        self.slider_list.append(res_align)

        self.__weibo_list = []
        self.sina = weibo.Sina(self.web_view)
        self.qq = weibo.Tencent(self.web_view)
        self.__weibo_list.append(self.sina)
        self.__weibo_list.append(self.qq)
        if default_locale != 'zh_CN':
            self.twitter = weibo.Twitter(self.web_view)
            #self.__weibo_list.append(self.twitter)
        self.__current_weibo = None

        self.weibo_name_l18n = {
                'Sina': _("Sina"),
                'Tencent': _("Tencent"),
                'Twitter': _("Twitter"),
                }

        self.window.body_box.pack_start(self.slider, True, True)
        self.init_share_box()
    def __init__(
        self,
        connection,
        ssid,
        key_mgmt=None,
        default_width=330,
        default_height=120,
        confirm_callback=None,
        cancel_callback=None,
    ):
        '''
        Initialize InputDialog class.
        
        @param title: Input dialog title.
        @param init_text: Initialize input text.
        @param default_width: Width of dialog, default is 330 pixel.
        @param default_height: Height of dialog, default is 330 pixel.
        @param confirm_callback: Callback when user click confirm button, this callback accept one argument that return by user input text.
        @param cancel_callback: Callback when user click cancel button, this callback not need argument.
        '''
        # Init.
        #DialogBox.__init__(self, _("Set password"), default_width, default_height, DIALOG_MASK_SINGLE_PAGE)
        DialogBox.__init__(self,
                           _("Please input password for %s") % ssid,
                           default_width, default_height,
                           DIALOG_MASK_SINGLE_PAGE)

        #self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
        self.confirm_callback = confirm_callback
        self.cancel_callback = cancel_callback

        self.connection = connection

        self.hint_align = gtk.Alignment()
        self.hint_align.set(0.5, 0.5, 0, 0)
        self.hint_align.set_padding(0, 0, 10, 10)
        self.hint_text = Label(_("Please input password for %s") % ssid,
                               enable_select=False,
                               enable_double_click=False)
        self.hint_align.add(self.hint_text)

        self.entry_align = gtk.Alignment()
        self.entry_align.set(0.0, 0.5, 0, 0)
        self.entry_align.set_padding(10, 0, 5, 9)
        if self.connection and isinstance(self.connection, NMRemoteConnection):
            (setting_name, method) = self.connection.guess_secret_info()
            if setting_name and method:
                init_text = nm_module.secret_agent.agent_get_secrets(
                    self.connection.object_path, setting_name, method)
            else:
                init_text = ""
        else:
            tray_log.debug()
            self.connection = nm_module.nm_remote_settings.new_wireless_connection(
                ssid, key_mgmt)
            init_text = ''
        self.entry = PasswordEntry(init_text)
        self.show_key_check = CheckButton(_("Show password"), 0)
        self.show_key_check.connect("toggled", self.show_key_check_button_cb)

        self.entry.set_size(default_width - 22, 25)
        self.main_box = gtk.VBox()
        entry_align = gtk.Alignment(0.0, 0.5, 0, 0)
        entry_align.set_padding(0, 0, 5, 0)
        entry_align.set_size_request(-1, 30)
        entry_align.add(self.entry)
        self.main_box.pack_start(entry_align, False, False)
        self.main_box.pack_start(self.show_key_check, False, False)

        self.confirm_button = Button(_("OK"))
        self.cancel_button = Button(_("Cancel"))

        self.entry.entry.connect("press-return",
                                 lambda w: self.click_confirm_button())
        self.confirm_button.connect("clicked",
                                    lambda w: self.click_confirm_button())
        self.cancel_button.connect("clicked",
                                   lambda w: self.click_cancel_button())

        self.entry_align.add(self.main_box)
        #self.body_box.pack_start(self.hint_align, True, True)
        self.body_box.pack_start(self.entry_align, True, True)

        #self.body_box.pack_start(self.main_box, True, True)

        self.right_button_box.set_buttons(
            [self.cancel_button, self.confirm_button])
        self.connect("show", self.focus_input)
Example #41
0
 def show_window(self):    
     DialogBox.show_window(self)
     self.present()
Example #42
0
class ShareToWeibo(object):
    '''share picture to weibo'''
    def __init__(self, filename=""):
        '''
        init share
        @param filename: the file to share
        '''
        self.upload_image = filename
        self.thumb_width = 188
        self.thumb_height = 168
        self.MAX_CHAR = 140
        #self.__text_frame_color = (0.76, 0.76, 0.76)
        self.__win_width = 602
        open(COOKIE_FILE,'wb').close()

        self.window = DialogBox(_("Share to social networks"), close_callback=gtk.main_quit)
        self.window.set_keep_above(True)
        self.window.set_size_request(self.__win_width+20, 288)
        self.window.set_resizable(False)
        self.window.titlebar.connect("expose-event", self.__expose_top_and_bottome)
        self.window.button_box.connect("expose-event", self.__expose_top_and_bottome)

        # create slider
        self.slider = HSlider()
        self.slider_list = []

        self.share_box = gtk.VBox(False, 2)     # first page, input context
        self.web_box = gtk.VBox(False, 10)      # second page, login
        self.result_box = gtk.VBox(False, 10)   # third page, share result

        share_align = gtk.Alignment()
        share_align.set(0.5, 0.5, 0, 0)
        share_align.add(self.share_box)
        share_align.connect("expose-event", self.__slider_expose)

        # go back button
        web_left_button = ImageButton(
            app_theme.get_pixbuf("share/back_normal.png"),
            app_theme.get_pixbuf("share/back_hover.png"),
            app_theme.get_pixbuf("share/back_press.png"))
        web_left_button.connect("clicked", lambda w: self.set_slide_index(0))
        web_left_button.set_can_focus(False)
        utils.set_clickable_cursor(web_left_button)
        # show url entry
        self.web_url_entry = InputEntry()
        self.web_url_entry.set_editable(False)
        self.web_url_entry.set_size(555, 20)
        self.web_url_entry.entry.right_menu_visible_flag = False
        # alig url entry
        web_navigate_vbox = gtk.VBox(False)
        web_navigate_vbox.pack_start(self.web_url_entry)
        web_navigate_t_align = gtk.Alignment()
        web_navigate_t_align.set(0.0, 0.5, 0, 0)
        web_navigate_t_align.add(web_navigate_vbox)
        # pack back button and url entry
        web_navigate_box = gtk.HBox(False, 7)
        web_navigate_box.pack_start(web_left_button, False, False)
        web_navigate_box.pack_start(web_navigate_t_align)

        web_navigate_align = gtk.Alignment()
        web_navigate_align.set(0.5, 0.5, 0, 0)
        web_navigate_align.set_padding(4, 0, 11, 13)
        web_navigate_align.add(web_navigate_box)

        # create a webkit
        self.web_view = WebView(COOKIE_FILE)
        self.web_view.connect("notify::load-status", self.web_view_load_status)
        self.web_view.connect("load-error", self.web_view_load_error)
        self.web_scrolled_window = ScrolledWindow()
        self.web_scrolled_window.add(self.web_view)
        self.web_scrolled_window.set_size_request(590, 228)

        self.web_box.pack_start(web_navigate_align, False, False)
        self.web_box.pack_start(self.web_scrolled_window)
        #self.web_box.set_size_request(-1, 258)
        web_align = gtk.Alignment()
        web_align.set(0.5, 0.0, 0, 1)
        web_align.add(self.web_box)
        web_align.connect("expose-event", self.__slider_expose)

        res_align = gtk.Alignment()
        res_align.set(0.5, 0.5, 0, 0)
        res_align.add(self.result_box)
        res_align.connect("expose-event", self.__slider_expose)

        self.slider.set_to_page(share_align)
        self.slider_list.append(share_align)
        self.slider_list.append(web_align)
        self.slider_list.append(res_align)

        self.__weibo_list = []
        self.sina = weibo.Sina(self.web_view)
        self.qq = weibo.Tencent(self.web_view)
        self.twitter = weibo.Twitter(self.web_view)
        self.__weibo_list.append(self.sina)
        self.__weibo_list.append(self.qq)
        self.__weibo_list.append(self.twitter)
        self.__current_weibo = None

        self.window.body_box.pack_start(self.slider, True, True)
        self.init_share_box()

    # webkit load-status, login success, go back
    def web_view_load_status(self, web, status):
        '''web_view notify load-status callback'''
        state = web.get_property("load-status")
        url = web.get_property('uri')
        if url:
            self.web_url_entry.set_editable(True)
            self.web_url_entry.set_text(url)
            self.web_url_entry.entry.move_to_start()
            self.web_url_entry.set_editable(False)
        if state == webkit.LOAD_FAILED:  # load failed
            print "load failed",
            print web.get_property('uri')

        elif state == webkit.LOAD_COMMITTED:
            if self.__current_weibo and self.__current_weibo.is_callback_url(url):
                web.stop_loading()  # if go to  callback url, stop loading
                # access token
                #print "load committed", url
                t = threading.Thread(target=self.weibo_login_thread)
                t.setDaemon(True)
                t.start()

    def web_view_load_error(self, web, fram, url, error, data=None):
        web.load_string(
            "<html><body><p><h1>%s</h1></p>%s</body></html>" % (
            _("Unable to load page"),
            _("Problem occurred while loading the URL '%s'") % (url)),
            "text/html", "UTF-8", "")
        print url
        return True
    
    # login or switch user
    def weibo_login(self, widget, weibo):
        '''weibo button clicked callback'''
        self.web_view.load_uri("about:blank")
        utils.set_cursor(widget)
        self.set_slide_index(1)
        self.__current_weibo = weibo
        t = threading.Thread(target=self.__current_weibo.request_oauth)
        t.setDaemon(True)
        t.start()

    def weibo_login_thread(self):
        '''in webkit login finish, get user info again'''
        self.__current_weibo.access_token()
        self.get_user_info_again()
        gtk.gdk.threads_enter()
        self.set_slide_index(0)
        gtk.gdk.threads_leave()

    def get_user_info_again(self):
        ''' login or switch user, and get user info again'''
        box = self.__current_weibo.get_box()
        #print "cuurent weibo:", self.__current_weibo.t_type
        gtk.gdk.threads_enter()
        children = box.get_children()
        for child in children:
            if child in self.__weibo_check_button_list:
                self.__weibo_check_button_list.remove(child)
            if child in self.__weibo_image_button_list:
                self.__weibo_image_button_list.remove(child)
            child.destroy()
        gtk.gdk.threads_leave()

        self.get_user_info(self.__current_weibo)

        gtk.gdk.threads_enter()
        box.show_all()
        gtk.gdk.threads_leave()

    def set_slide_index(self, index):
        '''
        set slide to index
        @param index: the index of widget in slider, an int num
        '''
        if index >= len(self.slider_list):
            return
        direct = "right"
        if index == 1 and self.window.button_box in self.window.window_frame.get_children():
            #self.slider.set_size_request(-1, 260)
            win = self.window
            if win.left_button_box in win.button_box.get_children():
                win.button_box.remove(win.left_button_box)
            if win.right_button_box in win.button_box.get_children():
                win.button_box.remove(win.right_button_box)
            tmp = gtk.HSeparator()
            tmp.set_size_request(-1, 1)
            tmp.show()
            win.button_box.pack_start(tmp)
            direct = "right"
            #if self.window.button_box in self.window.window_frame.get_children():
                #self.window.window_frame.remove(self.window.button_box)
        elif index == 0:
            #self.slider.set_size_request(-1, 223)
            win = self.window
            for each in win.button_box.get_children():
                each.destroy()
            if win.left_button_box not in win.button_box.get_children():
                win.button_box.pack_start(win.left_button_box)
            if win.right_button_box not in win.button_box.get_children():
                win.button_box.pack_start(win.right_button_box)
            direct = "left"
            #if self.window.button_box not in self.window.window_frame.get_children():
                #self.window.window_frame.pack_start(self.window.button_box, False, False)
        elif index == 2:
            self.window.left_button_box.set_buttons([])
            l = Label("  ")
            l.show()
            self.window.right_button_box.set_buttons([l])
            direct = "right"
            #self.slider.set_size_request(-1, 223)
            
        self.slider.slide_to_page(self.slider_list[index], direct)

    def weibo_check_toggle(self, button, weibo):
        '''weibo check button toggled callback. check the weibo to share'''
        if button.get_active():
            self.to_share_weibo[weibo] = 1
        else:
            self.to_share_weibo[weibo] = 0

    def create_ico_image(self, name):
        ''' create image from file'''
        pix1 = app_theme_get_dynamic_pixbuf('image/share/%s.png' % name).get_pixbuf()
        pix2 = app_theme_get_dynamic_pixbuf('image/share/%s_no.png' % name).get_pixbuf()
        return (pix1, pix2)
    
    def get_user_info(self, weibo):
        '''get weibo user info'''
        info = weibo.get_user_name()
        gtk.gdk.threads_enter()
        #self.get_user_error_text = ""
        weibo_hbox = weibo.get_box()
        hbox = gtk.HBox(False)
        vbox = gtk.VBox(False)
        weibo_hbox.pack_start(vbox, False, False)
        vbox.pack_start(hbox)
        #print weibo.t_type, info
        if info:
            self.is_get_user_info[weibo] = 1
            label = Label(text=info, label_width=70, enable_select=False)
            check = CheckButton()
            #check = gtk.CheckButton()
            check.connect("toggled", self.weibo_check_toggle, weibo)
            check.set_active(True)
            check_vbox = gtk.VBox(False)
            check_align = gtk.Alignment(0.5, 0.5, 0, 0)
            check_align.add(check_vbox)
            check_vbox.pack_start(check, False, False)
            button = ImageButton(
                app_theme.get_pixbuf("share/" + weibo.t_type + ".png"),
                app_theme.get_pixbuf("share/" + weibo.t_type + ".png"),
                app_theme.get_pixbuf("share/" + weibo.t_type + ".png"))
            utils.set_clickable_cursor(button)
            button.connect("enter-notify-event", self.show_tooltip, _("Click to switch user"))
            hbox.pack_start(check_align, False, False)
            hbox.pack_start(button, False, False, 5)
            hbox.pack_start(label, False, False)
        else:
            self.is_get_user_info[weibo] = 0
            check = CheckButton()
            #check = gtk.CheckButton()
            check.set_sensitive(False)
            check_vbox = gtk.VBox(False)
            check_align = gtk.Alignment(0.5, 0.5, 0, 0)
            check_align.add(check_vbox)
            check_vbox.pack_start(check, False, False)
            button = ImageButton(
                app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png"),
                app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png"),
                app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png"))
            utils.set_clickable_cursor(button)
            button.connect("enter-notify-event", self.show_tooltip, _("Click to login"))
            hbox.pack_start(check_align, False, False)
            hbox.pack_start(button, False, False, 5)
            # curl time out
            info_error = weibo.get_curl_error()
            if info_error:
                #self.get_user_error_text += "%s:%s." % (weibo.t_type, _(info_error))
                hbox.pack_start(
                    Label(text="(%s)" % _(info_error), label_width=70,enable_select=False,
                    text_color = app_theme.get_color("left_char_num1")), False, False)
            
        button.connect("clicked", self.weibo_login, weibo)
        self.__weibo_check_button_list.append(check)
        self.__weibo_image_button_list.append(button)
        gtk.gdk.threads_leave()
        return weibo_hbox
    
    def show_tooltip(self, widget, event, text):
        '''Create help tooltip.'''
        Tooltip.text(widget, text)

    def init_user_info_thread(self, button, text_view):
        '''get user name thread'''
        time.sleep(0.1)

        for weibo in self.__weibo_list:
            self.get_user_info(weibo)

        gtk.gdk.threads_enter()
        #self.share_box.set_sensitive(True)
        button.set_sensitive(True)
        text_view.set_editable(True)
        for weibo in self.__weibo_list:
            weibo.get_box().show_all()
            weibo.get_box().queue_draw()
        self.loading_label.destroy()
        gtk.gdk.threads_leave()
    
    # init share box, create share button, input
    def init_share_box(self):
        '''get weibo info, and create button'''
        self.to_share_weibo = {}
        self.to_share_weibo_res = {}
        self.deepin_info = {}
        self.is_get_user_info = {}
        self.__weibo_check_button_list = []
        self.__weibo_image_button_list = []

        # create Thumbnail
        if exists(self.upload_image):
            pixbuf = gtk.gdk.pixbuf_new_from_file(self.upload_image)
            pix_w = pixbuf.get_width()
            pix_h = pixbuf.get_height()
            if pix_w > pix_h:
                pix_s_w = self.thumb_width
                pix_s_h = int(pix_h / (float(pix_w) / self.thumb_width))
            else:
                pix_s_h = self.thumb_height
                pix_s_w = int(pix_w / (float(pix_h) / self.thumb_height))
            pixbuf = pixbuf.scale_simple(pix_s_w, pix_s_h, gtk.gdk.INTERP_TILES)
            thumb = gtk.image_new_from_pixbuf(pixbuf)
        else:
            thumb = gtk.Image()
        thumb.set_size_request(self.thumb_width, self.thumb_height)

        # weibo context input
        text_box = gtk.HBox(False, 2)
        text_vbox = gtk.VBox(False, 2)
        text_bg_vbox = gtk.VBox(False)
        text_bg_align = gtk.Alignment()
        text_bg_align.set(0.5, 0.5, 0, 0)
        text_bg_align.set_padding(5, 5, 16, 5)
        text_bg_align.connect("expose-event", self.text_view_bg_expose)
        text_scrolled_win = ScrolledWindow()
        text_scrolled_win.set_size_request(340, 157)

        text_view = gtk.TextView()
        text_view.set_left_margin(10)
        text_view.set_right_margin(10)
        text_view.set_pixels_above_lines(5)
        text_view.set_pixels_below_lines(5)
        text_view.set_wrap_mode(gtk.WRAP_WORD| gtk.WRAP_CHAR)
        text_view.connect("expose-event", self.text_view_expose)
        buf = text_view.get_buffer()
        text_scrolled_win.add(text_view)
        text_bg_vbox.pack_start(text_scrolled_win)
        text_bg_align.add(text_bg_vbox)

        text_align = gtk.Alignment() 
        text_align.set(0.5, 0.5, 0, 0)
        text_align.set_padding(25, 30, 10, 10)

        text_box.pack_start(thumb, False, False, 10)
        text_box.pack_start(text_bg_align)
        text_vbox.pack_start(text_box, False, False, 10)

        text_align.add(text_vbox)
        #tmp_align = gtk.Alignment()
        #tmp_align.set(0.5, 0, 0, 1)
        #self.share_box.pack_start(tmp_align, False, False)
        self.share_box.pack_start(text_align, False, False)

        # dialog button box
        left_box = self.window.left_button_box
        right_box = self.window.right_button_box

        # input tip label
        self.input_num_label = Label("%d" % self.MAX_CHAR,
            text_size=16, text_x_align=pango.ALIGN_CENTER, label_width=50, enable_select=False)
        self.input_num_label.text_color = app_theme.get_color("left_char_num")

        # login box
        #weibo_box = gtk.HBox(False, 1)
        #weibo_box.set_size_request(-1, 50)
        weibo_box_list = []
        self.loading_label = Label("%s..." % _("Loading"), text_size=12,
            label_width=70, enable_select=False)
        weibo_box_list.append(self.loading_label)

        for weibo in self.__weibo_list:
            box = gtk.HBox(False, 2)
            weibo.set_box(box)
            weibo_box_list.append(box)
        left_box.set_buttons(weibo_box_list)

        # share button
        button = Button(_("Share"))
        #button.set_size_request(75, 25)
        button.connect("clicked", self.share_button_clicked, text_view)
        buf.connect("changed", self.text_view_changed, button)  # check char num

        tmp_vbox = gtk.VBox(False)
        tmp_align = gtk.Alignment()
        tmp_align.set(0.5, 0.5, 0, 0)
        tmp_vbox.pack_start(button, False, False)
        #tmp_vbox.pack_start(tmp_align)
        tmp_align.add(tmp_vbox)
        right_box.set_buttons([self.input_num_label, tmp_align])

        # at first, set widget insensitive
        button.set_sensitive(False)
        text_view.set_editable(False)
        t = threading.Thread(target=self.init_user_info_thread, args=(button, text_view))
        t.setDaemon(True)
        t.start()

    # draw text view background
    def text_view_bg_expose(self, widget, event):
        '''draw text view bg'''
        cr = widget.window.cairo_create()
        rect = widget.allocation
        text_pixbuf = app_theme_get_dynamic_pixbuf('image/share/text_view.png').get_pixbuf()
        draw.draw_pixbuf(cr, text_pixbuf, rect.x, rect.y)

    # if text is empty, show tip info
    def text_view_expose(self, text_view, event):
        '''text_view expose'''
        buf = text_view.get_buffer()
        text = buf.get_text(*buf.get_bounds())

        if text == "" and text_view.get_editable() and not text_view.is_focus():
            win = text_view.get_window(gtk.TEXT_WINDOW_TEXT)
            cr = win.cairo_create()
            cr.move_to(10, 5)
            context = pangocairo.CairoContext(cr)
            layout = context.create_layout()
            layout.set_font_description(pango.FontDescription("Snas 10"))
            layout.set_alignment(pango.ALIGN_LEFT)
            layout.set_text(_("Please input text here"))
            cr.set_source_rgb(0.66, 0.66, 0.66)
            context.update_layout(layout)
            context.show_layout(layout)
    
    # show input char num
    def text_view_changed(self, buf, button):
        '''text_view changed callback'''
        count = buf.get_char_count()
        if count <= self.MAX_CHAR:
            #self.input_tip_label.set_text(_("left"))
            self.input_num_label.set_text("%d" % (self.MAX_CHAR - count))
            self.input_num_label.text_color = app_theme.get_color("left_char_num")
            if not button.is_sensitive():
                button.set_sensitive(True)
        else:
            #self.input_tip_label.set_text(_("exceeds"))
            self.input_num_label.set_text("-%d" % (count - self.MAX_CHAR))
            self.input_num_label.text_color = app_theme.get_color("left_char_num1")
            if button.is_sensitive():
                button.set_sensitive(False)

    def share_button_clicked(self, button, text_view):
        '''share_button_clicked callback'''
        # file is not exist.
        if not exists(self.upload_image):
            d = ConfirmDialog(_("Error"), "%s." % ( _("Picture does not exist.")))
            d.show_all()
            d.set_transient_for(self.window)
            return False
        has_share_web = False
        for weibo in self.to_share_weibo:
            if self.to_share_weibo[weibo]:
                has_share_web = True
                break
        # have no web selected
        if not has_share_web:
            d = ConfirmDialog(_("Error"), _("Please choose at least one platform to share on"))
            d.show_all()
            d.set_transient_for(self.window)
            return False
        # at first, set widget insensitive
        button.set_sensitive(False)
        text_view.set_editable(False)
        #self.window.left_button_box.set_sensitive(False)
        # set weibo checkbutton sensitive
        for check in self.__weibo_check_button_list:
            check.set_sensitive(False)
        # disconnect weibo ico button clicked function
        for img in self.__weibo_image_button_list:
            try:
                img.disconnect_by_func(self.weibo_login)
            except:
                pass
        button.set_label(_("Uploading"))
        t = threading.Thread(target=self.share_to_weibo_thread, args=(text_view, ))
        t.setDaemon(True)
        t.start()
    
    # upload image thread
    def share_to_weibo_thread(self, text_view):
        '''share in thread'''
        buf = text_view.get_buffer()
        text = buf.get_text(*buf.get_bounds())
        if text.strip() == "":
            text = _("from Deepin Screenshot")
        # get deepin official info
        self.deepin_info[self.sina] = self.sina.get_deepin_info()
        self.deepin_info[self.qq] = self.qq.get_deepin_info()
        if default_locale != 'zh_CN':
            self.deepin_info[self.twitter] = self.twitter.get_deepin_info()
        # upload
        for weibo in self.to_share_weibo:
            if self.to_share_weibo[weibo]:
                self.to_share_weibo_res[weibo] = weibo.upload_image(self.upload_image, text)
        self.share_to_weibo_result()
    
    # show upload result
    @post_gui
    def share_to_weibo_result(self):
        '''result of share to weibo'''
        font_color = app_theme.get_color("share_result_text")
        res_hbox = gtk.HBox(False)
        res_hbox.set_size_request(-1, 240)

        res_left_box = DialogLeftButtonBox()
        res_right_box = DialogRightButtonBox()

        res_left_box.button_align.set(0.5, 0.0, 0, 1)
        res_right_box.button_align.set(0.5, 0.0, 0, 1)
        res_left_box.button_align.set_padding(5, 9, 19, 0)
        res_right_box.button_align.set_padding(30, 0, 0, 0)

        res_left_box.set_size_request(405, -1)
        res_right_box.set_size_request(195, -1)
        
        res_hbox.pack_start(res_left_box)
        res_hbox.pack_start(
            VSeparator(app_theme.get_shadow_color("VSeparator").get_color_info(), 0, 0))
        res_hbox.pack_start(res_right_box)

        res_vbox = gtk.VBox(False)
        follow_vbox = gtk.VBox(False)

        tmp_img = gtk.Image()       # only use as a placeholder
        tmp_img.set_size_request(-1, 50) 
        res_vbox.pack_start(tmp_img, False, False)

        follow_tip_hbox = gtk.HBox(False)
        img = gtk.image_new_from_file(app_theme.get_theme_file_path("image/share/deepin_logo.png"))
        follow_tip_hbox.pack_start(img, False, False, 5)
        follow_tip_hbox.pack_start(
            Label("%s %s" % (_("Follow"), "Linux Deepin"), 
                text_color=app_theme_get_dynamic_color("#5f5f5f"),
                text_size=12, enable_select=False), False, False)
        follow_vbox.pack_start(follow_tip_hbox, False, False, 13)
        for weibo in self.to_share_weibo_res:
            vbox = gtk.VBox(False, 1)
            tip_box = gtk.HBox()
            error_box = gtk.HBox()
            vbox.pack_start(tip_box, False, False)
            vbox.pack_start(error_box, False, False)
            if self.to_share_weibo_res[weibo][0]:   # upload succeed
                img = gtk.image_new_from_file(app_theme.get_theme_file_path("image/share/share_succeed.png"))
                #link = LinkButton(_(weibo.t_type), text_size=13, self.to_share_weibo_res[weibo][1])
                link = Label(_(weibo.t_type), text_size=12, 
                    text_color=app_theme.get_color("link_text"))
                #, enable_gaussian=True, gaussian_radious=1, border_radious=0)
                link.add_events(gtk.gdk.BUTTON_PRESS_MASK)
                link.connect("enter-notify-event", lambda w, e: self.__draw_under_line(w))
                link.connect("leave-notify-event", lambda w, e: w.queue_draw())
                link.connect("button-press-event", self.goto_weibo_button_clicked, weibo)
                link_box = gtk.HBox(False)
                link_box.pack_start(link, False, False)
                utils.set_clickable_cursor(link)
                text = _("Share to")
                label = Label(text, text_size=12, 
                    text_color=font_color, enable_select=False)
                text = _("Successful")
                label1 = Label(text, text_size=12, 
                    text_color=font_color, enable_select=False)
                tip_box.pack_start(img, False, False, 15)
                tip_box.pack_start(label, False, False, 3)
                tip_box.pack_start(link_box, False, False, 3)
                tip_box.pack_start(label1, False, False)
                # only use as a placeholder
                img = gtk.Image()
                img.set_size_request(20, 1)
                error_box.pack_start(img, False, False, 16)
                tmp = Label(" ", text_size=9, label_width=200)
                tmp.set_size_request(200, 1)
                error_box.pack_start(tmp, False, False)
                #print text
            else:   # upload failed
                img = gtk.image_new_from_file(app_theme.get_theme_file_path("image/share/share_failed.png"))
                #text = "% %s %s." % (_(weibo.t_type), _("upload failed"))
                text = _("Share to")
                label1 = Label(text, text_size=12, 
                    text_color=font_color, enable_select=False)
                label2 = Label(_(weibo.t_type), text_size=12, 
                    text_color=font_color, enable_select=False)
                text = _("Failed")
                label3 = Label(text, text_size=12, 
                    text_color=font_color, enable_select=False)
                if weibo.curl.error:
                    error = "(%s)" % _(weibo.curl.error)
                elif weibo.get_error_msg():
                    error = "(%s)" % _(weibo.get_error_msg()) 
                else:
                    error = "(%s)" % _("Unknown reason")
                #print "%s: %s" % (weibo.t_type, error)
                #print "%s: %s" % (weibo.t_type, weibo.get_error_msg())
                label = Label(text, text_size=12,
                    text_color=font_color, enable_select=False)
                tip_box.pack_start(img, False, False, 15)
                tip_box.pack_start(label1, False, False, 3)
                tip_box.pack_start(label2, False, False, 3)
                tip_box.pack_start(label3, False, False)
                img = gtk.Image()   # only use as a placeholder
                img.set_size_request(20, 20)
                error_box.pack_start(img, False, False, 16)
                error_box.pack_start(Label(error, text_size=9, label_width=200,
                    text_color=font_color, enable_select=False), False, False)
                #print text
            res_vbox.pack_start(vbox, False, False, 10)

        for weibo in self.deepin_info:
            box = gtk.HBox(False, 15)
            # followed
            img = gtk.image_new_from_pixbuf(app_theme.get_pixbuf("share/"+weibo.t_type+".png").get_pixbuf())
            box.pack_start(img, False, False)
            if self.deepin_info[weibo] is not None and self.deepin_info[weibo][3]:
                if not default_locale.startswith("zh_"):
                    button = gtk.image_new_from_pixbuf(
                        app_theme.get_pixbuf("share/followed_en.png").get_pixbuf())
                else:
                    button = gtk.image_new_from_pixbuf(
                        app_theme.get_pixbuf("share/followed.png").get_pixbuf())
            else:   # to follow
                if not default_locale.startswith("zh_"):
                    button = ImageButton(
                        app_theme.get_pixbuf("share/follow_normal_en.png"),
                        app_theme.get_pixbuf("share/follow_hover_en.png"),
                        app_theme.get_pixbuf("share/follow_press_en.png"))
                else:
                    button = ImageButton(
                        app_theme.get_pixbuf("share/follow_normal.png"),
                        app_theme.get_pixbuf("share/follow_hover.png"),
                        app_theme.get_pixbuf("share/follow_press.png"))
                button.connect("clicked", self.friendships_add_button_clicked, weibo, box)
            box.pack_start(button, False, False)
            align = gtk.Alignment()
            align.set(0.0, 0.5, 0, 0)
            align.set_padding(0, 0, 30, 0)
            align.add(box)
            follow_vbox.pack_start(align, False, False, 8)

        res_left_box.set_buttons([res_vbox])
        res_right_box.set_buttons([follow_vbox])

        self.result_box.pack_start(res_hbox, False, False)
        self.result_box.show_all()
        self.set_slide_index(2)
    
    def goto_weibo_button_clicked(self, widget, event, weibo):
        '''goto my weibo'''
        #print "goto weibo button clicked", weibo.t_type, "xdg-open %s" % self.to_share_weibo_res[weibo][1]
        if weibo in self.to_share_weibo_res:
            if self.to_share_weibo_res[weibo][1]:
                utils.run_command("xdg-open %s" % self.to_share_weibo_res[weibo][1])
        
    def friendships_add_button_clicked(self, widget, weibo, box):
        '''add friendships'''
        #self.result_box.set_sensitive(False)
        if not self.is_get_user_info[weibo]:
            utils.run_command("xdg-open %s" % weibo.index_url)
            return True

        widget.set_sensitive(False)
        t = threading.Thread(target=self.friendships_add_thread, args=(widget, weibo, box))
        t.setDaemon(True)
        t.start()
    
    def friendships_add_thread(self, button, weibo, box):
        '''add friendships'''
        if weibo.friendships_create() is not None:
            gtk.gdk.threads_enter()
            button.destroy()
            if not default_locale.startswith("zh_"):
                button = gtk.image_new_from_pixbuf(
                    app_theme.get_pixbuf("share/followed_en.png").get_pixbuf())
            else:
                button = gtk.image_new_from_pixbuf(
                    app_theme.get_pixbuf("share/followed.png").get_pixbuf())
            button.show()
            box.pack_start(button, False, False)
            #button.set_label("已关注")
            gtk.gdk.threads_leave()
    
    # show window
    def show(self):
        '''show'''
        self.window.show_window()

    # close widnow
    def quit(self, widget):
        ''' close '''
        gtk.main_quit()

    def __slider_expose(self, widget, event):
        ''' slider expose redraw'''
        cr = widget.window.cairo_create()
        rect = widget.allocation
        cr.set_source_rgba(1.0, 1.0, 1.0, 0.8)
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)
        cr.fill()
    
    def __expose_top_and_bottome(self, widget, event):
        '''titlebar or button_box expose'''
        cr = widget.window.cairo_create()
        rect = widget.allocation
        cr.set_source_rgb(0.89, 0.89, 0.89)
        cr.rectangle(rect.x+2, rect.y+2, rect.width-4, rect.height-4)
        cr.fill()

    def __draw_under_line(self, widget):
        '''draw under line'''
        cr = widget.window.cairo_create()
        with utils.cairo_disable_antialias(cr):
            x, y, w, h = widget.allocation
            # #1A70b1
            cr.set_source_rgba(0.1, 0.43, 0.69, 1.0)
            cr.set_line_width(1)
            cr.move_to(x, y+h-3)
            cr.line_to(x+w, y+h-3)
            cr.stroke()
Example #43
0
    def __init__(self, filename=""):
        '''
        init share
        @param filename: the file to share
        '''
        self.upload_image = filename
        self.thumb_width = 188
        self.thumb_height = 168
        self.MAX_CHAR = 140
        #self.__text_frame_color = (0.76, 0.76, 0.76)
        self.__win_width = 602
        open(COOKIE_FILE,'wb').close()

        self.window = DialogBox(_("Share to social networks"), close_callback=gtk.main_quit)
        self.window.set_keep_above(True)
        self.window.set_size_request(self.__win_width+20, 288)
        self.window.set_resizable(False)
        self.window.titlebar.connect("expose-event", self.__expose_top_and_bottome)
        self.window.button_box.connect("expose-event", self.__expose_top_and_bottome)

        # create slider
        self.slider = HSlider()
        self.slider_list = []

        self.share_box = gtk.VBox(False, 2)     # first page, input context
        self.web_box = gtk.VBox(False, 10)      # second page, login
        self.result_box = gtk.VBox(False, 10)   # third page, share result

        share_align = gtk.Alignment()
        share_align.set(0.5, 0.5, 0, 0)
        share_align.add(self.share_box)
        share_align.connect("expose-event", self.__slider_expose)

        # go back button
        web_left_button = ImageButton(
            app_theme.get_pixbuf("share/back_normal.png"),
            app_theme.get_pixbuf("share/back_hover.png"),
            app_theme.get_pixbuf("share/back_press.png"))
        web_left_button.connect("clicked", lambda w: self.set_slide_index(0))
        web_left_button.set_can_focus(False)
        utils.set_clickable_cursor(web_left_button)
        # show url entry
        self.web_url_entry = InputEntry()
        self.web_url_entry.set_editable(False)
        self.web_url_entry.set_size(555, 20)
        self.web_url_entry.entry.right_menu_visible_flag = False
        # alig url entry
        web_navigate_vbox = gtk.VBox(False)
        web_navigate_vbox.pack_start(self.web_url_entry)
        web_navigate_t_align = gtk.Alignment()
        web_navigate_t_align.set(0.0, 0.5, 0, 0)
        web_navigate_t_align.add(web_navigate_vbox)
        # pack back button and url entry
        web_navigate_box = gtk.HBox(False, 7)
        web_navigate_box.pack_start(web_left_button, False, False)
        web_navigate_box.pack_start(web_navigate_t_align)

        web_navigate_align = gtk.Alignment()
        web_navigate_align.set(0.5, 0.5, 0, 0)
        web_navigate_align.set_padding(4, 0, 11, 13)
        web_navigate_align.add(web_navigate_box)

        # create a webkit
        self.web_view = WebView(COOKIE_FILE)
        self.web_view.connect("notify::load-status", self.web_view_load_status)
        self.web_view.connect("load-error", self.web_view_load_error)
        self.web_scrolled_window = ScrolledWindow()
        self.web_scrolled_window.add(self.web_view)
        self.web_scrolled_window.set_size_request(590, 228)

        self.web_box.pack_start(web_navigate_align, False, False)
        self.web_box.pack_start(self.web_scrolled_window)
        #self.web_box.set_size_request(-1, 258)
        web_align = gtk.Alignment()
        web_align.set(0.5, 0.0, 0, 1)
        web_align.add(self.web_box)
        web_align.connect("expose-event", self.__slider_expose)

        res_align = gtk.Alignment()
        res_align.set(0.5, 0.5, 0, 0)
        res_align.add(self.result_box)
        res_align.connect("expose-event", self.__slider_expose)

        self.slider.set_to_page(share_align)
        self.slider_list.append(share_align)
        self.slider_list.append(web_align)
        self.slider_list.append(res_align)

        self.__weibo_list = []
        self.sina = weibo.Sina(self.web_view)
        self.qq = weibo.Tencent(self.web_view)
        self.twitter = weibo.Twitter(self.web_view)
        self.__weibo_list.append(self.sina)
        self.__weibo_list.append(self.qq)
        self.__weibo_list.append(self.twitter)
        self.__current_weibo = None

        self.window.body_box.pack_start(self.slider, True, True)
        self.init_share_box()
    def __init__(self,
                 connection,
                 ssid,
                 key_mgmt=None,
                 default_width=330,
                 default_height=120,
                 confirm_callback=None, 
                 cancel_callback=None,
                 ):
        '''
        Initialize InputDialog class.
        
        @param title: Input dialog title.
        @param init_text: Initialize input text.
        @param default_width: Width of dialog, default is 330 pixel.
        @param default_height: Height of dialog, default is 330 pixel.
        @param confirm_callback: Callback when user click confirm button, this callback accept one argument that return by user input text.
        @param cancel_callback: Callback when user click cancel button, this callback not need argument.
        '''
        # Init.
        #DialogBox.__init__(self, _("Set password"), default_width, default_height, DIALOG_MASK_SINGLE_PAGE)
        DialogBox.__init__(self,
                           _("Please input password for %s") % ssid,
                           default_width,
                           default_height,
                           DIALOG_MASK_SINGLE_PAGE)

        #self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
        self.confirm_callback = confirm_callback
        self.cancel_callback = cancel_callback
    
        self.connection = connection
        
        self.hint_align = gtk.Alignment()
        self.hint_align.set(0.5, 0.5, 0, 0)
        self.hint_align.set_padding(0, 0, 10, 10)
        self.hint_text = Label(_("Please input password for %s")%ssid,
                               enable_select=False,
                               enable_double_click=False)
        self.hint_align.add(self.hint_text)

        self.entry_align = gtk.Alignment()
        self.entry_align.set(0.0, 0.5, 0, 0)
        self.entry_align.set_padding(10, 0, 5, 9)
        if self.connection and isinstance(self.connection, NMRemoteConnection):
            (setting_name, method) = self.connection.guess_secret_info()  
            if setting_name and method:
                init_text = nm_module.secret_agent.agent_get_secrets(self.connection.object_path,
                                                        setting_name,
                                                        method)
            else:
                init_text = ""
        else:
            tray_log.debug()
            self.connection = nm_module.nm_remote_settings.new_wireless_connection(ssid, key_mgmt)
            init_text = ''
        self.entry = PasswordEntry(init_text)
        self.show_key_check = CheckButton(_("Show password"), 0)
        self.show_key_check.connect("toggled", self.show_key_check_button_cb)

        self.entry.set_size(default_width - 22, 25)
        self.main_box = gtk.VBox()
        entry_align = gtk.Alignment(0.0, 0.5, 0, 0)
        entry_align.set_padding(0, 0, 5, 0)
        entry_align.set_size_request(-1, 30)
        entry_align.add(self.entry)
        self.main_box.pack_start(entry_align, False, False)
        self.main_box.pack_start(self.show_key_check, False, False)
        
        self.confirm_button = Button(_("OK"))
        self.cancel_button = Button(_("Cancel"))
        
        self.entry.entry.connect("press-return", lambda w: self.click_confirm_button())
        self.confirm_button.connect("clicked", lambda w: self.click_confirm_button())
        self.cancel_button.connect("clicked", lambda w: self.click_cancel_button())
        
        self.entry_align.add(self.main_box)
        #self.body_box.pack_start(self.hint_align, True, True)
        self.body_box.pack_start(self.entry_align, True, True)

        #self.body_box.pack_start(self.main_box, True, True)
        
        self.right_button_box.set_buttons([self.cancel_button, self.confirm_button])
        self.connect("show", self.focus_input)