def execAction(self): try: name = self.actions[ self.widgetlist.currentRow ] Words.tool().triggerAction( name.strip() ) except: message = "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ) self.forms.showMessageBox("Error", "Error", "%s" % message)
def continue_game(screen, game): if (len(game.current_words) < game.add_words_trigger): game.current_words.append(random.choice(game.wordbank)) Words.Word.word_str_to_obj(game) Words.remove_words_from_screen(screen, game) Words.move_words(screen, game) game.pop_word_meteors(screen) pygame.display.update() return
def execAction(self): try: name = self.actions[self.widgetlist.currentRow] Words.tool().triggerAction(name.strip()) except: message = "".join( traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])) self.forms.showMessageBox("Error", "Error", "%s" % message)
def __init__(self, scriptaction): self.scriptaction = scriptaction #self.currentpath = self.scriptaction.currentPath() self.forms = Kross.module("forms") self.dialog = self.forms.createDialog("Insert Shape") self.dialog.minimumWidth = 500 self.dialog.minimumHeight = 360 self.dialog.setButtons("Ok|Cancel") #self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed self.shapes = Words.shapeKeys() page = self.dialog.addPage("", "") widget = self.forms.createWidgetFromUI(page, '<ui version="4.0" >' ' <class>Form</class>' ' <widget class="QWidget" name="Form" >' ' <layout class="QHBoxLayout" >' ' <item>' ' <widget class="QListWidget" name="List">' ' <property name="currentRow"><number>%i</number></property>' ' %s' ' </widget>' ' </item>' ' </layout>' ' </widget>' '</ui>' % ( 0, ''.join( [ '<item><property name="text" ><string>%s</string></property></item>' % s for s in self.shapes ] ) ) ) self.widgetlist = widget["List"] if self.dialog.exec_loop(): self.doInsert()
def test_turnTextIntoObjects_works_with_unproblematic_inputs(self): expectedFirstWordOutput = "<span class=\"word\" id=\"0 If\" onClick=\"getDefinitionOrEdit(event)\"><div class=\"Preposition or suburdinating conjunction\"><output-font class=\"unstressed\">If</output-font></div><div class=\"dropdown-content\">If: <br> x <br> Preposition or suburdinating conjunction <br> </div></span>" text = "If the dull substance of my flesh were thought," lines = Words.turnTextIntoObjects(text) # line = lines[0].syll_str_line() firstWord = lines[0].list[0].syll_str() self.assertEqual(firstWord, expectedFirstWordOutput)
def __init__(self, scriptaction): self.scriptaction = scriptaction #self.currentpath = self.scriptaction.currentPath() self.forms = Kross.module("forms") self.dialog = self.forms.createDialog("Insert Shape") self.dialog.minimumWidth = 500 self.dialog.minimumHeight = 360 self.dialog.setButtons("Ok|Cancel") #self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed self.shapes = Words.shapeKeys() page = self.dialog.addPage("", "") widget = self.forms.createWidgetFromUI( page, '<ui version="4.0" >' ' <class>Form</class>' ' <widget class="QWidget" name="Form" >' ' <layout class="QHBoxLayout" >' ' <item>' ' <widget class="QListWidget" name="List">' ' <property name="currentRow"><number>%i</number></property>' ' %s' ' </widget>' ' </item>' ' </layout>' ' </widget>' '</ui>' % (0, ''.join([ '<item><property name="text" ><string>%s</string></property></item>' % s for s in self.shapes ]))) self.widgetlist = widget["List"] if self.dialog.exec_loop(): self.doInsert()
def continue_game(screen, game): if (len(game.current_words) < game.add_words_trigger): game.current_words.append(random.choice(game.wordbank)) if (game.add_word_delay < 1): if (game.check_quick_frame_count()): add_word(game) elif (game.add_word_seconds >= game.add_word_delay): game.quick_frame_count = 0 add_word(game) game.add_word_seconds = 0 Words.Word.word_str_to_obj(game) Words.remove_words_from_screen(screen, game) Words.move_words(screen, game) game.pop_word_bubbles(screen) pygame.display.update() return
def __init__(self, file): doc = Words.mainFrameSet().document() f = open(file, "w") html = doc.toHtml() html = re.sub("<head>","<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>",html,count=1) f.write(html) f.close()
def __init__(self, scriptaction): self.scriptaction = scriptaction #self.currentpath = self.scriptaction.currentPath() self.forms = Kross.module("forms") self.dialog = self.forms.createDialog("Execute Action") self.dialog.minimumWidth = 500 self.dialog.minimumHeight = 360 self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("Plain") #Auto Plain List Tree Tabbed self.objects = [ ('application', Words.application()), ('shell', Words.shell()), ('mainwindow', Words.mainWindow()), ('document', Words.document()), ] self.actions = [] for obj in self.objects: for s in dir(obj[1]): if s.startswith('slot'): self.actions.append( "%s.%s" % (obj[0],s) ) page = self.dialog.addPage("", "") widget = self.forms.createWidgetFromUI(page, '<ui version="4.0" >' ' <class>Form</class>' ' <widget class="QWidget" name="Form" >' ' <layout class="QHBoxLayout" >' ' <item>' ' <widget class="QListWidget" name="List">' ' <property name="currentRow"><number>%i</number></property>' ' %s' ' </widget>' ' </item>' ' </layout>' ' </widget>' '</ui>' % ( 0, ''.join( [ '<item><property name="text" ><string>%s</string></property></item>' % s for s in self.actions ] ) ) ) self.widgetlist = widget["List"] if self.dialog.exec_loop(): self.execAction()
def __init__(self, file): doc = Words.mainFrameSet().document() #cursor = doc.rootFrame().lastCursorPosition() #cursor = doc.lastCursor() #cursor.insertDefaultBlock() #cursor.insertHtml( ' '.join(f.readlines()) ) f = open(file, "r") doc.setHtml( ' '.join(f.readlines()) ) f.close()
def __init__(self, file): doc = Words.mainFrameSet().document() #cursor = doc.rootFrame().lastCursorPosition() #cursor = doc.lastCursor() #cursor.insertDefaultBlock() #cursor.insertHtml( ' '.join(f.readlines()) ) f = open(file, "r") doc.setHtml(' '.join(f.readlines())) f.close()
def importFile(self, fromFileName, options): fs = Words.mainFrameSet() if not fs: raise "No main frameset to import the content too." doc = fs.document() if not fs: raise "No document to import the content too." fileExt = os.path.splitext(fromFileName)[1].lower() if fileExt == '.txt' or fileExt == '.html': f = open(fromFileName, "r") if fileExt == '.txt': doc.setText(''.join(f.readlines())) else: doc.setHtml(' '.join(f.readlines())) f.close() else: #odt #TODO this crashes horrible :-( Words.document().openUrl(fromFileName)
def importFile(self, fromFileName, options): fs = Words.mainFrameSet() if not fs: raise "No main frameset to import the content too." doc = fs.document() if not fs: raise "No document to import the content too." fileExt = os.path.splitext(fromFileName)[1].lower() if fileExt == ".txt" or fileExt == ".html": f = open(fromFileName, "r") if fileExt == ".txt": doc.setText("".join(f.readlines())) else: doc.setHtml(" ".join(f.readlines())) f.close() else: # odt # TODO this crashes horrible :-( Words.document().openUrl(fromFileName)
def generate(self): try: length = int(self.userLength.get()) except ValueError: length = 5 try: number = int(self.userNumber.get()) except ValueError: number = 10 length = max(3, min(20, length)) return self.display(w.filtrated_generator(length, number))
def _start_words(self): if self._running: return if not self._words: if not self._get_char(): return self._words = Words.word_generator(self._get_char(), self._include.get()) self._running = True t = threading.Thread(target=self._update_word) t.setDaemon(True) t.start()
def __init__(self, file): doc = Words.mainFrameSet().document() f = open(file, "w") html = doc.toHtml() html = re.sub( "<head>", "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>", html, count=1) f.write(html) f.close()
def index(request): # simple view, either presenting an input screen or the analysis version. if request.method == 'POST': form = TextForm(request.POST) text = request.POST.get('text') lines = Words.turnTextIntoObjects(text) foot = getBestMeter(lines) context_dict = {'lines': lines, 'foot': foot} return analyse(request, context_dict) else: form = TextForm() return render(request, 'scansion/index.html', {'form': form})
def helper_test_a_file_of_poems(fileName): finalFileName = fileName + ".txt" fileContents = open(finalFileName, "r") fileText = fileContents.read() fileContents.close() fails = 0 correctGuesses = 0 result = "" poems_array = fileText.split("\n\n\n") textFileName = "Accuracy_results_for__" + fileName + "__.txt" textFile = open(textFileName, "w+") for poem in poems_array: poemFailed = False expectedMeter = poem.partition("\n")[0] poemText = poem.partition("\n")[2] poemObject = Words.turnTextIntoObjects(poemText) scansionMeter = views.getBestMeter(poemObject) z = re.match(expectedMeter, scansionMeter['meter']) if z and scansionMeter['count'] >= scansionMeter['total'] / 2: textFile.write("PASS") textFile.write("\t\"" + poemText.split("\n")[0] + "\", Expected: " + expectedMeter + ", Scansion's: " + scansionMeter['meter']) else: textFile.write("FAIL") poemFailed = True fails += 1 textFile.write("\t\"" + poemText.split("\n")[0] + "\", Expected: " + expectedMeter + ", Scansion's best guess: " + scansionMeter['meter']) if z: correctGuesses += 1 # if poemFailed: # textFile.write(" (Best guess: " + scansionMeter['secondMeter'] + ")") textFile.write("\n") if (fails <= len(poems_array) / 10): stringForTextFile = "\nPASS" result = "PASS" else: stringForTextFile = "\nFAIL" result = "FAIL" stringForTextFile += ": " stringForTextFile += str(fails) stringForTextFile += " fails out of " + str( len(poems_array)) + " poems. " + str( correctGuesses) + " correct 'best guesses'." textFile.write(stringForTextFile) textFile.close() return result
def doInsert(self): try: shapeId = self.shapes[ self.widgetlist.currentRow ] frame = Words.addFrame("myshape", shapeId) if frame == None: raise "No such shape \"%s\"" % shapeId #frame.setTextRunAround(tableframe.RunThrough) #frame.setPosition(200, 160) #frame.resize(160, 160) except: message = "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ) self.forms.showMessageBox("Error", "Error", "%s" % message)
def addList(text,liststyle): global Words, cursor # The block seems to be needed cause else additional insertHtml-calls don't respect the line-break whyever. cursor.insertDefaultBlock() #cursor.insertBlock() # We like to create a new list cursor.insertHtml("<br><h2>%s</h2>" % text) # Create a new style and set the liststyle s = Words.addParagraphStyle("My%sStyle" % text) #s.setListStyle( getattr(s,liststyle) ) # e.g. s.setListStyle( s.SquareItem ) # Create the list and apply the style l = cursor.insertList() l.setStyle(s) # Fill the list with some items for i in range(1, 6): if i != 1: cursor.insertBlock() cursor.insertHtml( "item nr=%i count=%i" % (i,l.countItems()) )
def doInsert(self): try: shapeId = self.shapes[self.widgetlist.currentRow] frame = Words.addFrame("myshape", shapeId) if frame == None: raise "No such shape \"%s\"" % shapeId #frame.setTextRunAround(tableframe.RunThrough) #frame.setPosition(200, 160) #frame.resize(160, 160) except: message = "".join( traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])) self.forms.showMessageBox("Error", "Error", "%s" % message)
def test_inputs_with_misspellings(self): expectedUnknownWordOutput = "<span class=\"word\" id=\"0 Afrg\" onClick=\"getDefinitionOrEdit(event)\"><div class=\"unknown\"><output-font class=\"unknown\">Afrg</output-font></div><div class=\"dropdown-content\">Afrg: <br>?<br>unknown<br></div></span>" text = "Afrg the dull substance of my flesh were thought," lines = Words.turnTextIntoObjects(text) firstWord = lines[0].list[0].syll_str() self.assertEqual(firstWord, expectedUnknownWordOutput)
def test_input_with_mix_of_dashes_and_spaces(self): expectedFirstWordOutput = "<span class=\"word\" id=\"0 If\" onClick=\"getDefinitionOrEdit(event)\"><div class=\"Preposition or suburdinating conjunction\"><output-font class=\"unstressed\">If</output-font></div><div class=\"dropdown-content\">If: <br> x <br> Preposition or suburdinating conjunction <br> </div></span>" text = "If-the-dull substance of my-flesh-were thought," lines = Words.turnTextIntoObjects(text) firstWord = lines[0].list[0].syll_str() self.assertEqual(firstWord, expectedFirstWordOutput)
def test_mix_of_dashes_on_full_poem(self): expectedFirstWordOutput = "<span class=\"word\" id=\"0 If\" onClick=\"getDefinitionOrEdit(event)\"><div class=\"Preposition or suburdinating conjunction\"><output-font class=\"unstressed\">If</output-font></div><div class=\"dropdown-content\">If: <br> x <br> Preposition or suburdinating conjunction <br> </div></span>" text = "If the dull-substance of my flesh-were thought, \n Injurious distance should not stop my way; \n For then despite of space I would be brought, \n From limits far remote where thou dost stay. \n No matter then although my foot did stand \n Upon the farthest earth removed from thee; \n For nimble thought can jump both sea and land \n As soon as think the place where he would be. \n But ah! thought kills me that I am not thought, \n To leap large lengths of miles when thou art gone, \n But that so much of earth and water wrought \n I must attend time's leisure with my moan, \n Receiving nought by elements so slow \n But heavy tears, badges of either's woe. \n " lines = Words.turnTextIntoObjects(text) firstWord = lines[0].list[0].syll_str() self.assertEquals(firstWord, expectedFirstWordOutput)
def test_inputs_with_all_capitals(self): expectedFirstWordOutput = "<span class=\"word\" id=\"0 IF\" onClick=\"getDefinitionOrEdit(event)\"><div class=\"Preposition or suburdinating conjunction\"><output-font class=\"unstressed\">IF</output-font></div><div class=\"dropdown-content\">IF: <br> x <br> Preposition or suburdinating conjunction <br> </div></span>" text = "IF THE DULL SUBSTANCE OF MY FLESH WERE THOUGHT," lines = Words.turnTextIntoObjects(text) firstWord = lines[0].list[0].syll_str() self.assertEqual(firstWord, expectedFirstWordOutput)
def test_second_word_with_underscores(self): expectedSecondWordOutput = "<span class=\"word\" id=\"1 the\" onClick=\"getDefinitionOrEdit(event)\"><div class=\"Determiner\"><output-font class=\"unstressed\">the</output-font></div><div class=\"dropdown-content\">the: <br> x <br> Determiner <br> </div></span>" text = "If_the_dull_substance_of_my_flesh_were_thought," lines = Words.turnTextIntoObjects(text) secondWord = lines[0].list[1].syll_str() self.assertEqual(secondWord, expectedSecondWordOutput)
class ImportDialog: """ The dialog we are using to provide some frontend to the user if the script runs for example embedded in Words. """ def __init__(self, action, config): import Kross, Words self.action = action self.config = config forms = Kross.module("forms") self.dialog = forms.createDialog("Import Doxygen XML File") self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed openpage = self.dialog.addPage("Open","Import Doxygen XML File","document-open") openwidget = forms.createFileWidget(openpage, "kfiledialog:///wordssampleimportfile") openwidget.setMode("Opening") #openwidget.minimumWidth = 540 #openwidget.minimumHeight = 400 openwidget.setFilter("*.xml|XML Files\n*|All Files") configpage = self.dialog.addPage("Options","Import Options","preferences-other") configwidget = forms.createWidgetFromUIFile(configpage, os.path.join(action.currentPath(),"importdoxyxmloptions.ui")) stylepage = self.dialog.addPage("Styles","Cascading Style Sheet","preferences-web-browser-stylesheets") stylewidget = forms.createWidgetFromUIFile(stylepage, os.path.join(action.currentPath(),"importdoxyxmlstyle.ui")) styleedit = stylewidget["textEdit"] if self.dialog.exec_loop(): fileName = openwidget.selectedFile() if not fileName: raise "No file selected" self.config.FileName = fileName self.config.TableOfContent = configwidget["TocCheckBox"].checked self.config.IndexPage = configwidget["IndexPageCheckBox"].checked self.config.OtherPages = configwidget["OtherPagesCheckBox"].checked self.config.EnablePages = configwidget["PagesCheckBox"].checked self.config.PageDescription = configwidget["PageDescriptionCheckBox"].checked self.config.EnableClasses = configwidget["ClassesCheckBox"].checked self.config.ClassDescription = configwidget["ClassDescriptionCheckBox"].checked self.config.MemberDescription = configwidget["MemberDescriptionCheckBox"].checked self.config.EnableSlots = configwidget["SlotsCheckBox"].checked self.config.EnableSignals = configwidget["SignalsCheckBox"].checked self.config.EnableProperties = configwidget["PropertiesCheckBox"].checked self.config.EnableFunctions = configwidget["FunctionsCheckBox"].checked self.config.EnableVariables = configwidget["VariablesCheckBox"].checked self.importFile(styleedit.plainText) def __del__(self): self.dialog.delayedDestruct() def importFile(self, styles): import Kross, Words try: file = open(self.config.FileName, "r") except IOError, (errno, strerror): raise "Failed to read file \"%s\":\n%s" % (self.config.FileName, strerror) xmldoc = xml.dom.minidom.parse( file ) kwdoc = Words.mainFrameSet().document() kwdoc.setDefaultStyleSheet("%s" % styles) class WordsFileWriter: def __init__(self, kwdoc): self.kwdoc = kwdoc self.lines = [] def write(self, line): self.lines.append( line.encode('utf-8') ) def flush(self): self.kwdoc.setHtml(' '.join(self.lines)) writer = Writer(xmldoc, self.config) kwwriter = WordsFileWriter(kwdoc) writer.writeHtml(kwwriter) kwwriter.flush()
def __init__(self, file): doc = Words.mainFrameSet().document() f = open(file, "r") doc.setText( ''.join(f.readlines()) ) f.close()
def test_foreign_words(self): expectedFirstWordOutput = "<span class=\"word\" id=\"0 oeuf\" onClick=\"getDefinitionOrEdit(event)\"><div class=\"unknown\"><output-font class=\"unknown\">oeuf</output-font></div><div class=\"dropdown-content\">oeuf: <br>?<br>unknown<br></div></span>" text = "oeuf something else in French" lines = Words.turnTextIntoObjects(text) firstWord = lines[0].list[0].syll_str() self.assertEquals(firstWord, expectedFirstWordOutput)
#!/usr/bin/env kross # -*- coding: utf-8 -*- import Words, time, sys, os #if Words.pageCount() < 1: Words.insertPage(0) #doc = Words.frameSet(0).document() doc = Words.mainFrameSet().document() # Set the default cascading stylesheet. doc.setDefaultStyleSheet(("li { margin-left:1em; }" ".my1 { text-transform: lowercase; }" ".my2 { text-transform: uppercase; }" ".my3 { text-transform: capitalize; }")) # Set the html with some general informations. doc.setHtml(( "<h1><font color=\"blue\">Python Sample: Text</font></h1>" "<p><i>italic</i> and <b>bold</b> and <u>underlined</u> and a <a href=\"test\">link</a></p>." "<div class='my1'>lOwErCaSe</div>" "<div class='my2'>uPpErCaSe</div>" "<div class='my3'>capitalize</div>" "<ul>" "<li>Time: <b>%s</b></li>" "<li>Operating System: <b>%s</b></li>" "<li>Python Version: <b>%s</b></li>" "<li>Documents: <b>%s</b></li>" "<li>Views: <b>%s</b></li>" "<li>Windows: <b>%s</b></li>" "<li>PageCount: <b>%s</b></li>"
def test_whole_text_misspelled(self): expectedUnknownWordOutput = "<span class=\"word\" id=\"0 oijityfytf\" onClick=\"getDefinitionOrEdit(event)\"><div class=\"unknown\"><output-font class=\"unknown\">oijityfytf</output-font></div><div class=\"dropdown-content\">oijityfytf: <br>?<br>unknown<br></div></span>" text = "oijityfytf ugiugty uyigytf" lines = Words.turnTextIntoObjects(text) firstWord = lines[0].list[0].syll_str() self.assertEqual(firstWord, expectedUnknownWordOutput)
#!/usr/bin/python3 # -*- coding: utf-8 -*- # Word generator import sys if sys.version_info.major == 3: import tkinter as tk else: import Tkinter as tk import random as r import Words as w w.initialize() # loads the index class MyApp(): def __init__(self, master): self.master = master self.gui() def gui(self): # length of the words self.lengthLab = tk.Label(self.master, text="Length (2 to 20)") self.userLength = tk.StringVar() self.lengthEnt = tk.Entry(self.master, textvariable=self.userLength, width=7) # amount of words to generate self.numberLab = tk.Label(self.master, text="Number") self.userNumber = tk.StringVar() self.numberEnt = tk.Entry(self.master, textvariable=self.userNumber,
import Words import User import Text2Speech import Score import FileIO #test data wordList = ["test", "test2", "test3"] words = Words.Words() user1 = User.User() speech = Text2Speech.Text2Speech() score = Score.Score() file = FileIO.FileIO() testChoice = input("q)uit, anything else to continue: ") while (testChoice.lower() != "q"): word = words.getRandVal(wordList) userGuess = user1.GetStrInput("Enter your answer to :" + word) userScore = score.ComputeScore(userGuess, word) print("Score:", userScore) print("Writing score to file") file.Write2CSV("data.csv", userScore) testChoice = input("q)uit, anything else to continue: ")
#!/usr/bin/env kross # -*- coding: utf-8 -*- import Words, time #Words.insertPage( Words.pageCount() ) #if Words.pageCount() < 1: Words.insertPage(0) doc = Words.mainFrameSet().document() cursor = doc.rootFrame().lastCursorPosition() #cursor = doc.lastCursor() variables = doc.variableNames() cursor.insertDefaultBlock() cursor.insertHtml("<b>Variables with Cursor</b><br>") for n in variables: cursor.insertHtml("%s: " % n) ok = doc.addVariable(cursor,n) cursor.insertDefaultBlock() print "VARIABLE ADDED =====> variablename=%s ok=%s" % (n,ok) for n in variables: doc.setVariableValue(n, "%s" % time.strftime('%H:%M.%S')) cursor.insertDefaultBlock() cursor.insertHtml("<b>Variables with HTML</b><br>") cursor.insertHtml("<p>%s</p>" % "".join([ "%s: %s<br>" % (v,doc.variableValue(v)) for v in variables ]))
#!/usr/bin/env kross # -*- coding: utf-8 -*- import Words idx = 0 shapes = Words.shapeKeys() for shapeId in shapes: frame = Words.addFrame("myshape", shapeId) if frame != None: #frame.setTextRunAround(tableframe.RunThrough) frame.setPosition(idx % 6 * 80 + 20, 100 * idx + 20) #frame.resize(160, 160) idx += 1
def test_word_after_a_misspelling(self): expectedSecondWordOutput = "<span class=\"word\" id=\"1 the\" onClick=\"getDefinitionOrEdit(event)\"><div class=\"Determiner\"><output-font class=\"unstressed\">the</output-font></div><div class=\"dropdown-content\">the: <br> x <br> Determiner <br> </div></span>" text = "Afrg the dull substance of my flesh were thought," lines = Words.turnTextIntoObjects(text) secondWord = lines[0].list[1].syll_str() self.assertEqual(secondWord, expectedSecondWordOutput)
def _show_word_count(): words = Words.word_count() plt.bar(words.keys(), words.values()) plt.show()
#!/usr/bin/env kross # -*- coding: utf-8 -*- import Words, time, sys, os #if Words.pageCount() < 1: Words.insertPage(0) #doc = Words.frameSet(0).document() doc = Words.mainFrameSet().document() # Set the default cascading stylesheet. doc.setDefaultStyleSheet( ( "li { margin-left:1em; }" ".my1 { text-transform: lowercase; }" ".my2 { text-transform: uppercase; }" ".my3 { text-transform: capitalize; }" ) ) # Set the html with some general informations. doc.setHtml( ( "<h1><font color=\"blue\">Python Sample: Text</font></h1>" "<p><i>italic</i> and <b>bold</b> and <u>underlined</u> and a <a href=\"test\">link</a></p>." "<div class='my1'>lOwErCaSe</div>" "<div class='my2'>uPpErCaSe</div>" "<div class='my3'>capitalize</div>" "<ul>"
def main(): words = Words.Words() words.word_length = get_word_length() words.set_words_with_length(words.word_length) loop(words)
self.dialog.delayedDestruct() config = MyConfig() try: # try to import Words. If this fails we are not running embedded in Words. import Words config.showDialog = True except ImportError: # looks as we are not running embedded within Words. So, let's use Kross to import the Words library. Words = Kross.module("words") if config.readOdfFile: Words.document().openUrl(config.readOdfFile) if not Words.document().url(): # if Words does not have a loaded document now we show a fileopen-dialog to let the user choose the odt file. forms = Kross.module("forms") dialog = forms.createDialog("ReportLab.org") dialog.setButtons("Ok|Cancel") dialog.setFaceType("Plain") openwidget = forms.createFileWidget(dialog.addPage("Open", "Open ODT File")) openwidget.setMode("Opening") openwidget.setFilter("*.odt|ODT Files\n*|All Files") if not dialog.exec_loop(): raise Exception("Aborted.") if not Words.document().openUrl(openwidget.selectedFile()): raise Exception("Failed to open file: %s" % openwidget.selectedFile())
def __init__(self, file): doc = Words.mainFrameSet().document() f = open(file, "w") f.write( doc.toText() ) f.close()
#!/usr/bin/env kross # -*- coding: utf-8 -*- import Words, time # fetch the main window komainwindow = Words.shell() # set the statusbar text komainwindow.slotSetStatusBarText("This is the sample_progressbar.py script") try: # increment the progressbar from 0% to 100% for i in range(1,101): komainwindow.slotProgress(i) # wait some seconds else we are to fast ;) time.sleep(0.1) finally: # reset the statusbar-text and the progressbar. komainwindow.slotSetStatusBarText("") komainwindow.slotProgress(-1)
def __init__(self, file): doc = Words.mainFrameSet().document() f = open(file, "w") f.write(doc.toText()) f.close()