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 log.warn(
'Icon theme {} not found. Will use backup icon.'.format(theme_name))
142 if has_icon
or fallback_icon:
143 return QIcon.fromTheme(theme_name, fallback_icon)
151 type_filter =
'action'
152 if isinstance(elem, QWidget):
153 type_filter =
'widget'
155 iconset = window.uiTree.find(
'.//' + type_filter +
'[@name="' + name +
'"]/property[@name="icon"]/iconset')
156 if iconset !=
None or theme_name:
158 theme_name = iconset.get(
'theme',
'')
169 _translate = QApplication.instance().translate
172 if hasattr(elem,
'objectName'):
173 name = elem.objectName()
177 if hasattr(elem,
'setText')
and hasattr(elem,
'text')
and elem.text() !=
"":
178 elem.setText(_translate(
"", elem.text()))
179 if hasattr(elem,
'setToolTip')
and hasattr(elem,
'toolTip')
and elem.toolTip() !=
"":
180 elem.setToolTip(_translate(
"", elem.toolTip()))
181 if hasattr(elem,
'setWindowTitle')
and hasattr(elem,
'windowTitle')
and elem.windowTitle() !=
"":
182 elem.setWindowTitle(_translate(
"", elem.windowTitle()))
183 if hasattr(elem,
'setTitle')
and hasattr(elem,
'title')
and elem.title() !=
"":
184 elem.setTitle(_translate(
"", elem.title()))
185 if hasattr(elem,
'setPlaceholderText')
and hasattr(elem,
'placeholderText')
and elem.placeholderText() !=
"":
186 elem.setPlaceholderText(_translate(
"", elem.placeholderText()))
187 if hasattr(elem,
'setLocale'):
188 elem.setLocale(QLocale().system())
190 if isinstance(elem, QTabWidget):
191 for i
in range(elem.count()):
192 elem.setTabText(i, _translate(
"", elem.tabText(i)))
193 elem.setTabToolTip(i, _translate(
"", elem.tabToolTip(i)))
195 if hasattr(elem,
'setIcon')
and name !=
'':
204 if hasattr(elem,
'trigger'):
205 func_name = name +
"_trigger"
206 if hasattr(window, func_name)
and callable(getattr(window, func_name)):
207 func = getattr(window, func_name)
208 log.info(
"Binding event {}:{}".format(window.objectName(), func_name))
209 elem.triggered.connect(getattr(window, func_name))
210 if hasattr(elem,
'click'):
211 func_name = name +
"_click"
212 if hasattr(window, func_name)
and callable(getattr(window, func_name)):
213 func = getattr(window, func_name)
214 log.info(
"Binding event {}:{}".format(window.objectName(), func_name))
215 elem.clicked.connect(getattr(window, func_name))
221 log.info(
'Initializing UI for {}'.format(window.objectName()))
225 if hasattr(window,
'setWindowTitle')
and window.windowTitle() !=
"":
226 _translate = QApplication.instance().translate
227 window.setWindowTitle(_translate(
"", window.windowTitle()))
233 for widget
in window.findChildren(QWidget):
237 for action
in window.findChildren(QAction):
241 log.info(
'Failed to initialize an element on {}'.format(window.objectName()))
246 from classes.app
import get_app
248 frameGm = window.frameGeometry()
250 frameGm.moveCenter(centerPoint)
251 window.move(frameGm.topLeft())
254 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.