Jessica Fae (jessica_fae) wrote,
Jessica Fae

  • Mood:

New and interesting things.

So, I have this new programming language that I’m learning. It’s called Ruby. For any of you out there who program this post may make sense, but for those of you to whom it does not make any sense, I apologize for that. hehe.

Ok, a simple Python program that writes a menu configuration file for setting backgrounds on my fluxbox windows manager. Limitations are that it’s very hard coded. It only works for the user account joel . Not for any account that wants to run it.

Here is the python code:

import os, string

images = os.listdir(“/home/joel/.fluxbox/backgrounds/”)
images.sort(lambda x, y: cmp(string.lower(x), string.lower(y)))
imagefile = file(“/home/joel/.fluxbox/imagemenu”, “w”)
imagefile.write(“[submenu] (Backgrounds) {Zarchanalin’s Backgrounds}\n”)
imagefile.write(“\t[exec] (Update Backgrounds) {python /home/joel/.fluxbox/}\n”)
for image in images:
entry = string.split(image, “.”)
imagefile.write(“\t[exec] (”)
imagefile.write(“) {bsetbg -c /home/joel/.fluxbox/backgrounds/”)
imagefile.write(“; cp /home/joel/.fluxbox/backgrounds/”)
imagefile.write(“ /home/joel/.fluxbox/background.jpg}\n”)

Now, the Ruby code. Improvements include the fact that it works for any user. It also has better formatting of file names. (i.e. it removes any ‘-’ or ‘_’s from the file name to write the menu). Now I could have done all the improvements in Python with a lot of research and work. Ruby it just sort of came naturally.

The Ruby Code:

class Menu
@@menu_path = ENV[“HOME”] + “/.fluxbox/imagemenu”
@@image_path = ENV[“HOME”] + “/.fluxbox/backgrounds/”
@@images = Dir::entries(@@image_path)
@@images.shift.shift.sort! {|a, b| a.downcase <=> b.downcase}
def Print_path
print @@menu_path
print “\n”
def List_directory
@@images.each do |image|
print image
print “\n”
def Write_menu (menuname)
File::open (@@menu_path, “w”){|f|
f.write(“[submenu] (Backgrounds) {” + menuname + “}\n”)
f.write(“\t[exec] (Update Backgrounds) {ruby /home/joel/ruby-source/makeimagemenu.rb}\n”)
@@images.each do |image|
f.write(“\t[exec] (” + image.gsub(“.jpg”,“”).gsub(“-”,“ ”).gsub(“_”, “ ”).capitalize + “) {bsetbg -c ” + @@image_path + image + “}\n”)


  • Ambassador of the Classroom?

    So, there are days that you feel like you've done a lot, and then there are days where you feel like you have done nothing at all. While most of my…

  • كلمة اليوم

    كلمة اليوم هي الفسوق! Today's word of the day comes to you in honor of being in Vegas! Though, apparently something (probably this app) deleted…

  • اختبار

    هذا هو اختبار

  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.