How can i keep randomizing the title in Ruby2D? - ruby2d

how can i keep randomizing the background and the title forever in Ruby2D?(Yes i want to destroy my computer)
Now,I tried this but it didnt work:
require 'ruby2d'
set background: 'random'//this worked,but when i try to add a loop to it,nope
set title: 'random'//this maked the title 'random'
i hope you can help me
UPDATE:
I managed to fix the background

When you set background, random is a keyword, but when you use it for title is like a normal word.
Try this:
require 'ruby2d'
def generate_code(number)
charset = Array('A'..'Z') + Array('a'..'z')
Array.new(number) { charset.sample }.join
end
random_title = generate_code(20)
set title: random_title
set background: 'random' #this worked,but when i try to add a loop to it,nope
show

Related

Forcing UIButton to have just one title line

I'm trying to force the UIButton to accept just one line of text, and if the title is too long I would like to have "..." at the end or in the middle of the title. but when I try out the code below, unfortunately, it doesn't work, it still gives multiline title text.
titleButton.titleLabel!.lineBreakMode = .byWordWrapping
titleButton.titleLabel!.numberOfLines = 1
titleButton.titleLabel!.textAlignment = .center
The main problem was the button style which was on the "plain", the magic happened after changing it to default!
It sounds like you want lineBreakMode.byTruncatingTail or .byTruncatingMiddle.

Cocoa/Swift: NSStatusBarItem's text gets trimmed when using a picture

When creating an NSStatusBar.systemStatusBar related application for MacOS, I stumbled upon a problem that seemed strange to begin with. The problem is: when using an image and a text for the NSStatusBar, the text was being clipped unless you manually specified a sufficient length, which would be hardcoded and causes problems with alternating lengths. How can this be solved?
// The -1 is supposed to mean "variable length"
let myStatusItem = NSStatusBar.systemStatusBar().statusItemWithLength(CGFloat(-1))
myStatusItem.image = NSImage(named: "customImage")
myStatusItem.title = "Some special information"
This would be the normal case where this problem will occur.
After playing around with some ridiculous variations, I realized that the problem can be fixed when using BOTH .title and .attributedTitle parameters of the NSStatusBar item.
Also make sure that you declare the .image BEFORE you declare the titles. If you want to use the .attributedTitle, define it after .title - if you want to use the plain .title, just define it after the .attributedTitle.
// The -1 is supposed to mean "variable length"
let myStatusItem = NSStatusBar.systemStatusBar().statusItemWithLength(CGFloat(-1))
myStatusItem.image = NSImage(named: "customImage")
myStatusItem.title = "Some special information"
myStatusItem.attributedTitle = NSAttributedString(string: "Some special information")

Crossrider : Using mouse position in context menu

We would like to use appAPI.openURL but in place of sending the data.selectedText I woould like to send the text of the element under the mouse. But I can't find the way of getting the mouse position. My idea was to add in the appAPI.ready the following
$().mousemove(function(event) {
myPositionX = event.pageX ;
myPositionY = event.pageY ;
}
And to have two global variable myPositionX and myPositionY which I could access in my background code to transmit as parameters of my URL.
But this doesn't seem to work.
Is what I'm doing crazy?
You'll be pleased to note that your are not crazy but simply missed the selector required to attach the handler to the page. Hence, to make you code work, bind the mousemove handler to the document object per the following tried and tested code:
$(document).mousemove(function(event) {
myPositionX = event.pageX ;
myPositionY = event.pageY ;
});

How can I insert an image on a Gtk.Label. Is this possible? Or do I need to find another solution?

I have a Database with this fields: Firstname, Lastname, picture.
I have a gtk.Label named infoLabel.
I would like to update the label a way like this:
Label.set_markup("<img src='pix/1.png'>\nName" + Firstname + " " + Lastname)
But it isn't works, because img isn't allowed in Pango markup. How I can do this?
Here is an example of a "Home" label.
label_with_icon = gtk.HBox()
icon = gtk.image_new_from_stock(gtk.STOCK_HOME, gtk.ICON_SIZE_MENU)
label_with_icon.pack_start(icon)
label_with_icon.pack_start(gtk.Label('Home'))
label_with_icon.show_all()
I wouldn't expect to be able to have an image in label, no.
But you should be able to replace any label with a container holding a GtkImage and the label, and solve it that way.
Of course you will have to have the image in local memory, first.
This is based on John La Rooy's answer, but I had to make some adjustments. Don't know why, maybe due to a different version of the library or something.
label_with_icon = gtk.HBox()
icon = Gtk.Image.new_from_file("/path/to/file.png") # not .image_new_from_file
label_with_icon.pack_start(icon, False, False, 0) # this method takes five args
label_with_icon.pack_start(gtk.Label('a caption'))
label_with_icon.show_all()

Gtk Button inner-border

I add a button to HBox, with expand equal to False, but I want the button to have more spacing between its label and border. I assume it is "inner-border" property, but it is read-only. How can I set it to e.g. 4px?
gtk.Label is a subclass of gtk.Misc which has the method set_padding. If you get the label out of the gtk.Button then you can just call set_padding on it.
You could do something like:
label = gtk.Label("Hello World")
button = gtk.Button()
/* Add 10 pixels border around the label */
label.set_padding(10, 10)
/* Add the label to the button */
button.add(label)
/* Show the label as the button will assume it is already shown */
label.show()
Wrong answer:
What you're looking for is called "padding". When you add your button to the container, for example by calling gtk.Box.pack_start, just set the padding parameter to a positive integer.
Update:
Seems I misread the question. In that case, my guess is that you're supposed to use gtk_widget_modify_style, as inner-border is a style property. You'll first get the style modifier you need by calling gtk_widget_get_modifier_style. You'll then be able to modify the style only for that button using the ressource styles matching rules.
you can use "inner-border" style property of gtk button.
here, small code snippets
In gtkrc file:
style "button_style"
{
GtkButton::inner-border = {10,10,10,10}
}
class "GtkButton" style "button_style"
In .py file:
gtk.rc_parse(rc_file_path + rc_file)
[Edit]
In gtkrc file:
style "button_style"
{
GtkButton::inner-border = {10,10,10,10}
}
widget "*.StyleButton" style "button_style" # apply style for specific name of widget
In .py file:
gtk.rc_parse(rc_file_path + rc_file)
#set name of button
self.style_button.set_name('StyleButton')
hope, it would be helpful.
I sometimes just add spaces in the label !
gtk.Button(" Label ")
to get some spacing.
Hope this could help you.