from PyKDE4.kdeui import KDialog
# also the KWindowSystem, so we can get ourselves to the foreground
from PyKDE4.kdeui import KWindowSystem
+# and NET, which is needed for getting Window Information
+from PyKDE4.kdeui import NET
# Setup the circle - TODO: Call it via KUniqueApplication.newInstance
- def toForeground(self):
- """Get into the foreground, so the user can click us."""
+ def toForeground(self, winId = None):
+ """Get window into the foreground, so the user can click us.
+ @param winId: Optional ID for the window to get into foreground."""
+ # if we get no other Id, we want to go into the foreground
"""Setup the items in the circle - used to show the app anew.
if self.isInside(pos, i):
# If pyRad didn't reach a final action, we stop here.
if event.button() == Qt.LeftButton:
- if self.labelClicked(i) is None:
+ # if STRG was held when clicking, we want to start a new program under all circumstances
+ shiftModifierPressed = event.modifiers().__and__(Qt.ShiftModifier) == Qt.ShiftModifier
+ if shiftModifierPressed:
+ if self.labelClicked(i, force_new_instance=False) is None:
+ if self.labelClicked(i) is None:
elif event.button() == Qt.RightButton and i != self.circle:
- def labelClicked(self, label):
+ def labelClicked(self, label):
"""React to a label being clicked.
+ # TODO: When STRG held, always open a new window, otherwise check first, if the program is already open and if yes activate it instead.
@return: True if the circle reached an end, None if it should continue existing."""
# We don't do anything else in that case.
- # if it's no folder and not None, we start the program
- # if this fails, the code ends here
- # and the circle stays visible.
+ # if it's no folder and not None, we show the program or start a new instance
+ # if this fails, the code ends here and the circle stays visible.
if label.action is not None:
+ #: The line to call the program
+ program_call = split_action(label.action)
+ # if we want a new instance, we call the program at once (faster than first checking
+ #: all currently known windows
+ wins = KWindowSystem.windows()
+ # if a window name equals the program to call, get it into the foreground
+ windowName = unicode(KWindowSystem.windowInfo(i, NET.WMName, NET.WMVisibleName).name())
+ if windowName.split()[-1].lower() == program_call.lower():
+ self.toForeground(KWindowSystem.windowInfo(i, NET.WMName, NET.WMVisibleName).win())
+ # if no window name fits, start a new program instance
def isInside(self, point, thing):
"""Check, if the point is inside the thing."""
if point.x() > thing.x() and point.x() < thing.x() + thing.width() and point.y() > thing.y() and point.y() < thing.y() + thing.height():