示例#1
0
 def __init__(self, version):
     super().__init__(application_id='com.github.unrud.VideoDownloader',
                      flags=Gio.ApplicationFlags.NON_UNIQUE)
     self.add_main_option('url', ord('u'),
                          GLib.OptionFlags.NONE, GLib.OptionArg.STRING,
                          N_('Prefill URL field'), 'URL')
     GLib.set_application_name(N_('Video Downloader'))
     self.version = version
     self.model = Model(self)
     self._settings = Gio.Settings.new(self.props.application_id)
     self.model.download_dir = self._settings.get_string('download-folder')
     self.model.prefer_mpeg = self._settings.get_boolean('prefer-mpeg')
     self.model.mode = self._settings.get_string('mode')
     r = self._settings.get_uint('resolution')
     for resolution in sorted(x[0] for x in self.model.resolutions):
         if r <= resolution:
             break
     self.model.resolution = resolution
     bind_property(
         self.model,
         'mode',
         func_a_to_b=lambda x: self._settings.set_string('mode', x))
     bind_property(
         self.model,
         'resolution',
         func_a_to_b=lambda x: self._settings.set_uint('resolution', x))
示例#2
0
 def __init__(self, handler=None):
     super().__init__()
     self._handler = handler
     self._downloader = downloader.Downloader(self)
     self._download_finished_filenames = []
     self._filemanager_proxy = Gio.DBusProxy.new_for_bus_sync(
         Gio.BusType.SESSION, Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES
         | Gio.DBusProxyFlags.DO_NOT_CONNECT_SIGNALS
         | Gio.DBusProxyFlags.DO_NOT_AUTO_START_AT_CONSTRUCTION, None,
         'org.freedesktop.FileManager1', '/org/freedesktop/FileManager1',
         'org.freedesktop.FileManager1')
     bind_property(self, 'download-dir', self, 'download-dir-abs',
                   expand_path)
     self.actions = Gio.SimpleActionGroup.new()
     self.actions.add_action_entries([
         ('download', lambda *_: self.set_property('state', 'download')),
         ('cancel', lambda *_: self.set_property('state', 'cancel')),
         ('back', lambda *_: self.set_property('state', 'start')),
         ('open-download-dir', self._open_download_dir)
     ])
     bind_property(self, 'url', self.actions.lookup_action('download'),
                   'enabled', bool)
     bind_property(self, 'state', self, 'prev-state',
                   self._state_transition)
     bind_property(self, 'state', self.actions.lookup_action('cancel'),
                   'enabled', lambda s: s == 'download')
示例#3
0
 def _build_content(self):
     content = LoginDialogContent()
     bind_property(self, 'username', content.username_wdg, 'text', bi=True)
     bind_property(self, 'password', content.password_wdg, 'text', bi=True)
     for prop in ['username', 'password']:
         bind_property(self, prop, func_a_to_b=self._update_form)
         bind_property(self, prop, func_a_to_b=self._update_form)
     return content
示例#4
0
 def __init__(self):
     super().__init__(application_id='com.github.unrud.VideoDownloader',
                      flags=Gio.ApplicationFlags.NON_UNIQUE)
     GLib.set_application_name(N_('Video Downloader'))
     self.model = Model(self)
     self._settings = Gio.Settings.new(self.props.application_id)
     self.model.download_dir = self._settings.get_string('download-folder')
     self.model.mode = self._settings.get_string('mode')
     r = self._settings.get_uint('resolution')
     for resolution in sorted(x[0] for x in self.model.resolutions):
         if r <= resolution:
             break
     self.model.resolution = resolution
     bind_property(
         self.model,
         'mode',
         func_a_to_b=lambda x: self._settings.set_string('mode', x))
     bind_property(
         self.model,
         'resolution',
         func_a_to_b=lambda x: self._settings.set_uint('resolution', x))
示例#5
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     self.model = self.get_application().model
     bind_property(self.model, 'error', self.error_buffer, 'text')
     bind_property(self.model, 'url', self.audio_url_wdg, 'text', bi=True)
     bind_property(self.model, 'url', self.video_url_wdg, 'text', bi=True)
     for resolution, description in self.model.resolutions:
         it = self.resolutions_store.append()
         self.resolutions_store.set(it, 0, str(resolution), 1, description)
     bind_property(self.model,
                   'resolution',
                   self.resolution_wdg,
                   'active-id',
                   str,
                   int,
                   bi=True)
     bind_property(self.model, 'state', self.main_stack_wdg,
                   'visible-child-name',
                   lambda s: {'cancel': 'download'}.get(s, s))
     bind_property(self.model,
                   'mode',
                   self.audio_video_stack_wdg,
                   'visible-child-name',
                   bi=True)
     bind_property(self.main_stack_wdg,
                   'visible-child-name',
                   func_a_to_b=self._update_focus_and_default)
     bind_property(self.audio_video_stack_wdg,
                   'visible-child-name',
                   func_a_to_b=self._update_focus_and_default)
     bind_property(self.model,
                   'download-dir-abs',
                   func_a_to_b=self._update_open_download_dir_wdg_tooltip)
     for name in [
             'download-bytes', 'download-bytes-total', 'download-speed',
             'download-eta'
     ]:
         bind_property(self.model,
                       name,
                       func_a_to_b=self._update_download_msg)
     bind_property(self.model,
                   'download-progress',
                   func_a_to_b=self._update_download_progress)
     self.model.connect('download-pulse', self._update_download_progress)
     for name in [
             'download-title', 'download-playlist-count',
             'download-playlist-index'
     ]:
         bind_property(self.model,
                       name,
                       func_a_to_b=self._update_download_title)
     bind_property(self.model,
                   'download-thumbnail',
                   func_a_to_b=self._add_thumbnail)
     bind_property(self.download_images_wdg,
                   'transition-running',
                   func_a_to_b=lambda b: b or self._clean_thumbnails())
     bind_property(Gtk.Settings.get_default(),
                   'gtk-application-prefer-dark-theme',
                   self.dark_mode_wdg,
                   'active',
                   bi=True)
示例#6
0
 def _build_content(self):
     content = PasswordDialogContent()
     bind_property(self, 'password', content.password_wdg, 'text', bi=True)
     bind_property(self, 'password', func_a_to_b=self._update_form)
     return content
示例#7
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     bind_property(self.model, 'error', self.error_buffer, 'text')
     bind_property(self.error_details_expander_wdg, 'expanded',
                   self.error_details_revealer_wdg, 'reveal-child')
     bind_property(self.model, 'url', self.audio_url_wdg, 'text', bi=True)
     bind_property(self.model, 'url', self.video_url_wdg, 'text', bi=True)
     for resolution, description in self.model.resolutions:
         it = self.resolutions_store.append()
         self.resolutions_store.set(it, 0, str(resolution), 1, description)
     bind_property(self.model,
                   'resolution',
                   self.resolution_wdg,
                   'active-id',
                   str,
                   int,
                   bi=True)
     bind_property(self.model, 'state', self.main_stack_wdg,
                   'visible-child-name', lambda s: {
                       s: s,
                       'cancel': 'download'
                   }[s])
     bind_property(self.model, 'state', func_a_to_b=self._update_header)
     bind_property(self.model,
                   'mode',
                   self.audio_video_stack_wdg,
                   'visible-child-name',
                   bi=True)
     bind_property(self.main_stack_wdg,
                   'visible-child-name',
                   func_a_to_b=self._update_focus_and_default)
     bind_property(self.audio_video_stack_wdg,
                   'visible-child-name',
                   func_a_to_b=self._update_focus_and_default)
     bind_property(self.model,
                   'download-dir-abs',
                   func_a_to_b=self._update_success_msg)
     self.success_msg_wdg.connect('activate-link', self._on_activate_link)
     for name in [
             'download-bytes', 'download-bytes-total', 'download-speed',
             'download-eta'
     ]:
         bind_property(self.model,
                       name,
                       func_a_to_b=self._update_download_msg)
     bind_property(self.model,
                   'download-progress',
                   func_a_to_b=self._update_download_progress)
     self.model.connect('download-pulse', self._update_download_progress)
     for name in [
             'download-title', 'download-playlist-count',
             'download-playlist-index'
     ]:
         bind_property(self.model,
                       name,
                       func_a_to_b=self._update_download_title)
     bind_property(self.model,
                   'download-thumbnail',
                   func_a_to_b=self._add_thumbnail)
     bind_property(self.download_images_wdg,
                   'transition-running',
                   func_a_to_b=lambda b: b or self._clean_thumbnails())
示例#8
0
 def __init__(self, application):
     super().__init__(application=application)
     self.uuid = str(uuid.uuid4())  # Id for matching notifications
     self.model = model = Model(self)
     # Setup actions
     for name in model.actions.list_actions():
         self.add_action(model.actions.lookup_action(name))
     about_action = Gio.SimpleAction.new('about', None)
     about_action.connect('activate', lambda *_: self._show_about_dialog())
     self.add_action(about_action)
     # Bind properties to UI
     bind_property(model, 'error', self.error_buffer, 'text')
     bind_property(model, 'url', self.audio_url_wdg, 'text', bi=True)
     bind_property(model, 'url', self.video_url_wdg, 'text', bi=True)
     for resolution, description in model.resolutions:
         it = self.resolutions_store.append()
         self.resolutions_store.set(it, 0, str(resolution), 1, description)
     bind_property(model,
                   'resolution',
                   self.resolution_wdg,
                   'active-id',
                   str,
                   int,
                   bi=True)
     bind_property(model,
                   'state',
                   self.main_stack_wdg,
                   'visible-child-name',
                   func_a_to_b=lambda s: {'cancel': 'download'}.get(s, s))
     bind_property(model, 'state', func_a_to_b=self._update_notification)
     bind_property(model,
                   'mode',
                   self.audio_video_stack_wdg,
                   'visible-child-name',
                   bi=True)
     bind_property(self.main_stack_wdg,
                   'visible-child-name',
                   func_a_to_b=self._update_focus_and_default)
     bind_property(self.audio_video_stack_wdg,
                   'visible-child-name',
                   func_a_to_b=self._update_focus_and_default)
     bind_property(model,
                   'download-dir-abs',
                   func_a_to_b=self._update_open_download_dir_wdg_tooltip)
     for name in [
             'download-bytes', 'download-bytes-total', 'download-speed',
             'download-eta'
     ]:
         bind_property(model, name, func_a_to_b=self._update_download_msg)
     bind_property(model,
                   'download-progress',
                   func_a_to_b=self._update_download_progress)
     model.connect('download-pulse', self._update_download_progress)
     for name in ['download-playlist-count', 'download-playlist-index']:
         bind_property(model,
                       name,
                       func_a_to_b=self._update_download_page_title)
     bind_property(model,
                   'download-title',
                   self.download_title_wdg,
                   'label',
                   func_a_to_b=lambda title: title or '…')
     bind_property(model,
                   'download-thumbnail',
                   func_a_to_b=self._add_thumbnail)
     bind_property(self.download_images_wdg,
                   'transition-running',
                   func_a_to_b=lambda b: b or self._clean_thumbnails())
     bind_property(Gtk.Settings.get_default(),
                   'gtk-application-prefer-dark-theme',
                   self.dark_mode_wdg,
                   'active',
                   bi=True)