32 import xml.etree.ElementTree
40 from classes.logger
import log
41 from classes
import settings
43 DEFAULT_THEME_NAME =
"Humanity"
53 if QIcon.themeName() ==
'' and not s.get(
"theme") ==
"No Theme":
56 if os.getenv(
'DESKTOP_SESSION') ==
'ubuntu':
57 QIcon.setThemeName(
'unity-icon-theme')
61 QIcon.setThemeName(DEFAULT_THEME_NAME)
72 for attempt
in range(1,6):
75 uic.loadUi(path, window)
81 except Exception
as ex:
91 window.uiTree = xml.etree.ElementTree.parse(path)
99 start_path =
":/icons/" + DEFAULT_THEME_NAME +
"/"
100 icon_path =
search_dir(start_path, theme_name)
101 return QIcon(icon_path), icon_path
109 base_dir = QDir(base_path)
110 for e
in base_dir.entryList():
112 path = base_dir.path() +
"/" + e
113 base_filename = e.split(
'.')[0]
116 if base_filename == theme_name:
137 has_icon = QIcon.hasThemeIcon(theme_name)
139 if has_icon
or fallback_icon:
140 return QIcon.fromTheme(theme_name, fallback_icon)
148 type_filter =
'action'
149 if isinstance(elem, QWidget):
150 type_filter =
'widget'
152 iconset = window.uiTree.find(
'.//' + type_filter +
'[@name="' + name +
'"]/property[@name="icon"]/iconset')
153 if iconset !=
None or theme_name:
155 theme_name = iconset.get(
'theme',
'')
166 _translate = QApplication.instance().translate
169 if hasattr(elem,
'objectName'):
170 name = elem.objectName()
174 if hasattr(elem,
'setText')
and hasattr(elem,
'text')
and elem.text() !=
"":
175 elem.setText(_translate(
"", elem.text()))
176 if hasattr(elem,
'setToolTip')
and hasattr(elem,
'toolTip')
and elem.toolTip() !=
"":
177 elem.setToolTip(_translate(
"", elem.toolTip()))
178 if hasattr(elem,
'setWindowTitle')
and hasattr(elem,
'windowTitle')
and elem.windowTitle() !=
"":
179 elem.setWindowTitle(_translate(
"", elem.windowTitle()))
180 if hasattr(elem,
'setTitle')
and hasattr(elem,
'title')
and elem.title() !=
"":
181 elem.setTitle(_translate(
"", elem.title()))
182 if hasattr(elem,
'setPlaceholderText')
and hasattr(elem,
'placeholderText')
and elem.placeholderText() !=
"":
183 elem.setPlaceholderText(_translate(
"", elem.placeholderText()))
184 if hasattr(elem,
'setLocale'):
185 elem.setLocale(QLocale().system())
187 if isinstance(elem, QTabWidget):
188 for i
in range(elem.count()):
189 elem.setTabText(i, _translate(
"", elem.tabText(i)))
190 elem.setTabToolTip(i, _translate(
"", elem.tabToolTip(i)))
192 if hasattr(elem,
'setIcon')
and name !=
'':
201 if hasattr(elem,
'trigger'):
202 func_name = name +
"_trigger"
203 if hasattr(window, func_name)
and callable(getattr(window, func_name)):
204 func = getattr(window, func_name)
205 elem.triggered.connect(getattr(window, func_name))
206 if hasattr(elem,
'click'):
207 func_name = name +
"_click"
208 if hasattr(window, func_name)
and callable(getattr(window, func_name)):
209 func = getattr(window, func_name)
210 elem.clicked.connect(getattr(window, func_name))
216 log.info(
'Initializing UI for {}'.format(window.objectName()))
220 if hasattr(window,
'setWindowTitle')
and window.windowTitle() !=
"":
221 _translate = QApplication.instance().translate
222 window.setWindowTitle(_translate(
"", window.windowTitle()))
228 for widget
in window.findChildren(QWidget):
232 for action
in window.findChildren(QAction):
235 log.info(
'Failed to initialize an element on {}'.format(window.objectName()))
240 from classes.app
import get_app
242 frameGm = window.frameGeometry()
244 frameGm.moveCenter(centerPoint)
245 window.move(frameGm.topLeft())
248 log.info(
"Transferring children from '{}' to '{}'".format(from_widget.objectName(), to_widget.objectName()))
def get_app
Returns the current QApplication instance of OpenShot.
def setup_icon
Using the window xml, set the icon on the given element, or if theme_name passed load that icon...
def connect_auto_events
Connect any events in a *.ui file with matching Python method names.
def load_theme
Load the current OS theme, or fallback to a default one.
def init_element
Initialize language and icons of the given element.
def load_ui
Load a Qt *.ui file, and also load an XML parsed version.
def search_dir
Search for theme name.
def init_ui
Initialize all child widgets and action of a window or dialog.
def get_default_icon
Get a QIcon, and fallback to default theme if OS does not support themes.
def get_icon
Get either the current theme icon or fallback to default theme (for custom icons).
def center
Center a window on the main window.
def get_settings
Get the current QApplication's settings instance.