Exemplo n.º 1
0
 def save_to_tmp_file(self):
     if self.rect_width > 0 and self.rect_height > 0:
         from tempfile import mkstemp
         import os
         tmp = mkstemp(".tmp", "deepin-screenshot")
         os.close(tmp[0])
         filename = tmp[1]
         self.window.finish_flag = True
         surface = self.make_pic_file(
             self.desktop_background.subpixbuf(*self.get_rectangel_in_monitor()))
         surface.write_to_png(filename)
         SCROT_BUS.emit_finish(1, filename)
     gtk.main_quit()
     return filename
Exemplo n.º 2
0
def open_file_dialog(fullscreen=True, filetype='png'):
    '''
    Save file to file.
    @param fullscreen: if get the fullscreen snapshot.
    @parser filetype: the filetype to save
    '''
    from constant import SAVE_OP_AUTO, SAVE_OP_AUTO_AND_CLIP, SAVE_OP_AS
    from _share.config import OperateConfig
    config = OperateConfig()
    save_op = config.get("save", "save_op")
    if save_op:
        save_op_index = int(save_op)
    else:
        save_op_index = SAVE_OP_AS
    pixbuf = get_screenshot_pixbuf(fullscreen)
    if save_op_index == SAVE_OP_AUTO or save_op_index == SAVE_OP_AUTO_AND_CLIP:
        filename = "%s/%s%s.%s" % (get_pictures_dir(), _(DEFAULT_FILENAME),
                                   get_format_time(), "png")
        pixbuf.save(filename, save_filetype)
        msg = "%s '%s'" % (_("Picture has been saved to file"), filename)
        SCROT_BUS.emit_finish(1, filename)
        notify("Deepin Screenshot", 0, summary=_("DScreenshot"), body=msg)
    else:
        dialog = gtk.FileChooserDialog(
            "Save..",
            None,
            gtk.FILE_CHOOSER_ACTION_SAVE,
            (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
            gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT))
        dialog.set_default_response(gtk.RESPONSE_ACCEPT)
        dialog.set_position(gtk.WIN_POS_CENTER)
        dialog.set_local_only(True)
        dialog.set_current_folder(get_pictures_dir())
        dialog.set_current_name("%s%s.%s" % (_(DEFAULT_FILENAME), get_format_time(), "png"))

        response = dialog.run()
        if response == gtk.RESPONSE_ACCEPT:
            filename = dialog.get_filename()
            pixbuf.save(filename, save_filetype)
            msg = "%s '%s'" % (_("Picture has been saved to file"), filename)
            SCROT_BUS.emit_finish(1, filename)
            notify("Deepin Screenshot", 0, summary=_("DScreenshot"), body=msg)
        elif response == gtk.RESPONSE_REJECT:
            print 'Closed, no files selected'
        dialog.destroy()
Exemplo n.º 3
0
def open_file_dialog(fullscreen=True, filetype='png'):
    '''
    Save file to file.
    @param fullscreen: if get the fullscreen snapshot.
    @parser filetype: the filetype to save
    '''
    from constant import SAVE_OP_AUTO, SAVE_OP_AUTO_AND_CLIP, SAVE_OP_AS
    from _share.config import OperateConfig
    config = OperateConfig()
    save_op = config.get("save", "save_op")
    if save_op:
        save_op_index = int(save_op)
    else:
        save_op_index = SAVE_OP_AS
    pixbuf = get_screenshot_pixbuf(fullscreen)
    if save_op_index == SAVE_OP_AUTO or save_op_index == SAVE_OP_AUTO_AND_CLIP:
        filename = "%s/%s%s.%s" % (get_pictures_dir(), _(DEFAULT_FILENAME),
                                   get_format_time(), "png")
        pixbuf.save(filename, save_filetype)
        msg = "%s '%s'" % (_("Picture has been saved to file"), filename)
        SCROT_BUS.emit_finish(1, filename)
        notify("Deepin Screenshot", 0, summary=_("DScreenshot"), body=msg)
    else:
        dialog = gtk.FileChooserDialog("Save..", None,
                                       gtk.FILE_CHOOSER_ACTION_SAVE,
                                       (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                                        gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT))
        dialog.set_default_response(gtk.RESPONSE_ACCEPT)
        dialog.set_position(gtk.WIN_POS_CENTER)
        dialog.set_local_only(True)
        dialog.set_current_folder(get_pictures_dir())
        dialog.set_current_name(
            "%s%s.%s" % (_(DEFAULT_FILENAME), get_format_time(), "png"))

        response = dialog.run()
        if response == gtk.RESPONSE_ACCEPT:
            filename = dialog.get_filename()
            pixbuf.save(filename, save_filetype)
            msg = "%s '%s'" % (_("Picture has been saved to file"), filename)
            SCROT_BUS.emit_finish(1, filename)
            notify("Deepin Screenshot", 0, summary=_("DScreenshot"), body=msg)
        elif response == gtk.RESPONSE_REJECT:
            print 'Closed, no files selected'
        dialog.destroy()
Exemplo n.º 4
0
 def save_snapshot(self, filename=None, filetype='png', clip_flag=False):
     '''
     Save snapshot.
     @param filename: the filename to save, a string type
     @param filetype: the filetype to save, a string type. Default is 'png'
     @param clip_flag: a flag if copy the snapshot to clipboard. Default is False
     '''
     failed_flag = False
     tipContent = ""
     parent_dir = get_parent_dir(__file__, 1)
     # Save snapshot.
     if self.rect_width == 0 or self.rect_height == 0:
         tipContent = _("The width or height of selected area cannot be 0")
         failed_flag = True
     else:
         self.window.finish_flag = True
         surface = self.make_pic_file(
             self.desktop_background.subpixbuf(*self.get_rectangel_in_monitor()))
         # Save to file
         if filename:
             tipContent = "%s '%s'" % (_("Picture has been saved to file"), filename)
             try:
                 surface.write_to_png(filename)
                 SCROT_BUS.emit_finish(1, filename)
                 # copy to clipboard
                 if clip_flag:
                     pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
                     clipboard = gtk.Clipboard(selection="CLIPBOARD")
                     clipboard.set_image(pixbuf)
                     clipboard.store()
                     #tipContent +=  _("Picture has been saved to clipboard")
                     #try:
                         #cmd = ('python2', '%s/%s' % (parent_dir, 'tipswindow.py'), _("Picture has been saved to clipboard"), '1')
                         #subprocess.Popen(cmd)
                     #except OSError:    
                         #cmd = ('python', '%s/%s' % (parent_dir, 'tipswindow.py'), _("Picture has been saved to clipboard"), '1')
                         #subprocess.Popen(cmd)
                     #notify("Deepin Screenshot", 0, summary=_("DSnapshot"), body=tipContent)
                     
             except Exception, e:
                 tipContent = "%s:%s" % (_("Failed to save the picture"), str(e))
         # Save snapshot to clipboard
         else: