Skip to content

Commit

Permalink
gui config is pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
LisaGlaser committed Jan 2, 2023
1 parent 071203f commit 35ba5fb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 82 deletions.
49 changes: 1 addition & 48 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,72 +12,25 @@ class ActionSendByrmapi(InterfaceActionBase):
supported_platforms = ['linux'] # Platform I tested this on
author = 'l glaser'
version = (0, 0, 5)

default_site_customization = 'rmapi ; /Books/Unread/Calibre;EPUB,PDF ; 1'
#: This field defines the GUI plugin class that contains all the code
#: that actually does something. Its format is module_path:class_name
#: The specified class must be defined in the specified module.
actual_plugin = 'calibre_plugins.send_by_rmapi.main:SendByrmapiAction'


def __init__(self, path_to_plugin):
InterfaceActionBase.__init__(self, path_to_plugin)
from calibre.customize.ui import customize_plugin,plugin_customization
if not plugin_customization(self):
customize_plugin(self, self.default_site_customization)

def is_customizable(self):
'''
This method must return True to enable customization via
Preferences->Plugins
'''
return True


# def customization_help(self, gui=1):
# # this is rather ugly; more fields input would be nicer...
# message = []
# message.append( "This plugin uses rmapi")
# message.append( "Example (using the default values:\n" )
# message.append( "rmapi ; /Books/Unread/Calibre/;EPUB,PDF" )
# message.append( "You might need to restart Calibre for the changes to take effect." )
# return ''.join(message)

def config_widget(self):
'''
Implement this method and :meth:`save_settings` in your plugin to
use a custom configuration dialog.
This method, if implemented, must return a QWidget. The widget can have
an optional method validate() that takes no arguments and is called
immediately after the user clicks OK. Changes are applied if and only
if the method returns True.
If for some reason you cannot perform the configuration at this time,
return a tuple of two strings (message, details), these will be
displayed as a warning dialog to the user and the process will be
aborted.
The base class implementation of this method raises NotImplementedError
so by default no user configuration is possible.
A little config Widget
'''
# It is important to put this import statement here rather than at the
# top of the module as importing the config class will also cause the
# GUI libraries to be loaded, which we do not want when using calibre
# from the command line
from calibre_plugins.send_by_rmapi.config import ConfigWidget
return ConfigWidget()

def about(self):
# Get the about text from a file inside the plugin zip file
# The get_resources function is a builtin function defined for all your
# plugin code. It loads files from the plugin zip file. It returns
# the bytes from the specified file.
#
# Note that if you are loading more than one file, for performance, you
# should pass a list of names to get_resources. In this case,
# get_resources will return a dictionary mapping names to bytes. Names that
# are not found in the zip file will not be in the returned dictionary.
text = get_resources('about.txt')
QMessageBox.about(self, 'About the Interface Plugin Demo',
text.decode('utf-8'))
Expand Down
6 changes: 5 additions & 1 deletion about.txt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
This plugin uses the rmapi interface to send epub files directly to your remarkable tablet.
This plugin uses the rmapi interface to send epub files directly to your remarkable tablet.

Currently it is set up to expect that rmapi is set up so that no password is needed.

The folder on the tablet should already exist.
43 changes: 20 additions & 23 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from calibre.utils.config import JSONConfig
from qt.core import QWidget, QHBoxLayout, QLabel, QLineEdit,QPushButton
from qt.core import QWidget, QFormLayout, QLabel, QLineEdit,QPushButton

# This is where all preferences for this plugin will be stored
# Remember that this name (i.e. plugins/interface_demo) is also
Expand All @@ -9,7 +9,6 @@
prefs = JSONConfig('plugins/send_by_rmapi')

# Set defaults
## default_site_customization = 'rmapi ; /Books/Unread/Calibre;EPUB,PDF ; 1'
prefs.defaults['command_rmapi'] = 'rmapi'
prefs.defaults['folder_on_device'] = '/Books/Unread/Calibre'

Expand All @@ -18,28 +17,26 @@ class ConfigWidget(QWidget):

def __init__(self):
QWidget.__init__(self)
self.l = QHBoxLayout()
self.setLayout(self.l)

self.label = QLabel('Command to run rmapi:')
self.l.addWidget(self.label)

self.msg0 = QLineEdit(self)
self.msg0.setText(prefs['command_rmapi'])
self.l.addWidget(self.msg0)
self.label.setBuddy(self.msg0)


self.l.addSpacing(5)
self.label = QLabel('Folder on reMarkable to send files to:')
self.l.addWidget(self.label)

self.msg1 = QLineEdit(self)
self.msg1.setText(prefs['folder_on_device'])
self.l.addWidget(self.msg1)
self.label.setBuddy(self.msg1)
# creating line edits
self.command = QLineEdit()
self.command.setText(prefs['command_rmapi'])

self.folder = QLineEdit()
self.folder.setText(prefs['folder_on_device'])

# creating a form layout
layout = QFormLayout()
layout.setFieldGrowthPolicy(layout.AllNonFixedFieldsGrow)
# adding rows
layout.addRow(QLabel("Command to run rmapi"), self.command)
layout.addRow(QLabel("The command you would type on the shell."))
layout.addRow(QLabel("Folder on reMarkable to send files to:"), self.folder)
## this could also be a setting, a checkbox if we want to create non-existing folders
layout.addRow(QLabel('If the folder does not exist rmapi will send an error.'),)
self.setLayout(layout)


def save_settings(self):
prefs['command_rmapi'] = self.msg0.text()
prefs['folder_on_device'] = self.msg1.text()
prefs['command_rmapi'] = self.command.text()
prefs['folder_on_device'] = self.folder.text()
10 changes: 0 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ class SendByrmapiAction(InterfaceAction):
remote_dir='/Books/Unread/Calibre'
formats=('epub','pdf')

#def __init__(self, gui, site_customization):

# InterfaceAction.__init__(self, gui, site_customization)
# # parse the user's customized input
# if site_customization:
# user_args = site_customization.split(';')
# user_args = [ usr_arg.strip() for usr_arg in user_args ]
# if user_args:
# self.rmapi_path=user_args[0]
# self.remote_dir=user_args[1]

def is_customizable(self):
'''
Expand Down

0 comments on commit 35ba5fb

Please sign in to comment.