Esempio n. 1
0
def copy_move_files_dialog(files, dest_folder, copy=None):
    if copy == Gdk.DragAction.COPY: action = _("Copy")  #@UndefinedVariable
    else: action = _("Replace")

    dialog = Gtk.Dialog(_('%s file(s) / folder(s)') % action)

    ok_button = dialog.add_button(action, Gtk.ResponseType.OK)
    cancel_button = dialog.add_button(
        "dialog-cancel", Gtk.ResponseType.CANCEL)  #@UnusedVariable

    ok_button.grab_default()
    label = Gtk.Label.new('\n' +
                          _("Are you really want to %s this item(s) to %s ?") %
                          (action, dest_folder))
    area = ScrolledText()
    area.text.set_editable(False)
    area.text.set_cursor_visible(False)
    area.buffer.set_text("\n".join([os.path.basename(path) for path in files]))
    dialog.vbox.pack_start(area.scroll, False, False, 0)
    dialog.set_border_width(5)
    dialog.vbox.pack_start(label, False, False, 0)
    dialog.set_icon_from_file(get_foobnix_resourse_path_by_name(ICON_FOOBNIX))
    dialog.set_default_size(400, 150)
    dialog.show_all()
    if dialog.run() == Gtk.ResponseType.OK:
        dialog.destroy()
        return True
    dialog.destroy()
    return False
Esempio n. 2
0
def convert_files(paths):
    if FFMPEG_NAME in os.listdir(CONFIG_DIR):
        if not "converter" in globals:
            global converter
            converter = Converter()
        converter.show_all()
        converter.progress_box.hide_all()
        converter.output.scroll.hide()
        converter.fill_form(paths)
        converter.format_combo.set_active(0)
    else:
        url = "http://foobnix.com/assets/downloads/" + FFMPEG_NAME
        dialog = Gtk.Dialog(_("Attention"))
        area = ScrolledText()
        area.buffer.set_text(
            _("Converter require specially compiled ffmpeg module for work.\n"
              + "You should download it automatically (click Download)\n" +
              "Also check if you have packages libmp3lame0 and libfaac0"))
        ok_button = dialog.add_button(_("Download"), Gtk.ResponseType.OK)

        cancel_button = dialog.add_button("dialog-cancel",
                                          Gtk.ResponseType.CANCEL)
        ok_button.grab_default()
        prog_bar = Gtk.ProgressBar()
        dialog.vbox.pack_start(area.scroll, False, False, 0)
        dialog.vbox.pack_start(prog_bar, False, False, 0)
        dialog.set_icon_from_file(LOGO)
        dialog.set_default_size(400, 150)
        dialog.show_all()
        prog_bar.hide()
        canceled = False
        if dialog.run() == Gtk.ResponseType.OK:
            prog_bar.show()
            remote_file = urllib.request.urlopen(url)
            size = float(remote_file.info()['Content-Length'])
            ffmpeg_path = os.path.join(CONFIG_DIR, FFMPEG_NAME)

            def on_close(*a):
                if os.path.isfile(
                        ffmpeg_path) and os.path.getsize(ffmpeg_path) < size:
                    os.remove(ffmpeg_path)
                dialog.destroy()
                return

            cancel_button.connect("released", on_close)

            def task():
                with open(ffmpeg_path, 'wb') as local_file:
                    got = 0
                    cycle = True
                    while cycle and not canceled:
                        try:
                            local_file.write(remote_file.read(20000))
                            if got + 20000 >= size:
                                cycle = False
                            got = os.path.getsize(ffmpeg_path)

                            def subtask():
                                prog_bar.set_fraction(got / size)
                                prog_bar.set_text(
                                    "Downloaded  %.2f of %.2fMb" %
                                    (float(got) / 1024 / 1024,
                                     size / 1024 / 1024))

                            GLib.idle_add(subtask)
                        except OSError as e:
                            if os.path.isfile(ffmpeg_path) and os.path.getsize(
                                    ffmpeg_path) < size:
                                os.remove(ffmpeg_path)

                os.chmod(ffmpeg_path, 0o755)
                GLib.idle_add(convert_files, paths)
                dialog.destroy()

            threading.Thread(target=task, args=()).start()
        else:
            dialog.destroy()
Esempio n. 3
0
    def __init__(self):
        ChildTopWindow.__init__(self,
                                title="Audio Converter",
                                width=500,
                                height=400)

        self.area = ScrolledText()
        vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 10)
        vbox.pack_start(self.area.scroll, False, False, 0)
        vbox.show()
        format_label = Gtk.Label.new(_('Format'))
        bitrate_label = Gtk.Label.new(_('Bitrate'))
        channels_label = Gtk.Label.new(_('Channels'))
        hertz_label = Gtk.Label.new(_('Frequency'))

        format_box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        bitrate_box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        channels_box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        hertz_box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)

        self.format_list = [
            "Choose", "  mp3", "  ogg", "  mp2", "  ac3", "  m4a", "  wav"
        ]
        self.bitrate_list = [
            "  64 kbps", "  96 kbps", "  128 kbps", "  160 kbps", "  192 kbps",
            "  224 kbps", "  256 kbps", "  320 kbps", "  384 kbps",
            "  448 kbps", "  640 kbps"
        ]
        self.channels_list = ["  1", "  2", "  6"]
        self.hertz_list = [
            "  22050 Hz", "  44100 Hz", "  48000 Hz", "  96000 Hz"
        ]

        self.format_combo = combobox_constr(self.format_list)
        self.format_combo.connect("changed", self.on_change_format)

        self.bitrate_combo = combobox_constr()
        self.channels_combo = combobox_constr()
        self.hertz_combo = combobox_constr()

        format_box.pack_start(format_label, False, False, 0)
        format_box.pack_start(self.format_combo, False, False, 0)
        bitrate_box.pack_start(bitrate_label, False, False, 0)
        bitrate_box.pack_start(self.bitrate_combo, False, False, 0)
        channels_box.pack_start(channels_label, False, False, 0)
        channels_box.pack_start(self.channels_combo, False, False, 0)
        hertz_box.pack_start(hertz_label, False, False, 0)
        hertz_box.pack_start(self.hertz_combo, False, False, 0)

        hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 30)
        hbox.pack_start(format_box, False, False, 0)
        hbox.pack_start(bitrate_box, False, False, 0)
        hbox.pack_start(channels_box, False, False, 0)
        hbox.pack_start(hertz_box, False, False, 0)
        hbox.set_border_width(10)
        hbox.show_all()

        vbox.pack_start(hbox, False, False, 0)

        self.button_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 10)
        close_button = Gtk.Button.new_with_label(_("Close"))
        close_button.set_size_request(150, 30)
        close_button.connect("clicked", lambda *a: self.hide())
        self.convert_button = Gtk.Button.new_with_label(_("Convert"))
        self.convert_button.set_size_request(150, 30)
        self.convert_button.connect("clicked", self.save)

        self.progressbar = Gtk.ProgressBar()

        self.stop_button = Gtk.Button.new_with_label(_("Stop"))
        self.stop_button.set_size_request(100, 30)
        self.stop_button.connect("clicked", self.on_stop)

        self.open_folder_button = Gtk.Button.new_with_label(_("Show files"))
        self.open_folder_button.connect('released', self.open_in_fm)

        self.progress_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
        self.progress_box.pack_end(self.open_folder_button, False, False, 0)
        self.progress_box.pack_end(self.stop_button, False, False, 0)
        self.progress_box.pack_end(self.progressbar, True, False, 0)

        self.output = ScrolledText()
        self.output.text.set_size_request(-1, 50)
        self.output.scroll.set_size_request(-1, 50)
        self.output.scroll.set_placement(Gtk.CornerType.BOTTOM_LEFT)
        vbox.pack_start(self.progress_box, False, False, 0)

        self.button_box.pack_end(self.convert_button, False, False, 0)
        self.button_box.pack_end(close_button, False, False, 0)

        self.button_box.show_all()

        vbox.pack_start(self.button_box, False, False, 0)
        vbox.pack_start(self.output.scroll, False, False, 0)
        self.add(vbox)
Esempio n. 4
0
def convert_files(paths):
    if FFMPEG_NAME in os.listdir(CONFIG_DIR):
        if not globals().has_key("converter"):
            global converter
            converter = Converter()
        converter.show_all()
        converter.progress_box.hide_all()
        converter.output.scroll.hide()
        converter.fill_form(paths)
        converter.format_combo.set_active(0)
    else:
        url = "http://foobnix.googlecode.com/files/" + FFMPEG_NAME
        dialog = gtk.Dialog(_("Attention"))
        area = ScrolledText()
        area.buffer.set_text(
            _("Converter require specially compiled ffmpeg module for work.\n"
              + "You should download it automatically (click Download)\n" +
              "Also check if you have packages libmp3lame0 and libfaac0"))
        ok_button = dialog.add_button(_("Download"), gtk.RESPONSE_OK)

        cancel_button = dialog.add_button(gtk.STOCK_CANCEL,
                                          gtk.RESPONSE_CANCEL)
        ok_button.grab_default()
        prog_bar = gtk.ProgressBar()
        dialog.vbox.pack_start(area.scroll)
        dialog.vbox.pack_start(prog_bar, False)
        dialog.set_icon_from_file(LOGO)
        dialog.set_default_size(400, 150)
        dialog.show_all()
        prog_bar.hide()
        if dialog.run() == gtk.RESPONSE_OK:
            prog_bar.show()
            import urllib2
            remote_file = urllib2.urlopen(url)
            size = float(remote_file.info()['Content-Length'])
            ffmpeg_path = os.path.join(CONFIG_DIR, FFMPEG_NAME)

            def on_close(*a):
                if os.path.isfile(
                        ffmpeg_path) and os.path.getsize(ffmpeg_path) < size:
                    os.remove(ffmpeg_path)
                dialog.destroy()
                return

            cancel_button.connect("released", on_close)

            def task():
                with open(ffmpeg_path, 'wb') as local_file:
                    for byte in xrange(int(size / 100)):
                        local_file.write(remote_file.read(1000))
                        got = os.path.getsize(ffmpeg_path)
                        prog_bar.set_fraction(got / size)
                        prog_bar.set_text(
                            "Downloaded  %.2f of %.2fMb" %
                            (float(got) / 1024 / 1024, size / 1024 / 1024))
                os.chmod(ffmpeg_path, 0777)
                time.sleep(1)  #for stability
                gobject.idle_add(convert_files, paths)
                dialog.destroy()

            thread.start_new_thread(task, ())
        else:
            dialog.destroy()