Bash code to get icon locations in ROX's PuppyPin.

Using applications, configuring, problems
Post Reply
Message
Author
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

Bash code to get icon locations in ROX's PuppyPin.

#1 Post by sunburnt »

I'm adding to my script "rox-pinbd" that adds & removes ROX desktop icons.
I need to get the bottom icon "y=" in a column of icons made of a range "x=".
The ranges that define "x=" columns are 96 apart: 0-95, 96-191, 192-283, etc.

So for an icon at the left of the screen, the "x=" value would be: 0-95, &
the "y=" value would be the largest number or the bottom of the column.

This allows to find the next icon's "y=" value at the bottom of a given column.
It's compared to the screen resolution's Vert. value to see if there's enough room.
If the calculated position is off the bottom of the screen, then test the next column.

This gets the next on screen empty spot to place the next icon,
the column "x=" value & it's empty bottom position "y=" for the new icon.

Basically filter PuppyPin for a range of "x=" to get the column, & then the
largest "y=" value to get the bottom icon in that column.
That's subtracted from the screens Vert. value to see if there's enough room.

I've written most of a long complex set of Bash code lines to do this...
Is there a better way to do this in a script, maybe awk?

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#2 Post by MU »

here is a script.
It looks for the highest y value, and prints the highest x value in this line.

But it will not work correct, if they are not arranged exactly on one line.
Lets say you have an icon at 10,60 and one at 70,58

then my script would report 10 60.
If you would place an icon right to it, it would cover the second one.
So that had to be refined.

But it might work, to position an icon under all other ones.

Mark

Code: Select all

#!/usr/bin/puppybasic
include "/usr/lib/wxbasicscript/basefunctions.inc"

pinboard = "/root/Choices/ROX-Filer/PuppyPin"

thefile = readfiletolist (pinboard)

 //----------------------------
// find highest Y coordinate and in that line the highest X 
c = 0
coords = {}

for each theline in thefile
  if instr(theline , "y=\"") then
    y = cutleft(theline, "y=\"")
    y = cutrightfromleft(y , "\"")
    y = right("0000" &  y , 5)

    x = cutleft(theline, "x=\"")
    x = cutrightfromleft(x , "\"")
    x = right("0000" &  x , 5)

    coords[c] = y & "#" & x

    c += 1
  end if
next

coords2 = natsort (coords)

//print coords2

highesty = val(cutright(coords2[count(coords2)-1] , "#"))
highestx = val(cutleft(coords2[count(coords2)-1] , "#"))

//print highestx , highesty

screen = xwin_screensize()
sx = val(screen[0])
sy = val(screen[1])

newy = highesty + 64 
if (newy + 48) > sy then
  print "error: icon is outside of screen"
  print "(screenheight: " & sy & " , new Y: " & newy + 48 & " incl. 48 for the icon-height)" 
else
  print "new  position: " & highestx , newy
end if




User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#3 Post by MU »

here, this might be better.

It tries to find a free position inside the icons, not just at the end.
I did not check it carefully, as I run enlightenment without rox, but according to the coordinates it gives me, it might work.

It simply cycles through the screen using "squares" of 64x64, and looks, if an icon is positioned there already.

Mark

Code: Select all

#!/usr/bin/puppybasic
include "/usr/lib/wxbasicscript/basefunctions.inc"

pinboard = "/root/Choices/ROX-Filer/PuppyPin"

thefile = readfiletolist (pinboard)

 //----------------------------
// create a list with all coordiates in the form 00010#00256
c = 0
coords = {}

for each theline in thefile
  if instr(theline , "y=\"") then
    y = cutleft(theline, "y=\"")
    y = cutrightfromleft(y , "\"")
    y = right("0000" &  y , 5)

    x = cutleft(theline, "x=\"")
    x = cutrightfromleft(x , "\"")
    x = right("0000" &  x , 5)

    coords[c] = y & "#" & x

    c += 1
  end if
next

coords2 = natsort (coords)

screen = xwin_screensize()
sx = val(screen[0])
sy = val(screen[1])


//print coords2

// scan the screen in squares

for stepx = 0 to sx - 64 step 64
  for stepy = 0 to sy - 64 step 64

    isfree = 1
    for each coord in coords2
      cy = val(cutright(coord , "#"))
      cx = val(cutleft(coord , "#"))

      if cx >= stepx then
        if cx <= (stepx + 64) then
          if cy >= stepy then
            if cy <= (stepy + 64) then
              isfree = 0
            end if
          end if
        end if
      end if
    next
    if isfree = 1 then
      print stepx , stepy
      end
    end if
  next
next

print "error: no free position found!"

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#4 Post by sunburnt »

Thanks MU; It's good to hear from you again...

I thought of a script like your last one... a fill in the holes type, but it
seemed even harder than just finding a bottom one that'll fit on-screen.

I'll test the second one first, as it's more sophisticated, & it may not need
to factor in the screen resolution to insure the icon's not off in the ozone.

Post Reply