Adds FadeControls
4 files changed, 66 insertions(+), 15 deletions(-)

M winrustler/fader.py
M winrustler/ui/__main__.py
A => winrustler/ui/res/1f47b.png
M winrustler/ui/widgets.py
M winrustler/fader.py +12 -8
@@ 29,13 29,17 @@ class FadeWindow(object):
 
     def run(self):
         style = user32.GetWindowLongA(self.hwnd, GWL_EXSTYLE)
-        style |= WS_EX_LAYERED
+        if self.opacity >= 255:
+            style &= ~WS_EX_LAYERED
+        else:
+            style |= WS_EX_LAYERED
         if 0 == user32.SetWindowLongA(self.hwnd, GWL_EXSTYLE, style):
             raise ctypes.WinError()
-        if 0 == user32.SetLayeredWindowAttributes(
-                self.hwnd,
-                wintypes.RGB(255, 255, 255),
-                self.opacity,
-                LWA_COLORKEY|LWA_ALPHA,
-                ):
-            raise ctypes.WinError()
+        if self.opacity < 255:
+            if 0 == user32.SetLayeredWindowAttributes(
+                    self.hwnd,
+                    wintypes.RGB(255, 255, 255),
+                    self.opacity,
+                    LWA_COLORKEY|LWA_ALPHA,
+                    ):
+                raise ctypes.WinError()

          
M winrustler/ui/__main__.py +18 -7
@@ 83,7 83,7 @@ class RustlerWindow(QDialog):
         super().__init__(*args, **kwargs)
         self.setWindowTitle("WinRustler")
 
-        from .widgets import WindowSelect, MoveControls#, MatchSelect
+        from .widgets import WindowSelect, MoveControls, FadeControls#, MatchSelect
 
         self._select = WindowSelect(self)
         #from PyQt5.QtWidgets import QPushButton

          
@@ 100,10 100,12 @@ class RustlerWindow(QDialog):
         #self._window_tab.addTab(self._match, icon('1f50d.png'), "&Match")
 
         self._move = MoveControls(self)
+        self._fade = FadeControls(self)
 
         from PyQt5.QtWidgets import QTabWidget
         self._function_tab = QTabWidget(self)
         self._function_tab.addTab(self._move, icon('1f4d0.png'), "M&ove")
+        self._function_tab.addTab(self._fade, icon('1f47b.png'), "F&ade")
 
         from PyQt5.QtWidgets import QDialogButtonBox
         self._bb = QDialogButtonBox(self)

          
@@ 165,10 167,11 @@ class RustlerWindow(QDialog):
             raise NotImplementedError()
 
     def request(self):
-        #hwnd = self._window_tab.currentWidget().hwnd()
-        hwnd = self._select.hwnd()
-        if hwnd is not None:
-            return self._function_tab.currentWidget().window_request(hwnd)
+        hwnd = self._select.hwnd
+        tab = self._function_tab.currentWidget() 
+        if tab is not None:
+            hwnd = self._select.hwnd()
+            return tab.window_request(hwnd)
 
     def showEvent(self, event):
         settings = QSettings("WinRustler Corp.", "WinRustler")

          
@@ 251,8 254,16 @@ class RustlerTray(QSystemTrayIcon):
     def show_rustle_message(self, req):
         icon = get_window_icon(req.hwnd)
         title = get_window_title(req.hwnd)
-        msg = "Moved {title} to {req.x} x {req.y}.".format(**locals())
-        self.showMessage("I moved a window.", msg, icon)
+        from winrustler.mover import MoveWindow
+        from winrustler.fader import FadeWindow
+        if isinstance(req, MoveWindow):
+            msg = "Moved {title} to {req.x} x {req.y}.".format(**locals())
+        elif isinstance(req, FadeWindow):
+            msg = "Set {title} opacity to {req.opacity}.".format(**locals())
+        else:
+            assert False, req
+            msg = "Did something, not sure what."
+        self.showMessage("I did something.", msg, icon)
 
     def _window_destroyed(self, ptr):
         self.window = None

          
A => winrustler/ui/res/1f47b.png +0 -0

        
M winrustler/ui/widgets.py +36 -0
@@ 188,3 188,39 @@ class MoveControls(QWidget):
     def window_request(self, hwnd):
         return MoveWindow(hwnd, self._x.value(), self._y.value(),
                 self._move_viewport.checkState() == Qt.Checked)
+
+
+from winrustler.fader import FadeWindow
+
+class FadeControls(QWidget):
+
+    DESCRIPTION_TEMPLATE = "<p>Set a window's opacity to {opacity}. At zero, it \
+    is transparent; at 255 it is opaque.</p>"
+
+    updated = pyqtSignal()
+
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+
+        from PyQt5.QtWidgets import QSlider, QLabel, QHBoxLayout
+        self._description = QLabel(parent=self)
+        self._opacity = QSlider(Qt.Horizontal, parent=self, minimum=0, maximum=255)#, tickInterval=127, tickPosition=QSlider.TicksBelow)
+        # This can't be a kwarg, probably because PyQt applies those in no
+        # particular order and this should happen after setting the maximum.
+        self._opacity.setValue(255)
+
+        from PyQt5.QtWidgets import QFormLayout
+        self._layout = QFormLayout(self)
+        self._layout.addRow(self._description)
+        self._layout.addRow("&Opacity", self._opacity)
+        self.setLayout(self._layout)
+
+        self._opacity.valueChanged.connect(self.updated)
+        self.updated.connect(self._refresh_engagement)
+        self._refresh_engagement()
+    
+    def _refresh_engagement(self):
+        self._description.setText(self.DESCRIPTION_TEMPLATE.format(opacity=self._opacity.value()))
+
+    def window_request(self, hwnd):
+        return FadeWindow(hwnd, self._opacity.value())