Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'gtk2'
- #setup some helper functions to block so the script doesn't exit before we've had a chance to see the behavior
- if !defined?(wait_until)
- def wait_until(announce=nil)
- priosave = Thread.current.priority
- Thread.current.priority = 0
- unless announce.nil? or yield
- respond(announce)
- end
- until yield
- sleep 0.25
- end
- Thread.current.priority = priosave
- end
- def wait_while(announce=nil)
- priosave = Thread.current.priority
- Thread.current.priority = 0
- unless announce.nil? or !yield
- respond(announce)
- end
- while yield
- sleep 0.25
- end
- Thread.current.priority = priosave
- end
- end
- if defined?(Gtk) && !defined?(Gtk.queue)
- module Gtk
- # Calling Gtk API in a thread other than the main thread may cause random segfaults
- def Gtk.queue &block
- GLib::Timeout.add(1) {
- begin
- block.call
- rescue
- respond "error in Gtk.queue: #{$!}"
- Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
- rescue SyntaxError
- respond "error in Gtk.queue: #{$!}"
- Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
- rescue SystemExit
- nil
- rescue SecurityError
- respond "error in Gtk.queue: #{$!}"
- Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
- rescue ThreadError
- respond "error in Gtk.queue: #{$!}"
- Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
- rescue SystemStackError
- respond "error in Gtk.queue: #{$!}"
- Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
- rescue Exception
- respond "error in Gtk.queue: #{$!}"
- Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
- rescue ScriptError
- respond "error in Gtk.queue: #{$!}"
- Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
- rescue LoadError
- respond "error in Gtk.queue: #{$!}"
- Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
- rescue NoMemoryError
- respond "error in Gtk.queue: #{$!}"
- Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
- rescue
- respond "error in Gtk.queue: #{$!}"
- Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
- end
- false # don't repeat timeout
- }
- end
- end
- end
- window_width = 400
- window_height = 800
- window_position = [ 0, 0 ]
- scale = nil
- map_offset_x = nil
- map_offset_y = nil
- narost_exit = false
- window_resized = true
- start = nil
- window = nil
- Gtk.queue {
- window = Gtk::Window.new
- window.title = "Test window"
- window.signal_connect('delete_event') { narost_exit = true}
- window.show_all
- window_width = [window_width,100].max
- window_height = [window_height,100].max
- window.resize(window_width, window_height)
- window_position[0] = [[0, window_position[0].to_i].max, (Gdk.screen_width-window_width)].min
- window_position[1] = [[0, window_position[1].to_i].max, (Gdk.screen_height-window_height)].min
- window.move(window_position[0], window_position[1])
- start = true
- }
- thread = Thread.new {
- Gtk.main
- }
- wait_until { start }
- require 'pp'
- pp Gdk.screen_width
- pp Gdk.screen_height
- wait_while { !narost_exit }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement