Customize minimize/close buttons

This commit is contained in:
Kiooeht 2011-05-04 23:48:44 -07:00
parent e401667e13
commit 39e77ee3c2
2 changed files with 61 additions and 5 deletions

View file

@ -621,7 +621,7 @@ class PesterOptions(QtGui.QDialog):
self.tabs = QtGui.QButtonGroup(self)
self.connect(self.tabs, QtCore.SIGNAL('buttonClicked(int)'),
self, QtCore.SLOT('changePage(int)'))
tabNames = ["Chum List", "Conversations", "Sound", "Logging", "Idle", "Theme"]
tabNames = ["Chum List", "Conversations", "Interface", "Sound", "Logging", "Idle", "Theme"]
for t in tabNames:
button = QtGui.QPushButton(t)
self.tabs.addButton(button)
@ -710,6 +710,20 @@ class PesterOptions(QtGui.QDialog):
if t == theme.name:
self.themeBox.setCurrentIndex(i)
self.buttonOptions = ["Minimize to Taskbar", "Minimize to Tray", "Quit"]
self.miniBox = QtGui.QComboBox(self)
self.miniBox.addItems(self.buttonOptions)
self.miniBox.setCurrentIndex(self.config.minimizeAction())
self.closeBox = QtGui.QComboBox(self)
self.closeBox.addItems(self.buttonOptions)
self.closeBox.setCurrentIndex(self.config.closeAction())
layout_mini = QtGui.QHBoxLayout()
layout_mini.addWidget(QtGui.QLabel("Minimize"))
layout_mini.addWidget(self.miniBox)
layout_close = QtGui.QHBoxLayout()
layout_close.addWidget(QtGui.QLabel("Close"))
layout_close.addWidget(self.closeBox)
self.ok = QtGui.QPushButton("OK", self)
self.ok.setDefault(True)
self.connect(self.ok, QtCore.SIGNAL('clicked()'),
@ -747,6 +761,14 @@ class PesterOptions(QtGui.QDialog):
#layout_chat.addWidget(self.userlinkscheck)
self.pages.addWidget(widget)
# Interface
widget = QtGui.QWidget()
layout_interface = QtGui.QVBoxLayout(widget)
layout_interface.setAlignment(QtCore.Qt.AlignTop)
layout_interface.addLayout(layout_mini)
layout_interface.addLayout(layout_close)
self.pages.addWidget(widget)
# Sound
widget = QtGui.QWidget()
layout_sound = QtGui.QVBoxLayout(widget)

View file

@ -342,6 +342,10 @@ class userConfig(object):
return not self.config.get('userLinks', True)
def idleTime(self):
return self.config.get('idleTime', 10)
def minimizeAction(self):
return self.config.get('miniAction', 0)
def closeAction(self):
return self.config.get('closeAction', 1)
def addChum(self, chum):
if chum.handle not in self.chums():
fp = open(self.filename) # what if we have two clients open??
@ -1398,11 +1402,9 @@ class PesterWindow(MovingWindow):
self.helpmenu.addAction(self.aboutAction)
self.closeButton = WMButton(PesterIcon(self.theme["main/close/image"]), self)
self.connect(self.closeButton, QtCore.SIGNAL('clicked()'),
self, QtCore.SLOT('closeToTray()'))
self.setButtonAction(self.closeButton, self.config.closeAction(), -1)
self.miniButton = WMButton(PesterIcon(self.theme["main/minimize/image"]), self)
self.connect(self.miniButton, QtCore.SIGNAL('clicked()'),
self, QtCore.SLOT('showMinimized()'))
self.setButtonAction(self.miniButton, self.config.minimizeAction(), -1)
self.namesdb = CaseInsensitiveDict()
self.chumdb = PesterProfileDB()
@ -2327,8 +2329,40 @@ class PesterWindow(MovingWindow):
self.idlethreshold = 60*idlesetting
# theme
self.themeSelected()
# button actions
minisetting = self.optionmenu.miniBox.currentIndex()
curmini = self.config.minimizeAction()
if minisetting != curmini:
self.config.set('miniAction', minisetting)
self.setButtonAction(self.miniButton, minisetting, curmini)
closesetting = self.optionmenu.closeBox.currentIndex()
curclose = self.config.closeAction()
if closesetting != curclose:
self.config.set('closeAction', closesetting)
self.setButtonAction(self.closeButton, closesetting, curclose)
self.optionmenu = None
def setButtonAction(self, button, setting, old):
if old == 0: # minimize to taskbar
self.disconnect(button, QtCore.SIGNAL('clicked()'),
self, QtCore.SLOT('showMinimized()'));
elif old == 1: # minimize to tray
self.disconnect(button, QtCore.SIGNAL('clicked()'),
self, QtCore.SLOT('closeToTray()'));
elif old == 2: # quit
self.disconnect(button, QtCore.SIGNAL('clicked()'),
self, QtCore.SLOT('close()'));
if setting == 0: # minimize to taskbar
self.connect(button, QtCore.SIGNAL('clicked()'),
self, QtCore.SLOT('showMinimized()'));
elif setting == 1: # minimize to tray
self.connect(button, QtCore.SIGNAL('clicked()'),
self, QtCore.SLOT('closeToTray()'));
elif setting == 2: # quit
self.connect(button, QtCore.SIGNAL('clicked()'),
self, QtCore.SLOT('close()'));
@QtCore.pyqtSlot()
def themeSelected(self):
themename = unicode(self.optionmenu.themeBox.currentText())