dumon 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb7a865d6495ecde56f343c847129901818c241c
4
- data.tar.gz: d5d81ad2bc4c91586cc976b431d2c8f380b3bacb
3
+ metadata.gz: 7adb0f9fe734dfbced3303b8c31eb026f4d2e5f9
4
+ data.tar.gz: 8396241a5b12fcbaa66a392f9d5ff9b56c4f7573
5
5
  SHA512:
6
- metadata.gz: a891d232b68a9b9be661204c0372b9daf0a7aa3a63f5a8f711dca8702da715ae54995f4e584ba27604a7a695d8ef474a25ada4912625663bbd574fec2a4a8e64
7
- data.tar.gz: da38eb17ddce231a535206c7224e5d0d9c154c1dc984c51192fc19d684ee1f79250e18102220278f803c578cef0f12e0550a0ec4a1d74e71697726c81719e521
6
+ metadata.gz: bf2206d041576a2c044f24f1fcefdc7a468d41969200818c53dba4df1397f3bc41212998a59cf2324ec8973e91b6ced72f3eef6d89a140e1efb043bb11ef811b
7
+ data.tar.gz: ad44ec873b5f08ec9372d9ef53020715584cd07a578e8401fb920506a3a33c1c58515565c13fc8efa148725b725fc6c37031285d413d2f5627d6c6f69f5eb178
@@ -124,7 +124,7 @@ module Dumon
124
124
 
125
125
  ###
126
126
  # Switch to given single output device with given resolution.
127
- # *param* output
127
+ # *output* output
128
128
  # *resolution* nil for default resolution
129
129
  def single(output, resolution=nil)
130
130
  raise NotImplementedError, 'this should be overridden by concrete sub-class'
@@ -0,0 +1,156 @@
1
+ module Dumon
2
+
3
+ ###
4
+ # This class represents a base class defining user interface
5
+ # (dialog window) for profile management.
6
+ class ProfileDlg
7
+
8
+ ###
9
+ # Constructor.
10
+ def initialize
11
+ @dumon_conf = Dumon::App.instance.read_config
12
+ end
13
+
14
+ ###
15
+ # Shows the dialog.
16
+ # Abstract method to be overridden by concrete sub-class.
17
+ def show
18
+ raise NotImplementedError, 'this should be overridden by concrete sub-class'
19
+ end
20
+
21
+ ###
22
+ # Reacts to an problem by profile use with a warning.
23
+ # *msg* message describing the problem
24
+ def on_warn(msg)
25
+ Dumon::logger.warn msg.join(', ')
26
+ end
27
+
28
+ ###
29
+ # Applies a profile from configuration according selection in tree view.
30
+ # *prof_name* profile name
31
+ def apply_profile(prof_name)
32
+ profile = @dumon_conf[:profiles][prof_name.to_sym]
33
+ profile[:mode] = profile[:mode].to_sym
34
+ begin
35
+ Dumon::App.instance.ui.omanager.switch profile
36
+ Dumon::logger.debug "Profile applied, name=#{prof_name}"
37
+ rescue ArgumentError => ae # BF #14
38
+ on_warn ['Profile use failed! (unconnected output?)', "profile name=#{prof_name}", "message=#{ae.message}"]
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+
45
+ ###
46
+ # This class represents an user interface for profile management based on Gtk library.
47
+ class GtkProfileDlg < ProfileDlg
48
+
49
+ ###
50
+ # Constructor.
51
+ def initialize
52
+ super
53
+
54
+ # create the dialog
55
+ @dialog = Gtk::Dialog.new('Profile management', nil, Gtk::Dialog::MODAL, [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_REJECT])
56
+ t = Gtk::Table.new(2, 2)
57
+ t.row_spacings = 5
58
+ t.column_spacings = 5
59
+
60
+ # disable entry/button if no mode set (probably after start of Dumon)
61
+ entry_store = Gtk::Entry.new
62
+ btn_save = Gtk::Button.new(Gtk::Stock::SAVE)
63
+ if Dumon::App.instance.current_profile.nil?
64
+ entry_store.text = '<make a choice first>'
65
+ entry_store.set_sensitive false
66
+ btn_save.set_sensitive false
67
+ end
68
+
69
+ # save new profile
70
+ btn_save.signal_connect('clicked') do
71
+ if entry_store.text.size > 0
72
+ @dumon_conf[:profiles][entry_store.text] = Dumon::App.instance.current_profile
73
+ Dumon::App.instance.write_config(@dumon_conf)
74
+ Dumon::logger.debug "Stored profile, name=#{entry_store.text}"
75
+ @dialog.destroy
76
+ end
77
+ end
78
+
79
+ t.attach(Gtk::HBox.new(false, 5).pack_start(Gtk::Label.new('Profile name:'), false, false).add(entry_store), 0, 1, 0, 1)
80
+ t.attach(btn_save, 1, 2, 0, 1)
81
+
82
+ # select/delete existing profile
83
+ model = Gtk::ListStore.new(String)
84
+ treeview = Gtk::TreeView.new(model)
85
+ treeview.headers_visible = false
86
+ renderer = Gtk::CellRendererText.new
87
+ column = Gtk::TreeViewColumn.new('', renderer, :text => 0)
88
+ treeview.append_column(column)
89
+
90
+ @dumon_conf[:profiles].keys.each do |k|
91
+ iter = model.append
92
+ iter.set_value 0, k.to_s
93
+ end
94
+
95
+ # apply
96
+ btn_apply = Gtk::Button.new(Gtk::Stock::APPLY)
97
+ btn_apply.signal_connect('clicked') do
98
+ selection = treeview.selection
99
+ if iter = selection.selected
100
+ apply_profile(iter[0])
101
+ @dialog.destroy
102
+ end
103
+ end
104
+ # double-click on treeview
105
+ treeview.signal_connect("row-activated") do |view, path|
106
+ if iter = view.model.get_iter(path)
107
+ apply_profile(iter[0])
108
+ @dialog.destroy
109
+ end
110
+ end
111
+ # delete
112
+ btn_delete = Gtk::Button.new(Gtk::Stock::DELETE)
113
+ btn_delete.signal_connect('clicked') do
114
+ selection = treeview.selection
115
+ if iter = selection.selected
116
+ prof_name = iter[0]
117
+ @dumon_conf[:profiles].delete prof_name.to_sym
118
+ Dumon::App.instance.write_config(@dumon_conf)
119
+ Dumon::logger.debug "Deleted profile, name=#{prof_name}"
120
+ @dialog.destroy
121
+ end
122
+ end
123
+
124
+ t.attach(treeview, 0, 1, 1, 2)
125
+ t.attach(Gtk::VBox.new(false, 5).pack_start(btn_apply, false, false).pack_start(btn_delete, false, false), 1, 2, 1, 2)
126
+
127
+ @dialog.vbox.add t
128
+
129
+ # ensure that the dialog box is destroyed when the user responds
130
+ @dialog.signal_connect('response') do |w, code|
131
+ if Gtk::Dialog::RESPONSE_OK.eql?(code) and entry.text.size > 0
132
+ Dumon::App.instance.write(entry.text => Dumon::App.instance.current_profile)
133
+ end
134
+
135
+ @dialog.destroy
136
+ end
137
+ end
138
+
139
+ def show #:nodoc:
140
+ @dialog.show_all
141
+ end
142
+
143
+ def on_warn(msg) #:nodoc:
144
+ super(msg)
145
+ md = Gtk::MessageDialog.new(
146
+ @dialog,
147
+ Gtk::Dialog::DESTROY_WITH_PARENT, Gtk::MessageDialog::WARNING,
148
+ Gtk::MessageDialog::BUTTONS_CLOSE,
149
+ msg.join("\n"))
150
+ md.run
151
+ md.destroy
152
+ end
153
+
154
+ end
155
+
156
+ end
@@ -1,3 +1,6 @@
1
+ require 'dumon/profile'
2
+
3
+
1
4
  module Dumon
2
5
 
3
6
  ###
@@ -246,103 +249,11 @@ module Dumon
246
249
  rslt
247
250
  end
248
251
 
249
- ###
250
- # Applies a profile from configuration according selection in tree view.
251
- def apply_profile(conf, prof_name)
252
- profile = conf[:profiles][prof_name.to_sym]
253
- profile[:mode] = profile[:mode].to_sym
254
- omanager.switch profile
255
- Dumon::logger.debug "Profile applied, name=#{prof_name}"
256
- end
257
-
258
252
  ###
259
253
  # Function to open a dialog box for profile management.
260
254
  def profile_management_dialog
261
- conf = Dumon::App.instance.read_config
262
-
263
- # create the dialog
264
- dialog = Gtk::Dialog.new('Profile management', nil, Gtk::Dialog::MODAL, [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_REJECT])
265
- t = Gtk::Table.new(2, 2)
266
- t.row_spacings = 5
267
- t.column_spacings = 5
268
-
269
- # save new profile
270
- entry_store = Gtk::Entry.new
271
- btn_save = Gtk::Button.new(Gtk::Stock::SAVE)
272
- btn_save.signal_connect('clicked') do
273
- if entry_store.text.size > 0
274
- conf[:profiles][entry_store.text] = Dumon::App.instance.current_profile
275
- Dumon::App.instance.write_config(conf)
276
- Dumon::logger.debug "Stored profile, name=#{entry_store.text}"
277
- dialog.destroy
278
- end
279
- end
280
- # disable entry/button if no mode set (probably after start of Dumon)
281
- if Dumon::App.instance.current_profile.nil?
282
- entry_store.text = '<make a choice first>'
283
- entry_store.set_sensitive false
284
- btn_save.set_sensitive false
285
- end
286
-
287
- t.attach(Gtk::HBox.new(false, 5).pack_start(Gtk::Label.new('Profile name:'), false, false).add(entry_store), 0, 1, 0, 1)
288
- t.attach(btn_save, 1, 2, 0, 1)
289
-
290
- # select/delete existing profile
291
- model = Gtk::ListStore.new(String)
292
- treeview = Gtk::TreeView.new(model)
293
- treeview.headers_visible = false
294
- renderer = Gtk::CellRendererText.new
295
- column = Gtk::TreeViewColumn.new('', renderer, :text => 0)
296
- treeview.append_column(column)
297
-
298
- conf[:profiles].keys.each do |k|
299
- iter = model.append
300
- iter.set_value 0, k.to_s
301
- end
302
-
303
- # apply
304
- btn_apply = Gtk::Button.new(Gtk::Stock::APPLY)
305
- btn_apply.signal_connect('clicked') do
306
- selection = treeview.selection
307
- if iter = selection.selected
308
- apply_profile(conf, iter[0])
309
- dialog.destroy
310
- end
311
- end
312
- # double-click on treeview
313
- treeview.signal_connect("row-activated") do |view, path|
314
- if iter = view.model.get_iter(path)
315
- apply_profile(conf, iter[0])
316
- dialog.destroy
317
- end
318
- end
319
- # delete
320
- btn_delete = Gtk::Button.new(Gtk::Stock::DELETE)
321
- btn_delete.signal_connect('clicked') do
322
- selection = treeview.selection
323
- if iter = selection.selected
324
- prof_name = iter[0]
325
- conf[:profiles].delete prof_name.to_sym
326
- Dumon::App.instance.write_config(conf)
327
- Dumon::logger.debug "Deleted profile, name=#{prof_name}"
328
- dialog.destroy
329
- end
330
- end
331
-
332
- t.attach(treeview, 0, 1, 1, 2)
333
- t.attach(Gtk::VBox.new(false, 5).pack_start(btn_apply, false, false).pack_start(btn_delete, false, false), 1, 2, 1, 2)
334
-
335
- dialog.vbox.add t
336
-
337
- # ensure that the dialog box is destroyed when the user responds
338
- dialog.signal_connect('response') do |w, code|
339
- if Gtk::Dialog::RESPONSE_OK.eql?(code) and entry.text.size > 0
340
- Dumon::App.instance.write(entry.text => Dumon::App.instance.current_profile)
341
- end
342
-
343
- dialog.destroy
344
- end
345
- dialog.show_all
255
+ dialog = Dumon::GtkProfileDlg.new
256
+ dialog.show
346
257
  end
347
258
 
348
259
  end
@@ -2,15 +2,16 @@ module Dumon
2
2
 
3
3
  # Version history.
4
4
  VERSION_HISTORY = [
5
- ['0.2.6', '2013-04-23', 'BF #13, Failure if no default resolution provided by output'],
6
- ['0.2.5', '2013-04-02', 'BF #12, Profile dialog fails if configuration is empty'],
5
+ ['0.2.7', '2013-05-08', 'BF #14: Failure if applied profile with unconnected output; Enh #7'],
6
+ ['0.2.6', '2013-04-23', 'BF #13: Failure if no default resolution provided by output'],
7
+ ['0.2.5', '2013-04-02', 'BF #12: Profile dialog fails if configuration is empty'],
7
8
  ['0.2.4', '2013-03-29', 'New CLI argument: --reset, tested with MRI Ruby 2.0.0'],
8
9
  ['0.2.3', '2013-03-17', 'BF #10: Profile dialog fails unless configuration exists'],
9
10
  ['0.2.2', '2013-03-15', 'Enh #6: Vertical location of outputs'],
10
- ['0.2.1', '2013-03-13', 'BF #9: Crash Ruby 1.8.7 because of Dir.home'],
11
+ ['0.2.1', '2013-03-13', 'BF #9: Crash Ruby 1.8.7 because of Dir.home'],
11
12
  ['0.2.0', '2013-03-12', 'Enh #5: Profiles; File based configuration'],
12
13
  ['0.1.7', '2013-02-13', 'Enh #4: About dialog'],
13
- ['0.1.6', '2013-02-11', 'BF #3: Crash by rendering popup menu if only one output is there'],
14
+ ['0.1.6', '2013-02-11', 'BF #3: Crash by rendering popup menu if only one output is there'],
14
15
  ['0.1.5', '2013-02-08', 'Enh #2: Support for primary output'],
15
16
  ['0.1.4', '2013-02-07', 'Enh #1: Starting as daemon'],
16
17
  ['0.1.3', '2013-02-03', 'Changed starting mechanism'],
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dumon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vaclav Sykora
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-23 00:00:00.000000000 Z
11
+ date: 2013-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gtk2
@@ -42,6 +42,7 @@ files:
42
42
  - dumon.gemspec
43
43
  - lib/dumon.rb
44
44
  - lib/dumon/omanager.rb
45
+ - lib/dumon/profile.rb
45
46
  - lib/dumon/ui.rb
46
47
  - lib/dumon/version.rb
47
48
  - lib/monitor24.png