Skip to content
Snippets Groups Projects
Commit 7b190fe9 authored by anarcat's avatar anarcat
Browse files

implement a very crude preferences dialog

to improve this, we would need a better layout and grouped
arguments. we could improve on the field names as well.

Closes: #20
parent a425934a
Branches dev/config
Tags
No related merge requests found
......@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
from glob import glob
import os
import pkg_resources
......@@ -35,7 +36,7 @@ import zbarpygtk
from qrencode import encode_scaled as _qrencode_scaled
from monkeysign.gpg import Keyring, GpgRuntimeError
from monkeysign.ui import MonkeysignUi
from monkeysign.ui import MonkeysignUi, MonkeysignArgumentParser
import monkeysign.translation
from monkeysign.msg_exception import errorhandler
......@@ -164,6 +165,7 @@ class MonkeysignScan(gtk.Window):
</menu>
<menu action="edit">
<menuitem action="copy"/>
<menuitem action="preferences"/>
</menu>
<menu action="identity"/>
<menu action="video"/>
......@@ -209,11 +211,12 @@ class MonkeysignScan(gtk.Window):
self.actiongroup = gtk.ActionGroup('MonkeysignGen_Menu')
self.actiongroup.add_actions([
('file', None, _('_File')),
('open', gtk.STOCK_OPEN, _('Open image...'), None, None, self.import_image),
('open', gtk.STOCK_OPEN, _('_Open image...'), None, None, self.import_image),
('save', gtk.STOCK_SAVE, _('_Save QR code as...'), None, None, self.save_qrcode),
('print', gtk.STOCK_PRINT, _('_Print QR code...'), None, None, self.print_op),
('edit', None, '_Edit'),
('copy', gtk.STOCK_COPY, _('_Copy QR code'), None, _('Copy image to clipboard'), self.clip_qrcode),
('preferences', gtk.STOCK_PREFERENCES, _('P_references'), None, _('Edit Monkeysign preferences'), self.edit_preferences),
('identity', None, _('Identity'), None, _('Choose identity')),
('video', None, _('Video device'), None, _('Select video device to use')),
('quit', gtk.STOCK_QUIT, _('_Quit'), None, None, self.destroy),
......@@ -480,6 +483,55 @@ class MonkeysignScan(gtk.Window):
print_op.connect("draw_page", self.print_qrcode)
res = print_op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, self)
def edit_preferences(self, operation=None):
dialog = gtk.Dialog(_('Monkeysign preferences'), self,
gtk.DIALOG_DESTROY_WITH_PARENT,
(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
dialog.set_default_response(gtk.RESPONSE_ACCEPT)
dialog.show()
content = dialog.get_content_area()
for action in self.msui.parser._actions:
if action.dest in self.msui.parser.ephemeral:
continue
val = vars(self.msui.options)[action.dest]
if isinstance(action, argparse._StoreAction):
def edit_option(button, name):
vars(self.msui.options)[name] = button.get_text()
print('%s is now %s' % (name, vars(self.msui.options)[name]))
box = gtk.HBox()
label = gtk.Label(action.dest)
box.pack_start(label)
label.show()
entry = gtk.Entry()
if val is not None and val != action.default:
entry.set_text(val)
entry.connect('changed', edit_option,
action.dest)
box.pack_start(entry)
box.show()
content.pack_end(box)
entry.show()
else:
def toggle_option(button, name):
vars(self.msui.options)[name] = button.get_active()
print('%s is now %s' % (name, vars(self.msui.options)[name]))
checkbox = gtk.CheckButton(action.dest)
checkbox.set_tooltip_text(action.help)
checkbox.set_active(val)
checkbox.connect('toggled', toggle_option,
action.dest)
content.pack_end(checkbox)
checkbox.show()
response = dialog.run()
if response == gtk.RESPONSE_ACCEPT:
print('saving config')
self.msui.parser.save_config(self.msui.options)
elif response == gtk.RESPONSE_CANCEL:
pass
dialog.destroy()
return
def print_qrcode(self, operation=None, context=None, page_nr=None):
"""actually print the qr code"""
ctx = context.get_cairo_context()
......
......@@ -84,7 +84,7 @@ class MonkeysignArgumentParser(argparse.ArgumentParser):
self.add_argument('-u', '--user', nargs='+',
help=_('user id to sign the key with (equivalent '
'to GPG\'s --local-user option)'))
self.add_argument('--cert-level', dest='certlevel',
self.add_argument('--certlevel', '--cert-level',
help=_('certification level to sign the key with '
'(equivalent to GPG\'s '
'--default-cert-level)'))
......@@ -126,7 +126,7 @@ class MonkeysignArgumentParser(argparse.ArgumentParser):
'overrides --mta. '
'(default: %s when specified)')
% default_mua)
self.add_argument('--no-mail', dest='nomail', action='store_true',
self.add_argument('--nomail', '--no-mail', action='store_true',
help=_('do not send email at all'))
self.add_argument('-t', '--to',
help=_('override destination email for testing '
......@@ -221,12 +221,12 @@ class MonkeysignArgumentParser(argparse.ArgumentParser):
for action in self._actions:
if action.dest in self.ephemeral:
continue
for key, val in vars(args).items():
if key == action.dest and val != action.default:
val = vars(args)[action.dest]
if val != action.default:
if isinstance(action, argparse._StoreAction):
lines.append('%s=%s' % (key, val))
lines.append('%s=%s' % (action.dest, val))
else:
lines.append(key)
lines.append(action.dest)
return lines
def write_config(self, config, fileobj):
......@@ -315,7 +315,8 @@ configuration files are parsed by default: %s"""
# temporary, to keep track of the OpenPGPkey we are signing
self.signing_key = None
self.options = MonkeysignArgumentParser(self).parse_args(args=args)
self.parser = MonkeysignArgumentParser(self)
self.options = self.parser.parse_args(args=args)
self.pattern = self.options.pattern
# set a default logging mechanism
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment