CSSMan

Share your scripts and packages with other Mudlet users.
User avatar
Vadi
Posts: 4902
Joined: Sat Mar 14, 2009 3:13 pm

CSSMan

Post by Vadi »

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 695 times

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

Re: CSSMan

Post 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).

User avatar
kevutian
Posts: 217
Joined: Fri Aug 20, 2010 8:18 pm
Location: United Kingdom
Contact:

Re: CSSMan

Post by kevutian »

Yeah, this would definitely be a great thing to have in Geyser.

Thanks for this.

User avatar
Akaya
Posts: 414
Joined: Thu Apr 19, 2012 1:36 am

Re: CSSMan

Post 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!

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

Re: CSSMan

Post 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.

User avatar
Akaya
Posts: 414
Joined: Thu Apr 19, 2012 1:36 am

Re: CSSMan

Post by Akaya »

Spent quite awhile trying to recreate the issue but I can't now. I must've been using it improperly. :\ Sorry.

User avatar
Angie
Posts: 51
Joined: Fri May 02, 2014 11:43 pm

Re: CSSMan

Post 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.
Angie @ Midnight Sun 2
Alayla @ God Wars 2

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

Re: CSSMan

Post by Vadi »

Just one. You'd want to merge them I suppose.

User avatar
Angie
Posts: 51
Joined: Fri May 02, 2014 11:43 pm

Re: CSSMan

Post 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.
Angie @ Midnight Sun 2
Alayla @ God Wars 2

fetaera
Posts: 191
Joined: Sat Aug 03, 2013 7:00 pm

Re: CSSMan

Post by fetaera »

Just pass 'background:' to them, omitting the other args?

Post Reply