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 03-27-2023, 06:40 AM   #1
igorius
Zealot
igorius began at the beginning.
 
Posts: 114
Karma: 34
Join Date: Jun 2015
Device: ipad & inkpad X
changing column type

I want to change a plugin which has a setting "reading status" which is set to "text".
I want to change this setting to "bool", "boolean", "yes/no".
I tried any of this settings but none works. What is the right thing to get this done?
Here is the relevant thing: (taken from koreader plugin)

{
'name': 'column_status',
'label': 'Reading status column:',
'tooltip': 'A regular “text” column to store the reading status of the\n'
'book, as entered on the book status page (“Finished”,\n'
'“Reading”, “On hold”).',
'type': 'text', (*1)
'sidecar_property': ['summary', 'status'],
}

(*1): Changed 'type': 'text', to 'type': 'bool', and the other above mentioned types.

available_columns = {
'comments': self.get_custom_columns(['comments']),
'datetime': self.get_custom_columns(['datetime']),
'float': self.get_custom_columns(['float']),
'int': self.get_custom_columns(['int']),
'rating': self.get_rating_columns(), # Includes built-in
'text': self.get_custom_columns(['text']),
'bool': self.get_custom_columns(['bool']), (*2)
}

(*2): added this line with the different types as mentioned above.

What types do i have for changing columns? Where is that documented? I didnt find anything in help/plugins or plugin API...
igorius is offline   Reply With Quote
Old 03-27-2023, 08:18 AM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,703
Karma: 6658935
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by igorius View Post
I want to change a plugin which has a setting "reading status" which is set to "text".
I want to change this setting to "bool", "boolean", "yes/no".
I tried any of this settings but none works. What is the right thing to get this done?
First, you can't change the type of an existing column. You must delete the column, restart calibre, then re-add the column with the new type.

Quote:
Here is the relevant thing: (taken from koreader plugin)

{
'name': 'column_status',
'label': 'Reading status column:',
'tooltip': 'A regular “text” column to store the reading status of the\n'
'book, as entered on the book status page (“Finished”,\n'
'“Reading”, “On hold”).',
'type': 'text', (*1)
'sidecar_property': ['summary', 'status'],
}

(*1): Changed 'type': 'text', to 'type': 'bool', and the other above mentioned types.

available_columns = {
'comments': self.get_custom_columns(['comments']),
'datetime': self.get_custom_columns(['datetime']),
'float': self.get_custom_columns(['float']),
'int': self.get_custom_columns(['int']),
'rating': self.get_rating_columns(), # Includes built-in
'text': self.get_custom_columns(['text']),
'bool': self.get_custom_columns(['bool']), (*2)
}

(*2): added this line with the different types as mentioned above.

What types do i have for changing columns? Where is that documented? I didnt find anything in help/plugins or plugin API...
I don't know what this is really asking for.

As I said above, there is no API for changing column types because you can't do that.

If you are looking for documentation of the API to prompt the user to create new columns, see CreateNewCustomColumn in src/calibre/gui2/preferences/create_custom_column.py. However, I think you already are looking at that.
chaley is offline   Reply With Quote
Old 03-27-2023, 09:50 AM   #3
igorius
Zealot
igorius began at the beginning.
 
Posts: 114
Karma: 34
Join Date: Jun 2015
Device: ipad & inkpad X
You didnt understand: I dont want to change the column, its type yes/no. I want to change the plugin! So what types do i have?
text, float, int, comments, datetime...
Does exist a type bool and what is its name? See in preferences, custom column. The boolean is named yes/no. Whats its real name which i can use in my plugin?

Oh, got it! Forgot to restart calibre. Its bool.

Last edited by igorius; 03-27-2023 at 10:49 AM.
igorius is offline   Reply With Quote
Old 03-27-2023, 10:17 AM   #4
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,703
Karma: 6658935
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by igorius View Post
You didnt understand: I dont want to change the column, its type yes/no. I want to change the plugin! So what types do i have?
text, float, int, comments, datetime...
Does exist a type bool and what is its name? See in preferences, custom column. The boolean is named yes/no. Whats its real name which i can use in my plugin?
Yes, a boolean type exists and its datatype (what I think you are referring to as 'name') is 'bool'.

For the complete list of datatypes see calibre/library/field_metadata.py line 293:
Code:
VALID_DATA_TYPES = frozenset([None, 'rating', 'text', 'comments', 'datetime',
                'int', 'float', 'bool', 'series', 'composite', 'enumeration'])
and in calibre/db/backend.py line 58:
Code:
CUSTOM_DATA_TYPES = frozenset(('rating', 'text', 'comments', 'datetime',
    'int', 'float', 'bool', 'series', 'composite', 'enumeration'))
and in calibre/gui2/preferences/create_custom_column.py line 822
Code:
    The datatype must be one of calibre's custom column types: 'bool',
    'comments', 'composite', 'datetime', 'enumeration', 'float', 'int',
    'rating', 'series', or 'text'. The datatype can't be changed in the dialog.
The information can be derived from calibre/gui2/preferences/create_custom_column.py.
Code:
column_types = dict(enumerate((
        ...
        {
            'datatype':'bool',  # The column datatype
            'text':_('Yes/No'), # The name used in the dialog's type dropdown
            'is_multiple':False
        },
        ...

    )))

Last edited by chaley; 03-27-2023 at 10:22 AM. Reason: Added a third source of datatypes
chaley is offline   Reply With Quote
Old 04-01-2023, 10:46 AM   #5
thiago.eec
Guru
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 908
Karma: 1171905
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
Quote:
Originally Posted by igorius View Post
{
'name': 'column_status',
'label': 'Reading status column:',
'tooltip': 'A regular “text” column to store the reading status of the\n'
'book, as entered on the book status page (“Finished”,\n'
'“Reading”, “On hold”
).',
'type': 'text', (*1)
'sidecar_property': ['summary', 'status'],
}


What types do i have for changing columns? Where is that documented? I didnt find anything in help/plugins or plugin API...
Looks like your changes are correct, using 'type': 'bool'.
The problem is that the information is coming from the device as text (look at the red text above). So, you need to treat this in the 'action.py' file.

Looking at the plugin's code, I would suggest changing the 'sync_to_calibre' method. Here is a possible solution:

Original:
Code:
def sync_to_calibre(self):
...
  keys_values_to_update[target] = value
...
Altered:
Code:
def sync_to_calibre(self):
...
  if value in ('Finished', 'Reading', 'On hold'):
    if value == 'Finished':
      value =  True
    else:
      value = False

  keys_values_to_update[target] = value
...
thiago.eec is offline   Reply With Quote
Old 04-02-2023, 07:27 PM   #6
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 8,425
Karma: 59666665
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Similar to this case:

I use Kobo Utilities, which stores the reading position in a column. This column is required to be of type 'text.' However, I'd like to use a longtext column (short title) which is 'comments'.

(This is something I'd meant to ask about before davidfor left us )

By looking at the code, I think I can do this by changing several instances of 'text' to ''text, commenst'.

dialogs.py, lines 927-929:

Code:
    def get_text_type_custom_columns(self):
        column_types = ['text']
        return self.get_custom_columns(column_types)
config.py

lines 357-365:

Code:
CUSTOM_COLUMN_DEFAULTS = {
                CUSTOM_COLUMN_DEFAULT_LOOKUP_READING_LOCATION : {
                    'column_heading': _("Kobo Reading Location"),
                    'datatype' : 'text',
                    'description' : _("Kobo Reading location from the device."),
                    'columns_list' : 'avail_text_columns',
                    'config_label' : _('Current Reading Location Column:'),
                    'config_tool_tip' : _("Select a custom column to store the current reading location. The column type must be 'text'. Leave this blank if you do not want to store or restore the current reading location."),
                },
lines 866-868

Code:
    def get_text_custom_columns(self):
        column_types = ['text']
        return self.get_custom_columns(column_types)
Before I try this, though: Is there much any difference between storing something in a text column and storing something in a longtext column that may break things?

The GetFileName plugin uses ['text','enumeration','custom','comments'] (what is custom?), which makes me think it should work.

I have a few other small edits to my version of KU to add some extra fonts so would like to do this myself

Last edited by ownedbycats; 04-02-2023 at 07:39 PM.
ownedbycats is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing font type in viewer rulet Library Management 1 07-15-2017 02:00 AM
Using "Build column from other column" custom-column type HFC3 Library Management 3 07-07-2013 03:11 AM
Changing custom columns type? Pepin33 Calibre 4 08-27-2012 08:44 PM
Changing the partition type ? rolgiati Kindle Developer's Corner 1 12-08-2011 09:39 PM
Changing column type for reading queue paulfiera Calibre 7 05-31-2011 01:10 PM


All times are GMT -4. The time now is 01:32 AM.


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