Skip to content

Commit

Permalink
Merge pull request #8 from FRiMN/config
Browse files Browse the repository at this point in the history
Config
  • Loading branch information
FRiMN committed Aug 29, 2015
2 parents 249bc44 + 826a712 commit 191b876
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 65 deletions.
46 changes: 46 additions & 0 deletions rackman.conf
Original file line number Diff line number Diff line change
@@ -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
208 changes: 144 additions & 64 deletions rackman.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


#import pygtk
#pygtk.require('2.0')
#pygtk.require('2.4')
import gtk
import cairo
import math
Expand All @@ -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()
Expand All @@ -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',
},
}


Expand All @@ -67,13 +124,74 @@ def initial():






def generate_menu(self):
items = []

# backgrounds
items.append( ('/{}'.format( _('_Background') ), None, None, 0, '<Branch>') )

for i in COLORS:
C = COLORS[i]
if C['eng_name'] == config['background_color']:
items.append( ('/{}/{}'.format( _('Background'), _(C['marker']) ), '<alt><shift>{}'.format(C['key']), self.color_change, 1, '<RadioItem>') )
for i in COLORS:
C = COLORS[i]
if C['eng_name'] is not config['background_color']:
items.append( ('/{}/{}'.format( _('Background'), _(C['marker']) ), '<alt><shift>{}'.format(C['key']), self.color_change, 2, '/{}/{}'.format( _('Background'), _(config['background_color']))) )

# foregrounds
items.append( ('/{}'.format( _('_Foreground') ), None, None, 0, '<Branch>') )

for i in COLORS:
C = COLORS[i]
if C['eng_name'] == config['foreground_color']:
items.append( ('/{}/{}'.format( _('Foreground'), _(C['marker']) ), '<ctrl><shift>{}'.format(C['key']), self.color_change, 1, '<RadioItem>') )
for i in COLORS:
C = COLORS[i]
if C['eng_name'] is not config['foreground_color']:
items.append( ('/{}/{}'.format( _('Foreground'), _(C['marker']) ), '<ctrl><shift>{}'.format(C['key']), self.color_change, 2, '/{}/{}'.format( _('Foreground'), _(config['foreground_color']))) )

# opacity
items.append( ('/{}'.format( _('_Opacity') ), None, None, 0, '<Branch>') )

opacitys = range(10, 101, 10)
for i in opacitys:
if i == config['slave_opacity'] * 100:
items.append( ('/{}/_{}'.format( _('Opacity'), i ), '<ctrl>{}'.format(str(i)[-2]), self.opacity_change, i, '<RadioItem>') )
for i in opacitys:
if i != config['slave_opacity'] * 100:
if i == 100:
items.append( ('/{}/10_0'.format( _('Opacity') ), '<ctrl>{}'.format(str(i)[-2]), self.opacity_change, i, '/{}/{}'.format( _('Opacity'), int(config['slave_opacity'] * 100) )) )
else:
items.append( ('/{}/_{}'.format( _('Opacity'), i ), '<ctrl>{}'.format(str(i)[-2]), self.opacity_change, i, '/{}/{}'.format( _('Opacity'), int(config['slave_opacity'] * 100) )) )

items.append( ('/{}'.format( _('_Metric') ), None, None, 0, '<Branch>') )
items.append( ('/{}/p_x'.format(_('Metric') ), None, self.metric_change, 1, '<RadioItem>') )
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, '<Branch>') )
items.append( ('/{}/{}'.format( _('Tools'), _('Rotate') ), '<ctrl>R', self.size_change, 1, '<Item>') )

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())


Expand Down Expand Up @@ -131,48 +249,7 @@ def __init__(self):
tableH.attach(va, 3,4, *value_row)


self.menu_items = (
('/{}'.format( _('_Background') ), None, None, 0, '<Branch>'),
('/{}/{}'.format( _('Background'), _('_White') ), '<alt><shift>W', self.color_change, 1, '<RadioItem>'),
('/{}/{}'.format( _('Background'), _('Blac_k') ), '<alt><shift>K', self.color_change, 2, '/{}/{}'.format( _('Background'), _('White') )),
('/{}/{}'.format( _('Background'), _('_Green') ), '<alt><shift>G', self.color_change, 3, '/{}/{}'.format( _('Background'), _('White') )),
('/{}/{}'.format( _('Background'), _('_Blue') ), '<alt><shift>B', self.color_change, 4, '/{}/{}'.format( _('Background'), _('White') )),
('/{}/{}'.format( _('Background'), _('_Red') ), '<alt><shift>R', self.color_change, 5, '/{}/{}'.format( _('Background'), _('White') )),
('/{}/{}'.format( _('Background'), _('_Orange') ), '<alt><shift>O', self.color_change, 6, '/{}/{}'.format( _('Background'), _('White') )),
('/{}/{}'.format( _('Background'), _('_Violet') ), '<alt><shift>V', self.color_change, 7, '/{}/{}'.format( _('Background'), _('White') )),
('/{}/{}'.format( _('Background'), _('_Pink') ), '<alt><shift>P', self.color_change, 8, '/{}/{}'.format( _('Background'), _('White') )),

('/{}'.format( _('_Foreground') ), None, None, 0, '<Branch>'),
('/{}/{}'.format( _('Foreground'), _('_Red') ), '<ctrl><shift>R', self.color_change, 5, '<RadioItem>'),
('/{}/{}'.format( _('Foreground'), _('_White') ), '<ctrl><shift>W', self.color_change, 1, '/{}/{}'.format( _('Foreground'), _('Red') )),
('/{}/{}'.format( _('Foreground'), _('Blac_k') ), '<ctrl><shift>K', self.color_change, 2, '/{}/{}'.format( _('Foreground'), _('Red') )),
('/{}/{}'.format( _('Foreground'), _('_Green') ), '<ctrl><shift>G', self.color_change, 3, '/{}/{}'.format( _('Foreground'), _('Red') )),
('/{}/{}'.format( _('Foreground'), _('_Blue') ), '<ctrl><shift>B', self.color_change, 4, '/{}/{}'.format( _('Foreground'), _('Red') )),
('/{}/{}'.format( _('Foreground'), _('_Orange') ), '<ctrl><shift>O', self.color_change, 6, '/{}/{}'.format( _('Foreground'), _('Red') )),
('/{}/{}'.format( _('Foreground'), _('_Violet') ), '<ctrl><shift>V', self.color_change, 7, '/{}/{}'.format( _('Foreground'), _('Red') )),
('/{}/{}'.format( _('Foreground'), _('_Pink') ), '<ctrl><shift>P', self.color_change, 8, '/{}/{}'.format( _('Foreground'), _('Red') )),

('/{}'.format( _('_Opacity') ), None, None, 0, '<Branch>'),
('/{}/_50'.format( _('Opacity') ), '<ctrl>5', self.opacity_change, 50, '<RadioItem>'),
('/{}/_10'.format( _('Opacity') ), '<ctrl>1', self.opacity_change, 10, '/{}/50'.format( _('Opacity') )),
('/{}/_20'.format( _('Opacity') ), '<ctrl>2', self.opacity_change, 20, '/{}/50'.format( _('Opacity') )),
('/{}/_30'.format( _('Opacity') ), '<ctrl>3', self.opacity_change, 30, '/{}/50'.format( _('Opacity') )),
('/{}/_40'.format( _('Opacity') ), '<ctrl>4', self.opacity_change, 40, '/{}/50'.format( _('Opacity') )),
('/{}/_60'.format( _('Opacity') ), '<ctrl>6', self.opacity_change, 60, '/{}/50'.format( _('Opacity') )),
('/{}/_70'.format( _('Opacity') ), '<ctrl>7', self.opacity_change, 70, '/{}/50'.format( _('Opacity') )),
('/{}/_80'.format( _('Opacity') ), '<ctrl>8', self.opacity_change, 80, '/{}/50'.format( _('Opacity') )),
('/{}/_90'.format( _('Opacity') ), '<ctrl>9', self.opacity_change, 90, '/{}/50'.format( _('Opacity') )),
('/{}/10_0'.format( _('Opacity') ), '<ctrl>0', self.opacity_change, 100,'/{}/50'.format( _('Opacity') )),

('/{}'.format( _('_Metric') ), None, None, 0, '<Branch>'),
('/{}/p_x'.format(_('Metric') ), None, self.metric_change, 1, '<RadioItem>'),
('/{}/_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, '<Branch>'),
('/{}/{}'.format( _('Tools'), _('Rotate') ), '<ctrl>R', self.size_change, 1, '<Item>'),
)
self.menu_items = ( generate_menu(self) )

menubar = self.get_main_menu()
tableH.attach(menubar, 0,4, *menu_row)
Expand All @@ -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) )

Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
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']),
],
obsoletes = [
'Rackman',
],
requires = [
'PyGTK (>=2.0)',
'PyGTK (>=2.4)',
],
scripts = [
'rackman'
Expand Down

0 comments on commit 191b876

Please sign in to comment.