How to set an image for the panel background with seesaw? - image

I want to set a custom image for the panel background in my clojure app. Using seesaw I can set some color for the background:
(defn make-panel []
(border-panel
:north (flow-panel :align :center
:items [(label :text "TEXT")])
:center (canvas :class :board
:background :black)
:border 5))
but how to choose an image using its url?

Seesaw lets you use an image for frame content, via the icon function (now in seesaw.icon), like so:
(frame :title "Hola!"
; ....
:content (label :icon img_bg)
where img_bg is a File, URL, etc. However, looking at the Seesaw code, I don't see a way to put a background image directly in a panel through the Seesaw API. You may have to drop down to Java interop and use the Swing API directly. This SO question would suggest that it's possible, and may get you started.

Related

Ruby Shoes: how to replace button text with an image/icon

I am trying to write a small Shoes app which contains a button. For example
Shoes.app :title => "Buttons" do
button_next = button "Next"
button_prev = button "Previous"
end
Now, instead of the texts "Next" or "Previous" there should be icons on the buttons: a green arrow, showing to the right for the button_next and a green arrow showing to the left for the button_prev.
Of couse I already have the icons as .jpg-files but I can't figure out how to replace the text with the icons on the buttons.
For now I found out this way:
Shoes.app do
next_image = image "next.jpg", :width => 50, :height => 35
next_image.click do
alert "Hey!"
end
end
It works in the way that I can click the image and a new window, saying "Hey!" appears. But it is not ok, because I miss the typical button-appearance like changing of the color when hovering over it, or the press-down-effect when clicking on it.
So my question is: how can I create a real button in Ruby Shoes and replace the name of the button with an icon? Any ideas?

How can I add an image to a table cell using the Axlsx gem?

I'm using the Axlsx gem to create an excel file and I'd like to add an image. I am currently able to add an image but it seems to add the image in a way that makes it float on top of other content.
I'd like it to exist within a cell. Is this possible?
It is an old question but we never know.
There is an answer in this post : Adding image to Excel file generated by Axlsx.?
You can specify the cell from which you want to put the image by using image.start_at
sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
image.width = 7
image.height = 6
image.hyperlink.tooltip = "Labeled Link"
image.start_at 2, 2
end
HTH

Group text and images as a block with Prawn?

I'm trying to build a PDF from user-generated content and I have a chunk of information that should be grouped together. I know of the group method to make sure text all gets rendered together, but this doesn't seem to work with a mix of text and images. Is there something that can do this with Prawn, or do I need to try to calculate cursor position and manually linebreak?
Edit: For illustration of what I'm looking to do:
pdf = PDF::Document.new
20.times do
pdf.group do
pdf.text "Something"
pdf.image "path/to/image.jpg"
pdf.text Time.now.to_s
end
end
And I would expect to not ever have "Something" on one page and the image on the next, but that is what I see. Is there some way I can achieve what I want?
Okay, I've figured it out. Prawn does not seem to take the image height into account when grouping, but you can hack your way around it:
pdf.group do
pdf.text "Best regards, (...)"
pdf.image "#{Rails.root}/vendor/signature.jpg", {
:height => 30,
:at => [0, pdf.y.to_i - #bottom_margin]
}
pdf.move_down(35)
pdf.text " "
end
The trick is to use absolute positioning for the image, and move the text cursor down manually.

Define paperclip style sizes dynamicaly

I have an application where a user chooses a template. On this template the user can upload an image.
I use paperclip to upload the images.
Each template has different image sizes.
Is it possible to set an image style => 'widthxheight' dynamically in paperclip?
I want this functionality because if the user decides to change template then they don't have to upload the photo again they just crop the 'original'.
Thanks for any help.
I will try to clear this up.
A user uploads an image for the header of a page. The style could be called "header" and the dimensions should be the dimensions for that header space, say "400x600"
Now the user views the images they have uploaded in a gallery. They want to select one of the images for their page but this time its for the "sidebar" which has dimensions "300x100". I don't want to make them upload the same image again. I want to create a new style called "sidebar" with dimensions "300x100". I also don't want to delete the "header" style or resize it.
How can I do this with paperclip?
If I understand you have in mind something like that: Paperclip change size
Additionally:
attr_accessor :size
...
self.dimensions = self.size.split("x")
Controller:
def create
...
#file.size = params[:size] # OR Simply include such field in form
...
end
Example:
Model:
class File
has_attached_file :upload
attr_accessor :size
before_save :extract_dimensions
serialize :dimensions
...
def extract_dimensions
...
self.dimensions = self.size.split("x")
end
end
Form:
<form action="some link">
...
<label>Size: </label><select name="file_size">
<option value="100x200">Large</option>
...
</select>
</form>

Ruby/Tk: how to get smaller button widget with image

I'm coding on Tk 8.5.9 from ActiveTcl on Ruby 1.8.7 on a Mac OS X 10.6.
To meet my application requirements I need to make the button widgets as small as the gif image but I am not able to. I have been hours searching and experimenting with negative results.
Greatly thankful in advance for any clues.
Following is the code i am trying to get small buttons from.
require 'tk'
require 'tkextlib/tile'
$up_img = TkPhotoImage.new("file"=>"arrowup-n.gif")
$down_img = TkPhotoImage.new("file"=>"arrowdown-n.gif")
root = TkRoot.new {title "Ek Composer"}
content = Tk::Tile::Frame.new(root).pack
Tk::Tile::Button.new(content) {width 1;image $up_img; command {move_up} }.pack
Tk::Tile::Button.new(content) {width 1;image $down_img;command {move_down}}.pack
def move_up
p "move up"
end
def move_down
p "move down"
end
Tk.mainloop
But the buttons remain too big :(.
It's awkward. The OSX theme really wants to add extra space at either end of the button.
You can try switching to the classic button (in tk itself) but that puts more space vertically and looks a bit less native. Or you can put the image in a label (which you can shrink exactly) and add bindings to it to make it respond to mouse clicks.
I added binding to label. Works fine. Thanks. Follows a code snippet of label with binding as button.
require 'tk'
$resultsVar = TkVariable.new
root = TkRoot.new
root.title = "Window"
$up_img = TkPhotoImage.new("file"=>"arrowup-n.gif")
$down_img = TkPhotoImage.new("file"=>"arrowdown-n.gif")
Lbl = TkLabel.new(root) do
image $up_img
borderwidth 0
font TkFont.new('times 20 bold')
foreground "red"
relief "groove"
pack("side" => "right", "padx"=> "50", "pady"=> "50")
end
Lbl.bind("ButtonPress-1") {
Lbl.configure("image"=>$down_img)
}
Lbl.bind("ButtonRelease-1") {
Lbl.configure("image"=>$up_img)
}
Lbl['textvariable'] = $resultsVar
$resultsVar.value = 'New value to display'
Tk.mainloop

Resources