Page 1 of 2

CSSMan

Posted: Tue Jun 25, 2013 7:58 am
by Vadi
Update: now part of https://wiki.mudlet.org/w/Manual:Geyser ... StyleSheet

This is a script I've made per Akaya's request that helps you manage your stylesheet: most importantly, it allows you to change specific parts of a stylesheet without having to keep track of the overall thing yourself.

The script is basic and does just one thing: if you'd like to improve upon it, feel free to do so! Please attach your work here after.

Usage

Creating a new CSS tracker:
Code: [show] | [select all] lua
-- note that CSSMan.new has a period, all others have : for access
mycssobject = CSSMan.new([[<your CSS here - one property per line>]])

-- if you haven't got any CSS properties to begin with, create it like so:
mycssobject = CSSMan.new([[]])
-- or:
mycssobject = CSSMan.new("")
Changing CSS properties:
Code: [show] | [select all] lua
mycssobject:set("font-family", "Ubuntu")
Retrieving a particular CSS property:
Code: [show] | [select all] lua
print(mycssobject:get("font-family"))
Finally, generating the complete CSS so you can use it with setStyleSheet, or setLabelStylesheet, or any other stylesheet-related function:
Code: [show] | [select all] lua
setLabelStyleSheet("my fancy label", mycssobject:getCSS())
Here are some examples with the code:
Code: [show] | [select all] lua
color1 = CSSMan.new([[
  background-color: rgb(26,26,26);
  border-width: 1px;
  border-color: green;
  border-style: solid;
  border-radius: 7;
  font-family: Han Solo;
]])

print("keys in the table:")
for k,v in pairs(color1:gettable()) do print(k,v) end

print("\n\nindividual keys:")
print(tostring(color1:get("font-family")))
print(tostring(color1:get("border-width")))
print(tostring(color1:get("fake")))

print("\n\key modification:")
color1:set("font-family", "Ubuntu")
print(tostring(color1:get("font-family")))

print("\n\nfinal CSS:")
print(color1:getCSS())

print("done!")
Script:
CSSman.xml.zip
(772 Bytes) Downloaded 1381 times
Update: now part of https://wiki.mudlet.org/w/Manual:Geyser ... StyleSheet

Re: CSSMan

Posted: Tue Jun 25, 2013 8:00 am
by Vadi
I think it'd be a nice idea to have this be integrated with Geyser later on (or Vyzor, but I think that manages CSS very well on its own already).

Re: CSSMan

Posted: Tue Jun 25, 2013 8:58 am
by kevutian
Yeah, this would definitely be a great thing to have in Geyser.

Thanks for this.

Re: CSSMan

Posted: Thu Sep 26, 2013 4:14 am
by Akaya
This script is really useful. I use it very heavily and do hope to see it integrated into Geyser.

I do have a request though. If a qt property is not set when CSSMan.new() is run and you try to set it later on, it doesn't work.

The way I've worked around this is to set every property I possibly can when running CSSMan.new() but it would be really nice if each property could be set w/o having it in the original stylesheet.

If this is still confusing... say I create a label with a background-color of red. Further down the road, I want to set the font-family to something besides the default. I am unable to do so unless I set some value for font-family when creating the label. This is an inconvience when you're unsure what the label will contain in its stylesheet. Like in the GUI Creator.

My 2 cents. This is still a fantastic script. Thank you!

Re: CSSMan

Posted: Thu Sep 26, 2013 6:28 am
by Vadi
Are you certain of this? The script by design allows for that type of use.

Running this code, which seems to reproduce what you mentioned:
Code: [show] | [select all] lua
print("creating color1...")
color1 = CSSMan.new("")
print("color1 created: "..tostring(color1))
print("\n\nkey modification:")
color1:set("font-family", "Ubuntu")
print(tostring(color1:get("font-family")))

print("\n\nfinal CSS:")
print(color1:getCSS())
Gives the following output:

Code: Select all

creating color1...
color1 created: table: 0xe9e970


key modification:
Ubuntu


final CSS:
font-family: Ubuntu;
Which makes it seem that it is working.

Re: CSSMan

Posted: Fri Sep 27, 2013 5:15 pm
by Akaya
Spent quite awhile trying to recreate the issue but I can't now. I must've been using it improperly. :\ Sorry.

Re: CSSMan

Posted: Fri May 02, 2014 11:56 pm
by Angie
Is it possible to use multiple stylesheets on the same label? My testing so far points to "no", but maybe I'm doing something wrong.

Re: CSSMan

Posted: Sat May 03, 2014 9:44 pm
by Vadi
Just one. You'd want to merge them I suppose.

Re: CSSMan

Posted: Sun May 04, 2014 10:11 am
by Angie
Thanks. I have a whole bunch of icons that have identical properties, except for a different background, so I thought it would be cleaner to split it. I will find a workaround.

Re: CSSMan

Posted: Sun May 04, 2014 7:06 pm
by phasma
Just pass 'background:' to them, omitting the other args?