예제 #1
0
 def button_pushed(self, ev):
     control = ev.Source
     n = int(ev.ActionCommand)
     type_name = self._results[n].type_name
     with_type = False
     if type_name == "ANY":
         with_type = True
         from mytools_Mri.ui.tools import create_popupmenu
         entries = ((1, 0, 0, "void", "VOID", None), 
                    (2, 1, 0, "boolean", "BOOLEAN", None), 
                    (3, 2, 0, "byte", "BYTE", None), 
                    (4, 3, 0, "short", "SHORT", None), 
                    (5, 4, 0, "unsigned short", "UNSIGNED_SHORT", None), 
                    (6, 5, 0, "long", "LONG", None), 
                    (7, 6, 0, "unsigned long", "UNSIGNED_LONG", None), 
                    (8, 7, 0, "hyper", "HYPER", None), 
                    (9, 8, 0, "unsigned hyper", "UNSIGNED_HYPER", None), 
                    (10, 9, 0, "float", "FLOAT", None), 
                    (11, 10, 0, "double", "DOUBLE", None), 
                    (12, 11, 0, "string", "STRING", None), 
                    (13, 12, 0, "type", "TYPE", None), 
                    (14, 13, 0, "enum", "ENUM", None), 
                    (None, 14, 0, "", "", None), 
                    (15, 15, 0, "struct", "STRUCT", None), 
                    (16, 16, 0, "exception", "EXCEPTION", None), 
                    (17, 17, 0, "sequence", "SEQUENCE", None), 
                    (18, 18, 0, "interface", "INTERFACE", None))
         popup = create_popupmenu(self.ctx, entries)
         r = popup.execute(ev.Source.getPeer(), Rectangle(0, ev.Source.getPosSize().Height, 0, 0), 0)
         if r == 0: return
         value_type_name = popup.getCommand(r)
         control.setLabel(popup.getItemText(r))
         if value_type_name in self.FROM_HISTORY:
             self.set_enable("edit_%s" % n, False)
         else:
             self.set_enable("edit_%s" % n, True)
             self._results[n].value_type = value_type_name
             return
     obj = None
     try:
         self._history_selector = HistorySelectorDialog(self.ctx, self.cast)
         obj = self._history_selector.execute(
                     "History", self.TreeSelectionListener(self), 
                     allow_void=True, void_listener=self.ItemListener(self))
         self._history_selector = None
     except Exception as e:
         print(e)
         traceback.print_exc()
     finally:
         if obj is None:
             return
     name = "edit_%s" % n
     if obj == "void":
         self.set_text(name, "void")
         self._results[n].value = None
         self._results[n].value_type = "VOID"
     elif obj:
         self.set_text(name, str(obj))
         self._results[n].value = obj
         self._results[n].value_type = value_type_name if with_type else type_name
예제 #2
0
 def mousePressed(
         self, mouseevent):  # グリッドコントロールをクリックした時。コントロールモデルにはNameプロパティはない。
     gridcontrol = mouseevent.Source  # グリッドコントロールを取得。
     if mouseevent.Buttons == MouseButton.LEFT:
         selectedrowindexes = dialogcommons.getSelectedRowIndexes(
             gridcontrol)
         if not selectedrowindexes:  # 選択行がない時(選択行を削除した時)。
             return  # 何もしない
         if mouseevent.ClickCount == 1:  # シングルクリックの時。
             if self.flg:
                 for menuid in range(1,
                                     self.gridpopupmenu.getItemCount() +
                                     1):  # ポップアップメニューを走査する。
                     itemtext = self.gridpopupmenu.getItemText(
                         menuid)  # 文字列にはショートカットキーがついてくる。
                     if itemtext.startswith("オプション表示"):
                         if not self.gridpopupmenu.isItemChecked(
                                 menuid):  # 選択項目にチェックが入っていない時。
                             self._toCell(
                                 gridcontrol, selectedrowindexes
                             )  # オプション表示していない時はシングルクリックでセルに入力する。
                             break
             else:
                 self.flg = True
         elif mouseevent.ClickCount == 2:  # ダブルクリックの時。
             self._toCell(gridcontrol, selectedrowindexes)
     elif mouseevent.Buttons == MouseButton.RIGHT:  # 右ボタンクリックの時。mouseevent.PopupTriggerではサブジェクトによってはTrueにならないので使わない。
         pos = Rectangle(mouseevent.X, mouseevent.Y, 0,
                         0)  # ポップアップメニューを表示させる起点。
         self.gridpopupmenu.execute(gridcontrol.getPeer(), pos,
                                    PopupMenuDirection.EXECUTE_DEFAULT
                                    )  # ポップアップメニューを表示させる。引数は親ピア、位置、方向
예제 #3
0
def macro():
    ctx = XSCRIPTCONTEXT.getComponentContext()  # コンポーネントコンテクストの取得。
    smgr = ctx.getServiceManager()  # サービスマネージャーの取得。
    doc = XSCRIPTCONTEXT.getDocument()  # マクロを起動した時のドキュメントのモデルを取得。   
    docframe = doc.getCurrentController().getFrame()  # モデル→コントローラ→フレーム、でドキュメントのフレームを取得。
    docwindow = docframe.getContainerWindow()  # ドキュメントのウィンドウを取得。
    toolkit = docwindow.getToolkit()  # ツールキットを取得。
    taskcreator = smgr.createInstanceWithContext('com.sun.star.frame.TaskCreator', ctx)
    args = NamedValue("PosSize", Rectangle(150, 150, 200, 200)), NamedValue("FrameName", "NewFrame")  # , NamedValue("MakeVisible", True)  # TaskCreatorで作成するフレームのコンテナウィンドウのプロパティ。
    frame = taskcreator.createInstanceWithArguments(args)  # コンテナウィンドウ付きの新しいフレームの取得。
    subwindow = frame.getContainerWindow()  # 新しいコンテナウィンドウを新しいフレームから取得。
    frame.setTitle("New Frame")  # フレームのタイトルを設定。
    docframe.getFrames().append(frame)  # 新しく作ったフレームを既存のフレームの階層に追加する。
    controlcontainer = smgr.createInstanceWithContext("com.sun.star.awt.UnoControlContainer", ctx)  # コントロールコンテナを生成。
    controlcontainermodel = smgr.createInstanceWithContext("com.sun.star.awt.UnoControlContainerModel", ctx)  # コントールコンテナのモデルを生成。
    controlcontainermodel.setPropertyValue("BackgroundColor", -1)  # 背景色。-1は何色?
    controlcontainer.setModel(controlcontainermodel)  # コントールコンテナにモデルを設定。
    controlcontainer.createPeer(toolkit, subwindow)  # 新しく作ったウィンドウ内にコントロールコンテナのコントロールをツールキットで描画する。
    controlcontainer.setPosSize(0, 0, 200, 200, POSSIZE)  # コントロールの表示座標を設定。4つ目の引数は前の引数の意味を設定する。
    frame.setComponent(controlcontainer, None)  # コントロールコンテナをフレームにのコンポーネントウィンドウに設定する。今回のコントローラはNone。
    label = createControl(smgr, ctx, "FixedText", 10, 0, 180, 30, ("Label", "VerticalAlign"), ("Label1", BOTTOM))  # 固定文字コントールを作成。
    edit = createControl(smgr, ctx, "Edit", 10, 40, 180, 30, (), ())  # 編集枠コントロールを作成。
    btn = createControl(smgr, ctx, "Button", 110, 130, 80, 35, ("DefaultButton", "Label"), (True, "btn"))  # ボタンコントロールを作成。
    controlcontainer.addControl("label", label)  # コントロールコンテナにコントロールを名前を設定して追加。
    controlcontainer.addControl("btn", btn)  # コントロールコンテナにコントロールを名前を設定して追加。
    controlcontainer.addControl("edit", edit)  # コントロールコンテナにコントロールを名前を設定して追加。
    edit.setFocus()  # 編集枠コントロールにフォーカスを設定する。
    btn.setActionCommand("btn")  # ボタンを起動した時のコマンド名を設定する。
    btn.addActionListener(BtnListener(controlcontainer, subwindow))  # ボタンにリスナーを設定。コントロールの集合を渡しておく。
    subwindow.setVisible(True)  # 新しく作ったウィンドウを見えるようにする。execute()メソッドはないのでノンモダルダイアログにはできない。
    def _showDialog(self, message, msg_args, title, buttons, stype):
        """
        Wrapper for com.sun.star.awt.XMessageBoxFactory.

        :arg message: May contain "%" values to interpolate.
        :arg msg_args: Values to use for interpolation.
        """
        rect = Rectangle()
        message = exceptions.interpolate_message(message, msg_args)
        message += " "  # padding so that it displays better
        logger.warning(message)
        try:
            box = self.toolkit.createMessageBox(self.parent, rect, stype,
                                                buttons, title, message)
        except IllegalArgumentException:
            # AOO 4.0 changes
            from com.sun.star.awt.MessageBoxType import (MESSAGEBOX, INFOBOX,
                                                         QUERYBOX, WARNINGBOX,
                                                         ERRORBOX)
            etype = MESSAGEBOX  # enumerated type
            if stype == MessageBox.STYPE_QUERY:
                etype = QUERYBOX
            elif stype == MessageBox.STYPE_WARN:
                etype = WARNINGBOX
            elif stype == MessageBox.STYPE_ERROR:
                etype = ERRORBOX
            elif stype == MessageBox.STYPE_INFO:
                etype = INFOBOX
            box = self.toolkit.createMessageBox(self.parent, etype, buttons,
                                                title, message)
        return box.execute()
예제 #5
0
 def _message(self, title, message, type, buttons):
     desktop = self._create_service("com.sun.star.frame.Desktop")
     frame = desktop.getActiveFrame()
     window = frame.getContainerWindow()
     toolkit = window.getToolkit()
     return toolkit.createMessageBox(window, Rectangle(), type, buttons,
                                     title, message)
예제 #6
0
 def mousePressed(
         self, mouseevent):  # グリッドコントロールをクリックした時。コントロールモデルにはNameプロパティはない。
     xscriptcontext, dateformat, formatstring = self.args
     gridcontrol = mouseevent.Source  # グリッドコントロールを取得。
     if mouseevent.Buttons == MouseButton.LEFT:
         if mouseevent.ClickCount == 2:  # ダブルクリックの時。
             doc = xscriptcontext.getDocument()
             selection = doc.getCurrentSelection()  # シート上で選択しているオブジェクトを取得。
             if selection.supportsService(
                     "com.sun.star.sheet.SheetCell"):  # 選択オブジェクトがセルの時。
                 rowindexes = getSelectedRowIndexes(
                     gridcontrol
                 )  # グリッドコントロールの選択行インデックスを返す。昇順で返す。負数のインデックスがある時は要素をクリアする。
                 if rowindexes:
                     datetxt = gridcontrol.getModel().getPropertyValue(
                         "GridDataModel").getCellData(
                             1, rowindexes[0])  # 選択行の日付文字列を取得。
                     selectedday = datetime.strptime(
                         datetxt, dateformat)  # 現在の最初のdatetimeオブジェクトを取得。
                     selection.setFormula(
                         selectedday.isoformat())  # セルに式として代入。
                     numberformats = doc.getNumberFormats(
                     )  # ドキュメントのフォーマット一覧を取得。デフォルトのフォーマット一覧はCalcの書式→セル→数値でみれる。
                     if formatstring is not None:  # 書式が与えられている時。
                         locale = Locale(
                             Language="ja", Country="JP"
                         )  # フォーマット一覧をくくる言語と国を設定。インストールしていないUIの言語でもよい。。
                         formatkey = numberformats.queryKey(
                             formatstring, locale, True
                         )  # formatstringが既存のフォーマット一覧にあるか調べて取得。第3引数のブーリアンは意味はないはず。
                         if formatkey == -1:  # デフォルトのフォーマットにformatstringがないとき。
                             formatkey = numberformats.addNew(
                                 formatstring,
                                 locale)  # フォーマット一覧に追加する。保存はドキュメントごと。
                     selection.setPropertyValue("NumberFormat",
                                                formatkey)  # セルの書式を設定。
             for menuid in range(1,
                                 self.gridpopupmenu.getItemCount() +
                                 1):  # ポップアップメニューを走査する。
                 itemtext = self.gridpopupmenu.getItemText(
                     menuid)  # 文字列にはショートカットキーがついてくる。
                 if itemtext.startswith("セル入力で閉じる"):
                     if self.gridpopupmenu.isItemChecked(
                             menuid):  # 選択項目にチェックが入っている時。
                         self.dialogframe.close(True)
                     else:
                         controller = doc.getCurrentController(
                         )  # 現在のコントローラを取得。
                         sheet = controller.getActiveSheet()
                         celladdress = selection.getCellAddress()
                         nextcell = sheet[celladdress.Row + 1,
                                          celladdress.Column]  # 下のセルを取得。
                         controller.select(nextcell)  # 下のセルを選択。
                     break
     elif mouseevent.Buttons == MouseButton.RIGHT:  # 右ボタンクリックの時。mouseevent.PopupTriggerではサブジェクトによってはTrueにならないので使わない。
         pos = Rectangle(mouseevent.X, mouseevent.Y, 0,
                         0)  # ポップアップメニューを表示させる起点。
         self.gridpopupmenu.execute(gridcontrol.getPeer(), pos,
                                    PopupMenuDirection.EXECUTE_DEFAULT
                                    )  # ポップアップメニューを表示させる。引数は親ピア、位置、方向
예제 #7
0
    def executeDialogFromComponent(self, xComponent):
        if xComponent is not None:
            w = xComponent.ComponentWindow
            if w is not None:
                return self.executeDialog(w.PosSize)

        return self.executeDialog(Rectangle(0, 0, 640, 400))
예제 #8
0
def createWindow(toolkit, parent, service, attr, nX, nY, nWidth, nHeight):
    aRect = Rectangle(X=nX, Y=nY, Width=nWidth, Height=nHeight)
    d = WindowDescriptor(Type=SIMPLE,
                         WindowServiceName=service,
                         ParentIndex=-1,
                         Bounds=aRect,
                         Parent=parent,
                         WindowAttributes=attr)
    return toolkit.createWindow(d)
예제 #9
0
파일: unomenu2.py 프로젝트: p--q/GUI
 def mousePressed(self, mouseevent):  # マウスがクリックされた時。
     control, dummy_controlmodel, name = eventSource(mouseevent)
     if name == "FixedText1":  # コントロール名で限定。
         if mouseevent.PopupTrigger:  # 右クリックのとき
             pos = Rectangle(mouseevent.X, mouseevent.Y, 0,
                             0)  # ポップアップメニューを表示させる起点。
             self.popupmenu.execute(
                 control.getPeer(), pos,
                 EXECUTE_DEFAULT)  # ポップアップメニューを表示させる。引数は親ピア、位置、方向。
예제 #10
0
 def dispatch(self, URL, Arguments):
     smgr = self.context.getServiceManager()
     box = smgr.createInstanceWithContext( \
         "com.sun.star.awt.Toolkit", self.context).createMessageBox( \
             smgr.createInstanceWithContext( \
                 "com.sun.star.frame.Desktop", self.context). \
                 getCurrentFrame().getComponentWindow(), \
             Rectangle(), "infobox", BUTTONS_OK, "passive", "python")
     box.execute()
     box.dispose()
예제 #11
0
def macro():
    ctx = XSCRIPTCONTEXT.getComponentContext()  # コンポーネントコンテクストの取得。
    smgr = ctx.getServiceManager()  # サービスマネージャーの取得。
    doc = XSCRIPTCONTEXT.getDocument()  # マクロを起動した時のドキュメントのモデルを取得。
    docframe = doc.getCurrentController().getFrame(
    )  # モデル→コントローラ→フレーム、でドキュメントのフレームを取得。
    docwindow = docframe.getContainerWindow()
    toolkit = docwindow.getToolkit()
    dialog, addControl = dialogCreator(
        ctx, smgr, {
            "PositionX": 100,
            "PositionY": 100,
            "Width": 300,
            "Height": 200,
            "Title": "Splitter Example",
            "Name": "dialog",
            "Step": 0,
            "TabIndex": 0,
            "Moveable": True
        })
    dialog.createPeer(toolkit, docwindow)  # ダイアログを描画。
    dialogwindow = dialog.getPeer()  # ダイアログウィンドウを取得。
    addControl(
        "Edit", {
            "PositionX": 0,
            "PositionY": 0,
            "Width": 300,
            "Height": 99,
            "AutoVScroll": True,
            "MultiLine": True
        })
    addControl(
        "Edit", {
            "PositionX": 0,
            "PositionY": 105,
            "Width": 300,
            "Height": 96,
            "AutoVScroll": True,
            "MultiLine": True
        })
    rectangle = Rectangle(X=0, Y=100, Width=300, Height=5)  # 作成するウィンドウの位置と大きさ
    createWindow(
        toolkit, {
            "WindowServiceName": "splitter",
            "Bounds": rectangle,
            "Parent": dialogwindow,
            "WindowAttributes": SHOW + BORDER,
            "BackgroundColor": 0xEEEEEE,
            "Border": 1
        }, {"addMouseMotionListener": mouse_motion(dialog)
            })  # ダイアログの上にさらにウィンドウを作成する。
    # モードレスダイアグにするとき
    createFrame = frameCreator(ctx, smgr, docframe)
    createFrame("newFrame", dialogwindow)
    dialog.setVisible(True)
예제 #12
0
파일: myparts.py 프로젝트: ivanovev/myparts
 def part_move_cb(self):
     if not self.part_eq():
         return
     sht = self.get_sheet()
     shtn = self.get_sheet_names(['Labels', sht.Name])
     if not shtn:
         return
     index = self.get_selection()
     if index == None:
         return
     menu = self.createUnoService('com.sun.star.awt.PopupMenu')
     for i in range(0, len(shtn)):
         menu.insertItem(i+1, shtn[i], 0, i)
     listener = MenuListener(self.part_move)
     menu.addMenuListener(listener)
     rect = Rectangle()
     btnpos = self.move_to_btn.PosSize
     rect.X = btnpos.X + btnpos.Width/2
     rect.Y = btnpos.Y + btnpos.Height/2
     menu.execute(self.dlg.Peer, rect, EXECUTE_DEFAULT)
예제 #13
0
def macro():
	ctx = XSCRIPTCONTEXT.getComponentContext()  # コンポーネントコンテクストの取得。
	smgr = ctx.getServiceManager()  # サービスマネージャーの取得。
	doc = XSCRIPTCONTEXT.getDocument()  # マクロを起動した時のドキュメントのモデルを取得。
	docframe = doc.getCurrentController().getFrame()  # モデル→コントローラ→フレーム、でドキュメントのフレームを取得。
	docwindow = docframe.getContainerWindow()  # ドキュメントのウィンドウ(コンテナウィンドウ=ピア)を取得。
	toolkit = docwindow.getToolkit()  # ピアからツールキットを取得。
	taskcreator = smgr.createInstanceWithContext('com.sun.star.frame.TaskCreator', ctx)
	args = NamedValue("PosSize", Rectangle(100, 100, 530, 290)), NamedValue("FrameName", "ImageControlSample")  # , NamedValue("MakeVisible", True)  # TaskCreatorで作成するフレームのコンテナウィンドウのプロパティ。
	frame = taskcreator.createInstanceWithArguments(args)  # コンテナウィンドウ付きの新しいフレームの取得。
	window = frame.getContainerWindow()  # 新しいコンテナウィンドウを新しいフレームから取得。
	frame.setTitle("Image Viewer")  # フレームのタイトルを設定。
	docframe.getFrames().append(frame)  # 新しく作ったフレームを既存のフレームの階層に追加する。
	actionlistener = ActionListener(ctx, smgr, frame)  # ボタンにつけるリスナー。コントロールコンテナはコントロールが追加されてから取得する。
	margin_horizontal = 20  # 水平マージン
	margin_vertical = 13  # 垂直マージン
	window_width = 537  # ウィンドウ幅
	window_height = 287  # ウィンドウの高さ
	line_height = 23  # Editコントロールやボタンコントロールなどの高さ
	buttonfilepick_width = 56  # ButtonFilePickボタンの幅。
	buttonclose_width = 90  # ButtonCloseボタンの幅。
	radiobutton_width = 120  # RadioButtonの幅。
	datalabel_width = 200  # FixedText2、FixedText3の幅。
	minwidth = margin_horizontal*2+radiobutton_width+buttonfilepick_width+5  # Edit1の幅>=1を幅の下限値とする。
	minheight = margin_vertical*5+line_height*2+1  # ImageControlの高さ>=1を高さの下限値とする。
	minsizes = minwidth, minheight  # コントロールが潰れてしまうと次のリサイズの計算がおかしくなるので下限値を設定する。
	editcontrol_Y = window_height-(margin_vertical+line_height)*2  # Edit1のY。頻用値を取得しておく。
	imagecontrolmargins = margin_horizontal*2, margin_vertical*5+line_height*2  # ウィンドウサイズの幅高さ-イメージコントロールの幅高さを取得。
	itemlistener = ItemListener(toolkit, window, imagecontrolmargins)
	pathsubstservice = smgr.createInstanceWithContext("com.sun.star.comp.framework.PathSubstitution", ctx)
	uno_path = pathsubstservice.getSubstituteVariableValue("$(prog)")  # fileurlでprogramフォルダへのパスが返ってくる。
	fileurl = "{}/intro.png".format(uno_path)  # 画像ファイルへのfileurl
	imageurl = os.path.normpath(unohelper.fileUrlToSystemPath(fileurl))  # fileurlをシステム固有のパスに変換して正規化する。
	controlcontainer, addControl = controlcontainerCreator(ctx, smgr, {"PositionX": 0, "PositionY": 0, "Width": window_width, "Height": window_height, "BackgroundColor": 0xF0F0F0, "PosSize": POSSIZE})  # ウィンドウに表示させるコントロールコンテナを取得。BackgroundColor: -1は不可。
	imagecontrol1 = addControl("ImageControl", {"PositionX": margin_horizontal, "PositionY": margin_vertical, "Width": window_width-margin_horizontal*2, "Height": window_height-margin_vertical*5-line_height*2, "Border": 0, "ScaleImage": True, "ScaleMode": ISOTROPIC, "ImageURL": fileurl, "PosSize": POSSIZE})
	edit1 = addControl("Edit", {"PositionX": margin_horizontal+radiobutton_width+2, "PositionY": editcontrol_Y, "Width": window_width-margin_horizontal*2-radiobutton_width-buttonfilepick_width-4, "Height": line_height, "Text": imageurl, "PosSize": POSSIZE})
	button1 = addControl("Button", {"PositionX": window_width-margin_horizontal-buttonfilepick_width, "PositionY": editcontrol_Y, "Width": buttonfilepick_width, "Height": line_height, "Label": "~Browse", "PosSize": POSSIZE}, {"setActionCommand": "filepick" ,"addActionListener": actionlistener})  # PushButtonTypeは動かない。
	radiobutton1 = addControl("RadioButton", {"PositionX": margin_horizontal, "PositionY": editcontrol_Y, "Width": radiobutton_width, "Height": line_height, "Label": "~No Scaling", "PosSize": POSSIZE}, {"addItemListener": itemlistener})
	radiobutton2 = addControl("RadioButton", {"PositionX": margin_horizontal, "PositionY": editcontrol_Y+line_height+int((margin_vertical*2-line_height)/3), "Width": radiobutton_width, "Height": line_height, "Label": "~ISOTROPIC", "State": 1, "PosSize": POSSIZE}, {"addItemListener": itemlistener})
	radiobutton3 = addControl("RadioButton", {"PositionX": margin_horizontal, "PositionY": editcontrol_Y+(line_height+int((margin_vertical*2-line_height)/3))*2, "Width": radiobutton_width, "Height": line_height, "Label": "~ANISOTROPIC", "PosSize": POSSIZE}, {"addItemListener": itemlistener})
	imagecontrolrectangle = imagecontrol1.getPosSize()
	graphic = imagecontrol1.getModel().getPropertyValue("Graphic")  # イメージコントロールの画像を取得。
	graphicrectangle = graphic.getPropertyValue("SizePixel")  # 画像のオリジナルの大きさを取得。
	fixedtext1 = addControl("FixedText", {"PositionX": margin_horizontal+radiobutton_width+2, "PositionY":  editcontrol_Y+line_height+int((margin_vertical*2-line_height)/3), "Width": datalabel_width, "Height": line_height, "Label": "{} x {} px Image Size".format(graphicrectangle.Width, graphicrectangle.Height), "VerticalAlign": MIDDLE, "PosSize": POSSIZE})  # デフォルトでは"VerticalAlign": TOP、になっている。
	fixedtext2 = addControl("FixedText", {"PositionX": margin_horizontal+radiobutton_width+2, "PositionY": editcontrol_Y+(line_height+int((margin_vertical*2-line_height)/3))*2, "Width": datalabel_width, "Height": line_height, "Label": "{} x {} px Display Size".format(imagecontrolrectangle.Width, imagecontrolrectangle.Height), "VerticalAlign": MIDDLE, "PosSize": POSSIZE})
	button2 = addControl("Button", {"PositionX": window_width-margin_horizontal-buttonclose_width, "PositionY": window_height-margin_vertical-line_height, "Width": buttonclose_width, "Height": line_height, "Label": "~Close dialog", "PosSize": POSSIZE}, {"setActionCommand": "close" ,"addActionListener": actionlistener})  # PushButtonTypeは動かない。
	actionlistener.setControl(imagecontrol1, edit1, fixedtext1)  # getControl()で追加するコントロールが追加されてからコントロールコンテナを取得する。
	radiobuttons = radiobutton1, radiobutton2, radiobutton3
	itemlistener.setControl(imagecontrol1, radiobuttons)
	controlcontainer.createPeer(toolkit, window)  # ウィンドウにコントロールを描画。
	controlcontainer.setVisible(True)  # コントロールの表示。
	window.setVisible(True)  # ウィンドウの表示
	controls = controlcontainer, imagecontrol1, edit1, button1, button2, radiobutton1, radiobutton2, radiobutton3, fixedtext1, fixedtext2
	window.addWindowListener(WindowListener(controls, minsizes))  # setVisible(True)でも呼び出されるので、その後でリスナーを追加する。
예제 #14
0
 def mousePressed(
         self, mouseevent):  # グリッドコントロールをクリックした時。コントロールモデルにはNameプロパティはない。
     gridcontrol = mouseevent.Source  # グリッドコントロールを取得。
     griddatamodel = gridcontrol.getModel().getPropertyValue(
         "GridDataModel")  # GridDataModelを取得。
     if mouseevent.Buttons == MouseButton.LEFT:  # 左ボタンクリックの時。
         if mouseevent.ClickCount == 1:  # シングルクリックの時。
             selectedrowindexes = getSelectedRowIndexes(
                 gridcontrol)  # 選択行のリストを取得。
             if selectedrowindexes:  # 選択行がある時。
                 rowdata = griddatamodel.getRowData(
                     selectedrowindexes[0])  # 選択行の最初の行のデータを取得。
                 txt = rowdata[0]
             else:
                 txt = ""  # 選択行がない時は空文字にする。
             gridcontrol.getContext().getControl("Edit1").setText(
                 txt)  # テキストボックスに選択行の初行の文字列を代入。
         elif mouseevent.ClickCount == 2:  # ダブルクリックの時。
             doc = self.xscriptcontext.getDocument()
             selection = doc.getCurrentSelection()  # シート上で選択しているオブジェクトを取得。
             if selection.supportsService(
                     "com.sun.star.sheet.SheetCell"):  # 選択オブジェクトがセルの時。
                 j = gridcontrol.getCurrentRow()  # 選択行インデックス。負数が返ってくることがある。
                 if j < 0:  # 負数の時は何もしない。
                     return
                 rowdata = griddatamodel.getRowData(
                     j)  # グリッドコントロールで選択している行のすべての列をタプルで取得。
                 selection.setString(
                     rowdata[0])  # グリッドコントロールは1列と決めつけて、その最初の要素をセルに代入。
                 controller = doc.getCurrentController()  # 現在のコントローラを取得。
                 sheet = controller.getActiveSheet()
                 celladdress = selection.getCellAddress()
                 nextcell = sheet[celladdress.Row + 1,
                                  celladdress.Column]  # 下のセルを取得。
                 controller.select(nextcell)  # 下のセルを選択。
                 nexttxt = nextcell.getString()  # 下のセルの文字列を取得。
                 edit1 = gridcontrol.getContext().getControl(
                     "Edit1")  # テキストボックスコントロールを取得。
                 edit1.setText(nexttxt)  # テキストボックスコントロールにセルの内容を取得。
     elif mouseevent.Buttons == MouseButton.RIGHT:  # 右ボタンクリックの時。mouseevent.PopupTriggerではサブジェクトによってはTrueにならないので使わない。
         rowindex = gridcontrol.getRowAtPoint(
             mouseevent.X,
             mouseevent.Y)  # クリックした位置の行インデックスを取得。該当行がない時は-1が返ってくる。
         if rowindex > -1:  # クリックした位置に行が存在する時。
             if not gridcontrol.isRowSelected(
                     rowindex):  # クリックした位置の行が選択状態でない時。
                 gridcontrol.deselectAllRows()  # 行の選択状態をすべて解除する。
                 gridcontrol.selectRow(rowindex)  # 右クリックしたところの行を選択する。
             pos = Rectangle(mouseevent.X, mouseevent.Y, 0,
                             0)  # ポップアップメニューを表示させる起点。
             self.gridpopupmenu.execute(gridcontrol.getPeer(), pos,
                                        PopupMenuDirection.EXECUTE_DEFAULT
                                        )  # ポップアップメニューを表示させる。引数は親ピア、位置、方向
예제 #15
0
파일: tree.py 프로젝트: mattwilsoncp/MRI
 def mouseReleased(self, ev):
     if ev.Buttons == MB_RIGHT and ev.ClickCount == 1:
         if not self.popup:
             self.popup = self._create_popup()
             if not self.popup: return
         pos = ev.Source.getPosSize()
         if self.use_point:
             _pos = Point(pos.X + ev.X, pos.Y + ev.Y)
         else:
             _pos = Rectangle(pos.X + ev.X, pos.Y + ev.Y, 0, 0)
         n = self.popup.execute(ev.Source.getPeer(), _pos, 0)
         if n > 0:
             self.do_command(ev, n)
예제 #16
0
def _create_frame(self, ctx, smgr, ps):
    self.frame = smgr.createInstanceWithContext(
        'com.sun.star.frame.TaskCreator', ctx).createInstanceWithArguments(
        (NamedValue('FrameName', mytools_Mri.values.MRINAME), 
        NamedValue('PosSize', Rectangle(*ps))))
    frame = self.frame
    self.window = frame.getContainerWindow()
    desktop = smgr.createInstanceWithContext(
        'com.sun.star.frame.Desktop', ctx)
    frame.setTitle(create_window_name(desktop))
    frame.setCreator(desktop)
    desktop.getFrames().append(frame)
    return frame, self.window
예제 #17
0
 def mousePressed(
         self, mouseevent):  # グリッドコントロールをクリックした時。コントロールモデルにはNameプロパティはない。
     gridcontrol = mouseevent.Source  # グリッドコントロールを取得。
     if mouseevent.Buttons == MouseButton.LEFT:  # オプション表示しているときはダブルクリック、そうでない時はシングルクリックでセル入力する。
         selectedrowindexes = dialogcommons.getSelectedRowIndexes(
             gridcontrol)
         if mouseevent.ClickCount == 1:  # シングルクリックの時。
             if self.flg:
                 for menuid in range(1,
                                     self.gridpopupmenu.getItemCount() +
                                     1):  # ポップアップメニューを走査する。
                     itemtext = self.gridpopupmenu.getItemText(
                         menuid)  # 文字列にはショートカットキーがついてくる。
                     if itemtext.startswith("オプション表示"):
                         if not self.gridpopupmenu.isItemChecked(
                                 menuid):  # 選択項目にチェックが入っていない時。
                             if selectedrowindexes:  # 選択行がある時。
                                 self._toCell(
                                     gridcontrol, selectedrowindexes
                                 )  # オプション表示していない時はシングルクリックでセルに入力する。
                                 break
                 else:  # 選択項目にチェックが入っている時、オプション表示部分の設定。
                     if selectedrowindexes:  # 選択行がある時。
                         griddatamodel = gridcontrol.getModel(
                         ).getPropertyValue(
                             "GridDataModel")  # GridDataModelを取得。
                         rowdata = griddatamodel.getRowData(
                             selectedrowindexes[0])  # 選択行の最初の行のデータを取得。
                         txt = rowdata[0]
                     else:
                         txt = ""  # 選択行がない時は空文字にする。
                     self.optioncontrolcontainer.getControl(
                         "Edit1").setText(txt)  # テキストボックスに選択行の初行の文字列を代入。
             else:
                 self.flg = True
         elif mouseevent.ClickCount == 2:  # ダブルクリックの時。
             self._toCell(gridcontrol, selectedrowindexes)
     elif mouseevent.Buttons == MouseButton.RIGHT:  # 右ボタンクリックの時。mouseevent.PopupTriggerではサブジェクトによってはTrueにならないので使わない。
         rowindex = gridcontrol.getRowAtPoint(
             mouseevent.X,
             mouseevent.Y)  # クリックした位置の行インデックスを取得。該当行がない時は-1が返ってくる。
         if rowindex > -1:  # クリックした位置に行が存在する時。
             if not gridcontrol.isRowSelected(
                     rowindex):  # クリックした位置の行が選択状態でない時。
                 gridcontrol.deselectAllRows()  # 行の選択状態をすべて解除する。
                 gridcontrol.selectRow(rowindex)  # 右クリックしたところの行を選択する。
         pos = Rectangle(mouseevent.X, mouseevent.Y, 0,
                         0)  # ポップアップメニューを表示させる起点。
         self.gridpopupmenu.execute(gridcontrol.getPeer(), pos,
                                    PopupMenuDirection.EXECUTE_DEFAULT
                                    )  # ポップアップメニューを表示させる。引数は親ピア、位置、方向
    def createNewPreviewFrame(self, xMSF, listener):
        xToolkit = None
        try:
            xToolkit = xMSF.createInstance("com.sun.star.awt.Toolkit")
        except Exception:
            # TODO Auto-generated catch block
            traceback.print_exc()

        #describe the window and its properties
        aDescriptor = WindowDescriptor()
        aDescriptor.Type = TOP
        aDescriptor.WindowServiceName = "window"
        aDescriptor.ParentIndex = -1
        aDescriptor.Parent = None
        aDescriptor.Bounds = Rectangle(10, 10, 640, 480)

        #Set Window Attributes
        gnDefaultWindowAttributes = \
            com_sun_star_awt_WindowAttribute_BORDER + \
            com_sun_star_awt_WindowAttribute_MOVEABLE + \
            com_sun_star_awt_WindowAttribute_SIZEABLE + \
            com_sun_star_awt_VclWindowPeerAttribute_CLIPCHILDREN

        aDescriptor.WindowAttributes = gnDefaultWindowAttributes
        #create a new blank container window
        xPeer = None
        try:
            xPeer = xToolkit.createWindow(aDescriptor)
        except IllegalArgumentException:
            traceback.print_exc()

        #define some further properties of the frame window
        #if it's needed .-)
        #xPeer->setBackground(...);
        #create new empty frame and set window on it
        xFrame = None
        try:
            xFrame = xMSF.createInstance("com.sun.star.frame.Frame")
        except Exception:
            traceback.print_exc()

        xFrame.initialize(xPeer)
        #from now this frame is useable ...
        #and not part of the desktop tree.
        #You are alone with him .-)
        if listener is not None:
            Desktop.getDesktop(xMSF).addTerminateListener(
                TerminateListenerProcAdapter(listener))

        return xFrame
예제 #19
0
 def createPreviewFrame(self, xmsf, xControl):
     controlPeer = xControl.Peer
     r = xControl.PosSize
     toolkit = xmsf.createInstance("com.sun.star.awt.Toolkit")
     aDescriptor = WindowDescriptor()
     aDescriptor.Type = SIMPLE
     aDescriptor.WindowServiceName = "window"
     aDescriptor.ParentIndex = -1
     aDescriptor.Parent = controlPeer
     #xWindowPeer; #argument !
     aDescriptor.Bounds = Rectangle(0, 0, r.Width, r.Height)
     aDescriptor.WindowAttributes = CLIPCHILDREN | SHOW
     self.xWindow = toolkit.createWindow(aDescriptor)
     self.xFrame = xmsf.createInstance("com.sun.star.frame.Frame")
     self.xFrame.initialize(self.xWindow)
     self.xWindow.setVisible(True)
예제 #20
0
파일: grid.py 프로젝트: mattwilsoncp/MRI
 def mousePressed(self, ev):
     if ev.Buttons == MB_RIGHT and ev.ClickCount == 1:
         if not self.popup:
             self.popup = self._create_popup()
             if not self.popup: return
         
         grid_model = ev.Source.getModel()
         if grid_model.ShowColumnHeader:
             if hasattr(grid_model, "ColumnHeaderHeight"):
                 header_height = grid_model.ColumnHeaderHeight
             else:
                 header_height = grid_model.ColumnModel.ColumnHeaderHeight
             if header_height is None: header_height = 20
             if ev.Y <= header_height:
                 return
         try:
             index = self.cast.pages.get_active()
             if index == 0:
                 # properties
                 self._update_popup_states(((2, True), (4, True), (8, False), (512, True)))
                 properties_title = ('Name', 'Value Type', 'Value', 'Info.', 'Attr.')
                 copy_cell_popup = self.popup.getPopupMenu(512)
                 for i, label in zip(range(513, 518), properties_title):
                     copy_cell_popup.setItemText(i, label)
             elif index == 1:
                 # methods
                 self._update_popup_states(((2, False), (4, False), (8, True), (512, True)))
                 
                 methods_title = ('Name', 'Arguments', 'Return Type', 'Declaring Class', 'Exceptions')
                 copy_cell_popup = self.popup.getPopupMenu(512)
                 for i, label in zip(range(513, 518), methods_title):
                     copy_cell_popup.setItemText(i, label)
             else:
                 self._update_popup_states(((2, False), (4, False), (8, False), (512, False)))
             
             pos = ev.Source.getPosSize()
             if self.use_point:
                 _pos = Point(pos.X + ev.X, pos.Y + ev.Y)
             else:
                 _pos = Rectangle(pos.X + ev.X, pos.Y + ev.Y, 0, 0)
             n = self.popup.execute(ev.Source.getPeer(), _pos, 0)
             if n > 0:
                 self.do_command(n)
         except Exception as e:
             print(e)
예제 #21
0
def generateChart(sheetObj, sheetIndex, ID, rWidth, rHeight, rX, rY, 
        range, colHeader=False, rowHeader=False):
	
	# Selecting data range to process
	cr = sheetObj.getCellRangeByName(range).getRangeAddress()

	dataRange = []
	dataRange.append(cr)
	
	# Size of the graph
	rect = Rectangle(rX,rY,rWidth,rHeight)
	
	# Generating the chart
	charts = sheetObj.getCharts()
	# If a chart with this name exists, delete it
	removeChart('chart', charts)
	#charts.addNewByName(str(ID), rect, tuple(dataRange), colHeader, rowHeader)
	charts.addNewByName('chart', rect, tuple(dataRange), colHeader, rowHeader)
	return charts.getByName('chart')
예제 #22
0
def show_message(ctx,
                 frame,
                 message,
                 title="",
                 type="messbox",
                 buttons=1,
                 labels=None):
    """ Show text in message box. """
    try:
        peer = frame.getContainerWindow()
    except:
        peer = frame

    older_imple = check_method_parameter(
        ctx, "com.sun.star.awt.XMessageBoxFactory", "createMessageBox", 1,
        "com.sun.star.awt.Rectangle")

    if older_imple:
        box = peer.getToolkit().createMessageBox(peer, Rectangle(), type,
                                                 buttons, title, message)
    else:
        if type == "messbox":
            name = "MESSAGEBOX"
        elif type == "infobox":
            name = "INFOBOX"
        elif type == "warningbox":
            name = "WARNINGBOX"
        elif type == "errorbox":
            name = "ERRORBOX"
        elif type == "querybox":
            name = "QUERYBOX"
        type = uno.getConstantByName("com.sun.star.awt.MessageBoxType." + name)
        box = peer.getToolkit().createMessageBox(peer, type, buttons, title,
                                                 message)

    ws = box.getWindows()
    if labels and len(ws) == len(labels):
        for label, w in zip(labels, ws):
            w.Label = label

    n = box.execute()
    box.dispose()
    return n
예제 #23
0
def macro():  # オートメーションではリスナーが呼ばれない、閉じるボタンでウィンドウを閉じるとLibreOfficeがクラッシュする。
	ctx = XSCRIPTCONTEXT.getComponentContext()  # コンポーネントコンテクストの取得。
	smgr = ctx.getServiceManager()  # サービスマネージャーの取得。
	doc = XSCRIPTCONTEXT.getDocument()  # マクロを起動した時のドキュメントのモデルを取得。
	docframe = doc.getCurrentController().getFrame()  # モデル→コントローラ→フレーム、でドキュメントのフレームを取得。
	docwindow = docframe.getContainerWindow()  # ドキュメントのウィンドウ(コンテナウィンドウ=ピア)を取得。
	toolkit = docwindow.getToolkit()  # ツールキットを取得。
	taskcreator = smgr.createInstanceWithContext('com.sun.star.frame.TaskCreator', ctx)
	args = NamedValue("PosSize", Rectangle(100, 100, 500, 500)), NamedValue("FrameName", "NewFrame")  # , NamedValue("MakeVisible", True)  # TaskCreatorで作成するフレームのコンテナウィンドウのプロパティ。
	frame = taskcreator.createInstanceWithArguments(args)  # コンテナウィンドウ付きの新しいフレームの取得。
	window = frame.getContainerWindow()  # 新しいコンテナウィンドウを新しいフレームから取得。
	frame.setTitle("MenuBar Example")  # フレームのタイトルを設定。
	docframe.getFrames().append(frame)  # 新しく作ったフレームを既存のフレームの階層に追加する。
	createMenu = menuCreator(ctx, smgr)
	items = ("~First MenuBar Item", 0),\
			("~Second MenuBar Item", 0)  # メニューバーの項目。
	menubar = createMenu("MenuBar", items)  # メニューバーの作成。
	window.setMenuBar(menubar)
	menulistener = MenuListener(window, menubar)
	items = ("First Entry", CHECKABLE+AUTOCHECK, {"checkItem": True}),\
			("First Radio Entry", RADIOCHECK+AUTOCHECK, {"enableItem": False}),\
			("Second Radio Entry", RADIOCHECK+AUTOCHECK),\
			("Third Radio Entry", RADIOCHECK+AUTOCHECK, {"checkItem": True}),\
			(),\
			("Fifth Entry", CHECKABLE+AUTOCHECK),\
			("Fourth Entry", CHECKABLE+AUTOCHECK, {"checkItem": True}),\
			("Sixth Entry", 0),\
			("~Close", 0, {"setCommand": "close"})  # 追加するメニュー項目。空のタプルは区切り線。
	popupmenu =  createMenu("PopupMenu", items, {"addMenuListener": menulistener})  # ポップアップメニューの作成。
	menubar.setPopupMenu(1, popupmenu)
	items = ("First Entry", CHECKABLE+AUTOCHECK, {"checkItem": True}),\
			("Second Entry", 0)
	popupmenu =  createMenu("PopupMenu", items, {"addMenuListener": menulistener})  # ポップアップメニューの作成。
	menubar.setPopupMenu(2, popupmenu)
	controlcontainer, addControl = controlcontainerCreator(ctx, smgr, {"PositionX": 0, "PositionY": 0, "Width": 500, "Height": 500, "PosSize": POSSIZE})  # ウィンドウに表示させるコントロールコンテナを取得。
	addControl("FixedText", {"PositionX": 20, "PositionY": 20, "Width": 460, "Height": 460, "PosSize": POSSIZE, "Label": "\n".join(getStatus(menubar)), "NoLabel": True, "MultiLine": True})
	menulistener.control = controlcontainer.getControl("FixedText1")  # メニューリスナーにFiexedTextコントロールを渡す。
	controlcontainer.createPeer(toolkit, window)  # ウィンドウにコントロールを描画。
	controlcontainer.setVisible(True)  # コントロールの表示。
	window.setVisible(True)  # ウィンドウの表示。
예제 #24
0
def macro():
	ctx = XSCRIPTCONTEXT.getComponentContext()  # コンポーネントコンテクストの取得。
	smgr = ctx.getServiceManager()  # サービスマネージャーの取得。
	doc = XSCRIPTCONTEXT.getDocument()  # マクロを起動した時のドキュメントのモデルを取得。
	docframe = doc.getCurrentController().getFrame()  # モデル→コントローラ→フレーム、でドキュメントのフレームを取得。
	docwindow = docframe.getContainerWindow()  # ドキュメントのウィンドウ(コンテナウィンドウ=ピア)を取得。
	toolkit = docwindow.getToolkit()  # ピアからツールキットを取得。
	taskcreator = smgr.createInstanceWithContext('com.sun.star.frame.TaskCreator', ctx)
	args = NamedValue("PosSize", Rectangle(100, 100, 530, 290)), NamedValue("FrameName", "ImageControlSample")  # , NamedValue("MakeVisible", True)  # TaskCreatorで作成するフレームのコンテナウィンドウのプロパティ。
	frame = taskcreator.createInstanceWithArguments(args)  # コンテナウィンドウ付きの新しいフレームの取得。
	window = frame.getContainerWindow()  # 新しいコンテナウィンドウを新しいフレームから取得。
	frame.setTitle("Image Control Sample")  # フレームのタイトルを設定。
	docframe.getFrames().append(frame)  # 新しく作ったフレームを既存のフレームの階層に追加する。
	actionlistener = ActionListener(ctx, smgr, frame)  # ボタンにつけるリスナー。コントロールコンテナはコントロールが追加されてから取得する。
	margin_horizontal = 20  # 水平マージン
	margin_vertical = 13  # 垂直マージン
	window_width = 537  # ウィンドウ幅
	window_height = 287  # ウィンドウの高さ
	headerlabel_height = 36  # Headerlabelの高さ。
	line_height = 23  # Editコントロールやボタンコントロールの高さ
	buttonfilepick_width = 56  # ButtonFilePickボタンの幅。
	buttonclose_width = 114  # ButtonCloseボタンの幅。
	consts = margin_horizontal, margin_vertical, headerlabel_height, line_height, buttonfilepick_width, buttonclose_width  # リスナーに渡す用。
	pathsubstservice = smgr.createInstanceWithContext("com.sun.star.comp.framework.PathSubstitution", ctx)
	uno_path = pathsubstservice.getSubstituteVariableValue("$(prog)")  # fileurlでprogramフォルダへのパスが返ってくる。
	fileurl = "{}/intro.png".format(uno_path)  # 画像ファイルへのfileurl
	imageurl = os.path.normpath(unohelper.fileUrlToSystemPath(fileurl))  # fileurlをシステム固有のパスに変換して正規化する。
	controlcontainer, addControl = controlcontainerCreator(ctx, smgr, {"PositionX": 0, "PositionY": 0, "Width": window_width, "Height": window_height, "BackgroundColor": 0xF0F0F0, "PosSize": POSSIZE})  # ウィンドウに表示させるコントロールコンテナを取得。BackgroundColor: -1は透過色のもよう。
	fixedtext1 = addControl("FixedText", {"PositionX": margin_horizontal, "PositionY": margin_vertical, "Width": window_width-margin_horizontal*2, "Height": headerlabel_height, "Label": "This code-sample demonstrates how to create an ImageControlSample within a dialog.", "MultiLine": True, "PosSize": POSSIZE})
	imagecontrol1 = addControl("ImageControl", {"PositionX": margin_horizontal, "PositionY": margin_vertical*2+headerlabel_height, "Width": window_width-margin_horizontal*2, "Height": window_height-margin_vertical*5-line_height*2-headerlabel_height, "Border": 0, "ScaleImage": True, "ScaleMode": ISOTROPIC, "ImageURL": fileurl, "PosSize": POSSIZE})  # "ScaleImage": Trueで画像が歪む。
	edit1 = addControl("Edit", {"PositionX": margin_horizontal, "PositionY": window_height-margin_vertical*2-line_height*2, "Width": window_width-margin_horizontal*2-buttonfilepick_width-2, "Height": line_height, "Text": imageurl, "PosSize": POSSIZE})
	button1 = addControl("Button", {"PositionX": window_width-margin_horizontal-buttonfilepick_width, "PositionY": window_height-margin_vertical*2-line_height*2, "Width": buttonfilepick_width, "Height": line_height, "Label": "~Browse", "PosSize": POSSIZE}, {"setActionCommand": "filepick" ,"addActionListener": actionlistener})  # PushButtonTypeの値はEnumではエラーになる。
	button2 = addControl("Button", {"PositionX": (window_width-buttonclose_width)/2, "PositionY": window_height-margin_vertical-line_height, "Width": buttonclose_width, "Height": line_height, "Label": "~Close dialog", "PosSize": POSSIZE}, {"setActionCommand": "close" ,"addActionListener": actionlistener})  # PushButtonTypeは動かない。
	actionlistener.setControl(imagecontrol1, edit1)  # getControl()で追加するコントロールが追加されてからコントロールコンテナを取得する。
	controlcontainer.createPeer(toolkit, window)  # ウィンドウにコントロールを描画。
	controlcontainer.setVisible(True)  # コントロールの表示。
	window.setVisible(True)  # ウィンドウの表示。
	controls = controlcontainer, fixedtext1, imagecontrol1, edit1, button1, button2
	window.addWindowListener(WindowListener(controls, consts))  # setVisible(True)でも呼び出されるので、その後で実行する。
예제 #25
0
 def message(self, message, title="", type="messbox", buttons=1):
     """ Message box, see css.awt.XMessageBoxFactory. """
     import mytools_Mri.tools
     
     desktop = self.smgr.createInstanceWithContext(
         "com.sun.star.frame.Desktop", self.ctx)
     frame = desktop.getActiveFrame()
     window = frame.getContainerWindow()
     if mytools_Mri.tools.check_method_parameter(
         self.ctx, "com.sun.star.awt.XMessageBoxFactory", 
         "createMessageBox", 1, "com.sun.star.awt.Rectangle"):
         msgbox = window.getToolkit().createMessageBox(
             window, Rectangle(), type, buttons, title, message)
     else:
         import uno
         _type = uno.Enum("com.sun.star.awt.MessageBoxType", 
                         {"messbox": "MESSAGEBOX", "infobox": "INFOBOX", 
                          "warningbox": "WARNINGBOX", "errorbox": "ERRORBOX", 
                          "querybox": "QUERYBOX"}[type])
         msgbox = window.getToolkit().createMessageBox(
             window, _type, buttons, title, message)
     n = msgbox.execute()
     msgbox.dispose()
     return n
예제 #26
0
def create_window(toolkit, parent, wtype, service, attrs, x, y, width, height):
    return toolkit.createWindow(
        WindowDescriptor(wtype, service, parent, -1, 
        Rectangle(x, y, width, height), attrs))
예제 #27
0
 def mousePressed(
         self, mouseevent):  # グリッドコントロールをクリックした時。コントロールモデルにはNameプロパティはない。
     gridcontrol = mouseevent.Source  # グリッドコントロールを取得。
     optioncontrolcontainer = self.optioncontrolcontainer
     if mouseevent.Buttons == MouseButton.LEFT:
         if mouseevent.ClickCount == 1:  # シングルクリックの時。
             selectedrowindexes = getSelectedRowIndexes(gridcontrol)
             if not selectedrowindexes:  # 選択行がない時(選択行を削除した時)。
                 return  # 何もしない
             upbuttoncontrol = optioncontrolcontainer.getControl("Button1")
             downbuttoncontrol = optioncontrolcontainer.getControl(
                 "Button2")
             insertbuttoncontrol = optioncontrolcontainer.getControl(
                 "Button3")
             upbuttoncontrol.setEnable(True)  # まず全てのボタンを有効にする。
             downbuttoncontrol.setEnable(True)
             insertbuttoncontrol.setEnable(True)
             if selectedrowindexes[0] == 0:  # 先頭行が選択されている時。
                 upbuttoncontrol.setEnable(False)  # 上へボタンを無効にする。
             griddatamodel = gridcontrol.getModel().getPropertyValue(
                 "GridDataModel")
             if selectedrowindexes[
                     -1] == griddatamodel.RowCount - 1:  # 最終行が選択されている時。
                 downbuttoncontrol.setEnable(False)  # 下へボタンを無効にする。
             indexcount = len(selectedrowindexes)  # 選択行数を取得。
             if indexcount > 1:  # 複数行を選択している時。
                 insertbuttoncontrol.setEnable(False)  # 行挿入ボタンを無効にする。
                 if indexcount != selectedrowindexes[
                         -1] - selectedrowindexes[0] + 1:  # 連続した行でない時。
                     upbuttoncontrol.setEnable(False)  # 上へボタンを無効にする。
                     downbuttoncontrol.setEnable(False)  # 下へボタンを無効にする。
             rowdata = griddatamodel.getRowData(
                 selectedrowindexes[0])  # 選択行の最初の行のデータを取得。
             optioncontrolcontainer.getControl("Edit1").setText(
                 rowdata[0])  # テキストボックスに選択行の初行の文字列を代入。
             if griddatamodel.RowCount == 1:  # 1行しかない時はまた発火できるように選択を外す。
                 gridcontrol.deselectRow(
                     0)  # 選択行の選択を外す。選択していない行を指定すると永遠ループになる。
         elif mouseevent.ClickCount == 2:  # ダブルクリックの時。
             doc = self.xscriptcontext.getDocument()
             selection = doc.getCurrentSelection()  # シート上で選択しているオブジェクトを取得。
             if selection.supportsService(
                     "com.sun.star.sheet.SheetCell"):  # 選択オブジェクトがセルの時。
                 griddata = gridcontrol.getModel().getPropertyValue(
                     "GridDataModel")  # GridDataModelを取得。
                 rowdata = griddata.getRowData(gridcontrol.getCurrentRow(
                 ))  # グリッドコントロールで選択している行のすべての列をタプルで取得。
                 if optioncontrolcontainer.getControl("CheckBox1").getState(
                 ):  # セルに追記、にチェックがある時。グリッドコントロールは1列と決めつけて処理する。
                     selection.setString("".join(
                         [selection.getString(), rowdata[0]]))  # セルに追記する。
                 else:
                     selection.setString(rowdata[0])  # セルに代入。
                     controller = doc.getCurrentController(
                     )  # 現在のコントローラを取得。
                     sheet = controller.getActiveSheet()
                     celladdress = selection.getCellAddress()
                     nextcell = sheet[celladdress.Row + 1,
                                      celladdress.Column]  # 下のセルを取得。
                     controller.select(nextcell)  # 下のセルを選択。
             gridpopupmenu = self.gridpopupmenu
             for menuid in range(1,
                                 gridpopupmenu.getItemCount() +
                                 1):  # ポップアップメニューを走査する。
                 itemtext = gridpopupmenu.getItemText(
                     menuid)  # 文字列にはショートカットキーがついてくる。
                 if itemtext.startswith("セル入力で閉じる"):
                     if gridpopupmenu.isItemChecked(
                             menuid):  # 選択項目にチェックが入っている時。
                         self.dialogframe.close(True)
                         break
     elif mouseevent.Buttons == MouseButton.RIGHT:  # 右ボタンクリックの時。mouseevent.PopupTriggerではサブジェクトによってはTrueにならないので使わない。
         pos = Rectangle(mouseevent.X, mouseevent.Y, 0,
                         0)  # ポップアップメニューを表示させる起点。
         self.gridpopupmenu.execute(gridcontrol.getPeer(), pos,
                                    PopupMenuDirection.EXECUTE_DEFAULT
                                    )  # ポップアップメニューを表示させる。引数は親ピア、位置、方向
예제 #28
0
def create_window(ctx, args):
    """ Creates docking window.
        @param ctx component context
        @param args arguments passed by the window content factory manager.
        @return new docking window
    """
    def create(name):
        return ctx.getServiceManager().createInstanceWithContext(name, ctx)

    if not args: return None

    frame = None  # frame of parent document window
    for arg in args:
        name = arg.Name
        if name == "ResourceURL":
            if arg.Value != RESOURCE_URL:
                return None
        elif name == "Frame":
            frame = arg.Value

    if frame is None: return None  # ToDo: raise exception

    global current_locale

    # this dialog has no title and placed at the top left corner.
    dialog1 = "vnd.sun.star.extension://com.addon.autotextaddon/dialogs_autotext/Dialog1.xdl"
    window = None
    if True:
        ctx = uno.getComponentContext()
        smgr = ctx.ServiceManager

        try:
            ui_locale = gettext.translation(
                'base',
                localedir=get_main_directory("com.addon.autotextaddon") +
                'python/locales',
                languages=[getLanguage()])
        except Exception as e:
            ui_locale = gettext.translation(
                'base',
                localedir=get_main_directory("com.addon.autotextaddon") +
                'python/locales',
                languages=["en"])

        ui_locale.install()
        _ = ui_locale.gettext
        toolkit = create("com.sun.star.awt.Toolkit")
        parent = frame.getContainerWindow()

        # Creates outer window
        # title name of this window is defined in WindowState configuration.
        desc = WindowDescriptor(
            SIMPLE, "window", parent, 0, Rectangle(0, 0, 400, 400),
            SHOW | SIZEABLE | MOVEABLE | CLOSEABLE | CLIPCHILDREN)
        window = toolkit.createWindow(desc)

        # Create inner window from dialog
        dp = create("com.sun.star.awt.ContainerWindowProvider")
        child = dp.createContainerWindow(dialog1, "", window, None)

        psm = uno.getComponentContext().ServiceManager
        dps = psm.createInstance("com.sun.star.text.AutoTextContainer")

        oRange = dps.getByName(current_group)
        ctx = uno.getComponentContext()
        smgr = ctx.ServiceManager

        # Initialize Dialog items

        #Initialize listeners
        action_listener = ActionListener(ctx, child)
        mouse_listener = MouseListener(ctx)

        # Autotext Listbox
        Autotext_Label = child.getControl("LabelListbox")
        Autotext_Label.Text = _("Auto Texts")

        GroupLabel = child.getControl("GroupLabel")
        GroupLabel.Text = _("Group")

        Preview_Label = child.getControl("LabelPreview")
        Preview_Label.Text = _("Preview")

        Autotext_ListBox = child.getControl("SavedAutotext")

        # there should be sorted entries by title and not name!

        Autotext_ListBox.addItems(update_auto_list(oRange), 0)

        Autotext_ListBox.addMouseListener(mouse_listener)
        #xray(smgr,ctx,Autotext_ListBox)
        OK_Button = child.getControl("OKButton")
        OK_Button.addActionListener(action_listener)
        OK_Button.setActionCommand('InsertAutoText')
        OK_Button.Label = _("Insert")

        AddSelection_Button = child.getControl("AddSelectionButton")
        AddSelection_Button.addActionListener(action_listener)
        AddSelection_Button.setActionCommand('AddSelectedAutoText')
        AddSelection_Button.Label = _("Add Selection")

        More_Button = child.getControl("MoreButton")
        More_Button.addActionListener(action_listener)
        More_Button.setActionCommand('MoreDispatch')
        More_Button.Label = _("More...")

        TeamList = child.getControl("GroupListBox")
        TeamList.addActionListener(ListBoxActionListener(ctx, child))

        global groups_to_insert
        global group_ids
        group_ids = dps.getElementNames()

        groups_to_insert = []

        for x in group_ids:
            groups_to_insert[len(groups_to_insert):] = [dps.getByName(x).Title]

        TeamList.addItems(groups_to_insert, 0)
        TeamList.getModel().SelectedItems = [group_ids.index(current_group)]

        child.setVisible(True)

        window.addWindowListener(WindowResizeListener(child))

        #child.setPosSize(0, 0, 0, 0, POS)  # if the dialog is not placed at
        # top left corner

    return window
예제 #29
0
 def mousePressed(
         self, mouseevent):  # グリッドコントロールをクリックした時。コントロールモデルにはNameプロパティはない。
     xscriptcontext, formatstring, outputcolumn, callback = self.args
     gridcontrol = mouseevent.Source  # グリッドコントロールを取得。
     if mouseevent.Buttons == MouseButton.LEFT:
         if mouseevent.ClickCount == 1:  # シングルクリックでセルに入力する。
             if self.flg:
                 closeflg = False  # ダイアログを閉じた時に立てるフラグ。
                 doc = xscriptcontext.getDocument()
                 selection = doc.getCurrentSelection(
                 )  # シート上で選択しているオブジェクトを取得。
                 if selection.supportsService(
                         "com.sun.star.sheet.SheetCell"):  # 選択オブジェクトがセルの時。
                     sheet = selection.getSpreadsheet()
                     rowindexes = dialogcommons.getSelectedRowIndexes(
                         gridcontrol
                     )  # グリッドコントロールの選択行インデックスを返す。昇順で返す。負数のインデックスがある時は要素をクリアする。
                     if rowindexes:
                         for menuid in range(
                                 1,
                                 self.gridpopupmenu.getItemCount() +
                                 1):  # ポップアップメニューを走査する。
                             itemtext = self.gridpopupmenu.getItemText(
                                 menuid)  # 文字列にはショートカットキーがついてくる。
                             if itemtext.startswith("セル入力で閉じる"):
                                 if self.gridpopupmenu.isItemChecked(
                                         menuid):  # 選択項目にチェックが入っている時。
                                     self.dialogframe.close(
                                         True
                                     )  # 用が終わったらさっさと閉じないとその前にブレークや例外がでるとマウスが使えなくなる。
                                     closeflg = True
                         datetxt = gridcontrol.getModel().getPropertyValue(
                             "GridDataModel").getCellData(
                                 1, rowindexes[0])  # 選択行の日付文字列を取得。
                         if outputcolumn is not None:  # 出力する列が指定されている時。
                             selection = sheet[
                                 selection.getCellAddress().Row,
                                 outputcolumn]  # 同じ行の指定された列のセルを取得。
                         if formatstring is not None:  # 書式が与えられている時。
                             numberformats = doc.getNumberFormats(
                             )  # ドキュメントのフォーマット一覧を取得。デフォルトのフォーマット一覧はCalcの書式→セル→数値でみれる。
                             localestruct = Locale(
                                 Language="ja", Country="JP"
                             )  # フォーマット一覧をくくる言語と国を設定。インストールしていないUIの言語でもよい。
                             formatkey = numberformats.queryKey(
                                 formatstring, localestruct, True
                             )  # formatstringが既存のフォーマット一覧にあるか調べて取得。第3引数のブーリアンは意味はないはず。
                             if formatkey == -1:  # デフォルトのフォーマットにformatstringがないとき。
                                 formatkey = numberformats.addNew(
                                     formatstring, localestruct
                                 )  # フォーマット一覧に追加する。保存はドキュメントごと。
                             selection.setPropertyValue(
                                 "NumberFormat", formatkey)  # セルの書式を設定。
                         datetxt = datetxt.split("(")[
                             0]  # 2018-8-7という書式にする。
                         selection.setFormula(
                             datetxt)  # 2018-8-7の書式で式としてセルに代入。
                         if callback is not None:  # コールバック関数が与えられている時。
                             try:
                                 callback(datetxt)
                             except:  # これをしないとエラーダイアログが出てこない。
                                 exceptiondialog2.createDialog(
                                     xscriptcontext)  # XSCRIPTCONTEXTを渡す。
                         if not closeflg:  # ダイアログが閉じられていない時。
                             celladdress = selection.getCellAddress()
                             nextcell = sheet[
                                 celladdress.Row + 1,
                                 celladdress.Column]  # 下のセルを取得。
                             doc.getCurrentController().select(
                                 nextcell)  # 下のセルを選択。
             else:
                 self.flg = True
     elif mouseevent.Buttons == MouseButton.RIGHT:  # 右ボタンクリックの時。mouseevent.PopupTriggerではサブジェクトによってはTrueにならないので使わない。
         pos = Rectangle(mouseevent.X, mouseevent.Y, 0,
                         0)  # ポップアップメニューを表示させる起点。
         self.gridpopupmenu.execute(gridcontrol.getPeer(), pos,
                                    PopupMenuDirection.EXECUTE_DEFAULT
                                    )  # ポップアップメニューを表示させる。引数は親ピア、位置、方向
def create_dockable_window(ctx, args):
    """ Creates docking window.
        @param ctx component context
        @param args arguments passed by the window content factory manager.
        @return new docking window
    """
    def create(name):
        return ctx.getServiceManager().createInstanceWithContext(name, ctx)

    if not args:
        return None

    frame = None  # frame of parent document window
    for arg in args:
        name = arg.Name
        if name == "ResourceURL":
            if arg.Value != RESOURCE_URL:
                return None
        elif name == "Frame":
            frame = arg.Value

    if frame is None:
        return None  # ToDo: raise exception

    # this dialog has no title and is placed at the top left corner.
    dialog1 = "vnd.sun.star.extension://tud.mci.tangram.Properties.DockingWindow/TitleDescDialog.xdl"
    window = None
    if True:
        try:
            toolkit = create("com.sun.star.awt.Toolkit")
            parent = frame.getContainerWindow()

            # Creates outer window (title name of this window is defined in WindowState configuration)
            desc = WindowDescriptor(
                SIMPLE, "window", parent, 0, Rectangle(0, 0, 100, 120),
                SHOW | SIZEABLE | MOVEABLE | CLOSEABLE | CLIPCHILDREN)
            window = toolkit.createWindow(desc)

            # Create inner window from dialog
            dp = create("com.sun.star.awt.ContainerWindowProvider")
            child = dp.createContainerWindow(dialog1, "", window, None)
            child.setVisible(True)
            child.setPosSize(
                0, 0, 0, 0,
                POS)  # if the dialog is not placed at top left corner

            window.addWindowListener(WindowResizeListener(child, window))

            controller = frame.getController()
            controller.addSelectionChangeListener(
                SelectionChangeListener(child, controller))

            tf_title = child.getControl("TextField_Title")
            listener1 = EditListener(1, controller, tf_title, child)
            tf_title.addKeyListener(listener1)
            tf_title.addFocusListener(listener1)
            tf_title.addTextListener(listener1)
            no_selection_text = tf_title.getText()

            tf_desc = child.getControl("TextField_Desc")
            listener2 = EditListener(2, controller, tf_desc, child)
            tf_desc.addKeyListener(listener2)
            tf_desc.addFocusListener(listener2)
            tf_desc.addTextListener(listener2)

            btn_save = child.getControl("CommandButton_Save")
            listener3 = ButtonListener(3, controller, child)
            btn_save.addActionListener(listener3)

            tf_title.setEnable(False)
            tf_desc.setEnable(False)
            btn_save.setEnable(False)
            tf_title.setText(str(no_selection_text))
            tf_desc.setText(str(no_selection_text))

        except Exception as e:
            print(e)
            #ctypes.windll.user32.MessageBoxA(0, str(e), "dialog add error", 1)

    return window
예제 #31
0
def createWindow(toolkit, attr, props):  # ウィンドウタイトルは変更できない。attrはcom.sun.star.awt.WindowAttributeの和。propsはPositionX, PositionY, Width, Height, ParentIndex。
    aRect = Rectangle(X=props.pop("PositionX"), Y=props.pop("PositionY"), Width=props.pop("Width"), Height=props.pop("Height"))
    d = WindowDescriptor(Bounds=aRect, WindowAttributes=attr)
    for key, val in props.items():
        setattr(d, key, val)
    return toolkit.createWindow(d)  # ウィンドウピアを返す。