You are not logged in.

#1 2009-09-03 11:07:50

Chokkan
Member
Registered: 2009-04-06
Posts: 129

openoffice uno module not found

I have a small script which used to work fine but now exits with the following error:

Traceback (most recent call last):
  File "/home/alex/.bin/planner1.py", line 69, in <module>
    import uno
ImportError: No module named uno

I have uno in /usr/lib/go-openoffice/basis3.1/program/uno.py along with a load of other uno type stuff. I've no idea how to fix this I'm afraid. Any ideas?
Here is my script, it just prints dates and puts them in a table:

#!/usr/bin/env python

###################################################################
#                                                                 #
#                         Finding The Dates                       #
#                             by Chokkan                          #
###################################################################
#   This script takes a range of dates and two weekdays from      #
#   the user. It then calculates the dates for all the weekdays   #
#   in that  range.                                               #
###################################################################

import datetime, sys

#This is the fuction that finds the dates for the weekdays specified.
#Credit to croto on the Ubuntu forums for this.

def get_weekday_dates(start, end, weekdays):
    delta = datetime.timedelta(1)
    dates = []
    while start<end:
        if start.weekday() in weekdays: dates.append(start)
        start += delta
    return dates

print "|||||||||||||||| The Date Script ||||||||||||||||\n"
print "||||||||||So awesome you'll wish you could||||||||\n"
print "||||||||||use it more than 3 times a year.||||||||\n"
#Which set of start and end dates will we use?
term = input("Please choose:\n1) First Term\n2) Second Term\n3) Third Term\n\nTerm: ")

if term == 1:
   start = datetime.date(2009,4,10)
   end = datetime.date(2009,7,20)
elif term == 2:
   start = datetime.date(2009,9,5)
   end = datetime.date(2009,12,27)
elif term == 3:
   start = datetime.date(2010,1,5)
   end = datetime.date(2010,3,20)
print "\n"
print "0) Monday"
print "1) Tuesday"
print "2) Wednesday"
print "3) Thursday"
print "4) Friday\n"

#Now we get the two days from the user, take all the data, and call our function.
days = get_weekday_dates(start, end, [input("Enter the first day: "),input("Now enter the second day: ")]);

output = []
#Iterate over the dates and append them to a list.
for date in days:
    output.append(date.strftime("%-m.%-e")) # Output will be e.g 4.22
print output

count=1
for s in output:
    count+=1
print count

###################################################################
#                                                                 #
#                      Table Creation Using Uno           #
#                                                                 #
###################################################################

# bootstrap uno component context     
import uno
import unohelper

# a UNO struct later needed to create a document
from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
from com.sun.star.text.TextContentAnchorType import AS_CHARACTER
from com.sun.star.awt import Size

def insertTextIntoCell( table, cellName, text, color, height ):
    tableText = table.getCellByName( cellName )
    cursor = tableText.createTextCursor()
    cursor.setPropertyValue( "CharColor", color )
    cursor.setPropertyValue( "CharHeight", height )
    tableText.setString( text )

localContext = uno.getComponentContext()
                   
resolver = localContext.ServiceManager.createInstanceWithContext(
                "com.sun.star.bridge.UnoUrlResolver", localContext )

smgr = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" )
remoteContext = smgr.getPropertyValue( "DefaultContext" )

desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",remoteContext)

# open a writer document
doc = desktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, () )

text = doc.Text
cursor = text.createTextCursor()
myStyle = doc.StyleFamilies.getByName("PageStyles").getByName("Default")
myStyle.RightMargin = 1000 # 10 mm
myStyle.TopMargin = 1000 # 10 mm
myStyle.BottomMargin = 1000 # 10 mm

import string
# What class is this. This info goes at the top of the page.
nenkumi = sys.argv[1]
cursor.setPropertyValue("CharHeight", 12)

# The class name and the no. of possible lessons goes at the top.
text.insertString( cursor, "%s Term Planner    %s Possible Classes\n"% (nenkumi, count), 0 ) 

# Create a text table
table = doc.createInstance( "com.sun.star.text.TextTable" )

# with correct number of rows and 2 columns
table.initialize( count, 2)

text.insertTextContent( cursor, table, 0 )
rows = table.Rows

table.setPropertyValue( "BackTransparent", uno.Bool(0) )

# The properties of the first row.
row0 = rows.getByIndex(0)
row0.setPropertyValue( "BackTransparent", uno.Bool(0) )
row0.setPropertyValue( "BackColor", 1234562 )


textColor = 16777215 # Green!
charHeight = 17

# The first row, labled "Date" and "Lesson".
insertTextIntoCell( table, "A1", "Date", textColor, charHeight )
insertTextIntoCell( table, "B1", "Lesson", textColor, charHeight )


table.getCellRangeByName("A2:A%i"% (count)).setPropertyValue("CharHeight", charHeight)

#We insert the dates into the rows of the left column.
cellnum = 1 #This is the second row.
for s in output:
    table.getCellByPosition(0,cellnum).setValue(s)
    cellnum+=1

< Daenyth> tomkx: my girlfriend is linux
< Daenyth> srsly
< Daenyth> she loves the way I «make install»
< Daenyth> all her /dev entries are mode 7 for me

Offline

#2 2009-09-04 22:29:14

thisoldman
Member
From: Pittsburgh
Registered: 2009-04-25
Posts: 1,172

Re: openoffice uno module not found

Perhaps your paths are incorrect? Does this help?

$ locate uno.py
/usr/lib/openoffice/basis-link/program/uno.py

$ sudo pacman -Qo /usr/lib/openoffice/basis-link/program/uno.py
/usr/lib/openoffice/basis-link/program/uno.py is owned by openoffice-base 3.1.1-1

Offline

#3 2009-09-05 02:57:33

Chokkan
Member
Registered: 2009-04-06
Posts: 129

Re: openoffice uno module not found

Hi, and thanks for the reply. I'm using go-openoffice, so perhaps that is where my problems lie. Here is my output for the commands you posted.

# locate uno.py
/usr/lib/go-openoffice/basis3.1/program/uno.py
# pacman -Qo /usr/lib/go-openoffice/basis3.1/program/uno.py
/usr/lib/go-openoffice/basis3.1/program/uno.py is owned by go-openoffice 3.1.0.99.3-1

I checked, and uno.py does exist in /usr/lib/go-openoffice/basis-link/program/ and it is also owned by go-openoffice.


< Daenyth> tomkx: my girlfriend is linux
< Daenyth> srsly
< Daenyth> she loves the way I «make install»
< Daenyth> all her /dev entries are mode 7 for me

Offline

#4 2009-09-05 12:42:07

thisoldman
Member
From: Pittsburgh
Registered: 2009-04-25
Posts: 1,172

Re: openoffice uno module not found

Did you check the extension from the Openbox menu bar, "Tools > Extensions..."?

Does the script work if you place it in the same directory as uno.py?

Offline

#5 2009-09-06 22:20:14

Chokkan
Member
Registered: 2009-04-06
Posts: 129

Re: openoffice uno module not found

I'm not familiar with Tools > Extensions, it's not in my menu.

I tried running it in the same directory, but still no luck.

I'm following this thread I found which seems to be a similar problem.
http://sourceforge.net/tracker/index.ph … tid=657832

If I export the paths, I can import uno, but I get a similar failure with com.sun.star. I'll keep trying.

I'm thinking that this may be a problem with go-openoffice in Arch. Would somebody mind trying it?

Last edited by Chokkan (2009-09-07 22:10:38)


< Daenyth> tomkx: my girlfriend is linux
< Daenyth> srsly
< Daenyth> she loves the way I «make install»
< Daenyth> all her /dev entries are mode 7 for me

Offline

#6 2009-11-28 15:42:20

Chokkan
Member
Registered: 2009-04-06
Posts: 129

Re: openoffice uno module not found

Well, there is no problem with this on Ubuntu, which I recently installed on my Aspire One. If I knew where to start with a bug report, I would like to help get this sorted but it seems not to be a problem for anyone else. I admit, it isn't the most critical module in Python. Anyway, just posting for posterity.


< Daenyth> tomkx: my girlfriend is linux
< Daenyth> srsly
< Daenyth> she loves the way I «make install»
< Daenyth> all her /dev entries are mode 7 for me

Offline

Board footer

Powered by FluxBB