def add_device_panel(self, type, obj, device): from xl.collection import CollectionScanThread from xlgui.panel.device import DevicePanel, FlatPlaylistDevicePanel import xlgui.panel paneltype = DevicePanel if hasattr(device, 'panel_type'): if device.panel_type == 'flatplaylist': paneltype = FlatPlaylistDevicePanel elif issubclass(device.panel_type, xlgui.panel.Panel): paneltype = device.panel_type panel = paneltype(self.main.window, self.main, device, device.get_name()) sort = True panel.connect('append-items', lambda panel, items, sort=sort: self.main.on_append_items(items, sort=sort)) panel.connect('queue-items', lambda panel, items, sort=sort: self.main.on_append_items(items, queue=True, sort=sort)) panel.connect('replace-items', lambda panel, items, sort=sort: self.main.on_append_items(items, replace=True, sort=sort)) self.device_panels[device.get_name()] = panel glib.idle_add(self.add_panel, *panel.get_panel()) thread = CollectionScanThread(device.get_collection()) thread.connect('done', panel.load_tree) self.progress_manager.add_monitor(thread, _("Scanning %s..." % device.name), gtk.STOCK_REFRESH)
def add_device_panel(self, type, obj, device): from xl.collection import CollectionScanThread from xlgui.panel.device import DevicePanel, FlatPlaylistDevicePanel import xlgui.panel paneltype = DevicePanel if hasattr(device, 'panel_type'): if device.panel_type == 'flatplaylist': paneltype = FlatPlaylistDevicePanel elif issubclass(device.panel_type, xlgui.panel.Panel): paneltype = device.panel_type panel = paneltype(self.main.window, self.main, device, device.get_name()) sort = True panel.connect('append-items', lambda panel, items, play, sort=sort: self.main. on_append_items(items, play, sort=sort)) panel.connect('queue-items', lambda panel, items, sort=sort: self.main. on_append_items(items, queue=True, sort=sort)) panel.connect('replace-items', lambda panel, items, sort=sort: self.main. on_append_items(items, replace=True, sort=sort)) self.device_panels[device.get_name()] = panel GLib.idle_add(providers.register, 'main-panel', panel) thread = CollectionScanThread(device.get_collection()) thread.connect('done', panel.load_tree) self.progress_manager.add_monitor(thread, _("Scanning %s..." % device.name), Gtk.STOCK_REFRESH)
def rescan_collection_with_progress(self, startup=False): libraries = self.exaile.collection.get_libraries() if not self.exaile.collection._scanning and len(libraries) > 0: from xl.collection import CollectionScanThread thread = CollectionScanThread(self.exaile.collection, startup_scan=startup) thread.connect('done', self.on_rescan_done) self.progress_manager.add_monitor(thread, _("Scanning collection..."), gtk.STOCK_REFRESH)
def on_rescan_collection(self, *e): """ Called when the user wishes to rescan the collection """ libraries = self.exaile.collection.get_libraries() if not self.exaile.collection._scanning and len(libraries) > 0: from xl.collection import CollectionScanThread thread = CollectionScanThread(self.exaile.collection) thread.connect('done', self.on_rescan_done) self.progress_manager.add_monitor(thread, _("Scanning collection..."), gtk.STOCK_REFRESH)
def rescan_collection_with_progress(self, startup=False, force_update=False): libraries = self.exaile.collection.get_libraries() if not self.exaile.collection._scanning and len(libraries) > 0: from xl.collection import CollectionScanThread thread = CollectionScanThread( self.exaile.collection, startup_scan=startup, force_update=force_update ) thread.connect('done', self.on_rescan_done) self.progress_manager.add_monitor( thread, _("Scanning collection..."), 'drive-harddisk' )
def __init__(self, exaile, uris): Gtk.Window.__init__(self, transient_for=exaile.gui.main.window) self.init_template() self.exaile = exaile self.collection = Collection("GT Import Collection") for uri in uris: self.collection.add_library(Library(uri)) self.manager = ProgressManager(self.content_area) self.rescan_thread = CollectionScanThread(self.collection) self.rescan_thread.connect('done', self._on_rescan_done) self.import_thread = None self.manager.add_monitor(self.rescan_thread, _("Importing tracks"), Gtk.STOCK_REFRESH)
def add_device_panel(self, type, obj, device): from xl.collection import CollectionScanThread from xlgui.panel.device import DevicePanel, FlatPlaylistDevicePanel import xlgui.panel paneltype = DevicePanel if hasattr(device, 'panel_type'): if device.panel_type == 'flatplaylist': paneltype = FlatPlaylistDevicePanel elif issubclass(device.panel_type, xlgui.panel.Panel): paneltype = device.panel_type panel = paneltype(self.main.window, self.main, device, device.get_name()) do_sort = True panel.connect( 'append-items', lambda _panel, items, play: self.main.on_append_items( items, play, sort=do_sort ), ) panel.connect( 'queue-items', lambda _panel, items: self.main.on_append_items( items, queue=True, sort=do_sort ), ) panel.connect( 'replace-items', lambda _panel, items: self.main.on_append_items( items, replace=True, sort=do_sort ), ) self.device_panels[device.get_name()] = panel GLib.idle_add(providers.register, 'main-panel', panel) thread = CollectionScanThread(device.get_collection()) thread.connect('done', panel.load_tree) self.progress_manager.add_monitor( thread, _("Scanning %s..." % device.name), 'drive-harddisk' )
def __init__(self, exaile, uris): self.exaile = exaile self._init_builder() self.collection = Collection("GT Import Collection") for uri in uris: self.collection.add_library(Library(uri)) self.manager = ProgressManager(self.content_area) self.rescan_thread = CollectionScanThread(self.collection) self.rescan_thread.connect( 'done', lambda t: glib.idle_add(self._on_rescan_done)) self.update_thread = None self.import_thread = None self.manager.add_monitor(self.rescan_thread, _("Importing tracks"), gtk.STOCK_REFRESH)
def __init__(self, exaile, uris): self.exaile = exaile self._init_builder() self.collection = Collection("GT Import Collection") for uri in uris: self.collection.add_library(Library(uri)) self.manager = ProgressManager(self.content_area) self.rescan_thread = CollectionScanThread(self.collection) self.rescan_thread.connect('done', lambda t: glib.idle_add(self._on_rescan_done)) self.update_thread = None self.import_thread = None self.manager.add_monitor(self.rescan_thread, _("Importing tracks"), gtk.STOCK_REFRESH)
class GtImporter(object): ''' Shows a dialog that allows importing of grouping tags from a directory not included in the current collection. ''' def __init__(self, exaile, uris): self.exaile = exaile self._init_builder() self.collection = Collection("GT Import Collection") for uri in uris: self.collection.add_library(Library(uri)) self.manager = ProgressManager(self.content_area) self.rescan_thread = CollectionScanThread(self.collection) self.rescan_thread.connect('done', lambda t: glib.idle_add(self._on_rescan_done)) self.update_thread = None self.import_thread = None self.manager.add_monitor(self.rescan_thread, _("Importing tracks"), gtk.STOCK_REFRESH) def _init_builder(self): builder = gtk.Builder() builder.add_from_file(os.path.join(os.path.dirname(__file__), 'gt_import.ui')) # retrieve widgets self.window = builder.get_object('window') self.content_area = builder.get_object('content_area') self.ok_button = builder.get_object('ok_button') self.tags_model = builder.get_object('tags_model') self.tags_view = builder.get_object('tags_view') self.tags_vbox = builder.get_object('tags_vbox') self.radio_merge = builder.get_object('radio_merge') self.radio_replace = builder.get_object('radio_replace') # signals signals = { 'on_cancel_button_clicked': self._on_cancel_button_clicked, 'on_import_checkbox_toggled': self._on_import_checkbox_toggled, 'on_ok_button_clicked': self._on_ok_button_clicked, 'on_window_destroy': self._on_window_destroy } builder.connect_signals(signals, None) def show(self): return self.window.show() # # Status routines # def _on_rescan_done(self): '''Called when the collection is finished loading''' if self.rescan_thread is None: return self.rescan_thread = None logger.info('Import directory scan completed, importing groups') # now that the collection has loaded, import the groups from them self.import_thread = TrackImportThread(self.collection, self.exaile.collection) self.import_thread.connect('done', self._on_import_done) self.manager.add_monitor(self.import_thread, _("Importing groups"), gtk.STOCK_JUMP_TO) def _on_import_done(self, thread): '''Called when the grouping data is retrieved''' if self.import_thread is None: return track_data = self.import_thread.track_data self.import_thread = None logger.info('Group import finished, %s new tracks found' % len(track_data)) if len(track_data) == 0: self.window.destroy() # TODO: this isn't on another thread, but if we don't call # threads_enter/leave then it deadlocks. Not sure why... locations = ';'.join([l.get_location() for l in self.collection.get_libraries()]) gtk.gdk.threads_enter() dialogs.info(self.window, 'No new tracks found at "%s"' % locations) gtk.gdk.threads_leave() return self.tags_view.freeze_child_notify() self.tags_view.set_model(None) # add the data to the model for old_group_str, new_group_str, matched_track, newgroups in track_data: self.tags_model.append((True, str(matched_track), old_group_str, new_group_str, matched_track, newgroups)) self.tags_view.set_model(self.tags_model) self.tags_view.thaw_child_notify() self.ok_button.set_sensitive(True) self.tags_vbox.set_visible(True) def _on_update_done(self, thread): if self.update_thread is None: return self.update_thread = None logger.info('Track update complete') self.window.destroy() # # Widget events # def _on_cancel_button_clicked(self, widget): if self.rescan_thread is not None: self.rescan_thread.stop() elif self.import_thread is not None: self.import_thread.stop() elif self.update_thread is not None: self.update_thread.stop() self.window.destroy() def _on_import_checkbox_toggled(self, cell, path): self.tags_model[path][0] = not cell.get_active() def _on_ok_button_clicked(self, widget): self.ok_button.set_sensitive(False) self.tags_vbox.set_sensitive(False) data = [(row[4], row[5]) for row in self.tags_model if row[0] == True] logger.info('Updating %s tracks' % len(data)) self.update_thread = TrackUpdateThread(data, self.radio_replace.get_active()) self.update_thread.connect('done', self._on_update_done) self.manager.add_monitor(self.update_thread, _("Updating groups"), gtk.STOCK_CONVERT) def _on_window_destroy(self, widget): self.collection.close()
class GtImporter(Gtk.Window): ''' Shows a dialog that allows importing of grouping tags from a directory not included in the current collection. ''' __gtype_name__ = 'GtImporter' content_area, \ ok_button, \ tags_model, \ tags_view, \ tags_vbox, \ radio_merge, \ radio_replace = GtkTemplate.Child.widgets(7) def __init__(self, exaile, uris): Gtk.Window.__init__(self, transient_for=exaile.gui.main.window) self.init_template() self.exaile = exaile self.collection = Collection("GT Import Collection") for uri in uris: self.collection.add_library(Library(uri)) self.manager = ProgressManager(self.content_area) self.rescan_thread = CollectionScanThread(self.collection) self.rescan_thread.connect('done', self._on_rescan_done) self.import_thread = None self.manager.add_monitor(self.rescan_thread, _("Importing tracks"), 'document-open') # # Status routines # @idle_add() def _on_rescan_done(self, thread): '''Called when the collection is finished loading''' if self.rescan_thread is None: return self.rescan_thread = None logger.info('Import directory scan completed, importing groups') # now that the collection has loaded, import the groups from them self.import_track_data = [] self.import_thread = SimpleProgressThread(track_import_thread, self.collection, self.exaile.collection, self.import_track_data) self.import_thread.connect('done', self._on_import_done) self.manager.add_monitor(self.import_thread, _("Importing groups"), 'document-open') @idle_add() def _on_import_done(self, thread): '''Called when the grouping data is retrieved''' if self.import_thread is None: return track_data = self.import_track_data self.import_thread = None self.import_track_data = None logger.info('Group import finished, %s new tracks found', len(track_data)) if len(track_data) == 0: self.destroy() locations = ';'.join( [l.get_location() for l in self.collection.get_libraries()]) dialogs.info(self.exaile.gui.main.window, 'No new tracks found at "%s"' % locations) return self.tags_view.freeze_child_notify() self.tags_view.set_model(None) # add the data to the model for old_group_str, new_group_str, matched_track, newgroups in track_data: self.tags_model.append((True, str(matched_track), old_group_str, new_group_str, matched_track, newgroups)) self.tags_view.set_model(self.tags_model) self.tags_view.thaw_child_notify() self.ok_button.set_sensitive(True) self.tags_vbox.set_visible(True) @idle_add() def _on_update_done(self, thread): if self.update_thread is None: return self.update_thread = None logger.info('Track update complete') self.destroy() # # Widget events # @GtkTemplate.Callback def on_cancel_button_clicked(self, widget): if self.rescan_thread is not None: self.rescan_thread.stop() elif self.import_thread is not None: self.import_thread.stop() elif self.update_thread is not None: self.update_thread.stop() self.destroy() @GtkTemplate.Callback def on_import_checkbox_toggled(self, cell, path): self.tags_model[path][0] = not cell.get_active() @GtkTemplate.Callback def on_ok_button_clicked(self, widget): self.ok_button.set_sensitive(False) self.tags_vbox.set_sensitive(False) data = [(row[4], row[5]) for row in self.tags_model if row[0]] logger.info('Updating %s tracks', len(data)) self.update_thread = SimpleProgressThread( track_update_thread, data, self.radio_replace.get_active()) self.update_thread.connect('done', self._on_update_done) self.manager.add_monitor(self.update_thread, _("Updating groups"), 'system-run') @GtkTemplate.Callback def on_window_destroy(self, widget): self.collection.close()
class GtImporter(Gtk.Window): ''' Shows a dialog that allows importing of grouping tags from a directory not included in the current collection. ''' __gtype_name__ = 'GtImporter' content_area, \ ok_button, \ tags_model, \ tags_view, \ tags_vbox, \ radio_merge, \ radio_replace = GtkTemplate.Child.widgets(7) def __init__(self, exaile, uris): Gtk.Window.__init__(self, transient_for=exaile.gui.main.window) self.init_template() self.exaile = exaile self.collection = Collection("GT Import Collection") for uri in uris: self.collection.add_library(Library(uri)) self.manager = ProgressManager(self.content_area) self.rescan_thread = CollectionScanThread(self.collection) self.rescan_thread.connect('done', lambda t: GLib.idle_add(self._on_rescan_done)) self.update_thread = None self.import_thread = None self.manager.add_monitor(self.rescan_thread, _("Importing tracks"), Gtk.STOCK_REFRESH) # # Status routines # def _on_rescan_done(self): '''Called when the collection is finished loading''' if self.rescan_thread is None: return self.rescan_thread = None logger.info('Import directory scan completed, importing groups') # now that the collection has loaded, import the groups from them self.import_thread = TrackImportThread(self.collection, self.exaile.collection) self.import_thread.connect('done', self._on_import_done) self.manager.add_monitor(self.import_thread, _("Importing groups"), Gtk.STOCK_JUMP_TO) def _on_import_done(self, thread): '''Called when the grouping data is retrieved''' if self.import_thread is None: return track_data = self.import_thread.track_data self.import_thread = None logger.info('Group import finished, %s new tracks found' % len(track_data)) if len(track_data) == 0: self.destroy() locations = ';'.join([l.get_location() for l in self.collection.get_libraries()]) dialogs.info(self.exaile.gui.main.window, 'No new tracks found at "%s"' % locations) return self.tags_view.freeze_child_notify() self.tags_view.set_model(None) # add the data to the model for old_group_str, new_group_str, matched_track, newgroups in track_data: self.tags_model.append((True, str(matched_track), old_group_str, new_group_str, matched_track, newgroups)) self.tags_view.set_model(self.tags_model) self.tags_view.thaw_child_notify() self.ok_button.set_sensitive(True) self.tags_vbox.set_visible(True) def _on_update_done(self, thread): if self.update_thread is None: return self.update_thread = None logger.info('Track update complete') self.destroy() # # Widget events # @GtkTemplate.Callback def on_cancel_button_clicked(self, widget): if self.rescan_thread is not None: self.rescan_thread.stop() elif self.import_thread is not None: self.import_thread.stop() elif self.update_thread is not None: self.update_thread.stop() self.destroy() @GtkTemplate.Callback def on_import_checkbox_toggled(self, cell, path): self.tags_model[path][0] = not cell.get_active() @GtkTemplate.Callback def on_ok_button_clicked(self, widget): self.ok_button.set_sensitive(False) self.tags_vbox.set_sensitive(False) data = [(row[4], row[5]) for row in self.tags_model if row[0] == True] logger.info('Updating %s tracks' % len(data)) self.update_thread = TrackUpdateThread(data, self.radio_replace.get_active()) self.update_thread.connect('done', self._on_update_done) self.manager.add_monitor(self.update_thread, _("Updating groups"), Gtk.STOCK_CONVERT) @GtkTemplate.Callback def on_window_destroy(self, widget): self.collection.close()
class GtImporter(object): ''' Shows a dialog that allows importing of grouping tags from a directory not included in the current collection. ''' def __init__(self, exaile, uris): self.exaile = exaile self._init_builder() self.collection = Collection("GT Import Collection") for uri in uris: self.collection.add_library(Library(uri)) self.manager = ProgressManager(self.content_area) self.rescan_thread = CollectionScanThread(self.collection) self.rescan_thread.connect( 'done', lambda t: glib.idle_add(self._on_rescan_done)) self.update_thread = None self.import_thread = None self.manager.add_monitor(self.rescan_thread, _("Importing tracks"), gtk.STOCK_REFRESH) def _init_builder(self): builder = gtk.Builder() builder.add_from_file( os.path.join(os.path.dirname(__file__), 'gt_import.ui')) # retrieve widgets self.window = builder.get_object('window') self.content_area = builder.get_object('content_area') self.ok_button = builder.get_object('ok_button') self.tags_model = builder.get_object('tags_model') self.tags_view = builder.get_object('tags_view') self.tags_vbox = builder.get_object('tags_vbox') self.radio_merge = builder.get_object('radio_merge') self.radio_replace = builder.get_object('radio_replace') # signals signals = { 'on_cancel_button_clicked': self._on_cancel_button_clicked, 'on_import_checkbox_toggled': self._on_import_checkbox_toggled, 'on_ok_button_clicked': self._on_ok_button_clicked, 'on_window_destroy': self._on_window_destroy } builder.connect_signals(signals, None) def show(self): return self.window.show() # # Status routines # def _on_rescan_done(self): '''Called when the collection is finished loading''' if self.rescan_thread is None: return self.rescan_thread = None logger.info('Import directory scan completed, importing groups') # now that the collection has loaded, import the groups from them self.import_thread = TrackImportThread(self.collection, self.exaile.collection) self.import_thread.connect('done', self._on_import_done) self.manager.add_monitor(self.import_thread, _("Importing groups"), gtk.STOCK_JUMP_TO) def _on_import_done(self, thread): '''Called when the grouping data is retrieved''' if self.import_thread is None: return track_data = self.import_thread.track_data self.import_thread = None logger.info('Group import finished, %s new tracks found' % len(track_data)) if len(track_data) == 0: self.window.destroy() # TODO: this isn't on another thread, but if we don't call # threads_enter/leave then it deadlocks. Not sure why... locations = ';'.join( [l.get_location() for l in self.collection.get_libraries()]) gtk.gdk.threads_enter() dialogs.info(self.window, 'No new tracks found at "%s"' % locations) gtk.gdk.threads_leave() return self.tags_view.freeze_child_notify() self.tags_view.set_model(None) # add the data to the model for old_group_str, new_group_str, matched_track, newgroups in track_data: self.tags_model.append((True, str(matched_track), old_group_str, new_group_str, matched_track, newgroups)) self.tags_view.set_model(self.tags_model) self.tags_view.thaw_child_notify() self.ok_button.set_sensitive(True) self.tags_vbox.set_visible(True) def _on_update_done(self, thread): if self.update_thread is None: return self.update_thread = None logger.info('Track update complete') self.window.destroy() # # Widget events # def _on_cancel_button_clicked(self, widget): if self.rescan_thread is not None: self.rescan_thread.stop() elif self.import_thread is not None: self.import_thread.stop() elif self.update_thread is not None: self.update_thread.stop() self.window.destroy() def _on_import_checkbox_toggled(self, cell, path): self.tags_model[path][0] = not cell.get_active() def _on_ok_button_clicked(self, widget): self.ok_button.set_sensitive(False) self.tags_vbox.set_sensitive(False) data = [(row[4], row[5]) for row in self.tags_model if row[0] == True] logger.info('Updating %s tracks' % len(data)) self.update_thread = TrackUpdateThread(data, self.radio_replace.get_active()) self.update_thread.connect('done', self._on_update_done) self.manager.add_monitor(self.update_thread, _("Updating groups"), gtk.STOCK_CONVERT) def _on_window_destroy(self, widget): self.collection.close()