diff --git a/rackman.conf b/rackman.conf new file mode 100644 index 0000000..6e16db4 --- /dev/null +++ b/rackman.conf @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- + +# Держать главное окно поверх всех остальных +# Менеджер окон может игнорировать эти установки +# True -- да +# False -- нет +master_above = True + +# Держать измеритель поверх всех остальных окон +# Менеджер окон может игнорировать эти установки +# True -- да +# False -- нет +slave_above = True + +# Заголовок главного окна +# <строка> +master_title = "Rackman [Master]" + +# Заголовок измерителя +# <строка> +slave_title = "Rackman [Slave]" + +# Прозрачность измерителя +# <число> (от 0 до 1) +slave_opacity = 0.5 + +# Перекрывать главное окно измерителем +# True -- да +# False -- нет +transient = False + +# Цвет фона и линий измерителя по-умолчанию +# 'Black' -- чёрный +# 'White' -- белый +# 'Green' -- зелёный +# 'Blue' -- синий +# 'Red' -- красный +# 'Orange' -- оранжевый +# 'Violet' -- фиолетовый +# 'Pink' -- розовый +background_color = 'White' +foreground_color = 'Red' + +# Скорость перемещения и изменения размеров окна измерителя в Fast Mode +# <число> (в пикселях) +fast_mode_speed = 50 \ No newline at end of file diff --git a/rackman.py b/rackman.py index d34d374..d386d56 100644 --- a/rackman.py +++ b/rackman.py @@ -7,7 +7,7 @@ #import pygtk -#pygtk.require('2.0') +#pygtk.require('2.4') import gtk import cairo import math @@ -17,12 +17,29 @@ -__version__ = '1.7.0' +__version__ = '1.8.2' def initial(): - global window, screen, _, COLORS, icon + global window, screen, _, COLORS, icon, config + + + + config = {} + + conf_file_name = "rackman.conf" + conf_path_curdir = os.path.join('./', conf_file_name) + conf_path_share = os.path.join('/usr/share/rackman/', conf_file_name) + conf_path_home = os.path.join(os.path.expanduser('~'),'.config/rackman/', conf_file_name) + + conf_paths = (conf_path_share, conf_path_home, conf_path_curdir) + for conf_path in conf_paths: + if os.path.isfile( conf_path ): + print "Read config {}".format(conf_path) + execfile(conf_path, config) # чтение предустановок из файла конфигурации + + window = gtk.Window() screen = window.get_screen() @@ -42,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', + }, } @@ -67,13 +124,74 @@ 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']))) ) + + # opacity + items.append( ('/{}'.format( _('_Opacity') ), None, None, 0, '') ) + + opacitys = range(10, 101, 10) + for i in opacitys: + if i == config['slave_opacity'] * 100: + items.append( ('/{}/_{}'.format( _('Opacity'), i ), '{}'.format(str(i)[-2]), self.opacity_change, i, '') ) + for i in opacitys: + if i != config['slave_opacity'] * 100: + if i == 100: + items.append( ('/{}/10_0'.format( _('Opacity') ), '{}'.format(str(i)[-2]), self.opacity_change, i, '/{}/{}'.format( _('Opacity'), int(config['slave_opacity'] * 100) )) ) + else: + items.append( ('/{}/_{}'.format( _('Opacity'), i ), '{}'.format(str(i)[-2]), self.opacity_change, i, '/{}/{}'.format( _('Opacity'), int(config['slave_opacity'] * 100) )) ) + + 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) self.window.set_opacity(1) self.window.set_resizable(False) - self.window.set_title("Rackman [Master]") + self.window.set_title( config['master_title'] ) self.window.set_icon(icon) + self.window.set_keep_above(config['master_above']) self.window.connect("destroy", lambda w: gtk.main_quit()) @@ -131,48 +249,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) @@ -189,9 +266,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) ) @@ -237,20 +314,23 @@ class Slave: def __init__(self, parent): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_decorated(False) - self.window.set_title("Rackman [Slave]") + self.window.set_title( config['slave_title'] ) self.window.set_icon(icon) self.window.set_resizable(True) - self.window.set_keep_above(True) - #self.window.set_transient_for(parent.window) - self.window.set_opacity(0.5) + self.window.set_keep_above(config['slave_above']) + if config['transient'] == True: + self.window.set_transient_for(parent.window) + else: + self.window.set_transient_for(None) + self.window.set_opacity( config['slave_opacity'] ) self.parent = parent self.metric = ('px', 1, 0, 2) self.area = gtk.DrawingArea() - self.background = COLORS[ _('White') ] - self.foreground = COLORS[ _('Red') ] + self.background = COLORS[ _( config['background_color'] ) ]['rgb'] + self.foreground = COLORS[ _( config['foreground_color'] ) ]['rgb'] self.window.add(self.area) @@ -269,10 +349,10 @@ def __init__(self, parent): def resizing(self, widget, event): x, y = widget.get_size() ox, oy = widget.get_position() - + acc = 1 if event.state & gtk.gdk.SHIFT_MASK: - acc = 50 + acc = config['fast_mode_speed'] if event.state & gtk.gdk.CONTROL_MASK: if event.hardware_keycode == 114: # right diff --git a/setup.py b/setup.py index 661ab2b..02cd6e1 100644 --- a/setup.py +++ b/setup.py @@ -17,6 +17,7 @@ data_files = [ ('/usr/share/icons/hicolor/scalable/apps/', ['rackman.svg']), ('/usr/share/applications', ['rackman.desktop']), + ('/usr/share/rackman', ['rackman.conf']), ('/usr/share/locale/ru/LC_MESSAGES', ['./locale/ru/LC_MESSAGES/rackman.mo']), ('/usr/share/locale/en/LC_MESSAGES', ['./locale/en/LC_MESSAGES/rackman.mo']), ], @@ -24,7 +25,7 @@ 'Rackman', ], requires = [ - 'PyGTK (>=2.0)', + 'PyGTK (>=2.4)', ], scripts = [ 'rackman'