Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/ghini-1.0-dev' into ghini-1.0-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
weblate committed Jul 28, 2017
2 parents b94081b + 4593c93 commit 226eebe
Show file tree
Hide file tree
Showing 53 changed files with 2,688 additions and 1,704 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ registered.users.txt
issue-.sql
issue-0177.py
issue-0177.py.txt
_static
try-me

aaa-start-here.py
Expand Down
3 changes: 1 addition & 2 deletions bauble/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ def main(uri=None):
open_exc = e
# break
except Exception, e:
msg = _("Could not open connection.\n\n%s") % \
utils.xml_safe(repr(e))
msg = _("Could not open connection.\n\n%s") % e
utils.message_details_dialog(msg, traceback.format_exc(),
gtk.MESSAGE_ERROR)
uri = None
Expand Down
16 changes: 3 additions & 13 deletions bauble/plugins/report/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright 2008-2010 Brett Adams
# Copyright 2012-2015 Mario Frasca <mario@anche.no>.
# Copyright 2012-2017 Mario Frasca <mario@anche.no>.
#
# This file is part of ghini.desktop.
#
Expand Down Expand Up @@ -60,19 +60,9 @@
default_config_pref = 'report.xsl'
formatter_settings_expanded_pref = 'report.settings.expanded'

# _paths = {}

# def add_path(parent, descendant, query):
# """
# Register a query that will give all of the descendants under parent

# e.g. add_path(Family, Species) would register a query to retrieve
# all of the Species under a family
# """
# if parent not in _paths:
# _paths[parent] = {descendent: query}
# else descendant not in _paths[parent]:
# _paths[parent][descendent] = query
# to be populated by the dialog box, with fields mentioned in the template
options = {}


def _get_pertinent_objects(cls, get_query_func, objs, session):
Expand Down
112 changes: 100 additions & 12 deletions bauble/plugins/report/mako/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import os
import shutil
import tempfile
import math

import gtk

Expand Down Expand Up @@ -76,7 +77,7 @@
}


def add_text(x, y, s, size, align=0, italic=False, strokes=1):
def add_text(x, y, s, size, align=0, italic=False, strokes=1, rotate=0):
"""compute the `use` elements to be added and the width of the result
align 0: left; align 1: right; align 0.5: centre
Expand All @@ -99,18 +100,24 @@ def add_text(x, y, s, size, align=0, italic=False, strokes=1):
'<use transform="translate(%s,0)" xlink:href="#%s"/>' %
(totalwidth, glyph_ref))
totalwidth += glyph_wid
radians = rotate / 180.0 * math.pi
if align != 0:
x -= align * (totalwidth * size)
x -= (totalwidth * size) * align * math.cos(radians)
y -= (totalwidth * size) * align * math.sin(radians)
italic_text = italic and 'matrix(1,0,-0.1,1,2,0)' or ''
rotate_text = rotate and ('rotate(%s)' % rotate) or ''
# we can't do the following before having placed all glyphs
result_list.insert(
0, (('<g transform="translate(%s, %s)scale(%s)'+italic_text+'">')
% (x, y, size)))
0, (('<g transform="translate(%s, %s)scale(%s)' + italic_text + rotate_text + '">')
% (round(x, 6), round(y, 6), size)))
result_list.append('</g>')
result = "\n".join(result_list)
return result, x+totalwidth*size, y
return (result,
x + totalwidth * size * math.cos(radians),
y + totalwidth * size * math.sin(radians))


def add_code39(x, y, s, unit=1, height=10, align=0):
def add_code39(x, y, s, unit=1, height=10, align=0, colour='#0000ff'):
result_list = []
cumulative_x = 0
if not s:
Expand All @@ -119,7 +126,7 @@ def add_code39(x, y, s, unit=1, height=10, align=0):
for i in s:
if i not in Code39.MAP.keys():
i = u' '
result_list.append(Code39.letter(i, height, translate=(cumulative_x, 0)))
result_list.append(Code39.letter(i, height, translate=(cumulative_x, 0), colour=colour))
cumulative_x += 16
cumulative_x -= 1
shift = -align * cumulative_x
Expand All @@ -131,7 +138,7 @@ def add_code39(x, y, s, unit=1, height=10, align=0):

class Code39:
# Class for encoding as Code39 barcode.

# Every symbol gets encoded as a sequence of 5 black bars separated by 4
# white spaces. Bars and spaces may be thin (one unit), or thick (three
# units). A thin white space separates the sequences. All barcodes start
Expand Down Expand Up @@ -203,15 +210,47 @@ def path(cls, letter, height):
return format % d

@classmethod
def letter(cls, letter, height, translate=None):
def letter(cls, letter, height, translate=None, colour='#0000ff'):
if translate is not None:
transform_text = 'transform="translate(%s,%s)" ' % translate
transform_text = ' transform="translate(%s,%s)"' % translate
else:
transform_text = ''
return '<path ' + transform_text + 'd="%s" style="stroke:#0000ff;stroke-width:1"/>' % cls.path(letter, height)
return '<path%(transform)s d="%(path)s" style="stroke:%(colour)s;stroke-width:1"/>' % {
'transform': transform_text,
'path': cls.path(letter, height),
'colour': colour,
}


class add_qr_functor:
import pyqrcode
def __init__(self):
import io
import re
self.buffer = io.BytesIO()
self.pattern = re.compile('<svg.*>(<path.*>)</svg>')

def __call__(self, x, y, text, scale=1):
qr = self.pyqrcode.create(text)
self.buffer.truncate(0)
self.buffer.seek(0)
qr.svg(self.buffer, xmldecl=False, quiet_zone=0, scale=scale)
match = self.pattern.match(self.buffer.getvalue())
result_list = [match.group(1)]
if x != 0 or y != 0:
result_list.insert(0, '<g transform="translate(%s,%s)">' % (x, y))
result_list.append('</g>')
return '\n'.join(result_list)

add_qr = add_qr_functor()


class MakoFormatterSettingsBox(SettingsBox):
import re
pattern = re.compile("^## OPTION ([a-z_]*): \("
"type: ([a-z_]*), "
"default: '(.*)', "
"tooltip: '(.*)'\)$")

def __init__(self, report_dialog=None, *args):
super(MakoFormatterSettingsBox, self).__init__(*args)
Expand All @@ -223,6 +262,8 @@ def __init__(self, report_dialog=None, *args):
self.settings_box = self.widgets.settings_box
self.widgets.remove_parent(self.widgets.settings_box)
self.pack_start(self.settings_box)
self.widgets.template_chooser.connect('file-set', self.on_file_set)
self.defaults = []

def get_settings(self):
"""
Expand All @@ -231,11 +272,58 @@ def get_settings(self):
'private': self.widgets.private_check.get_active()}

def update(self, settings):
if 'template' in settings and settings['template']:
if settings.get('template'):
self.widgets.template_chooser.set_filename(settings['template'])
self.on_file_set()
if 'private' in settings:
self.widgets.private_check.set_active(settings['private'])

def on_file_set(self, *args, **kwargs):
self.defaults = []
options_box = self.widgets.mako_options_box
# empty the options box
map(options_box.remove, options_box.get_children())
# which options does the template accept? (can be None)
with open(self.widgets.template_chooser.get_filename()) as f:
# scan the header filtering lines starting with # OPTION
option_lines = filter(None,
[self.pattern.match(i.strip())
for i in f.readlines()])
option_fields = [i.groups() for i in option_lines]
from bauble.plugins.report import options
current_row = 0
# populate the options box
for fname, ftype, fdefault, ftooltip in option_fields:
row = gtk.HBox()
label = gtk.Label(fname.replace('_', ' ') + _(':'))
label.set_alignment(0, 0.5)
entry = gtk.Entry()
options.setdefault(fname, fdefault)
entry.set_text(options[fname])
entry.set_tooltip_text(ftooltip)
# entry updates the corresponding item in report.options
entry.connect('changed', self.set_option, fname)
self.defaults.append((entry, fdefault))
options_box.attach(label, 0, 1, current_row, current_row+1,
xoptions=gtk.FILL)
options_box.attach(entry, 1, 2, current_row, current_row+1,
xoptions=gtk.FILL)
current_row += 1
if self.defaults:
button = gtk.Button(_('Reset to defaults'))
button.connect('clicked', self.reset_options)
options_box.attach(button, 0, 2, current_row, current_row+1,
xoptions=gtk.FILL)
options_box.show_all()

def reset_options(self, widget):
for entry, text in self.defaults:
entry.set_text(text)

def set_option(self, widget, fname):
from bauble.plugins.report import options
options[fname] = widget.get_text()


_settings_box = MakoFormatterSettingsBox()

Expand Down
Loading

0 comments on commit 226eebe

Please sign in to comment.