lib/grumblr/ui.rb in grumblr-2.2.0 vs lib/grumblr/ui.rb in grumblr-2.3.0

- old
+ new

@@ -1,9 +1,10 @@ require 'gtk2' module Grumblr + APP_NAME = 'Grumblr' APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')) DATA_ROOT = File.join(APP_ROOT, 'data') VERSION = File.open(File.join(APP_ROOT,'VERSION')) { |f| f.read } class UI < Gtk::Window @@ -15,31 +16,33 @@ filename = File.join(Grumblr::DATA_ROOT, 'pixmaps', 'grumblr.svg') self.logo = Gdk::Pixbuf.new(filename, 128, 128) set_size_request 440, 340 - set_border_width 4 + set_border_width 0 set_allow_shrink false - set_title 'Grumblr' + set_title Grumblr::APP_NAME set_icon self.logo set_default_width $cfg.get(:window_width).to_i set_default_height $cfg.get(:window_height).to_i move $cfg.get(:window_x_pos).to_i, $cfg.get(:window_y_pos).to_i signal_connect(:destroy) { quit } signal_connect(:delete_event) { minimize } signal_connect(:check_resize) do |widget| - x, y = widget.position - w, h = widget.size - $cfg.set :window_x_pos, x - $cfg.set :window_y_pos, y - $cfg.set :window_width, w - $cfg.set :window_height, h + position_x, position_y = widget.position + size_w, size_h = widget.size + $cfg.set :window_x_pos, position_x + $cfg.set :window_y_pos, position_y + $cfg.set :window_width, size_w + $cfg.set :window_height, size_h end signal_connect(:window_state_event) do |widget, e| case e.event_type when Gdk::Event::WINDOW_STATE minimize if e.changed_mask.iconified? and e.new_window_state.iconified? + else + nil end end show end @@ -161,11 +164,11 @@ video_data = file_chooser_button :video_data, filter @video_title = Gtk::LabeledEntry.new 'Title (optional)' page.pack_start video_data, false - page.pack_start @video_title, true + page.pack_start @video_title, false end page.pack_start @video_embed, false page.pack_start scrollable(@video_caption), true @@ -215,25 +218,25 @@ $app.quit end toolbar.insert 3, item ### Buttons - clear_button = Gtk::Button.new 'Clear' + clear_button = Gtk::Button.new ' Clear ' clear_button.set_focus_on_click false clear_button.signal_connect(:clicked) do |widget| page = @notebook.get_nth_page @notebook.page message_type = @notebook.get_menu_label_text page reset_form message_type.downcase end - @private_button = Gtk::ToggleButton.new 'Private' + @private_button = Gtk::ToggleButton.new ' Private ' @private_button.signal_connect(:toggled) do |widget| $cfg.set :private, widget.active? end @private_button.set_active $cfg.get(:private) - submit_button = Gtk::Button.new 'Send' + submit_button = Gtk::Button.new ' Send ' submit_button.signal_connect(:released) do |widget| post end @tags = Gtk::LabeledEntry.new 'space/comma separated tags' @@ -249,11 +252,11 @@ button_box = Gtk::HBox.new false, 4 button_box.pack_start clear_button, false button_box.pack_start @private_button, false button_box.pack_start @tags, true button_box.pack_start format_box, false - button_box.pack_start submit_button, true + button_box.pack_start submit_button, false ### Layout pack_start toolbar, false pack_start @notebook pack_start button_box, false @@ -308,13 +311,14 @@ MessageDialog.new $! end def collect_data_for(fieldset, message_type) data = {} - for key in fieldset[message_type] + fieldset[message_type].each do |key| name = "@#{message_type}_#{key.gsub(/-/,'_')}" - if var = instance_variable_get(name) + var = instance_variable_get(name) + if var value = var.get_value data.merge!({ key => value }) end end data @@ -332,11 +336,11 @@ button.show_all instance_variable_set "@#{name}", button end def reset_fields_for(fieldset, message_type) - for key in fieldset[message_type] + fieldset[message_type].each do |key| name = "@#{message_type}_#{key.gsub(/-/,'_')}" var = instance_variable_get(name) var.clear if var end end @@ -449,11 +453,11 @@ Gtk::AboutDialog.set_url_hook do |dialog, url| system("xdg-open #{url}") end super self.logo = $gui.logo - self.program_name = 'Grumblr' + self.program_name = Grumblr::APP_NAME self.version = Grumblr::VERSION self.copyright = "Copyright (c)2009, Paul Philippov" self.comments = "Tumblr companion for GNOME" self.license = "New BSD License.\nhttp://creativecommons.org/licenses/BSD/" self.website = "http://themactep.com/grumblr/" @@ -481,11 +485,11 @@ end end def menu menu = Gtk::Menu.new - for item in [ ontop, sep, destroy_account, sep, about, sep, quit ] + [ ontop, sep, destroy_account, sep, about, sep, quit ].each do |item| menu.append item end menu.show_all end @@ -631,30 +635,34 @@ self.set_accepts_tab false self.set_right_margin 5 self.set_left_margin 5 self.modify_text Gtk::STATE_NORMAL, PALE self.buffer.set_text @label + self.signal_connect(:focus_in_event) do |widget, type| if widget.buffer.text == @label widget.modify_text Gtk::STATE_NORMAL, DARK widget.buffer.set_text '' end report_length false - end + end + self.signal_connect(:focus_out_event) do |widget, type| self.clear if widget.buffer.text == '' $statusbar.push 0, $app.blog.title false end + self.signal_connect(:key_release_event) do |widget, type| report_length false end end def report_length $statusbar.push 0, "Length: #{self.buffer.text.chars.count}" + self.buffer.text.strip end def get_value value = self.buffer.get_text value == @label ? "" : value