removed fixmes

This commit is contained in:
Andreas Preikschat 2012-06-27 19:00:02 +02:00
parent 39916e4232
commit 0f8054c1fd
2 changed files with 38 additions and 56 deletions

View File

@ -54,8 +54,6 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
The QWidget-derived parent of the wizard. The QWidget-derived parent of the wizard.
""" """
QtGui.QWizard.__init__(self, parent) QtGui.QWizard.__init__(self, parent)
#FIXME: remove self.thememanager and use self.parent() instead.
self.thememanager = parent
self.setupUi(self) self.setupUi(self)
self.registerFields() self.registerFields()
self.updateThemeAllowed = True self.updateThemeAllowed = True
@ -196,7 +194,7 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
# Do not trigger on start up # Do not trigger on start up
if self.currentPage != self.welcomePage: if self.currentPage != self.welcomePage:
self.updateTheme() self.updateTheme()
self.thememanager.generateImage(self.theme, True) self.parent().generateImage(self.theme, True)
def updateLinesText(self, lines): def updateLinesText(self, lines):
""" """
@ -228,13 +226,11 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
""" """
Detects Page changes and updates as approprate. Detects Page changes and updates as approprate.
""" """
if self.page(pageId) == self.areaPositionPage: self.setOption(QtGui.QWizard.HaveCustomButton1,
self.setOption(QtGui.QWizard.HaveCustomButton1, True) self.page(pageId) == self.areaPositionPage)
else:
self.setOption(QtGui.QWizard.HaveCustomButton1, False)
if self.page(pageId) == self.previewPage: if self.page(pageId) == self.previewPage:
self.updateTheme() self.updateTheme()
frame = self.thememanager.generateImage(self.theme) frame = self.parent().generateImage(self.theme)
self.previewBoxLabel.setPixmap(frame) self.previewBoxLabel.setPixmap(frame)
self.displayAspectRatio = float(frame.width()) / frame.height() self.displayAspectRatio = float(frame.width()) / frame.height()
self.resizeEvent() self.resizeEvent()
@ -244,16 +240,16 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
Generate layout preview and display the form. Generate layout preview and display the form.
""" """
self.updateTheme() self.updateTheme()
width = self.thememanager.mainwindow.renderer.width width = self.parent().mainwindow.renderer.width
height = self.thememanager.mainwindow.renderer.height height = self.parent().mainwindow.renderer.height
pixmap = QtGui.QPixmap(width, height) pixmap = QtGui.QPixmap(width, height)
pixmap.fill(QtCore.Qt.white) pixmap.fill(QtCore.Qt.white)
paint = QtGui.QPainter(pixmap) paint = QtGui.QPainter(pixmap)
paint.setPen(QtGui.QPen(QtCore.Qt.blue, 2)) paint.setPen(QtGui.QPen(QtCore.Qt.blue, 2))
paint.drawRect(self.thememanager.mainwindow.renderer. paint.drawRect(self.parent().mainwindow.renderer.
get_main_rectangle(self.theme)) get_main_rectangle(self.theme))
paint.setPen(QtGui.QPen(QtCore.Qt.red, 2)) paint.setPen(QtGui.QPen(QtCore.Qt.red, 2))
paint.drawRect(self.thememanager.mainwindow.renderer. paint.drawRect(self.parent().mainwindow.renderer.
get_footer_rectangle(self.theme)) get_footer_rectangle(self.theme))
paint.end() paint.end()
self.themeLayoutForm.exec_(pixmap) self.themeLayoutForm.exec_(pixmap)
@ -623,10 +619,10 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
os.path.split(unicode(self.theme.background_filename))[1] os.path.split(unicode(self.theme.background_filename))[1]
saveTo = os.path.join(self.path, self.theme.theme_name, filename) saveTo = os.path.join(self.path, self.theme.theme_name, filename)
saveFrom = self.theme.background_filename saveFrom = self.theme.background_filename
if not self.edit_mode and \ if not self.edit_mode and not \
not self.thememanager.checkIfThemeExists(self.theme.theme_name): self.parent().checkIfThemeExists(self.theme.theme_name):
return return
self.thememanager.saveTheme(self.theme, saveFrom, saveTo) self.parent().saveTheme(self.theme, saveFrom, saveTo)
return QtGui.QDialog.accept(self) return QtGui.QDialog.accept(self)
def _colorButton(self, field): def _colorButton(self, field):

View File

@ -138,18 +138,14 @@ class ThemeManager(QtGui.QWidget):
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'config_updated'), self.configUpdated) QtCore.SIGNAL(u'config_updated'), self.configUpdated)
# Variables # Variables
#FIXME: convert to camelCase. self.themeList = []
self.theme_list = []
self.path = AppLocation.get_section_data_path(self.settingsSection) self.path = AppLocation.get_section_data_path(self.settingsSection)
check_directory_exists(self.path) check_directory_exists(self.path)
#FIXME: convert to camelCase. self.thumbPath = os.path.join(self.path, u'thumbnails')
self.thumb_path = os.path.join(self.path, u'thumbnails') check_directory_exists(self.thumbPath)
check_directory_exists(self.thumb_path)
self.themeForm.path = self.path self.themeForm.path = self.path
#FIXME: convert to camelCase. self.oldBackgroundImage = None
self.old_background_image = None self.badV1NameChars = re.compile(r'[%+\[\]]')
#FIXME: convert to camelCase.
self.bad_v1_name_chars = re.compile(r'[%+\[\]]')
# Last little bits of setting up # Last little bits of setting up
self.configUpdated() self.configUpdated()
@ -197,19 +193,10 @@ class ThemeManager(QtGui.QWidget):
return return
real_theme_name = unicode(item.data(QtCore.Qt.UserRole).toString()) real_theme_name = unicode(item.data(QtCore.Qt.UserRole).toString())
theme_name = unicode(item.text()) theme_name = unicode(item.text())
# FIXME: Shorten code. visible = real_theme_name == theme_name
# visible = real_theme_name == theme_name: self.deleteAction.setVisible(visible)
# self.deleteAction.setVisible(visible) self.renameAction.setVisible(visible)
# self.renameAction.setVisible(visible) self.globalAction.setVisible(visible)
# self.globalAction.setVisible(visible)
self.deleteAction.setVisible(False)
self.renameAction.setVisible(False)
self.globalAction.setVisible(False)
# If default theme restrict actions
if real_theme_name == theme_name:
self.deleteAction.setVisible(True)
self.renameAction.setVisible(True)
self.globalAction.setVisible(True)
self.menu.exec_(self.themeListWidget.mapToGlobal(point)) self.menu.exec_(self.themeListWidget.mapToGlobal(point))
def changeGlobalFromTab(self, theme_name): def changeGlobalFromTab(self, theme_name):
@ -338,11 +325,11 @@ class ThemeManager(QtGui.QWidget):
theme = self.getThemeData( theme = self.getThemeData(
unicode(item.data(QtCore.Qt.UserRole).toString())) unicode(item.data(QtCore.Qt.UserRole).toString()))
if theme.background_type == u'image': if theme.background_type == u'image':
self.old_background_image = theme.background_filename self.oldBackgroundImage = theme.background_filename
self.themeForm.theme = theme self.themeForm.theme = theme
self.themeForm.exec_(True) self.themeForm.exec_(True)
self.mainwindow.imageManager.deleteImage(theme.theme_name) self.mainwindow.imageManager.deleteImage(theme.theme_name)
self.old_background_image = None self.oldBackgroundImage = None
self.mainwindow.renderer.update_theme(theme.theme_name) self.mainwindow.renderer.update_theme(theme.theme_name)
def onDeleteTheme(self): def onDeleteTheme(self):
@ -370,10 +357,10 @@ class ThemeManager(QtGui.QWidget):
``theme`` ``theme``
The theme to delete. The theme to delete.
""" """
self.theme_list.remove(theme) self.themeList.remove(theme)
thumb = u'%s.png' % theme thumb = u'%s.png' % theme
delete_file(os.path.join(self.path, thumb)) delete_file(os.path.join(self.path, thumb))
delete_file(os.path.join(self.thumb_path, thumb)) delete_file(os.path.join(self.thumbPath, thumb))
try: try:
encoding = get_filesystem_encoding() encoding = get_filesystem_encoding()
shutil.rmtree(os.path.join(self.path, theme).encode(encoding)) shutil.rmtree(os.path.join(self.path, theme).encode(encoding))
@ -451,7 +438,7 @@ class ThemeManager(QtGui.QWidget):
The plugins will call back in to get the real list if they want it. The plugins will call back in to get the real list if they want it.
""" """
log.debug(u'Load themes from dir') log.debug(u'Load themes from dir')
self.theme_list = [] self.themeList = []
self.themeListWidget.clear() self.themeListWidget.clear()
files = SettingsManager.get_files(self.settingsSection, u'.png') files = SettingsManager.get_files(self.settingsSection, u'.png')
if firstTime: if firstTime:
@ -482,7 +469,7 @@ class ThemeManager(QtGui.QWidget):
'%s (default)')) % text_name '%s (default)')) % text_name
else: else:
name = text_name name = text_name
thumb = os.path.join(self.thumb_path, u'%s.png' % text_name) thumb = os.path.join(self.thumbPath, u'%s.png' % text_name)
item_name = QtGui.QListWidgetItem(name) item_name = QtGui.QListWidgetItem(name)
if validate_thumb(theme, thumb): if validate_thumb(theme, thumb):
icon = build_icon(thumb) icon = build_icon(thumb)
@ -492,7 +479,7 @@ class ThemeManager(QtGui.QWidget):
item_name.setData( item_name.setData(
QtCore.Qt.UserRole, QtCore.QVariant(text_name)) QtCore.Qt.UserRole, QtCore.QVariant(text_name))
self.themeListWidget.addItem(item_name) self.themeListWidget.addItem(item_name)
self.theme_list.append(text_name) self.themeList.append(text_name)
self._pushThemes() self._pushThemes()
def _pushThemes(self): def _pushThemes(self):
@ -505,7 +492,7 @@ class ThemeManager(QtGui.QWidget):
""" """
Return the list of loaded themes Return the list of loaded themes
""" """
return self.theme_list return self.themeList
def getThemeData(self, theme_name): def getThemeData(self, theme_name):
""" """
@ -629,7 +616,7 @@ class ThemeManager(QtGui.QWidget):
this method, please keep in mind, that some parameters are redundant. this method, please keep in mind, that some parameters are redundant.
""" """
theme_name = xml_tree.find(u'Name').text.strip() theme_name = xml_tree.find(u'Name').text.strip()
theme_name = self.bad_v1_name_chars.sub(u'', theme_name) theme_name = self.badV1NameChars.sub(u'', theme_name)
theme_folder = os.path.join(dir, theme_name) theme_folder = os.path.join(dir, theme_name)
theme_exists = os.path.exists(theme_folder) theme_exists = os.path.exists(theme_folder)
if theme_exists and not self.overWriteMessageBox(theme_name): if theme_exists and not self.overWriteMessageBox(theme_name):
@ -644,12 +631,12 @@ class ThemeManager(QtGui.QWidget):
if background.text.strip() == u'2': if background.text.strip() == u'2':
image_name = xml_tree.find(u'BackgroundParameter1').text.strip() image_name = xml_tree.find(u'BackgroundParameter1').text.strip()
# image file has same extension and is in subfolder # image file has same extension and is in subfolder
imagefile = filter(lambda name: os.path.splitext(name)[1].lower() image_file = filter(lambda name: os.path.splitext(name)[1].lower()
== os.path.splitext(image_name)[1].lower() and name.find(r'/'), == os.path.splitext(image_name)[1].lower() and name.find(r'/'),
zip.namelist()) zip.namelist())
if len(imagefile) >= 1: if len(image_file) >= 1:
out_file = open(os.path.join(themedir, image_name), u'wb') out_file = open(os.path.join(themedir, image_name), u'wb')
out_file.write(zip.read(imagefile[0])) out_file.write(zip.read(image_file[0]))
out_file.close() out_file.close()
else: else:
log.exception(u'Theme file does not contain image file "%s"' % log.exception(u'Theme file does not contain image file "%s"' %
@ -697,9 +684,8 @@ class ThemeManager(QtGui.QWidget):
theme_dir = os.path.join(self.path, name) theme_dir = os.path.join(self.path, name)
check_directory_exists(theme_dir) check_directory_exists(theme_dir)
theme_file = os.path.join(theme_dir, name + u'.xml') theme_file = os.path.join(theme_dir, name + u'.xml')
if self.old_background_image and \ if self.oldBackgroundImage and image_to != self.oldBackgroundImage:
image_to != self.old_background_image: delete_file(self.oldBackgroundImage)
delete_file(self.old_background_image)
out_file = None out_file = None
try: try:
out_file = open(theme_file, u'w') out_file = open(theme_file, u'w')
@ -726,7 +712,7 @@ class ThemeManager(QtGui.QWidget):
if os.path.exists(sample_path_name): if os.path.exists(sample_path_name):
os.unlink(sample_path_name) os.unlink(sample_path_name)
frame.save(sample_path_name, u'png') frame.save(sample_path_name, u'png')
thumb = os.path.join(self.thumb_path, u'%s.png' % name) thumb = os.path.join(self.thumbPath, u'%s.png' % name)
create_thumb(sample_path_name, thumb, False) create_thumb(sample_path_name, thumb, False)
log.debug(u'Theme image written to %s', sample_path_name) log.debug(u'Theme image written to %s', sample_path_name)
@ -734,8 +720,8 @@ class ThemeManager(QtGui.QWidget):
""" """
Called to update the themes' preview images. Called to update the themes' preview images.
""" """
self.mainwindow.displayProgressBar(len(self.theme_list)) self.mainwindow.displayProgressBar(len(self.themeList))
for theme in self.theme_list: for theme in self.themeList:
self.mainwindow.incrementProgressBar() self.mainwindow.incrementProgressBar()
self.generateAndSaveImage( self.generateAndSaveImage(
self.path, theme, self.getThemeData(theme)) self.path, theme, self.getThemeData(theme))
@ -831,7 +817,7 @@ class ThemeManager(QtGui.QWidget):
""" """
theme = Theme(xml_data) theme = Theme(xml_data)
new_theme = ThemeXML() new_theme = ThemeXML()
new_theme.theme_name = self.bad_v1_name_chars.sub(u'', theme.Name) new_theme.theme_name = self.badV1NameChars.sub(u'', theme.Name)
if theme.BackgroundType == 0: if theme.BackgroundType == 0:
new_theme.background_type = \ new_theme.background_type = \
BackgroundType.to_string(BackgroundType.Solid) BackgroundType.to_string(BackgroundType.Solid)