From e9b338a1786a681e4a9ee5b7ff436b9db87f6620 Mon Sep 17 00:00:00 2001 From: Nik Volkov Date: Fri, 28 Aug 2015 19:22:49 +0700 Subject: [PATCH] =?UTF-8?q?=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B8=D1=80?= =?UTF-8?q?=D1=83=D0=B5=D0=BC=D0=BE=D0=B5=20=D0=BC=D0=B5=D0=BD=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rackman.py | 165 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 111 insertions(+), 54 deletions(-) diff --git a/rackman.py b/rackman.py index e993a7f..d53f53f 100644 --- a/rackman.py +++ b/rackman.py @@ -59,14 +59,54 @@ def initial(): COLORS = { - _('Black'): (0, 0, 0), - _('White'): (1, 1, 1), - _('Green'): (0, 1, 0), - _('Blue'): (0, 0, 1), - _('Red'): (1, 0, 0), - _('Orange'): (1, 0.5, 0), - _('Violet'): (0.5, 0, 0.5), - _('Pink'): (1, 0.5, 1), + _('Black'): { + 'rgb': (0, 0, 0), + 'key': 'K', + 'marker': 'Blac_k', + 'eng_name': 'Black', + }, + _('White'): { + 'rgb': (1, 1, 1), + 'key': 'W', + 'marker': '_White', + 'eng_name': 'White', + }, + _('Green'): { + 'rgb': (0, 1, 0), + 'key': 'G', + 'marker': '_Green', + 'eng_name': 'Green', + }, + _('Blue'): { + 'rgb': (0, 0, 1), + 'key': 'B', + 'marker': '_Blue', + 'eng_name': 'Blue', + }, + _('Red'): { + 'rgb': (1, 0, 0), + 'key': 'R', + 'marker': '_Red', + 'eng_name': 'Red', + }, + _('Orange'): { + 'rgb': (1, 0.5, 0), + 'key': 'O', + 'marker': '_Orange', + 'eng_name': 'Orange', + }, + _('Violet'): { + 'rgb': (0.5, 0, 0.5), + 'key': 'V', + 'marker': '_Violet', + 'eng_name': 'Violet', + }, + _('Pink'): { + 'rgb': (1, 0.5, 1), + 'key': 'P', + 'marker': '_Pink', + 'eng_name': 'Pink', + }, } @@ -84,6 +124,64 @@ def initial(): + + + +def generate_menu(self): + items = [] + + # backgrounds + items.append( ('/{}'.format( _('_Background') ), None, None, 0, '') ) + + for i in COLORS: + C = COLORS[i] + if C['eng_name'] == config['background_color']: + items.append( ('/{}/{}'.format( _('Background'), _(C['marker']) ), '{}'.format(C['key']), self.color_change, 1, '') ) + for i in COLORS: + C = COLORS[i] + if C['eng_name'] is not config['background_color']: + items.append( ('/{}/{}'.format( _('Background'), _(C['marker']) ), '{}'.format(C['key']), self.color_change, 2, '/{}/{}'.format( _('Background'), _(config['background_color']))) ) + + # foregrounds + items.append( ('/{}'.format( _('_Foreground') ), None, None, 0, '') ) + + for i in COLORS: + C = COLORS[i] + if C['eng_name'] == config['foreground_color']: + items.append( ('/{}/{}'.format( _('Foreground'), _(C['marker']) ), '{}'.format(C['key']), self.color_change, 1, '') ) + for i in COLORS: + C = COLORS[i] + if C['eng_name'] is not config['foreground_color']: + items.append( ('/{}/{}'.format( _('Foreground'), _(C['marker']) ), '{}'.format(C['key']), self.color_change, 2, '/{}/{}'.format( _('Foreground'), _(config['foreground_color']))) ) + + items.append( ('/{}'.format( _('_Opacity') ), None, None, 0, '') ) + items.append( ('/{}/_50'.format( _('Opacity') ), '5', self.opacity_change, 50, '') ) + items.append( ('/{}/_10'.format( _('Opacity') ), '1', self.opacity_change, 10, '/{}/50'.format( _('Opacity') )) ) + items.append( ('/{}/_20'.format( _('Opacity') ), '2', self.opacity_change, 20, '/{}/50'.format( _('Opacity') )) ) + items.append( ('/{}/_30'.format( _('Opacity') ), '3', self.opacity_change, 30, '/{}/50'.format( _('Opacity') )) ) + items.append( ('/{}/_40'.format( _('Opacity') ), '4', self.opacity_change, 40, '/{}/50'.format( _('Opacity') )) ) + items.append( ('/{}/_60'.format( _('Opacity') ), '6', self.opacity_change, 60, '/{}/50'.format( _('Opacity') )) ) + items.append( ('/{}/_70'.format( _('Opacity') ), '7', self.opacity_change, 70, '/{}/50'.format( _('Opacity') )) ) + items.append( ('/{}/_80'.format( _('Opacity') ), '8', self.opacity_change, 80, '/{}/50'.format( _('Opacity') )) ) + items.append( ('/{}/_90'.format( _('Opacity') ), '9', self.opacity_change, 90, '/{}/50'.format( _('Opacity') )) ) + items.append( ('/{}/10_0'.format( _('Opacity') ), '0', self.opacity_change, 100,'/{}/50'.format( _('Opacity') )) ) + + items.append( ('/{}'.format( _('_Metric') ), None, None, 0, '') ) + items.append( ('/{}/p_x'.format(_('Metric') ), None, self.metric_change, 1, '') ) + items.append( ('/{}/_mm'.format(_('Metric') ), None, self.metric_change, 2, '/{}/px'.format( _('Metric') )) ) + items.append( ('/{}/_in'.format(_('Metric') ), None, self.metric_change, 3, '/{}/px'.format( _('Metric') )) ) + items.append( ('/{}/_pt (Adobe)'.format( _('Metric') ), None, self.metric_change, 4, '/{}/px'.format( _('Metric') )) ) + + items.append( ('/{}'.format( _('_Tools') ), None, None, 0, '') ) + items.append( ('/{}/{}'.format( _('Tools'), _('Rotate') ), 'R', self.size_change, 1, '') ) + + return items + + + + + + class Master: def __init__(self): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) @@ -149,48 +247,7 @@ def __init__(self): tableH.attach(va, 3,4, *value_row) - self.menu_items = ( - ('/{}'.format( _('_Background') ), None, None, 0, ''), - ('/{}/{}'.format( _('Background'), _('_White') ), 'W', self.color_change, 1, ''), - ('/{}/{}'.format( _('Background'), _('Blac_k') ), 'K', self.color_change, 2, '/{}/{}'.format( _('Background'), _('White') )), - ('/{}/{}'.format( _('Background'), _('_Green') ), 'G', self.color_change, 3, '/{}/{}'.format( _('Background'), _('White') )), - ('/{}/{}'.format( _('Background'), _('_Blue') ), 'B', self.color_change, 4, '/{}/{}'.format( _('Background'), _('White') )), - ('/{}/{}'.format( _('Background'), _('_Red') ), 'R', self.color_change, 5, '/{}/{}'.format( _('Background'), _('White') )), - ('/{}/{}'.format( _('Background'), _('_Orange') ), 'O', self.color_change, 6, '/{}/{}'.format( _('Background'), _('White') )), - ('/{}/{}'.format( _('Background'), _('_Violet') ), 'V', self.color_change, 7, '/{}/{}'.format( _('Background'), _('White') )), - ('/{}/{}'.format( _('Background'), _('_Pink') ), 'P', self.color_change, 8, '/{}/{}'.format( _('Background'), _('White') )), - - ('/{}'.format( _('_Foreground') ), None, None, 0, ''), - ('/{}/{}'.format( _('Foreground'), _('_Red') ), 'R', self.color_change, 5, ''), - ('/{}/{}'.format( _('Foreground'), _('_White') ), 'W', self.color_change, 1, '/{}/{}'.format( _('Foreground'), _('Red') )), - ('/{}/{}'.format( _('Foreground'), _('Blac_k') ), 'K', self.color_change, 2, '/{}/{}'.format( _('Foreground'), _('Red') )), - ('/{}/{}'.format( _('Foreground'), _('_Green') ), 'G', self.color_change, 3, '/{}/{}'.format( _('Foreground'), _('Red') )), - ('/{}/{}'.format( _('Foreground'), _('_Blue') ), 'B', self.color_change, 4, '/{}/{}'.format( _('Foreground'), _('Red') )), - ('/{}/{}'.format( _('Foreground'), _('_Orange') ), 'O', self.color_change, 6, '/{}/{}'.format( _('Foreground'), _('Red') )), - ('/{}/{}'.format( _('Foreground'), _('_Violet') ), 'V', self.color_change, 7, '/{}/{}'.format( _('Foreground'), _('Red') )), - ('/{}/{}'.format( _('Foreground'), _('_Pink') ), 'P', self.color_change, 8, '/{}/{}'.format( _('Foreground'), _('Red') )), - - ('/{}'.format( _('_Opacity') ), None, None, 0, ''), - ('/{}/_50'.format( _('Opacity') ), '5', self.opacity_change, 50, ''), - ('/{}/_10'.format( _('Opacity') ), '1', self.opacity_change, 10, '/{}/50'.format( _('Opacity') )), - ('/{}/_20'.format( _('Opacity') ), '2', self.opacity_change, 20, '/{}/50'.format( _('Opacity') )), - ('/{}/_30'.format( _('Opacity') ), '3', self.opacity_change, 30, '/{}/50'.format( _('Opacity') )), - ('/{}/_40'.format( _('Opacity') ), '4', self.opacity_change, 40, '/{}/50'.format( _('Opacity') )), - ('/{}/_60'.format( _('Opacity') ), '6', self.opacity_change, 60, '/{}/50'.format( _('Opacity') )), - ('/{}/_70'.format( _('Opacity') ), '7', self.opacity_change, 70, '/{}/50'.format( _('Opacity') )), - ('/{}/_80'.format( _('Opacity') ), '8', self.opacity_change, 80, '/{}/50'.format( _('Opacity') )), - ('/{}/_90'.format( _('Opacity') ), '9', self.opacity_change, 90, '/{}/50'.format( _('Opacity') )), - ('/{}/10_0'.format( _('Opacity') ), '0', self.opacity_change, 100,'/{}/50'.format( _('Opacity') )), - - ('/{}'.format( _('_Metric') ), None, None, 0, ''), - ('/{}/p_x'.format(_('Metric') ), None, self.metric_change, 1, ''), - ('/{}/_mm'.format(_('Metric') ), None, self.metric_change, 2, '/{}/px'.format( _('Metric') )), - ('/{}/_in'.format(_('Metric') ), None, self.metric_change, 3, '/{}/px'.format( _('Metric') )), - ('/{}/_pt (Adobe)'.format( _('Metric') ), None, self.metric_change, 4, '/{}/px'.format( _('Metric') )), - - ('/{}'.format( _('_Tools') ), None, None, 0, ''), - ('/{}/{}'.format( _('Tools'), _('Rotate') ), 'R', self.size_change, 1, ''), - ) + self.menu_items = ( generate_menu(self) ) menubar = self.get_main_menu() tableH.attach(menubar, 0,4, *menu_row) @@ -207,9 +264,9 @@ def color_change(self, ret, widget): color_context = widget.name.split('/')[-2] if color_context == _('Background'): - slave.background = COLORS[ _(color_name) ] + slave.background = COLORS[ _(color_name) ]['rgb'] elif color_context == _('Foreground'): - slave.foreground = COLORS[ _(color_name) ] + slave.foreground = COLORS[ _(color_name) ]['rgb'] else: raise ValueError( "Unknown color_context: {}".format(color_context) ) @@ -270,8 +327,8 @@ def __init__(self, parent): self.area = gtk.DrawingArea() - self.background = COLORS[ _( config['background_color'] ) ] - self.foreground = COLORS[ _( config['foreground_color'] ) ] + self.background = COLORS[ _( config['background_color'] ) ]['rgb'] + self.foreground = COLORS[ _( config['foreground_color'] ) ]['rgb'] self.window.add(self.area)