-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.py
More file actions
295 lines (245 loc) · 12 KB
/
Copy pathconfig.py
File metadata and controls
295 lines (245 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from PyQt5.Qt import (QWidget, QVBoxLayout, QHBoxLayout, QLabel, QComboBox,
QCheckBox, QSpinBox, QGroupBox, QLineEdit, QPushButton,
QFontDatabase)
from calibre.utils.config import JSONConfig
# Plugin preferences
prefs = JSONConfig('plugins/remarkable_sync')
# Default settings
prefs.defaults['default_folder_uuid'] = ''
prefs.defaults['default_folder_name'] = 'Root'
prefs.defaults['device_type'] = 'rmpp' # Default to Paper Pro
prefs.defaults['auto_convert_epub'] = True
prefs.defaults['pdf_font_family'] = '' # Empty means use default
prefs.defaults['pdf_font_size'] = 24.0 # In pixels (matching manual conversion)
prefs.defaults['pdf_line_height'] = 125 # percentage
prefs.defaults['pdf_margin_left'] = 15
prefs.defaults['pdf_margin_right'] = 15
prefs.defaults['pdf_margin_top'] = 45
prefs.defaults['pdf_margin_bottom'] = 35
prefs.defaults['pdf_footer_template'] = '''<footer style="justify-content: end; font-size: x-small; color: gray;">
<div></div>
<script>document.currentScript.parentNode.querySelector("div").innerHTML = "" + (_PAGENUM_ + 1) + " - " + Math.round(_PAGENUM_ * 100 / _TOTAL_PAGES_) + " % "</script>
</footer>'''
# Custom column settings for reading position sync
prefs.defaults['col_rm_uuid'] = '' # Column for reMarkable document UUID (required for sync)
prefs.defaults['col_progress'] = '' # Column for reading progress (0-100%)
prefs.defaults['col_page'] = '' # Column for current page number
prefs.defaults['col_last_read'] = '' # Column for last read timestamp
# Font sizes in pixels (matching Calibre's PDF output settings)
RMPP_FONT_SIZES = [9.0, 11.0, 12.0, 13.0, 14.0, 17.0, 19.0, 21.0, 22.0, 24.0, 28.0, 32.0]
# Device types with their screen specifications
# Format: (name, width_px, height_px, dpi)
REMARKABLE_DEVICES = {
'rmpp': ('reMarkable Paper Pro', 1620, 2160, 229),
'rmpp_move': ('reMarkable Paper Pro Move', 954, 1696, 229),
'rm2': ('reMarkable 2', 1404, 1872, 226),
}
def get_device_page_size(device_type):
"""
Get the page size in pixels for a device type.
Returns (width, height) in pixels for use with devicepixel unit.
"""
if device_type not in REMARKABLE_DEVICES:
device_type = 'rmpp' # Default to Paper Pro
_, width_px, height_px, dpi = REMARKABLE_DEVICES[device_type]
return (width_px, height_px)
class ConfigWidget(QWidget):
def __init__(self):
QWidget.__init__(self)
self.layout = QVBoxLayout()
self.setLayout(self.layout)
# Folder selection
folder_group = QGroupBox('Upload Settings')
folder_layout = QVBoxLayout()
folder_label = QLabel('Default folder for new books:')
folder_layout.addWidget(folder_label)
self.folder_combo = QComboBox()
self.refresh_folders()
folder_layout.addWidget(self.folder_combo)
refresh_btn = QPushButton('Refresh Folders')
refresh_btn.clicked.connect(self.refresh_folders)
folder_layout.addWidget(refresh_btn)
# Device type selection
device_layout = QHBoxLayout()
device_layout.addWidget(QLabel('Device type:'))
self.device_type = QComboBox()
current_device = prefs['device_type']
for key, (name, _, _, _) in REMARKABLE_DEVICES.items():
self.device_type.addItem(name, key)
if key == current_device:
self.device_type.setCurrentIndex(self.device_type.count() - 1)
device_layout.addWidget(self.device_type)
device_layout.addStretch()
folder_layout.addLayout(device_layout)
folder_group.setLayout(folder_layout)
self.layout.addWidget(folder_group)
# Conversion settings
conversion_group = QGroupBox('PDF Conversion Settings')
conversion_layout = QVBoxLayout()
self.auto_convert = QCheckBox('Auto-convert EPUB to PDF')
self.auto_convert.setChecked(prefs['auto_convert_epub'])
conversion_layout.addWidget(self.auto_convert)
font_family_layout = QHBoxLayout()
font_family_layout.addWidget(QLabel('Font family:'))
self.font_family = QComboBox()
self.font_family.setEditable(True) # Allow custom input
# Add empty option for system default
self.font_family.addItem('(System default)', '')
# Populate with available system fonts (static method in Qt5/6)
current_font = prefs['pdf_font_family']
current_index = 0
for i, family in enumerate(sorted(QFontDatabase.families()), 1):
self.font_family.addItem(family, family)
if family == current_font:
current_index = i
if current_font and current_font != '(System default)' and current_index == 0:
self.font_family.addItem(current_font, current_font)
current_index = self.font_family.count() - 1
self.font_family.setCurrentIndex(current_index)
font_family_layout.addWidget(self.font_family)
conversion_layout.addLayout(font_family_layout)
font_size_layout = QHBoxLayout()
font_size_layout.addWidget(QLabel('Base font size:'))
self.font_size = QComboBox()
current_font_size = prefs['pdf_font_size']
for size in RMPP_FONT_SIZES:
self.font_size.addItem(f'{int(size)} px', size)
if size == current_font_size:
self.font_size.setCurrentIndex(self.font_size.count() - 1)
font_size_layout.addWidget(self.font_size)
font_size_layout.addStretch()
conversion_layout.addLayout(font_size_layout)
line_height_layout = QHBoxLayout()
line_height_layout.addWidget(QLabel('Line height:'))
self.line_height = QSpinBox()
self.line_height.setRange(100, 200)
self.line_height.setSuffix('%')
self.line_height.setValue(prefs['pdf_line_height'])
line_height_layout.addWidget(self.line_height)
line_height_layout.addStretch()
conversion_layout.addLayout(line_height_layout)
# Margins
margins_label = QLabel('Margins (pt):')
conversion_layout.addWidget(margins_label)
margins_h_layout = QHBoxLayout()
margins_h_layout.addWidget(QLabel('Left:'))
self.margin_left = QSpinBox()
self.margin_left.setRange(0, 100)
self.margin_left.setValue(prefs['pdf_margin_left'])
margins_h_layout.addWidget(self.margin_left)
margins_h_layout.addWidget(QLabel('Right:'))
self.margin_right = QSpinBox()
self.margin_right.setRange(0, 100)
self.margin_right.setValue(prefs['pdf_margin_right'])
margins_h_layout.addWidget(self.margin_right)
margins_h_layout.addStretch()
conversion_layout.addLayout(margins_h_layout)
margins_v_layout = QHBoxLayout()
margins_v_layout.addWidget(QLabel('Top:'))
self.margin_top = QSpinBox()
self.margin_top.setRange(0, 100)
self.margin_top.setValue(prefs['pdf_margin_top'])
margins_v_layout.addWidget(self.margin_top)
margins_v_layout.addWidget(QLabel('Bottom:'))
self.margin_bottom = QSpinBox()
self.margin_bottom.setRange(0, 100)
self.margin_bottom.setValue(prefs['pdf_margin_bottom'])
margins_v_layout.addWidget(self.margin_bottom)
margins_v_layout.addStretch()
conversion_layout.addLayout(margins_v_layout)
conversion_group.setLayout(conversion_layout)
self.layout.addWidget(conversion_group)
# Sync settings
sync_group = QGroupBox('Sync Settings')
sync_layout = QVBoxLayout()
sync_layout.addWidget(QLabel('Custom columns for reading position (create in Preferences → Add your own columns):'))
col_uuid_layout = QHBoxLayout()
col_uuid_layout.addWidget(QLabel('reMarkable UUID:'))
self.col_rm_uuid = QComboBox()
col_uuid_layout.addWidget(self.col_rm_uuid)
col_uuid_layout.addStretch()
sync_layout.addLayout(col_uuid_layout)
col_progress_layout = QHBoxLayout()
col_progress_layout.addWidget(QLabel('Progress (%):'))
self.col_progress = QComboBox()
col_progress_layout.addWidget(self.col_progress)
col_progress_layout.addStretch()
sync_layout.addLayout(col_progress_layout)
col_page_layout = QHBoxLayout()
col_page_layout.addWidget(QLabel('Current page:'))
self.col_page = QComboBox()
col_page_layout.addWidget(self.col_page)
col_page_layout.addStretch()
sync_layout.addLayout(col_page_layout)
col_last_read_layout = QHBoxLayout()
col_last_read_layout.addWidget(QLabel('Last read:'))
self.col_last_read = QComboBox()
col_last_read_layout.addWidget(self.col_last_read)
col_last_read_layout.addStretch()
sync_layout.addLayout(col_last_read_layout)
# Store reference to populate later (needs db access)
self._column_combos = {
'col_rm_uuid': (self.col_rm_uuid, ['text']),
'col_progress': (self.col_progress, ['float', 'int']),
'col_page': (self.col_page, ['int']),
'col_last_read': (self.col_last_read, ['datetime', 'text']),
}
sync_group.setLayout(sync_layout)
self.layout.addWidget(sync_group)
self.layout.addStretch()
def refresh_folders(self):
"""Refresh folder list from reMarkable"""
from calibre_plugins.remarkable_sync.remarkable import get_all_folders
self.folder_combo.clear()
self.folder_combo.addItem('Root', '')
folders = get_all_folders()
current_uuid = prefs['default_folder_uuid']
current_index = 0
for i, folder in enumerate(folders, 1):
pin_marker = '📌 ' if folder.get('pinned') else ''
display_name = f"{pin_marker}{folder['path']}"
self.folder_combo.addItem(display_name, folder['uuid'])
if folder['uuid'] == current_uuid:
current_index = i
self.folder_combo.setCurrentIndex(current_index)
def populate_custom_columns(self, db):
"""Populate custom column dropdowns from database"""
if db is None:
return
custom_columns = db.field_metadata.custom_field_metadata()
for pref_key, (combo, allowed_types) in self._column_combos.items():
combo.clear()
combo.addItem('(None)', '')
current_value = prefs.get(pref_key, '')
current_index = 0
for col_name, col_meta in custom_columns.items():
col_type = col_meta.get('datatype', '')
if col_type in allowed_types:
display_name = col_meta.get('name', col_name)
combo.addItem(f"{display_name} ({col_type})", col_name)
if col_name == current_value:
current_index = combo.count() - 1
combo.setCurrentIndex(current_index)
def save_settings(self):
"""Save settings"""
prefs['default_folder_uuid'] = self.folder_combo.currentData()
prefs['default_folder_name'] = self.folder_combo.currentText()
prefs['device_type'] = self.device_type.currentData()
prefs['auto_convert_epub'] = self.auto_convert.isChecked()
font_text = self.font_family.currentText()
if not font_text or font_text == '(System default)':
prefs['pdf_font_family'] = ''
else:
prefs['pdf_font_family'] = font_text
prefs['pdf_font_size'] = self.font_size.currentData()
prefs['pdf_line_height'] = self.line_height.value()
prefs['pdf_margin_left'] = self.margin_left.value()
prefs['pdf_margin_right'] = self.margin_right.value()
prefs['pdf_margin_top'] = self.margin_top.value()
prefs['pdf_margin_bottom'] = self.margin_bottom.value()
prefs['col_rm_uuid'] = self.col_rm_uuid.currentData() or ''
prefs['col_progress'] = self.col_progress.currentData() or ''
prefs['col_page'] = self.col_page.currentData() or ''
prefs['col_last_read'] = self.col_last_read.currentData() or ''