Example #1
0
    def on_drag_drop(self, to_tree, drag_context, x, y, selection):
        # ff - from_filter
        self.copy = drag_context.action
        to_filter_model = to_tree.get_model()
        to_model = to_filter_model.get_model()
        if to_tree.get_dest_row_at_pos(x, y):
            to_filter_path, to_filter_pos = to_tree.get_dest_row_at_pos(x, y)
            to_filter_iter = to_filter_model.get_iter(to_filter_path)
            to_iter = to_filter_model.convert_iter_to_child_iter(
                to_filter_iter)
        else:
            to_filter_path = None
            to_filter_pos = None
            to_filter_iter = None
            to_iter = None

        from_tree = drag_context.get_source_widget()

        if not from_tree: return None

        ff_model, ff_paths = from_tree.get_selection().get_selected_rows()

        new_iter = None
        self.row_to_remove = []

        ff_row_refs = [
            gtk.TreeRowReference(ff_model, ff_path) for ff_path in ff_paths
        ]
        """to tree is NavigationTreeControl"""
        is_copy_move = False
        if isinstance(self, self.controls.tree.__class__):
            if from_tree is not to_tree:
                return
            if sys.version_info < (2, 6):
                return
            dest_folder = self.get_dest_folder(to_filter_model, to_filter_iter,
                                               to_filter_path)
            rows = [to_model[ff_path] for ff_path in ff_paths]
            files = [
                row[self.path[0]] for row in rows
                if os.path.dirname(row[self.path[0]]) != dest_folder
            ]
            if (to_filter_pos and
                ((to_filter_pos == gtk.TREE_VIEW_DROP_INTO_OR_BEFORE) or
                 (to_filter_pos == gtk.TREE_VIEW_DROP_INTO_OR_AFTER))
                    and os.path.isfile(
                        to_filter_model[to_filter_path][self.path[0]])):
                to_filter_pos = gtk.TREE_VIEW_DROP_AFTER
            if files and copy_move_files_dialog(files, dest_folder, self.copy):
                is_copy_move = True
                text = _(
                    "Copying:") if self.copy == gtk.gdk.ACTION_COPY else _(
                        "Replacing:")  #@UndefinedVariable
                self.pr_window = CopyProgressWindow(_("Progress"), files, 300,
                                                    100)
                self.pr_window.label_from.set_text(text)
                self.pr_window.label_to.set_text(
                    _("To: ") + dest_folder + "\n")
                for ff_path, ff_row_ref, file in zip(ff_paths, ff_row_refs,
                                                     files):
                    new_path = self.replace_inside_navig_tree(
                        file, dest_folder)
                    if not new_path: continue
                    self.one_row_replacing(ff_row_ref, ff_path, ff_model,
                                           from_tree, to_model, to_tree,
                                           to_iter, to_filter_pos,
                                           to_filter_path, new_iter, new_path,
                                           is_copy_move)
                self.remove_replaced(ff_model)
                self.pr_window.destroy()
                self.save_beans_from_tree()
            return

        for ff_row_ref in ff_row_refs:
            self.one_row_replacing(ff_row_ref, ff_path, ff_model, from_tree,
                                   to_model, to_tree, to_iter, to_filter_pos,
                                   to_filter_path, new_iter)

        if from_tree == to_tree:
            self.remove_replaced(ff_model)

        self.row_to_remove = []

        self.rebuild_tree(to_tree)
Example #2
0
    def on_drag_drop(self, to_tree, drag_context, x, y, selection):
        # ff - from_filter
        self.copy = drag_context.action
        to_filter_model = to_tree.get_model()
        to_model = to_filter_model.get_model()
        if to_tree.get_dest_row_at_pos(x, y):
            to_filter_path, to_filter_pos = to_tree.get_dest_row_at_pos(x, y)
            to_filter_iter = to_filter_model.get_iter(to_filter_path)
            to_iter = to_filter_model.convert_iter_to_child_iter(
                to_filter_iter)
        else:
            to_filter_path = None
            to_filter_pos = None
            to_filter_iter = None
            to_iter = None

        from_tree = drag_context.get_source_widget()

        if not from_tree: return None

        ff_model, ff_paths = from_tree.get_selection().get_selected_rows()

        if "PlaylistTreeControl" in str(to_tree) and to_tree != from_tree:
            self.controls.search_progress.start()
            self.spinner = True

            def task(to_iter):
                all_rows = []
                for ff_path in ff_paths:
                    ff_iter = ff_model.get_iter(ff_path)
                    beans = self.get_all_beans_by_parent(ff_model, ff_iter)
                    all_rows += self.fill_beans_and_get_rows(
                        beans, self.simple_content_filter)

                self.spinner = False

                for i, row in enumerate(all_rows):
                    pos = gtk.TREE_VIEW_DROP_AFTER if i else to_filter_pos
                    if row[self.path[0]] and get_file_extension(
                            row[self.path[0]]) in [".m3u", ".m3u8"]:
                        self.add_m3u(ff_model, ff_iter, to_tree, to_model,
                                     to_iter, pos)
                        continue
                    to_iter = self.to_add_drag_item(to_tree,
                                                    to_model,
                                                    to_iter,
                                                    pos,
                                                    None,
                                                    row=row)
                self.controls.search_progress.stop()
                self.update_tracknumber()

            t = threading.Thread(target=task, args=(to_iter, ))
            t.start()
            """trick to show spinner before end of handling"""
            while t.isAlive():
                time.sleep(0.1)
                while gtk.events_pending():
                    if self.spinner:  #self.controls.search_progress.get_property('active'):
                        gtk.main_iteration()
                    else:
                        break  # otherwise endless cycle'''

            return

        new_iter = None
        self.row_to_remove = []

        ff_row_refs = [
            gtk.TreeRowReference(ff_model, ff_path) for ff_path in ff_paths
        ]
        """to tree is NavigationTreeControl"""
        is_copy_move = False
        if isinstance(self, self.controls.tree.__class__):
            if from_tree is not to_tree:
                return
            if sys.version_info < (2, 6):
                return
            dest_folder = self.get_dest_folder(to_filter_model, to_filter_iter,
                                               to_filter_path)
            rows = [to_model[ff_path] for ff_path in ff_paths]
            files = [
                row[self.path[0]] for row in rows
                if os.path.dirname(row[self.path[0]]) != dest_folder
            ]
            if to_filter_pos:
                if os.path.isfile(
                        to_filter_model[to_filter_path][self.path[0]]):
                    if to_filter_pos != gtk.TREE_VIEW_DROP_BEFORE:
                        to_filter_pos = gtk.TREE_VIEW_DROP_AFTER
                elif to_filter_pos in (gtk.TREE_VIEW_DROP_BEFORE,
                                       gtk.TREE_VIEW_DROP_AFTER):
                    info_dialog(
                        _("Attention!!!"),
                        _("When you release the mouse button the mouse" +
                          " pointer must be over the folder exactly." +
                          " Please retry!"))
                    return
            if files and copy_move_files_dialog(files, dest_folder, self.copy):
                is_copy_move = True
                text = _(
                    "Copying:") if self.copy == gtk.gdk.ACTION_COPY else _(
                        "Replacing:")  #@UndefinedVariable
                self.pr_window = CopyProgressWindow(_("Progress"), files, 300,
                                                    100)
                self.pr_window.label_from.set_text(text)
                self.pr_window.label_to.set_text(
                    _("To: ") + dest_folder + "\n")
                for ff_path, ff_row_ref, file in zip(ff_paths, ff_row_refs,
                                                     files):
                    new_path = self.replace_inside_navig_tree(
                        file, dest_folder)
                    if not new_path: continue
                    self.one_row_replacing(ff_row_ref, ff_path, ff_model,
                                           from_tree, to_tree, to_model,
                                           to_iter, to_filter_pos,
                                           to_filter_path, new_iter, new_path,
                                           is_copy_move)
                self.remove_replaced(ff_model)
                self.pr_window.destroy()
                self.save_beans_from_tree()
            return

        for ff_row_ref in ff_row_refs:
            new_iter = self.one_row_replacing(ff_row_ref, ff_path, ff_model,
                                              from_tree, to_tree, to_model,
                                              to_iter, to_filter_pos,
                                              to_filter_path, new_iter)

        if from_tree == to_tree:
            self.remove_replaced(ff_model)

        self.row_to_remove = []

        self.rebuild_tree(to_tree)
Example #3
0
  def on_drag_drop(self, to_tree, drag_context, x, y, selection):
      # ff - from_filter
      self.copy = drag_context.action
      to_filter_model = to_tree.get_model()
      to_model = to_filter_model.get_model()
      if to_tree.get_dest_row_at_pos(x, y):
          to_filter_path, to_filter_pos = to_tree.get_dest_row_at_pos(x, y)
          to_filter_iter = to_filter_model.get_iter(to_filter_path)
          to_iter = to_filter_model.convert_iter_to_child_iter(to_filter_iter)
      else:
          to_filter_path = None
          to_filter_pos = None     
          to_filter_iter = None
          to_iter = None
          
      from_tree = drag_context.get_source_widget()        
      
      if not from_tree: return None
      
      ff_model, ff_paths = from_tree.get_selection().get_selected_rows()
      
      if "RadioTreeControl" in str(to_tree) and to_tree != from_tree:
          return
      
      if "PlaylistTreeControl" in str(to_tree) and to_tree != from_tree:
          def task(to_iter):
              all_rows = []
              for ff_path in ff_paths:
                  ff_iter = ff_model.get_iter(ff_path)
                  beans = self.get_all_beans_by_parent(ff_model, ff_iter)
                  all_rows += self.fill_beans_and_get_rows(beans, self.simple_content_filter)
                  
              for i, row in enumerate(all_rows):
                      pos = AFTER if i else to_filter_pos
                      if is_m3u(row[self.path[0]]):
                          self.add_m3u(ff_model, ff_iter, to_tree, to_model, to_iter, pos)
                          continue
                      to_iter = self.to_add_drag_item(to_tree, to_model, to_iter, pos, None, row=row)
              self.update_tracknumber()
         
          self.controls.search_progress.background_spinner_wrapper(task, to_iter)                              
          
          return 
      
      new_iter = None
      self.row_to_remove = []
      
      ff_row_refs = [gtk.TreeRowReference(ff_model, ff_path) for ff_path in ff_paths]
      
      """to tree is NavigationTreeControl"""
      if isinstance(self, self.controls.tree.__class__):
          if from_tree is not to_tree:
              return
          if sys.version_info < (2, 6):
              return
          dest_folder = self.get_dest_folder(to_filter_model, to_filter_iter, to_filter_path)
          rows = [to_model[ff_path] for ff_path in ff_paths]
          files = [row[self.path[0]] for row in rows if os.path.dirname(row[self.path[0]]) != dest_folder]
          if to_filter_pos:
              if os.path.isfile(to_filter_model[to_filter_path][self.path[0]]):
                  if to_filter_pos != BEFORE:
                      to_filter_pos = AFTER
              elif to_filter_pos in (BEFORE, 
                                     AFTER):
                  info_dialog(_("Attention!!!"), 
                              _("When you release the mouse button the mouse" +
                               " pointer must be over the folder exactly." +
                               " Please retry!"))
                  return
          if files and copy_move_files_dialog(files, dest_folder, self.copy):
              text = _("Copying:") if self.copy == gtk.gdk.ACTION_COPY else _("Replacing:") #@UndefinedVariable
              self.pr_window = CopyProgressWindow(_("Progress"), files, 300, 100)
              self.pr_window.label_from.set_text(text)
              self.pr_window.label_to.set_text(_("To: ") + dest_folder + "\n")
              for ff_path, ff_row_ref, file in zip(ff_paths, ff_row_refs, files):
                  new_path = self.replace_inside_navig_tree(file, dest_folder)
                  if not new_path: continue
                  row = to_model[ff_path]
                  new_row = list(row)
                  if to_iter:
                      if to_model.get_value(to_iter, self.is_file[0]):
                          new_row[self.parent_level[0]] = to_model.get_value(to_iter, self.parent_level[0])
                          new_dir = os.path.dirname(to_model.get_value(to_iter, self.path[0]))
                      else:
                          new_row[self.parent_level[0]] = to_model.get_value(to_iter, self.level[0])
                          new_dir = to_model.get_value(to_iter, self.path[0])
                  else:
                      new_row[self.parent_level[0]] = None
                      if self.model[0][self.is_file[0]]:
                          new_dir = os.path.dirname(self.model[0][self.path[0]])
                      else:
                          new_dir = self.model[0][self.path[0]]
                  new_row[self.path[0]] = os.path.join(new_dir, os.path.basename(row[self.path[0]]))
                             
                  self.tree_insert_row(new_row)
                  
                  def task(row):
                      for child_row in row.iterchildren():
                          child_row[self.path[0]] = os.path.join(row[self.path[0]], os.path.basename(child_row[self.path[0]]))
                          self.tree_insert_row(child_row)
                          task(child_row)
                          if self.copy == gtk.gdk.ACTION_MOVE: #@UndefinedVariable
                              self.row_to_remove.append(self.get_row_reference_from_iter(ff_model, 
                                                          ff_model.convert_child_iter_to_iter(child_row.iter)))
                  task(row)
                  if self.copy == gtk.gdk.ACTION_MOVE: #@UndefinedVariable
                      self.row_to_remove.append(ff_row_ref)
                  
              self.remove_replaced(ff_model)
              self.pr_window.destroy()
              self.save_beans_from_tree()
          return
                    
      for ff_row_ref in ff_row_refs: 
          new_iter = self.one_row_replacing(ff_row_ref, ff_path, ff_model, from_tree,
                                to_tree, to_model, to_iter, to_filter_pos, to_filter_path,
                                new_iter)
      
      if from_tree == to_tree:
          self.remove_replaced(ff_model)
          
      self.row_to_remove = []
 
      self.rebuild_tree(to_tree)        
Example #4
0
  def on_drag_drop(self, to_tree, drag_context, x, y, selection):
      # ff - from_filter
      self.copy = drag_context.action
      to_filter_model = to_tree.get_model()
      to_model = to_filter_model.get_model()
      if to_tree.get_dest_row_at_pos(x, y):
          to_filter_path, to_filter_pos = to_tree.get_dest_row_at_pos(x, y)
          to_filter_iter = to_filter_model.get_iter(to_filter_path)
          to_iter = to_filter_model.convert_iter_to_child_iter(to_filter_iter)
      else:
          to_filter_path = None
          to_filter_pos = None     
          to_filter_iter = None
          to_iter = None
          
      from_tree = drag_context.get_source_widget()        
      
      if not from_tree: return None
      
      ff_model, ff_paths = from_tree.get_selection().get_selected_rows()
      
      if "RadioTreeControl" in str(to_tree) and to_tree != from_tree:
          return
      
      if "PlaylistTreeControl" in str(to_tree) and to_tree != from_tree:
          self.controls.search_progress.start()
          self.spinner = True
          def task(to_iter):
              all_rows = []
              for ff_path in ff_paths:
                  ff_iter = ff_model.get_iter(ff_path)
                  beans = self.get_all_beans_by_parent(ff_model, ff_iter)
                  all_rows += self.fill_beans_and_get_rows(beans, self.simple_content_filter)
              
              self.spinner = False
                  
              for i, row in enumerate(all_rows):
                      pos = AFTER if i else to_filter_pos
                      if row[self.path[0]] and get_file_extension(row[self.path[0]]) in [".m3u", ".m3u8"]:
                          self.add_m3u(ff_model, ff_iter, to_tree, to_model, to_iter, pos)
                          continue
                      to_iter = self.to_add_drag_item(to_tree, to_model, to_iter, pos, None, row=row)
              self.controls.search_progress.stop()
              self.update_tracknumber()
                                        
          t = threading.Thread(target=task, args=(to_iter,))
          t.start()
          """trick to show spinner before end of handling"""
          while t.isAlive():
              time.sleep(0.1)
              while gtk.events_pending():
                  if self.spinner:#self.controls.search_progress.get_property('active'):
                      gtk.main_iteration()
                  else:
                      break # otherwise endless cycle'''
                  
          return 
      
      new_iter = None
      self.row_to_remove = []
      
      ff_row_refs = [gtk.TreeRowReference(ff_model, ff_path) for ff_path in ff_paths]
      
      """to tree is NavigationTreeControl"""
      is_copy_move = False
      if isinstance(self, self.controls.tree.__class__):
          if from_tree is not to_tree:
              return
          if sys.version_info < (2, 6):
              return
          dest_folder = self.get_dest_folder(to_filter_model, to_filter_iter, to_filter_path)
          rows = [to_model[ff_path] for ff_path in ff_paths]
          files = [row[self.path[0]] for row in rows if os.path.dirname(row[self.path[0]]) != dest_folder]
          if to_filter_pos:
              if os.path.isfile(to_filter_model[to_filter_path][self.path[0]]):
                  if to_filter_pos != BEFORE:
                      to_filter_pos = AFTER
              elif to_filter_pos in (BEFORE, 
                                     AFTER):
                  info_dialog(_("Attention!!!"), 
                              _("When you release the mouse button the mouse" +
                               " pointer must be over the folder exactly." +
                               " Please retry!"))
                  return
          if files and copy_move_files_dialog(files, dest_folder, self.copy):
              is_copy_move = True
              text = _("Copying:") if self.copy == gtk.gdk.ACTION_COPY else _("Replacing:") #@UndefinedVariable
              self.pr_window = CopyProgressWindow(_("Progress"), files, 300, 100)
              self.pr_window.label_from.set_text(text)
              self.pr_window.label_to.set_text(_("To: ") + dest_folder + "\n")
              for ff_path, ff_row_ref, file in zip(ff_paths, ff_row_refs, files):
                  new_path = self.replace_inside_navig_tree(file, dest_folder)
                  if not new_path: continue
                  self.one_row_replacing(ff_row_ref, ff_path, ff_model, from_tree,
                      to_tree, to_model, to_iter, to_filter_pos, to_filter_path,
                      new_iter, new_path, is_copy_move)
              self.remove_replaced(ff_model)
              self.pr_window.destroy()
              self.save_beans_from_tree()
          return
                    
      for ff_row_ref in ff_row_refs: 
          new_iter = self.one_row_replacing(ff_row_ref, ff_path, ff_model, from_tree,
                                to_tree, to_model, to_iter, to_filter_pos, to_filter_path,
                                new_iter)
      
      if from_tree == to_tree:
          self.remove_replaced(ff_model)
          
      self.row_to_remove = []
 
      self.rebuild_tree(to_tree)