# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'toggleDir.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
dir = 'rtl'
try:
_fromUtf8
= QtCore.
QString.
fromUtf8except AttributeError:
def _fromUtf8(s):
return s
try:
def _translate(context, text, disambig):
return QtGui.
QApplication.
translate(context, text, disambig, _encoding
) except AttributeError:
def _translate(context, text, disambig):
return QtGui.
QApplication.
translate(context, text, disambig
)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(350, 350)
MainWindow.
setMinimumSize(QtCore.
QSize(350,
350)) MainWindow.
setMaximumSize(QtCore.
QSize(350,
350)) self.
centralwidget = QtGui.
QWidget(MainWindow
) self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.
verticalLayout = QtGui.
QVBoxLayout(self.
centralwidget) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.fontName.setObjectName(_fromUtf8("fontName"))
self.horizontalLayout.addWidget(self.fontName)
self.
fontSize = QtGui.
QSpinBox(self.
centralwidget) self.fontSize.setProperty("value", 11)
self.fontSize.setObjectName(_fromUtf8("fontSize"))
self.horizontalLayout.addWidget(self.fontSize)
self.verticalLayout.addLayout(self.horizontalLayout)
self.
edit = QtGui.
QTextEdit(self.
centralwidget) self.edit.setObjectName(_fromUtf8("edit"))
self.edit.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.verticalLayout.addWidget(self.edit)
self.
toggleDirBtn = QtGui.
QPushButton(self.
centralwidget) font.setPointSize(15)
self.toggleDirBtn.setFont(font)
self.toggleDirBtn.setObjectName(_fromUtf8("toggleDirBtn"))
self.verticalLayout.addWidget(self.toggleDirBtn)
MainWindow.setCentralWidget(self.centralwidget)
option=self.edit.document().defaultTextOption()
option.setTextDirection(QtCore.Qt.RightToLeft)
self.edit.document().setDefaultTextOption(option)
self.edit.setLayoutDirection(QtCore.Qt.RightToLeft) #switch scrollerbar
self.edit.setTabStopWidth(33) #set tab size for editor
self.fontName.currentFontChanged.connect(self._fontName)
self.fontSize.valueChanged.connect(self._fontSize)
self.toggleDirBtn.clicked.connect(self._toggleDir)
self.retranslateUi(MainWindow)
def _fontName(self):
font.setFamily(self.fontName.currentText())
font.setPointSize(int(self.fontSize.value()))
self.edit.setFont(font)
self.edit.setFocus()
def _fontSize(self):
font.setFamily(self.fontName.currentText())
font.setPointSize(int(self.fontSize.value()))
self.edit.setFont(font)
self.edit.setFocus()
def _toggleDir(self):
global dir
if dir == 'rtl':
option=self.edit.document().defaultTextOption()
option.setTextDirection(QtCore.Qt.LeftToRight)
self.edit.document().setDefaultTextOption(option)
self.edit.setLayoutDirection(QtCore.Qt.LeftToRight) #switch scrollerbar
dir = 'ltr'
else:
option=self.edit.document().defaultTextOption()
option.setTextDirection(QtCore.Qt.RightToLeft)
self.edit.document().setDefaultTextOption(option)
self.edit.setLayoutDirection(QtCore.Qt.RightToLeft) #switch scrollerbar
dir = 'rtl'
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.toggleDirBtn.setText(_translate("MainWindow", "Toggle Direction", None))
if __name__ == "__main__":
import sys
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'toggleDir.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
dir = 'rtl'
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(350, 350)
MainWindow.setMinimumSize(QtCore.QSize(350, 350))
MainWindow.setMaximumSize(QtCore.QSize(350, 350))
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.fontName = QtGui.QFontComboBox(self.centralwidget)
self.fontName.setObjectName(_fromUtf8("fontName"))
self.horizontalLayout.addWidget(self.fontName)
self.fontSize = QtGui.QSpinBox(self.centralwidget)
self.fontSize.setProperty("value", 11)
self.fontSize.setObjectName(_fromUtf8("fontSize"))
self.horizontalLayout.addWidget(self.fontSize)
self.verticalLayout.addLayout(self.horizontalLayout)
self.edit = QtGui.QTextEdit(self.centralwidget)
self.edit.setObjectName(_fromUtf8("edit"))
self.edit.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.verticalLayout.addWidget(self.edit)
self.toggleDirBtn = QtGui.QPushButton(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(15)
self.toggleDirBtn.setFont(font)
self.toggleDirBtn.setObjectName(_fromUtf8("toggleDirBtn"))
self.verticalLayout.addWidget(self.toggleDirBtn)
MainWindow.setCentralWidget(self.centralwidget)
option=self.edit.document().defaultTextOption()
option.setTextDirection(QtCore.Qt.RightToLeft)
self.edit.document().setDefaultTextOption(option)
self.edit.setLayoutDirection(QtCore.Qt.RightToLeft) #switch scrollerbar
self.edit.setTabStopWidth(33) #set tab size for editor
self.fontName.currentFontChanged.connect(self._fontName)
self.fontSize.valueChanged.connect(self._fontSize)
self.toggleDirBtn.clicked.connect(self._toggleDir)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def _fontName(self):
font = QtGui.QFont()
font.setFamily(self.fontName.currentText())
font.setPointSize(int(self.fontSize.value()))
self.edit.setFont(font)
self.edit.setFocus()
def _fontSize(self):
font = QtGui.QFont()
font.setFamily(self.fontName.currentText())
font.setPointSize(int(self.fontSize.value()))
self.edit.setFont(font)
self.edit.setFocus()
def _toggleDir(self):
global dir
if dir == 'rtl':
option=self.edit.document().defaultTextOption()
option.setTextDirection(QtCore.Qt.LeftToRight)
self.edit.document().setDefaultTextOption(option)
self.edit.setLayoutDirection(QtCore.Qt.LeftToRight) #switch scrollerbar
dir = 'ltr'
else:
option=self.edit.document().defaultTextOption()
option.setTextDirection(QtCore.Qt.RightToLeft)
self.edit.document().setDefaultTextOption(option)
self.edit.setLayoutDirection(QtCore.Qt.RightToLeft) #switch scrollerbar
dir = 'rtl'
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.toggleDirBtn.setText(_translate("MainWindow", "Toggle Direction", None))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
Bookmarks