From 4e0db2b51d66643b3cce6987b327d1d18ffe97f5 Mon Sep 17 00:00:00 2001 From: Lars Kanis <kanis@comcard.de> Date: Fri, 26 Jun 2015 15:10:43 +0200 Subject: [PATCH] Add simple example with thread and runOnUiThread usage. --- Manifest.txt | 1 + examples/thread.rb | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 examples/thread.rb diff --git a/Manifest.txt b/Manifest.txt index 39d4f81..df29889 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -128,6 +128,7 @@ examples/textedit/commands.rb examples/textedit/helpwindow.rb examples/textedit/prefdialog.rb examples/textedit/textedit.rb +examples/thread.rb examples/unicode.rb ext/fox16_c/FXRbApp.cpp ext/fox16_c/FXRbDataTarget.cpp diff --git a/examples/thread.rb b/examples/thread.rb new file mode 100644 index 0000000..de35ed9 --- /dev/null +++ b/examples/thread.rb @@ -0,0 +1,55 @@ +#!/usr/bin/env ruby + +require 'fox16' + +class ThreadedWindow < Fox::FXMainWindow + include Fox + + def initialize(app) + # Call the base class initializer first + super(app, "Threaded Widget Test", :opts => DECOR_ALL, width: 200, height: 500) + + @vframe = FXVerticalFrame.new(self, + FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y, :padding => 0) do |frame| + FXButton.new(frame, "Klick to add", opts: FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_X) do |button| + button.connect(SEL_COMMAND, method(:on_button_clicked)) + end + end + end + + def on_button_clicked(sender, sel, ptr) + FXHorizontalFrame.new(@vframe, + FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y, :padding => 10) do |frame| + + label = FXLabel.new frame, "..." + + Thread.new do + 50.times do |seconds| + runOnUiThread do + label.text = "#{(50 - seconds)/10.0} seconds to remove" + end + sleep 0.1 + end + + runOnUiThread do + @vframe.removeChild(frame) + @vframe.create; @vframe.show; @vframe.recalc + end + end + end + @vframe.create; @vframe.show; @vframe.recalc + end + + # Create and show this window + def create + super + show(PLACEMENT_SCREEN) + end +end + +if __FILE__ == $0 + application = Fox::FXApp.new("ThreadApp", "FoxTest") + ThreadedWindow.new(application) + application.create + application.run +end -- GitLab