~ubuntu-branches/debian/sid/djvusmooth/sid

« back to all changes in this revision

Viewing changes to lib/gui/maparea_properties.py

  • Committer: Package Import Robot
  • Author(s): Daniel Stender
  • Date: 2015-09-15 15:34:11 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20150915153411-zlz201vxr4wk5d3p
Tags: 0.2.16-1
* New upstream release (Closes: #799017).
* deb/control:
  + added dh-python to build deps.
  + put python-djvu and python-wxgtk3.0 also into build-deps (needed by the
    tests).
  + dropped Depends: against python-xdg (Closes: #793364).
* deb/copyright: updated.
* deb/watch: watch pypi.debian.net.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
# Copyright © 2008-2014 Jakub Wilk <jwilk@jwilk.net>
4
4
# Copyright © 2009 Mateusz Turcza <mturcza@mimuw.edu.pl>
5
5
#
6
 
# This package is free software; you can redistribute it and/or modify
7
 
# it under the terms of the GNU General Public License as published by
8
 
# the Free Software Foundation; version 2 dated June, 1991.
9
 
#
10
 
# This package is distributed in the hope that it will be useful, but
11
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
 
# General Public License for more details.
 
6
# This file is part of djvusmooth.
 
7
#
 
8
# djvusmooth is free software; you can redistribute it and/or modify it
 
9
# under the terms of the GNU General Public License version 2 as published
 
10
# by the Free Software Foundation.
 
11
#
 
12
# djvusmooth is distributed in the hope that it will be useful, but WITHOUT
 
13
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
14
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 
15
# more details.
14
16
 
15
17
import wx
16
18
import wx.lib.colourselect
34
36
        kwargs.setdefault('enabled', True)
35
37
        idict.__init__(self, **kwargs)
36
38
 
37
 
SHAPE_TEXT = Shape(label = _('Text'), model_class = models.annotations.TextMapArea)
38
 
SHAPE_LINE = Shape(label = _('Line'), model_class = models.annotations.LineMapArea, enabled=False)
39
 
SHAPE_RECTANGLE = Shape(label = _('Rectangle'), model_class = models.annotations.RectangleMapArea)
 
39
SHAPE_TEXT = Shape(label=_('Text'), model_class=models.annotations.TextMapArea)
 
40
SHAPE_LINE = Shape(label=_('Line'), model_class=models.annotations.LineMapArea, enabled=False)
 
41
SHAPE_RECTANGLE = Shape(label=_('Rectangle'), model_class=models.annotations.RectangleMapArea)
40
42
SHAPES = (
41
43
    SHAPE_RECTANGLE,
42
 
    Shape(label = _('Oval'), model_class = models.annotations.OvalMapArea),
43
 
    Shape(label = _('Polygon'), model_class = models.annotations.PolygonMapArea, enabled=False),
 
44
    Shape(label=_('Oval'), model_class=models.annotations.OvalMapArea),
 
45
    Shape(label=_('Polygon'), model_class=models.annotations.PolygonMapArea, enabled=False),
44
46
    SHAPE_LINE,
45
47
    SHAPE_TEXT,
46
48
)
47
49
 
48
50
SHADOW_BORDERS = (
49
 
    idict(model_class = models.annotations.BorderShadowIn,  label = _('Shadow in')),
50
 
    idict(model_class = models.annotations.BorderShadowOut, label = _('Shadow out')),
51
 
    idict(model_class = models.annotations.BorderEtchedIn,  label = _('Etched in')),
52
 
    idict(model_class = models.annotations.BorderEtchedOut, label = _('Etched out'))
 
51
    idict(model_class=models.annotations.BorderShadowIn, label=_('Shadow in')),
 
52
    idict(model_class=models.annotations.BorderShadowOut, label=_('Shadow out')),
 
53
    idict(model_class=models.annotations.BorderEtchedIn, label=_('Etched in')),
 
54
    idict(model_class=models.annotations.BorderEtchedOut, label=_('Etched out'))
53
55
)
54
56
 
55
57
def color_as_html(color):
56
 
    return '#%02x%02x%02x' % color.Get()
 
58
    '''
 
59
    >>> c = wx.Colour(6, 23, 42)
 
60
    >>> color_as_html(c)
 
61
    '#06172a'
 
62
    '''
 
63
    return '#{0:02x}{1:02x}{2:02x}'.format(*color)
57
64
 
58
65
class MapareaPropertiesDialog(wx.Dialog):
59
66
 
62
69
 
63
70
    def _setup_main_properties_box(self):
64
71
        node = self._node
65
 
        box = wx.StaticBox(self, label = _('Main properties'))
 
72
        box = wx.StaticBox(self, label=_('Main properties'))
66
73
        box_sizer = wx.StaticBoxSizer(box)
67
74
        grid_sizer = wx.FlexGridSizer(0, 2, 5, 5)
68
 
        uri_label = wx.StaticText(self, label = 'URI: ')
69
 
        uri_edit = wx.TextCtrl(self, size = (self.DEFAULT_TEXT_WIDTH, -1))
 
75
        uri_label = wx.StaticText(self, label='URI: ')
 
76
        uri_edit = wx.TextCtrl(self, size=(self.DEFAULT_TEXT_WIDTH, -1))
70
77
        if node is not None:
71
78
            uri_edit.SetValue(self._node.uri)
72
 
        target_label = wx.StaticText(self, label = _('Target frame') + ': ')
 
79
        target_label = wx.StaticText(self, label=(_('Target frame') + ': '))
73
80
        target_edit = wx.ComboBox(self,
74
 
            size = (self.DEFAULT_TEXT_WIDTH, -1),
 
81
            size=(self.DEFAULT_TEXT_WIDTH, -1),
75
82
            style = wx.CB_DROPDOWN,
76
83
            choices = HTML_TARGETS
77
84
        )
78
85
        if node is not None:
79
86
            target_edit.SetValue(self._node.target or '')
80
 
        comment_label = wx.StaticText(self, label = _('Comment') + ': ')
81
 
        comment_edit = wx.TextCtrl(self, size = (self.DEFAULT_TEXT_WIDTH, -1))
 
87
        comment_label = wx.StaticText(self, label=(_('Comment') + ': '))
 
88
        comment_edit = wx.TextCtrl(self, size=(self.DEFAULT_TEXT_WIDTH, -1))
82
89
        if node is not None:
83
90
            comment_edit.SetValue(self._node.comment)
84
91
        for widget in uri_label, uri_edit, target_label, target_edit, comment_label, comment_edit:
91
98
 
92
99
    def _setup_shape_box(self):
93
100
        box = wx.RadioBox(self,
94
 
            label = _('Shape'),
95
 
            choices = [shape.label for shape in SHAPES]
 
101
            label=_('Shape'),
 
102
            choices=[shape.label for shape in SHAPES]
96
103
        )
97
104
        for i, shape in enumerate(SHAPES):
98
105
            box.EnableItem(i, shape.enabled)
157
164
            border = node.border
158
165
        except AttributeError:
159
166
            border = None
160
 
        box = wx.StaticBox(self, label = _('Border'))
161
 
        box_sizer = wx.StaticBoxSizer(box, orient = wx.VERTICAL)
 
167
        box = wx.StaticBox(self, label=_('Border'))
 
168
        box_sizer = wx.StaticBoxSizer(box, orient=wx.VERTICAL)
162
169
        box_grid_sizer = wx.FlexGridSizer(0, 3, 5, 10)
163
170
        border_width_sizer = wx.BoxSizer(wx.HORIZONTAL)
164
 
        border_width_label = wx.StaticText(self, label = _('Width') + ': ')
165
 
        border_width_edit = wx.SpinCtrl(self, size = (self.DEFAULT_SPIN_WIDTH, -1))
 
171
        border_width_label = wx.StaticText(self, label=(_('Width') + ': '))
 
172
        border_width_edit = wx.SpinCtrl(self, size=(self.DEFAULT_SPIN_WIDTH, -1))
166
173
        border_width_edit.SetRange(djvu.const.MAPAREA_SHADOW_BORDER_MIN_WIDTH, djvu.const.MAPAREA_SHADOW_BORDER_MAX_WIDTH)
167
174
        border_width_edit.SetValue(djvu.const.MAPAREA_SHADOW_BORDER_MIN_WIDTH)
168
175
        border_width_sizer.Add(border_width_label, 0, wx.ALIGN_CENTER_VERTICAL)
169
176
        border_width_sizer.Add(border_width_edit, 0, wx.ALIGN_CENTER_VERTICAL)
170
 
        radio_none = wx.RadioButton(self, label = _('None'))
171
 
        radio_xor = wx.RadioButton(self, label = _('XOR'))
 
177
        radio_none = wx.RadioButton(self, label=_('None'))
 
178
        radio_xor = wx.RadioButton(self, label=_('XOR'))
172
179
        if isinstance(border, models.annotations.XorBorder):
173
180
            radio_xor.SetValue(True)
174
 
        radio_solid = wx.RadioButton(self, label = _('Solid color') + ': ')
 
181
        radio_solid = wx.RadioButton(self, label=(_('Solid color') + ': '))
175
182
        solid_color_selector = wx.lib.colourselect.ColourSelect(self, wx.ID_ANY)
176
183
        if isinstance(border, models.annotations.SolidBorder):
177
184
            radio_solid.SetValue(True)
189
196
        for i, shadow_border in enumerate(SHADOW_BORDERS):
190
197
            if i == 2:
191
198
                box_grid_sizer.Add(border_width_sizer, 0, wx.ALIGN_CENTER_VERTICAL)
192
 
            widget = wx.RadioButton(self, label = shadow_border.label)
 
199
            widget = wx.RadioButton(self, label=shadow_border.label)
193
200
            if isinstance(border, shadow_border.model_class):
194
201
                widget.SetValue(True)
195
202
                have_shadow_border = True
201
208
        self.Bind(wx.EVT_RADIOBUTTON, self.on_select_nonshadow_border, radio_xor)
202
209
        self.Bind(wx.EVT_RADIOBUTTON, self.on_select_no_border, radio_none)
203
210
        self.Bind(wx.EVT_RADIOBUTTON, self.on_select_solid_border, radio_solid)
204
 
        avis_checkbox = wx.CheckBox(self, label = _('Always visible')) # TODO: hide it for irrelevant shapes, i.e. `line` and maybe `text`
 
211
        avis_checkbox = wx.CheckBox(self, label=_('Always visible'))  # TODO: hide it for irrelevant shapes, i.e. `line` and maybe `text`
205
212
        if border is None or isinstance(border, models.annotations.NoBorder):
206
213
            avis_checkbox.Enable(False)
207
214
        elif node is not None and node.border_always_visible is True:
223
230
 
224
231
    def _setup_extra_boxes(self):
225
232
        node = self._node
226
 
        extra_boxes = \
227
 
        [
228
 
            wx.StaticBox(self, label = label)
 
233
        extra_boxes = [
 
234
            wx.StaticBox(self, label=label)
229
235
            for label in (_('Highlight color and opacity'), _('Line-specific properties'), _('Text-specific properties'))
230
236
        ]
231
237
        extra_sizers = map(wx.StaticBoxSizer, extra_boxes)
239
245
        for extra_sizer, extra_grid_sizer in zip(extra_sizers, extra_grid_sizers):
240
246
            extra_sizer.Add(extra_grid_sizer, 0, wx.EXPAND | wx.ALL, 5)
241
247
        highlight_specific_sizer, line_specific_sizer, text_specific_sizer = extra_grid_sizers
242
 
        highlight_color_label = wx.CheckBox(self, label = _('Highlight color') + ': ')
 
248
        highlight_color_label = wx.CheckBox(self, label=(_('Highlight color') + ': '))
243
249
        highlight_color_selector = wx.lib.colourselect.ColourSelect(self, wx.ID_ANY)
244
250
        highlight_color_selector.SetColour(wx.BLUE)
245
251
        highlight_color_selector.Enable(False)
246
252
        def on_switch_highlight_color(event):
247
253
            highlight_color_selector.Enable(event.IsChecked())
248
254
        self.Bind(wx.EVT_CHECKBOX, on_switch_highlight_color, highlight_color_label)
249
 
        opacity_label = wx.StaticText(self, label = _('Opacity') + ': ')
 
255
        opacity_label = wx.StaticText(self, label=(_('Opacity') + ': '))
250
256
        opacity_slider = wx.Slider(self,
251
 
            value = djvu.const.MAPAREA_OPACITY_DEFAULT,
252
 
            size = (self.DEFAULT_TEXT_WIDTH, -1),
 
257
            value=djvu.const.MAPAREA_OPACITY_DEFAULT,
 
258
            size=(self.DEFAULT_TEXT_WIDTH, -1),
253
259
            style = wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS
254
260
        )
255
261
        for widget in highlight_color_label, highlight_color_selector, opacity_label, opacity_slider:
263
269
                highlight_color_selector.Enable(True)
264
270
                highlight_color_selector.SetColour(node.highlight_color)
265
271
            opacity_slider.SetValue(node.opacity)
266
 
        line_width_label = wx.StaticText(self, label = _('Line width') + ': ')
267
 
        line_width_edit = wx.SpinCtrl(self, size = (self.DEFAULT_SPIN_WIDTH, -1))
 
272
        line_width_label = wx.StaticText(self, label=(_('Line width') + ': '))
 
273
        line_width_edit = wx.SpinCtrl(self, size=(self.DEFAULT_SPIN_WIDTH, -1))
268
274
        line_width_edit.SetRange(djvu.const.MAPAREA_LINE_MIN_WIDTH, 99)
269
275
        line_width_edit.SetValue(djvu.const.MAPAREA_LINE_MIN_WIDTH)
270
 
        line_color_label = wx.StaticText(self, label = _('Line color') + ': ')
 
276
        line_color_label = wx.StaticText(self, label=(_('Line color') + ': '))
271
277
        line_color_selector = wx.lib.colourselect.ColourSelect(self, wx.ID_ANY)
272
 
        line_arrow_checkbox = wx.CheckBox(self, label = _('Arrow'))
 
278
        line_arrow_checkbox = wx.CheckBox(self, label=_('Arrow'))
273
279
        dummy = (0, 0)
274
280
        for widget in line_arrow_checkbox, dummy, line_width_label, line_width_edit, line_color_label, line_color_selector:
275
281
            line_specific_sizer.Add(widget, 0, wx.ALIGN_CENTER_VERTICAL)
279
285
            line_arrow_checkbox.SetValue(node.line_arrow)
280
286
        else:
281
287
            line_color_selector.SetColour(djvu.const.MAPAREA_LINE_COLOR_DEFAULT)
282
 
        text_background_color_label = wx.CheckBox(self, label = _('Background color') + ': ')
 
288
        text_background_color_label = wx.CheckBox(self, label=(_('Background color') + ': '))
283
289
        text_background_color_selector = wx.lib.colourselect.ColourSelect(self, wx.ID_ANY)
284
290
        text_background_color_selector.SetColour(wx.WHITE)
285
291
        text_background_color_selector.Enable(False)
286
292
        def on_switch_text_background_color(event):
287
293
            text_background_color_selector.Enable(event.IsChecked())
288
294
        self.Bind(wx.EVT_CHECKBOX, on_switch_text_background_color, text_background_color_label)
289
 
        text_color_label = wx.StaticText(self, label = _('Text color') + ': ')
 
295
        text_color_label = wx.StaticText(self, label=(_('Text color') + ': '))
290
296
        text_color_selector = wx.lib.colourselect.ColourSelect(self, wx.ID_ANY)
291
 
        text_pushpin = wx.CheckBox(self, label = _('Pushpin'))
 
297
        text_pushpin = wx.CheckBox(self, label=_('Pushpin'))
292
298
        for widget in text_background_color_label, text_background_color_selector, text_color_label, text_color_selector, text_pushpin:
293
299
            text_specific_sizer.Add(widget, 0, wx.ALIGN_CENTER_VERTICAL)
294
300
        if isinstance(node, models.annotations.TextMapArea):
316
322
        return extra_sizers
317
323
 
318
324
    def __init__(self, parent, node=None, origin=None):
319
 
        wx.Dialog.__init__(self, parent, title = _('Overprinted annotation (hyperlink) properties'))
 
325
        wx.Dialog.__init__(self, parent, title=_('Overprinted annotation (hyperlink) properties'))
320
326
        self._node = node
321
327
        if origin is None:
322
328
            self._origin = None
331
337
        extra_sizers = self._setup_extra_boxes()
332
338
        for box_sizer in [main_properties_box_sizer, shape_box_sizer, border_box_sizer] + extra_sizers:
333
339
            sizer.Add(box_sizer, 0, wx.EXPAND | wx.ALL, 5)
334
 
        line = wx.StaticLine(self, -1, style = wx.LI_HORIZONTAL)
 
340
        line = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL)
335
341
        sizer.Add(line, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 5)
336
342
        button_sizer = wx.StdDialogButtonSizer()
337
343
        button = wx.Button(self, wx.ID_OK)
403
409
 
404
410
__all__ = ['MapareaPropertiesDialog']
405
411
 
406
 
# vim:ts=4 sw=4 et
 
412
# vim:ts=4 sts=4 sw=4 et