Index: gc_lang/fr/oxt/Conjugueur/Conjugueur.py ================================================================== --- gc_lang/fr/oxt/Conjugueur/Conjugueur.py +++ gc_lang/fr/oxt/Conjugueur/Conjugueur.py @@ -10,18 +10,42 @@ import helpers from com.sun.star.task import XJobExecutor from com.sun.star.awt import XActionListener from com.sun.star.awt import XTopWindowListener +from com.sun.star.datatransfer import XTransferable + + +class ClipBoardObject (unohelper.Base, XTransferable): + + def __init__ (self): + self.sText = "" + + # XTransferable + def getTransferData (self, xFlavor): + if xFlavor.MimeType == "text/plain;charset=utf-16": + return self.sText + return + + def getTransferDataFlavors (self): + xFlavor = uno.createUnoStruct("com.sun.star.datatransfer.DataFlavor") + xFlavor.MimeType = "text/plain;charset=utf-16" + xFlavor.HumanPresentableName = "Unicode-Text" + return (xFlavor,) + + def isDataFlavorSupported (self, xFlavor): + return xFlavor.MimeType == "text/plain;charset=utf-16" class Conjugueur (unohelper.Base, XActionListener, XTopWindowListener, XJobExecutor): def __init__ (self, ctx): self.ctx = ctx self.xSvMgr = self.ctx.ServiceManager self.xContainer = None self.xDialog = None + self.xClipboard = None + self.xClipboardObject = None self.lDropDown = ["être", "avoir", "aller", "vouloir", "pouvoir", "devoir", "acquérir", "connaître", "dire", "faire", \ "mettre", "partir", "prendre", "répondre", "savoir", "sentir", "tenir", "vaincre", "venir", "voir", \ "appeler", "envoyer", "commencer", "manger", "trouver", "accomplir", "agir", "finir", "haïr", "réussir"] self.sWarning = "Verbe non vérifié.\nOptions “pronominal” et “temps composés” désactivées." @@ -203,10 +227,12 @@ self.condb3 = self._addWidget('condb3', 'FixedText', nX2, nY7b+35, nWidth, nHeightCj, Label = "") self.condb4 = self._addWidget('condb4', 'FixedText', nX2, nY7b+42, nWidth, nHeightCj, Label = "") self.condb5 = self._addWidget('condb5', 'FixedText', nX2, nY7b+49, nWidth, nHeightCj, Label = "") self.condb6 = self._addWidget('condb6', 'FixedText', nX2, nY7b+56, nWidth, nHeightCj, Label = "") + self.copybutton = self._addWidget('copybutton', 'Button', nX1, nY7+68, 10, 10, Label = ">", TextColor = 0x000088, HelpText="Presse-papiers") + # dialog height self.xDialog.Height = 350 xWindowSize = helpers.getWindowSize() self.xDialog.PositionX = int((xWindowSize.Width / 2) - (self.xDialog.Width / 2)) self.xDialog.PositionY = int((xWindowSize.Height / 2) - (self.xDialog.Height / 2)) @@ -228,10 +254,12 @@ self.xContainer.getControl('oint').setActionCommand('Change') self.xContainer.getControl('otco').addActionListener(self) self.xContainer.getControl('otco').setActionCommand('Change') self.xContainer.getControl('ofem').addActionListener(self) self.xContainer.getControl('ofem').setActionCommand('Change') + self.xContainer.getControl('copybutton').addActionListener(self) + self.xContainer.getControl('copybutton').setActionCommand('CopyData') self.xContainer.addTopWindowListener(self) # listener with XTopWindowListener methods #self.xContainer.execute() # Modal dialog ## set verb self.input.Text = sArgs if sArgs else "être" @@ -250,10 +278,12 @@ elif xActionEvent.ActionCommand == 'New': self._newVerb() elif xActionEvent.ActionCommand == 'Change': if self.oVerb: self._displayResults() + elif xActionEvent.ActionCommand == 'CopyData': + self.stringToClipboard(self.sTextForClipboard) else: print(str(xActionEvent)) except: traceback.print_exc() @@ -277,17 +307,27 @@ return def windowDeactivated (self, xEvent): return + # Clipboard + # see: https://forum.openoffice.org/en/forum/viewtopic.php?f=21&t=93562 + def stringToClipboard (self, sText): + if not self.xClipboard: + self.xClipboard = self.xSvMgr.createInstance("com.sun.star.datatransfer.clipboard.SystemClipboard") + self.xClipboardObject = ClipBoardObject() + self.xClipboardObject.sText = sText + self.xClipboard.setContents(self.xClipboardObject, None) + # XJobExecutor def trigger (self, args): try: xDialog = Conjugueur(self.ctx) xDialog.run(args) except: traceback.print_exc() + def _newVerb (self): self.oneg.State = False self.opro.State = False self.oint.State = False @@ -417,10 +457,11 @@ self.simp4.Label = dConjTable["simp4"] self.simp5.Label = dConjTable["simp5"] self.simp6.Label = dConjTable["simp6"] # refresh self.xContainer.setVisible(True) + self.sTextForClipboard = "\n".join( [ s for s in dConjTable.values() ] ) except: traceback.print_exc() # g_ImplementationHelper = unohelper.ImplementationHelper() # g_ImplementationHelper.addImplementation(Conjugueur, 'dicollecte.Conjugueur', ('com.sun.star.task.Job',))