class Widgets::BaseWidget
Base Widget class. Defines some common behavior across top level widgets in the bar.
Attributes
Interval with which to update this widget
The options this widget was created with
Public Class Methods
Source
# File src/widgets.rb, line 73 def self.from_options widget class_name = widget[:type].to_s.camelize if Widgets.const_defined? class_name klass = Widgets.const_get class_name kwidget = klass.new widget kwidget.add_css_class widget[:type] return kwidget end end
Create a Widgets::Widget from a hash with options
Source
# File src/widgets.rb, line 21 def initialize options={} @options = options @interval = options[:interval] || DEFAULT_INTERVAL @proc = options[:proc] || Proc.new {} super :horizontal, @options[:padding] || 0 add_css_class "barwidget" add_css_class @options[:class] if @options[:class] self.name = @options[:name] if @options[:name] set_halign @options[:halign] || :center @click_controller = Gtk::GestureClick.new @click_controller.button = Gdk::BUTTON_PRIMARY add_controller(@click_controller) if options.include? :on_click and not @noclick @click_controller.signal_connect("pressed") { instance_exec(&options[:on_click]) } set_cursor Gdk::Cursor.new(:pointer) # https://docs.gtk.org/gdk4/ctor.Cursor.new_from_name.html end if options.include? :cursor set_cursor Gdk::Cursor.new options[:cursor] end end
Calls superclass method
Public Instance Methods
Source
# File src/widgets.rb, line 47 def update # nothing end
Update method for this widget
Source
# File src/widgets.rb, line 52 def update_safe begin update rescue => ex warn "#{self.class.name.split('::').last}: #{ex} (#{ex.backtrace.first})" end end
Like update but with error handling