PySide/ja: Difference between revisions

From FreeCAD Documentation
(Created page with "彼らは主題を3つの部分に分け、PySide、PythonそしてFreeCAD内部への露出のレベルによって区別しました。最初のページには概要と背...")
(Updating to match new version of source page)
 
(26 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
<H2>PySide</H2>


{{Docnav
[http://en.wikipedia.org/wiki/PySide PySide]はクロスプラットフォームのGUIツールキットQtのPythonバインディングです。 FreeCADはPython内部のすべてのGUI(Graphic User Interface)目的にPySideを使用します。 PySideは、以前にFreeCADによってGUIに使用されていたPyQtパッケージに代わるものです。 PySideはより許容されるライセンスを持っています。 違いの詳細については[http://qt-project.org/wiki/Differences_Between_PySide_and_PyQt PySideとPyQtの違い]を参照してください。
|[[Pivy|Pivy]]
|[[Interface_creation|Interface creation]]
}}


{{TOCright}}
FreeCAD内部からPyQtモジュールを使用することでFreeCADのインターフェイスを完全に制御することができます。例えば以下のことを行うことができます。
* 独自のパネル、ウィジット、ツールバーの追加
* 既存のパネルへの要素の追加や非表示
* 全ての要素の間のコネクションに対する変更、リダイレクト、追加


<span id="Introduction"></span>
PyQtには豊富な[http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/classes.html APIドキュメント]があり、またネット上にはどの様にそれが動作するのか教えてくれるチュートリアルがたくさんあります。
<div class="mw-translate-fuzzy">
<H2>PySide</H2>
</div>


<div class="mw-translate-fuzzy">
もしFreeCADインターフェイスをいじりたいのであれば一番最初にやるべきことはFreeCADのメインウィンドウの参照を作成することです:
[http://en.wikipedia.org/wiki/PySide PySide]はクロスプラットフォームのGUIツールキットQtのPythonバインディングです。 FreeCADはPython内部のすべてのGUI(Graphic User Interface)目的にPySideを使用します。 PySideは、以前にFreeCADによってGUIに使用されていたPyQtパッケージに代わるものです。 PySideはより許容されるライセンスを持っています。 違いの詳細については[http://qt-project.org/wiki/Differences_Between_PySide_and_PyQt PySideとPyQtの違い]を参照してください。
</div>


When you install FreeCAD, you should get both Qt and PySide as part of the package. If you are [[Compiling|compiling]] yourself then you must verify that these two libraries are installed in order for FreeCAD to run correctly. Of course, PySide will only work if Qt is present.
import sys
from PyQt4 import QtGui
app = QtGui.qApp
mw = app.activeWindow()


In the past, FreeCAD used PyQt, another Qt binding for Python, but in 2013 ([https://github.com/FreeCAD/FreeCAD/commit/1dc122dc9a commit 1dc122dc9a]) the project migrated to PySide because it has a more permissible [[License|License]].
すると例えばインターフェイスの全てのウィジットをブラウジングすることなどができるようになります:


For more information see:
for child in mw.children():
* [https://en.wikipedia.org/wiki/PySide Wikipedia:PySide]
print 'widget name = ', child.objectName(), ', widget type = ', child
* [https://wiki.qt.io/Differences_Between_PySide_and_PyQt Differences Between PySide and PyQt]


[[File:PySideScreenSnapshot1.jpg]] [[File:PySideScreenSnapshot2.jpg]]
Qtインターフェイスのウィジットは普通、"コンテナ"ウィジット内に入れ子状態になっています。つまりメインウィンドウの子ウィンドウ自体も他の子ウィンドウを収納できるのです。ウィジットのタイプによって行えることは様々です。何ができるのかについてはAPIドキュメントをチェックしてください。
{{Caption|Examples created with PySide. Left: a simple dialog. Right: a more complex dialog with graphs.}}


==PySide in FreeCAD with Qt5==
新しいウィジットの追加には例えばdockWidget(FreeCADのサイドパネルの一つに配置できます)が便利です:


FreeCAD was developed to be used with Python 2 and Qt4. As these two libraries became obsolete, FreeCAD transitioned to Python 3 and Qt5. In most cases this transition was done without needing to break backwards compatibility.
myWidget = QtGui.QDockWidget()
mw.addDockWidget(QtCore.Qt.RightDockWidgetArea,myWidget)


Normally, the {{incode|PySide}} module provides support for Qt4, while {{incode|PySide2}} provides support for Qt5. However, in FreeCAD there is no need to use {{incode|PySide2}} directly, as a special {{incode|PySide}} module is included to handle Qt5.
さらにいろいろなものをウィジットに直接追加できます:


This {{incode|PySide}} module is located in the {{incode|Ext/}} directory of an installation of FreeCAD compiled for Qt5.
myWidget.setObjectName("my Nice New Widget")
{{Code|code=
myWidget.resize(QtCore.QSize(300,100)) # ウィジットのサイズ設定
/usr/share/freecad/Ext/PySide
label = QtGui.QLabel("Hello World", myWidget) # ラベルを作成
}}
label.setGeometry(QtCore.QRect(50,50,200,24)) # そのサイズを設定
label.setObjectName("myLabel") # 名前を設定することで名前を使って検索できるようにします


This module just imports the necessary classes from {{incode|PySide2}}, and places them in the {{incode|PySide}} namespace. This means that in most cases the same code can be used with both Qt4 and Qt5, as long as we use the single {{incode|PySide}} module.
しかしよく好まれる方法は一度にウィジットの設定を全て行えるUIオブジェクトの作成です。この方法の大きな利点はQt Designerを使うことでこういったUIオブジェクトを[[Dialog creation/jp|グラフィカルな方法]]で作成できるということです。Qt Designerによって生成された標準的なオブジェクトは以下のようになります:
{{Code|code=

PySide2.QtCore -> PySide.QtCore
class myWidget_Ui(object):
PySide2.QtGui -> PySide.QtGui
def setupUi(self, myWidget):
PySide2.QtSvg -> PySide.QtSvg
myWidget.setObjectName("my Nice New Widget")
PySide2.QtUiTools -> PySide.QtUiTools
myWidget.resize(QtCore.QSize(300,100).expandedTo(myWidget.minimumSizeHint())) # ウィジットのサイズを設定
}}
self.label = QtGui.QLabel(myWidget) # ラベルを作成
self.label.setGeometry(QtCore.QRect(50,50,200,24)) # そのサイズを設定
self.label.setObjectName("label") # 名前を設定することで名前を使って検索できるようにします
def retranslateUi(self, draftToolbar): # ウィジットの翻訳を管理する組み込みのQt関数
myWidget.setWindowTitle(QtGui.QApplication.translate("myWidget", "My Widget", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("myWidget", "Welcome to my new widget!", None, QtGui.QApplication.UnicodeUTF8))

使用するには以下のようにして新しく作成したウィジットに適用するだけで構いません:


The only unusual aspect is that the {{incode|PySide2.QtWidgets}} classes are placed in the {{incode|PySide.QtGui}} namespace.
myNewFreeCADWidget = QtGui.QDockWidget() # 新しいウィジットを作成
myNewFreeCADWidget.ui = myWidget_Ui() # UIスクリプトをロード
myNewFreeCADWidget.ui.setupUi(myNewFreeCADWidget) # UIを設定
FCmw.addDockWidget(QtCore.Qt.RightDockWidgetArea,myNewFreeCADWidget) # メインウィンドウにウィジットを追加
{{Code|code=
{{Code|code=
PySide2.QtWidgets.QCheckBox -> PySide.QtGui.QCheckBox
print 'Hello World'
}}
}}
{{Top}}
With Python's print statement you have only limited control of the appearance and behaviour. PySide supplies the missing control and also handles environments (such as the FreeCAD macro file environment) where the built-in facilities of Python are not enough.
==Examples of PySide use==


<div class="mw-translate-fuzzy">
PySide's abilities range from:
* [[PySide_Beginner_Examples|Beginner PySide Examples]] ( Hello World、お知らせ、テキストを入力、番号を入力
* [[PySide_Intermediate_Examples|PySide Intermediate Examples]] (ウィンドウのサイズ変更、ウィジェットの非表示、ポップアップメニュー、マウスの位置、マウスイベント)
* [[PySide_Advanced_Examples|Advanced PySide Examples]] (ウィジェットなど)
</div>


<div class="mw-translate-fuzzy">
[[File:PySideScreenSnapshot1.jpg]]
彼らは主題を3つの部分に分け、PySide、PythonそしてFreeCAD内部への露出のレベルによって区別しました。最初のページには概要と背景資料があり、PySideとそのまとめ方について説明していますが、2ページ目と3ページ目は、ほとんどが異なるレベルのコード例です。

</div>
to:


<div class="mw-translate-fuzzy">
[[File:PySideScreenSnapshot2.jpg]]
その意図は、問題に取り組むユーザがコードを簡単にコピーして自分の作業に貼り付け、必要に応じてそれを修正し、FreeCADによる問題解決に戻ることができるように、関連ページがPySideを実行する単純なPythonコードを提供することです。うまくいけば、彼らはPySideの質問に対する答えを探すためにインターネットを越えて追いかけに行く必要はありません。同時にこのページは、Web上で利用可能なさまざまな包括的なPySideチュートリアルと参照サイトを置き換えることを意図していません。
</div>
{{Top}}
==Documentation==


There are some differences in handling of widgets in Qt4 (PySide) and Qt5 (PySide2). The programmer should be aware of these incompatibilities, and should consult the official documentation if something doesn't seem to work as expected on a given platform. Nevertheless, Qt4 is considered obsolete, so most development should target Qt5 and Python 3.
PySideは次の3ページで説明されていますが、それらは相互に従う必要があります。

* [[PySide_Beginner_Examples|Beginner PySide Examples]] (Hello World, announcements, enter text, enter number)
* [[PySide_Medium_Examples|Medium PySide Examples]] (window sizing, hiding widgets, popup menus, mouse position, mouse events)
* [[PySide_Advanced_Examples|Advanced PySide Examples]] (widgets etc.)

彼らは主題を3つの部分に分け、PySide、PythonそしてFreeCAD内部への露出のレベルによって区別しました。最初のページには概要と背景資料があり、PySideとそのまとめ方について説明していますが、2ページ目と3ページ目は、ほとんどが異なるレベルのコード例です。


The PySide documentation refers to the Python-style classes; however, since Qt is originally a C++ library, the same information should be available in the corresponding C++ reference.
The intention is that the associated pages will provide simple Python code to run PySide so that the user working on a problem can easily copy the code, paste it into their own work, adapt it as necessary and return to their problem solving with FreeCAD. Hopefully they don't have to go chasing off across the internet looking for answers to PySide questions. At the same time this page is not intended to replace the various comprehensive PySide tutorials and reference sites available on the web.
* [https://doc.qt.io/qtforpython/modules.html Qt Modules] available from PySide2 (Qt5).
* [https://doc.qt.io/qt-5/modules-cpp.html All Qt classes by module] in Qt5 for C++.
* [https://deptinfo-ensip.univ-poitiers.fr/ENS/pyside-docs/index.html Qt Modules] available from PySide (Qt4).
{{Top}}


<div class="mw-translate-fuzzy">
{{docnav|Pivy|Scripted objects}}
{{docnav|Pivy|Scripted objects}}
</div>


{{Powerdocnavi{{#translation:}}}}
[[Category:Poweruser Documentation]]
[[Category:Developer Documentation{{#translation:}}]]
{{clear}}
[[Category:Python Code{{#translation:}}]]

Latest revision as of 16:26, 4 April 2024

PySide

PySideはクロスプラットフォームのGUIツールキットQtのPythonバインディングです。 FreeCADはPython内部のすべてのGUI(Graphic User Interface)目的にPySideを使用します。 PySideは、以前にFreeCADによってGUIに使用されていたPyQtパッケージに代わるものです。 PySideはより許容されるライセンスを持っています。 違いの詳細についてはPySideとPyQtの違いを参照してください。

When you install FreeCAD, you should get both Qt and PySide as part of the package. If you are compiling yourself then you must verify that these two libraries are installed in order for FreeCAD to run correctly. Of course, PySide will only work if Qt is present.

In the past, FreeCAD used PyQt, another Qt binding for Python, but in 2013 (commit 1dc122dc9a) the project migrated to PySide because it has a more permissible License.

For more information see:

Examples created with PySide. Left: a simple dialog. Right: a more complex dialog with graphs.

PySide in FreeCAD with Qt5

FreeCAD was developed to be used with Python 2 and Qt4. As these two libraries became obsolete, FreeCAD transitioned to Python 3 and Qt5. In most cases this transition was done without needing to break backwards compatibility.

Normally, the PySide module provides support for Qt4, while PySide2 provides support for Qt5. However, in FreeCAD there is no need to use PySide2 directly, as a special PySide module is included to handle Qt5.

This PySide module is located in the Ext/ directory of an installation of FreeCAD compiled for Qt5.

/usr/share/freecad/Ext/PySide

This module just imports the necessary classes from PySide2, and places them in the PySide namespace. This means that in most cases the same code can be used with both Qt4 and Qt5, as long as we use the single PySide module.

PySide2.QtCore -> PySide.QtCore
PySide2.QtGui -> PySide.QtGui
PySide2.QtSvg -> PySide.QtSvg
PySide2.QtUiTools -> PySide.QtUiTools

The only unusual aspect is that the PySide2.QtWidgets classes are placed in the PySide.QtGui namespace.

PySide2.QtWidgets.QCheckBox -> PySide.QtGui.QCheckBox

Top

Examples of PySide use

彼らは主題を3つの部分に分け、PySide、PythonそしてFreeCAD内部への露出のレベルによって区別しました。最初のページには概要と背景資料があり、PySideとそのまとめ方について説明していますが、2ページ目と3ページ目は、ほとんどが異なるレベルのコード例です。

その意図は、問題に取り組むユーザがコードを簡単にコピーして自分の作業に貼り付け、必要に応じてそれを修正し、FreeCADによる問題解決に戻ることができるように、関連ページがPySideを実行する単純なPythonコードを提供することです。うまくいけば、彼らはPySideの質問に対する答えを探すためにインターネットを越えて追いかけに行く必要はありません。同時にこのページは、Web上で利用可能なさまざまな包括的なPySideチュートリアルと参照サイトを置き換えることを意図していません。

Top

Documentation

There are some differences in handling of widgets in Qt4 (PySide) and Qt5 (PySide2). The programmer should be aware of these incompatibilities, and should consult the official documentation if something doesn't seem to work as expected on a given platform. Nevertheless, Qt4 is considered obsolete, so most development should target Qt5 and Python 3.

The PySide documentation refers to the Python-style classes; however, since Qt is originally a C++ library, the same information should be available in the corresponding C++ reference.

Top

Pivy
Scripted objects