Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 04-19-2018, 06:21 PM   #1
luckylittle
Member
luckylittle began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Nov 2012
Device: Kindle Fire
Question SelectedItems in Ebook Editor

I am developing a renaming plugin that will do similar thing as request_change_ext function in the FileList class (https://github.com/kovidgoyal/calibr...k/file_list.py).


However, i don't seem to understand where is .selectedItems() coming from in request_rename_common?

Can someone led some light on it, please?
luckylittle is offline   Reply With Quote
Old 04-19-2018, 07:57 PM   #2
luckylittle
Member
luckylittle began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Nov 2012
Device: Kindle Fire
I looked into it closer now, is this the correct statement?

* self.build creates a container of names, categories, icons (https://github.com/kovidgoyal/calibr...e_list.py#L321)

* the above leverages function get_state to get the array of selected items (https://github.com/kovidgoyal/calibr...e_list.py#L255)
luckylittle is offline   Reply With Quote
Advert
Old 04-19-2018, 11:43 PM   #3
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,776
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
selectedItems() is a Qt method from the QTreeWidget class. self.build() populates the QTreeWidget. IIRC it only uses get_state() if the state before the build is to be preserved (i.e. the selected files and expanded nodes).
kovidgoyal is offline   Reply With Quote
Old 04-21-2018, 08:38 AM   #4
luckylittle
Member
luckylittle began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Nov 2012
Device: Kindle Fire
Ok, i am able to get it working for one file at the time - getting the selected name with
Quote:
self.gui.file_list.current_name
But what about bulk select?

Also, my plugin is ONLY visible in menu and not on the toolbar (although allowed_in_toolbar=True and for_toolbar=True), do you know what could be the reason?
luckylittle is offline   Reply With Quote
Old 04-21-2018, 08:47 AM   #5
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,776
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Use selected_names

And are you saying you cannot add your plugin to the toolbar? Look at the demo plugin or one of the other plugins to check what the difference is.
kovidgoyal is offline   Reply With Quote
Advert
Old 04-21-2018, 08:41 PM   #6
luckylittle
Member
luckylittle began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Nov 2012
Device: Kindle Fire
I fixed the toolbar, but selected_names doesn't exist:
Quote:
AttributeError: 'FileListWidget' object has no attribute 'selected_names'
The whole function:
Quote:
def request_remove_ext(self):
# Import calibre/src/calibre/gui2/tweak_book/file_list.py
from calibre.gui2.tweak_book.file_list import FileList
self.boss.add_savepoint('Before: File Extension Remover')
names = self.gui.file_list.selected_names
if names is not None:
def change_name(name):
base = posixpath.splitext(name)[0]
return base
name_map = {n:change_name(n) for n in names}
self.boss.bulk_rename_requested.emit(name_map)
---
To add, this works, but with only one selected file:
Quote:
def request_remove_ext(self):
# Import calibre/src/calibre/gui2/tweak_book/file_list.py
from calibre.gui2.tweak_book.file_list import FileList
self.boss.add_savepoint('Before: File Extension Remover')
name = self.gui.file_list.current_name
name_without_ext = posixpath.splitext(name)[0]
self.boss.rename_requested(name,name_without_ext)
luckylittle is offline   Reply With Quote
Old 04-21-2018, 11:34 PM   #7
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,776
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
file_list.file_list.selected_names
kovidgoyal is offline   Reply With Quote
Old 04-23-2018, 06:49 AM   #8
luckylittle
Member
luckylittle began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Nov 2012
Device: Kindle Fire
Thanks, this was very helpful.

If you want to know reasoning behind this, read this wiki.
luckylittle is offline   Reply With Quote
Reply

Tags
editor, extension, file list, filename

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Android eBook Metadata editor? Freshenstein Android Devices 0 12-03-2015 10:56 PM
Using ebook-editor in command line Francois_C Editor 12 04-17-2015 10:17 AM
Calibre Ebook Editor filmo Kobo Reader 0 01-13-2014 10:11 AM
eBook Editor - font size GregTheGrate Editor 1 12-16-2013 01:13 AM
Greetings from an ebook Anthology Editor! chawkins Introduce Yourself 2 09-17-2011 05:42 PM


All times are GMT -4. The time now is 06:10 PM.


MobileRead.com is a privately owned, operated and funded community.