-
Notifications
You must be signed in to change notification settings - Fork 0
/
preferences_window.rb
124 lines (104 loc) · 4.36 KB
/
preferences_window.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
###############################################################################
# Copyright 2022 Ian McIntosh <[email protected]>
# Copyright 2022 Georges Khaznadar <[email protected]> (migration to gtk3)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
require 'glade_window'
class PreferencesWindow < GladeWindow
DEFAULT_FOREGROUND_COLOR = '#202020'
DEFAULT_BACKGROUND_COLOR = '#E6E36B'
DEFAULT_OPACITY = 0.85
MM_TO_INCHES = (1.0 / 25.4) # 1 inch = 25.4 millimeters
def initialize
super('preferences_window', :widgets => [:foreground_color_button, :background_color_button, :text_fontbutton, :system_ppi_setting_label, :use_custom_ppi_radiobutton, :custom_ppi_settings_container, :ppi_horizontal_spinbutton, :ppi_vertical_spinbutton])
# GTK signal handlers
@window.signal_connect('delete_event') { hide }
@system_ppi_setting_label.markup = sprintf("(%d x %d)", system_ppi_horizontal, system_ppi_vertical)
@window.signal_connect('key_press_event') { |_window, event|
if event.keyval == Gdk::Keyval::KEY_Escape
hide
end
}
end
def foreground_color ; @foreground_color_button.color ; end
def background_color ; @background_color_button.color ; end
def font ; @text_fontbutton.font_name ; end
def watch_mouse? ; @watch_mouse_checkbutton.active? ; end
def watch_mouse=(value) ; @watch_mouse_checkbutton.active = value ; end
attr_reader :opacity
def ppi_horizontal
if @use_custom_ppi_radiobutton.active?
@ppi_horizontal_spinbutton.value
else
system_ppi_horizontal
end
end
def ppi_vertical
if @use_custom_ppi_radiobutton.active?
@ppi_vertical_spinbutton.value
else
system_ppi_vertical
end
end
def system_ppi_horizontal ; Gdk::Screen.default.width / (Gdk::Screen.default.width_mm * MM_TO_INCHES) ; end
def system_ppi_vertical ; Gdk::Screen.default.width / (Gdk::Screen.default.width_mm * MM_TO_INCHES) ; end
###################################################################
# Settings
###################################################################
def read_settings(settings)
@foreground_color_button.color = Gdk::Color.parse(settings['foreground_color'] || DEFAULT_FOREGROUND_COLOR)
@background_color_button.color = Gdk::Color.parse(settings['background_color'] || DEFAULT_BACKGROUND_COLOR)
@text_fontbutton.font_name = settings['font'] if settings['font']
@opacity = settings['opacity'] || DEFAULT_OPACITY
@ppi_horizontal_spinbutton.value = settings['horizontal_pixels_per_inch'] || system_ppi_horizontal
@ppi_vertical_spinbutton.value = settings['vertical_pixels_per_inch'] || system_ppi_vertical
@use_custom_ppi_radiobutton.active = (settings['use_custom_pixels_per_inch'] || false)
end
def write_settings(settings)
settings['foreground_color'] = self.foreground_color.to_s
settings['background_color'] = self.background_color.to_s
settings['font'] = self.font
settings['opacity'] = @opacity
settings['use_custom_pixels_per_inch'] = @use_custom_ppi_radiobutton.active?
settings['horizontal_pixels_per_inch'] = @ppi_horizontal_spinbutton.value
settings['vertical_pixels_per_inch'] = @ppi_vertical_spinbutton.value
end
private
#
# Signal Handlers
#
def on_style_changed
$ruler_window.show_all
$ruler_window.queue_draw
end
def on_ppi_vertical_spinbutton_changed
on_style_changed
end
def on_ppi_horizontal_spinbutton_changed
on_style_changed
end
def on_use_custom_ppi_radiobutton_toggled
@custom_ppi_settings_container.sensitive = @use_custom_ppi_radiobutton.active?
@system_ppi_setting_label.sensitive = !@use_custom_ppi_radiobutton.active?
on_style_changed
end
def on_close_clicked
hide
end
end
# Local Variables:
# tab-width: 2
# End: