python script hacker needed!

Forest is people. People is you. You is us.
Post Reply
User avatar
martinmckenna
Posts: 2714
Joined: Thu Jun 28, 2007 7:26 pm
Location: insitu
Contact:

python script hacker needed!

Post by martinmckenna » Thu Dec 06, 2007 10:11 pm

hi

we are making a events booklet . and we need the date on every page , ive found a plug for scribus that makes calenders and also events listing. the events format is 7 days to the page , if someone could hack this python script to make it do one day per page that would be very sweet.

ive had a look at it , but with me knowing nothing about python and the script being in french , am screwed

we would find this very helpful in the making of the events book , cause writing every date by hand is very painful! [/u]
You do not have the required permissions to view the files attached to this post.

User avatar
martinmckenna
Posts: 2714
Joined: Thu Jun 28, 2007 7:26 pm
Location: insitu
Contact:

Post by martinmckenna » Thu Dec 06, 2007 10:25 pm

dont use that script ive found the proper one to hack and its in english
You do not have the required permissions to view the files attached to this post.

chombee
Posts: 1327
Joined: Thu Apr 20, 2006 3:01 pm

Post by chombee » Thu Dec 06, 2007 11:45 pm

Okay. Well the original version of the script creates a page with:

* Left column with one big cell, apparently for an image
* Right column split vertically into 8 equal-sized cells. One with the month in it, and the others for each of the seven days.

Keeping in mind that I've barely tested this and never written any Scribus scripts before, and haven't read the docs ... The attached hacked version seems to work, changes the right column so that the 7 day cells are now one day cell, seven times as high. The month cell is still there, the same size. Also it was placing empty 'padding' cells at the start and end of a month if the month didn't begin at the start of a week or end at the end of a week, I got rid of those cause they don't make sense when it's one day per page.

Is that good enough?

It should be fairly easy to improve on this. For example, instead of the right column having a cell that says "December" and a cell that says "1" (for the 1st of December page) it should be fairly easy to have one cell that says "Monday 1st December". Let me know what you want and I'll see if I can do it.

If anyone's interested, the relevant part of the code is the createMonthCalender function at line 239, and the createHeader function below it. Here's my version of that part:

Code: Select all

    def createMonthCalendar(self, month):
        cal = calendar.monthcalendar(self.year, month + 1)

        for week in cal:
            for day in week:
                if day == 0: continue
                self.createLayout()
                self.createHeader(self.months[month])
                cel = createText(self.gmean + self.marginl,
                                         self.margint + self.rowSize,
                                         self.width - self.gmean,
                                         self.height - self.rowSize)
                self.applyTextToFrame(str(day), cel)

    def createHeader(self, monthName):
        cel = createText(self.gmean + self.marginl, self.margint,
                                 self.width - self.gmean, self.rowSize)
        self.applyTextToFrame(monthName, cel)
You do not have the required permissions to view the files attached to this post.
I've had it with you. If I had an image of a laser gun I would absolutely position it right here in my hand...
Ha! I have a real laser absolutely positioned in my hand!

chombee
Posts: 1327
Joined: Thu Apr 20, 2006 3:01 pm

Post by chombee » Thu Dec 06, 2007 11:46 pm

I've had it with you. If I had an image of a laser gun I would absolutely position it right here in my hand...
Ha! I have a real laser absolutely positioned in my hand!

User avatar
martinmckenna
Posts: 2714
Joined: Thu Jun 28, 2007 7:26 pm
Location: insitu
Contact:

Post by martinmckenna » Thu Dec 06, 2007 11:56 pm

Thanks for doing that, it works on my comp

could you get it to make the header the month and the date some like this "january 1 " so its only one box on each page . i should of said that before sry ,

ive tryed myself with some bizare results , kinda change a number here and there see what happens !

User avatar
martinmckenna
Posts: 2714
Joined: Thu Jun 28, 2007 7:26 pm
Location: insitu
Contact:

Post by martinmckenna » Fri Dec 07, 2007 12:02 am

do yo think it could also do the day name: January monday 1

User avatar
martinmckenna
Posts: 2714
Joined: Thu Jun 28, 2007 7:26 pm
Location: insitu
Contact:

Post by martinmckenna » Fri Dec 07, 2007 12:05 am

sryi didnt read all your post , yes one cell with monday 1 january in it would be cool

chombee
Posts: 1327
Joined: Thu Apr 20, 2006 3:01 pm

Post by chombee » Fri Dec 07, 2007 1:06 pm

Okay how about this?

Any other tweaks let me know.

Btw if we wanted to do some more event calendar scripting there's this Python module for creating HTML event calendars:

http://neverfriday.com/eventcal/

Hack a little CGI for it and you could have, for example, an interactive online calendar. I guess we already have something like that.
You do not have the required permissions to view the files attached to this post.
I've had it with you. If I had an image of a laser gun I would absolutely position it right here in my hand...
Ha! I have a real laser absolutely positioned in my hand!

User avatar
martinmckenna
Posts: 2714
Joined: Thu Jun 28, 2007 7:26 pm
Location: insitu
Contact:

Post by martinmckenna » Fri Dec 07, 2007 1:19 pm

yeap thats the one , thanks alot . you ve save me a lot of time . i tried to do it last night but no joy , i really dont know what am doing . so ill study what you did to learn

this script stuff is a really powerful tool , i think gimp and blender use python too , i need to get a python for dummies book.

chombee
Posts: 1327
Joined: Thu Apr 20, 2006 3:01 pm

Post by chombee » Fri Dec 07, 2007 3:18 pm

Don't buy a python book there are plenty of free ones online. (Although if you are going to buy one, the big O'Reilly ones are probably best.)

Since we only need to create per-day calendars, quite a lot of what's in that script could probably be cut out for our purposes. Leaving you with a much simpler script to study and modify. Anyway, it's pretty easy to make changes to it, so anything you want let me know.

Official Python tutorial: http://docs.python.org/tut/tut.html

A good online gateway to Python reference documentation: http://pydoc.org/ (although this is all built-in to Python itself anyway)

Good Python quick reference: http://rgruet.free.fr/

Books:

Eff-bot guide to the Python standard library: http://effbot.org/librarybook/

How to think like a computer scientist (with Python, a book for beginners): http://www.ibiblio.org/obp/thinkCSpy/

A Byte of Python (also for beginners): http://swaroopch.info/text/

Dive into Python (something of a crash course): http://www.diveintopython.org/toc/index.html

There are more.
I've had it with you. If I had an image of a laser gun I would absolutely position it right here in my hand...
Ha! I have a real laser absolutely positioned in my hand!

User avatar
martinmckenna
Posts: 2714
Joined: Thu Jun 28, 2007 7:26 pm
Location: insitu
Contact:

Post by martinmckenna » Fri Dec 07, 2007 3:20 pm

Thanks , the events book is almost done

User avatar
martinmckenna
Posts: 2714
Joined: Thu Jun 28, 2007 7:26 pm
Location: insitu
Contact:

Post by martinmckenna » Fri Dec 07, 2007 7:14 pm

i think this event has illustrated the power of free software . that if you have the source code at least you don have to write from scratch and can build on previous software , and guess if we tided the plug in up a bit make it just do that, we could also give back to community .

User avatar
ravanwin
Posts: 5060
Joined: Thu Aug 26, 2004 8:08 pm
Location: edinburgh
Contact:

Post by ravanwin » Mon Dec 10, 2007 1:11 pm

well geeked boys.

looking forward to the new book.
r

Post Reply