Skip to content

Instantly share code, notes, and snippets.

@denysonique
Created August 18, 2011 07:05
Show Gist options
  • Select an option

  • Save denysonique/1153564 to your computer and use it in GitHub Desktop.

Select an option

Save denysonique/1153564 to your computer and use it in GitHub Desktop.
require 'eventmachine'
require 'Qt4'
require 'emdrb'
require './client_ui'
$time_remaining ||= Time.new(0,1,1,1)
$time_used ||= Time.new(0)
class ClientController
def initialize
end
def time_remaining
$time_remaining
end
def time_remaining=(time)
$time_remaining = time
end
def time_used
$time_used
end
def time_used=(time)
$time_used = time
end
def open_session
end
def close_session
end
def status
'Available'
end
def get_ip
puts 'you asked for ip'
'1.2.3.4'
end
end
def initialize_ui
$app = Qt::Application.new(ARGV)
$ui = Ui::MainWindow.new
$window = Qt::MainWindow.new
$ui.setup_ui($window)
$window.show
$ui.pushButton.connect(SIGNAL :clicked) { puts $server.foo rescue puts 'bar' }
end
initialize_ui
# EventMachine::start_server 'localhost', 8888, Control
SERVER_URI = 'druby://localhost:7777'
EventMachine.run do
DRb.start_drbserver
$server = DRbObject.new_with_uri(SERVER_URI)
EM.add_periodic_timer(1) do
$time_remaining -= 1
$time_used += 1
$ui.lcd_time_remaining.display($time_remaining.strftime("%H:%M:%S"))
$ui.lcd_time_used.display($time_used.strftime("%H:%M:%S"))
end
EM.add_periodic_timer(0.01) do
$app.process_events
exit if $window.hidden?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment