So I've been trying to make ruby read my Qt4 design and it's not working, at all.
I've created a design in Qt4 Designer and saved it as a .ui file. Then I used rbuic4 to convert it to a design_ui.rb and Qt4. My current ruby main file looks like this:
require 'gui/design_ui.rb'
require 'Qt4'
class AppMain < Ui_MainWindow
def initialize(app)
#app = app
end
end
# create and show dialog
if $0 == __FILE__
app = Qt::Application.new(ARGV)
dialog = AppMain.new(app)
dialog.show
app.exec
end
I Seriously can't find a decent guide to properly using ruby and Qt4 Designer. They all do different stuff and none of them works. Please help a newbie out here?
Something like this:
class AppMain < Qt::MainWindow
def initialize(parent = nil)
super
#ui = Ui_Main_window.new
#ui.setupUi self
end
end
Then
application = Qt::Application.new(ARGV)
main_window = AppMain.new
main_window.show
application.exec
Related
I'm trying to override the after_failed_example method so I can inflict some custom file naming on our screenshots. I'm loading the module as an initializer.
So far, so good, but the Capybara.page.current_url is blank, making me think I need to require something additional?
require "capybara-screenshot/rspec"
module Capybara
module Screenshot
module RSpec
class << self
attr_accessor :use_description_as_filename
attr_accessor :save_html_file
end
self.use_description_as_filename = true
self.save_html_file = true
def self.after_failed_example(example)
if example.example_group.include?(Capybara::DSL) # Capybara DSL method has been included for a feature we can snapshot
Capybara.using_session(Capybara::Screenshot.final_session_name) do
puts ">>>> Capybara.page.current_url: " + Capybara.page.current_url.to_s
if Capybara::Screenshot.autosave_on_failure && failed?(example) && Capybara.page.current_url != ''
saver = Capybara::Screenshot.new_saver(Capybara, Capybara.page, Capybara::Screenshot.save_html_file?, set_saver_filename_prefix(example))
saver.save
example.metadata[:screenshot] = {}
example.metadata[:screenshot][:html] = saver.html_path if saver.html_saved?
example.metadata[:screenshot][:image] = saver.screenshot_path if saver.screenshot_saved?
end
end
end
private
def self.set_saver_filename_prefix(example)
return example.description.to_s.gsub(" ", "-") if Capybara::Screenshot.use_description_as_filename?
return Capybara::Screenshot.filename_prefix_for(:rspec, example)
end
end
end
end
end
This is successfully overriding the capybara-screenshot/rspec method, and any of the Capybara::Screenshot static information is accessible, but not Capybara session related information (afa I can tell).
For example, Capybara.page.current_url.to_s is null when overridden, but present when not.
I was missing a require (kind of silly mistake):
require 'capybara/rspec'
I don't know if I'm getting the whole documentation totally wrong but there is an issue I'm dealing with since two days and I just don't get what I'm doing wrong. I'm using fxruby to built a small GUI, and I need a progressbar within that. When I initialize it with no parameters its just ridiculously small, so I tried to use the barSize option (wich is responsible for the width, at least the documentation says so). This is my source code:
require 'fox16'
require 'pp'
include Fox
class Test < FXMainWindow
def initialize(app)
super(app, "Test")
hFrame1 = FXHorizontalFrame.new(self)
#progBar = FXProgressBar.new(hFrame1)
pp #progBar.barSize
#progBar.barSize=100
#progBar.setTotal(10)
#progBar.setProgress(5)
pp #progBar.barSize
def create
super
show(PLACEMENT_SCREEN)
end
end
end
FXApp.new do |app|
Test.new(app)
app.create
app.run
end
But this is what it looks like:
]1
So obviously the height gets changed. Obviously I also tried things like
:width => 150
in the constructor but it did not work at all. Seems like I'm just to stupid for fxruby. Could anyone point me to the right way please?
You need to learn about layout parameters. Try this modification of your Test class and I think you will know where to go from there:
class Test < FXMainWindow
def initialize(app)
super(app, "Test", :width => 200, :height => 100)
hFrame1 = FXHorizontalFrame.new(self, LAYOUT_FILL)
#progBar = FXProgressBar.new(hFrame1, :opts => LAYOUT_FILL_X)
pp #progBar.barSize
#progBar.barSize=10
#progBar.setTotal(10)
#progBar.setProgress(5)
pp #progBar.barSize
def create
super
show(PLACEMENT_SCREEN)
end
end
end
i'm still fairly new to server side scripts and try myself a little bit on ruby to write me little helpers and to learn some new things.
I currently try to write a small ruby app which sends a json file of all images within a specific folder to my page where i can use those to handle them further in js.
I read quite a few introductions to ruby and rails and got a recommendation to look into rack as a lightweight communicator between server and app.
While the ruby part works fine, i have difficulties to understand how to send out the generated JSON as a reaction to a future ajax call (e.g.). Hope someone can give me a few hints or sources to look into for further understanding. Thanks!
require 'json'
class listImages
def call(env)
imageDir = Dir.chdir("./img");
files = Dir.glob("img*")
n = 0
tempHash = {}
files.each do |i|
tempHash["img#{n}"] = i
n += 1
end
File.open("temp.json","w") do |f|
f.write(tempHash.to_json)
end
[200,{"Content-Type" => "application/javascript"}, ["temp.json"]]
end
puts "All done!"
end
run listImages.new
if $0 == __FILE__
require 'rack'
Rack::Handler::WEBrick.run MyApp.new
end
You don't have to save the JSON to a file before you can send it. Just send it directly:
[200, {"Content-Type" => "application/json"}, [tempHash.to_json]]
With your current code, you are only sending the String "temp.json".
That said, the rest of your code looks a little bit messy/not conform Ruby coding standards:
Start your classnames with an uppercase: class ListImages, not class listImages.
Use underscores, not camelcase for variable names: image_dir, not imageDir.
The puts "All done!" statement is outside the method definition and will be called early, when the class is loaded.
You define a class ListImages but in the last line of your code you refer to MyApp.
I'm writing a horse race/bet game using Shoes and I was wondering how I would be able to change the GUI in different areas of code. When I run this, I get the horse on one application and then the race line on another application, but I want them both on the same application. Do I need to set the actual Shoes app as a variable itself?
class Horse
def initialize()
#puts "YOYOYOYO"
##number=i
Shoes.app{
#icon= image 'horsey.jpg'
#icon.left = 100
#icon.top = 50
}
end
def neigh()
#puts "Neighhhh"
end
def raceTime()
time=rand(100)%20
return time+10
end
end
class HorseIcon
def initialize(h)
#horse= h
#imageloc='horsey.jpg'
end
end
class Game
def initialize(h1, h2)
contestants=[h1, h2]
Shoes.app{
#icon= image 'raceline.jpg'
#icon.left = 100
#icon.top = 70
}
end
def race()
end
end
game= Game.new(1,2)
seabiscuit= Horse.new()
You are using two separate Shoes.app classes. I think that's your problem.
Judging by your code you seem to have a background in some other language, like Python.
I suggest you clone the Shoes git and look at 'Shoes/samples' directory and play around with it.
Or just look at this.
It will help you see what the code should look like.
PS : It will also give you some pointers toward Ruby style. You normally don't use {} for block when using multiple lines. You would use:
Shoes.app do
# code goes here
end
I am developing an application using ruby and qt as front end. I used qtdesigner to draw gui and converted the code using rbuic4. But i am unable get any action for buttons placed on main programm. I created main.rb and called generated code using require './muprogramm.rb'. Here is the sample code for opening file dialog for button mbusb_close (object name)
require './muprogramm.rb'
require 'Qt4'
class Form < Qt::Widget
slots 'file_dialog()'
def initialize(parent = nil)
super
#ui = Ui_Frame.new
#ui.setupUi(self)
Qt::Object.connect(#ui.mbusb_close, SIGNAL('clicked()'), self, SLOT('file_dialog()'))
end
def file_dialog
f = Qt::FileDialog
text = File.new(f.getOpenFileName).read
##ui.editor_window.setText 'WikiBooks: Ruby'
end
end
a = Qt::Application.new(ARGV)
u = Ui_Frame.new
w = Qt::Frame.new
u.setupUi(w)
w.show
a.exec
The resource available in the net is vague. Any help is appreciated
Just use the subclass that you created directly:
require './muprogramm.rb'
require 'Qt4'
class Form < Qt::Widget
slots 'file_dialog()'
def initialize(parent = nil)
super
#ui = Ui_Frame.new
#ui.setupUi(self)
Qt::Object.connect(#ui.mbusb_close, SIGNAL('clicked()'), self, SLOT('file_dialog()'))
end
def file_dialog
f = Qt::FileDialog
text = File.new(f.getOpenFileName).read
##ui.editor_window.setText 'WikiBooks: Ruby'
end
end
a = Qt::Application.new(ARGV)
w = Form.new
w.show
a.exec