Stipulating directories with geyser setStyleSheet properties

Proeliatora
Posts: 9
Joined: Tue Apr 05, 2011 5:12 am

Stipulating directories with geyser setStyleSheet properties

Post by Proeliatora »

I'm wondering if its possible to use a variable or getMudletHomeDir() when setting the directory for an image in a stylesheet.

I can do this:
Code: [show] | [select all] lua
hunting_label:setStyleSheet[[
  border-image: url(C:/Users/Cassie/.config/mudlet/profiles/Svaldifari/Graphics/Icons/hunting-on.png);
]]
...which works fine but my boyfriend uses my system also which means that the directories will be different on his computer. Its going to be quite annoying if I have to update it manually or put in a heap of conditionals to set it so I'm hoping I'm just ignorant of the way to accomplish this.

Cheers,
Kat

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Stipulating directories with geyser setStyleSheet proper

Post by Jor'Mox »

It is just a string that you are passing, so you can set it in advance, like this:
Code: [show] | [select all] lua
path = getMudletHomeDir() .. "/Graphics/Icons/hunting-on.png"
hunting_label:setStyleSheet[[
  border-image: url(]] .. path .. ");"

Proeliatora
Posts: 9
Joined: Tue Apr 05, 2011 5:12 am

Re: Stipulating directories with geyser setStyleSheet proper

Post by Proeliatora »

This (from above) produces the error 'unexpected symbol near '..''
Code: [show] | [select all] lua
path = getMudletHomeDir() .. "/Graphics/Icons/hunting-on.png"
hunting_label:setStyleSheet[[
  border-image: url(]] .. path .. ");"
I've fiddled around with [[ ]] and " " and I still can't seem to get it to work.

I had of course already attempted to use this before I posted this so I guess our assumptions were the same but yeah it doesn't work.
Code: [show] | [select all] lua
hunting_label:setStyleSheet[[
  border-image: url(]]..getMudletHomeDir()..[[/Graphics/Icons/hunting-on.png);]]
It seems to be the [[ ]] that are causing the problem though as I also attempted the following which doesn't cause the error but changes the label to a blank background.
Code: [show] | [select all] lua
hunting_label:setStyleSheet(
  "border-image: url("..getMudletHomeDir().."/Graphics/Icons/hunting-on.png);")
Any more ideas?

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Stipulating directories with geyser setStyleSheet proper

Post by Jor'Mox »

I just forgot the ( ) around everything for some reason. Write it as:
hunting_label:setStyleSheet([[border-image: url(]] .. path .. ");") and it should be fine.

Proeliatora
Posts: 9
Joined: Tue Apr 05, 2011 5:12 am

Re: Stipulating directories with geyser setStyleSheet proper

Post by Proeliatora »

I was just about to add that one to the list of things I tried lol. Same result.. no error but sets it to a blank background.

Edit: Incidentally I have checked and rechecked the path, file names and file type for the image so its not just a typo or something in the path either.

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Stipulating directories with geyser setStyleSheet proper

Post by Jor'Mox »

Here is something to try. Take your original version (where you wrote out the whole path) and put parentheses around the entire string you are passing the function. That should still work without any problems. Then, set some variable equal to that whole string (including the border-image: part and all that, and put the variable in place of the string in the function call. That should still work, I would think. Then try to build that string in pieces using getMudletHomeDir...and you should be good.

Proeliatora
Posts: 9
Joined: Tue Apr 05, 2011 5:12 am

Re: Stipulating directories with geyser setStyleSheet proper

Post by Proeliatora »

Already tried something similar but you gave me another idea.
Code: [show] | [select all] lua
local path = "C:/Users/Cassie/.config/mudlet/profiles/Svaldifari"

hunting_label:setStyleSheet([[
  border-image: url(]]..path..[[/Graphics/Icons/hunting-on.png);
]])
That works but getMudletHomeDir() actually returns "C:\Users\Cassie\.config\mudlet\profiles\Svaldifari".

This seems to indicate it might be a problem with \ vs /. Seems strange since I can use getMudletHomeDir() with table load and save but this should solve the problem either way since I can just use a conditional to set a home directory variable depending on character name. Or better yet return getMudletHomeDir() and replace the \ with /.

Thanks for your help. I was running out of ideas on what could have caused the problem.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Stipulating directories with geyser setStyleSheet proper

Post by Vadi »

table.load() - which is all Lua - doens't care about \ or /. Qt's CSS though does. In some weird ways.

Proeliatora
Posts: 9
Joined: Tue Apr 05, 2011 5:12 am

Re: Stipulating directories with geyser setStyleSheet proper

Post by Proeliatora »

I did come to that conclusion about 30 seconds after deliberating over my previous comment. Good to know I was right though.

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Stipulating directories with geyser setStyleSheet proper

Post by Jor'Mox »

Well, if that is the problem, then you can just replace the \'s with /'s. string.gsub(getMudletHomeDir(),[[\]],"/") should do the trick.

Post Reply