Skip to content

Commit

Permalink
fix more pylint warnings
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@21773 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Feb 21, 2019
1 parent d795347 commit b971cd2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 46 deletions.
3 changes: 2 additions & 1 deletion src/xpra/platform/win32/gdi_screen_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ def get_image(self, x=0, y=0, width=0, height=0):
else:
raise Exception("unsupported bit depth: %s" % self.bit_depth)
bpp = self.bit_depth//8
v = ImageWrapper(0, 0, width, height, pixels, rgb_format, self.bit_depth, rowstride, bpp, planes=ImageWrapper.PACKED, thread_safe=True)
v = ImageWrapper(0, 0, width, height, pixels, rgb_format,
self.bit_depth, rowstride, bpp, planes=ImageWrapper.PACKED, thread_safe=True)
if self.bit_depth==8:
count = GetSystemPaletteEntries(self.dc, 0, 0, None)
log("palette size: %s", count)
Expand Down
56 changes: 31 additions & 25 deletions src/xpra/platform/win32/shadow_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
# later version. See the file COPYING for details.

import os
import ctypes
from collections import namedtuple
from ctypes import (
create_string_buffer, create_unicode_buffer,
sizeof, byref, addressof, c_int,
)
from ctypes.wintypes import RECT, POINT, BYTE, MAX_PATH

from xpra.os_util import strtobytes
Expand Down Expand Up @@ -91,23 +94,24 @@ def get_cursor_data(hCursor):
pixels = None
try:
ii = ICONINFO()
ii.cbSize = ctypes.sizeof(ICONINFO)
if not GetIconInfo(hCursor, ctypes.byref(ii)):
ii.cbSize = sizeof(ICONINFO)
if not GetIconInfo(hCursor, byref(ii)):
raise WindowsError() #@UndefinedVariable
x = ii.xHotspot
y = ii.yHotspot
cursorlog("get_cursor_data(%#x) hotspot at %ix%i, hbmColor=%#x, hbmMask=%#x", hCursor, x, y, ii.hbmColor or 0, ii.hbmMask or 0)
cursorlog("get_cursor_data(%#x) hotspot at %ix%i, hbmColor=%#x, hbmMask=%#x",
hCursor, x, y, ii.hbmColor or 0, ii.hbmMask or 0)
if not ii.hbmColor:
#FIXME: we don't handle black and white cursors
return None
iie = ICONINFOEXW()
iie.cbSize = ctypes.sizeof(ICONINFOEXW)
if not GetIconInfoExW(hCursor, ctypes.byref(iie)):
iie.cbSize = sizeof(ICONINFOEXW)
if not GetIconInfoExW(hCursor, byref(iie)):
raise WindowsError() #@UndefinedVariable
name = iie.szResName[:MAX_PATH]
cursorlog("wResID=%i, sxModName=%s, szResName=%s", iie.wResID, iie.sxModName[:MAX_PATH], name)
bm = Bitmap()
if not GetObjectA(ii.hbmColor, ctypes.sizeof(Bitmap), ctypes.byref(bm)):
if not GetObjectA(ii.hbmColor, sizeof(Bitmap), byref(bm)):
raise WindowsError() #@UndefinedVariable
cursorlog("cursor bitmap: type=%i, width=%i, height=%i, width bytes=%i, planes=%i, bits pixel=%i, bits=%#x",
bm.bmType, bm.bmWidth, bm.bmHeight, bm.bmWidthBytes, bm.bmPlanes, bm.bmBitsPixel, bm.bmBits or 0)
Expand All @@ -131,10 +135,10 @@ def get_cursor_data(hCursor):
raise WindowsError() #@UndefinedVariable

buf_size = bm.bmWidthBytes*h
buf = ctypes.create_string_buffer(b"", buf_size)
r = GetBitmapBits(bitmap, buf_size, ctypes.byref(buf))
cursorlog("get_cursor_data(%#x) GetBitmapBits(%#x, %#x, %#x)=%i", hCursor, bitmap, buf_size, ctypes.addressof(buf), r)
if r==0:
buf = create_string_buffer(b"", buf_size)
r = GetBitmapBits(bitmap, buf_size, byref(buf))
cursorlog("get_cursor_data(%#x) GetBitmapBits(%#x, %#x, %#x)=%i", hCursor, bitmap, buf_size, addressof(buf), r)
if not r:
cursorlog.error("Error: failed to copy screen bitmap data")
return None
elif r!=buf_size:
Expand Down Expand Up @@ -189,10 +193,10 @@ def init_capture(w, h, pixel_depth=32):
30 : "r210",
}[pixel_depth]
if NVFBC_CUDA:
from xpra.codecs.nvfbc.fbc_capture_win import NvFBC_CUDACapture
from xpra.codecs.nvfbc.fbc_capture_win import NvFBC_CUDACapture #@UnresolvedImport
capture = NvFBC_CUDACapture()
else:
from xpra.codecs.nvfbc.fbc_capture_win import NvFBC_SysCapture
from xpra.codecs.nvfbc.fbc_capture_win import NvFBC_SysCapture #@UnresolvedImport
capture = NvFBC_SysCapture()
capture.init_context(w, h, pixel_format)
except Exception as e:
Expand Down Expand Up @@ -234,7 +238,7 @@ def refresh_shape(self):
shapelog("refresh_shape() notifying: %s", cb)
try:
cb(self, pspec, *args)
except:
except Exception:
shapelog.error("error in shape notify callback %s", cb, exc_info=True)

def connect(self, signal, cb, *args):
Expand All @@ -257,21 +261,21 @@ def enum_windows_cb(hwnd, lparam):
if not IsWindowVisible(hwnd):
l("skipped invisible window %#x", hwnd)
return True
pid = ctypes.c_int()
thread_id = GetWindowThreadProcessId(hwnd, ctypes.byref(pid))
pid = c_int()
thread_id = GetWindowThreadProcessId(hwnd, byref(pid))
if pid==ourpid:
l("skipped our own window %#x", hwnd)
return True
#skipping IsWindowEnabled check
length = GetWindowTextLengthW(hwnd)
buf = ctypes.create_unicode_buffer(length+1)
buf = create_unicode_buffer(length+1)
if GetWindowTextW(hwnd, buf, length+1)>0:
window_title = buf.value
else:
window_title = ''
l("get_shape_rectangles() found window '%s' with pid=%i and thread id=%i", window_title, pid, thread_id)
rect = RECT()
if GetWindowRect(hwnd, ctypes.byref(rect))==0:
if GetWindowRect(hwnd, byref(rect))==0:
l("GetWindowRect failure")
return True
left, top, right, bottom = rect.left, rect.top, rect.right, rect.bottom
Expand All @@ -296,8 +300,8 @@ def enum_windows_cb(hwnd, lparam):
# ('rgstate', DWORD * 6),
#]
#ti = TITLEBARINFO()
#ti.cbSize = ctypes.sizeof(ti)
#GetTitleBarInfo(hwnd, ctypes.byref(ti))
#ti.cbSize = sizeof(ti)
#GetTitleBarInfo(hwnd, byref(ti))
#if ti.rgstate[0] & win32con.STATE_SYSTEM_INVISIBLE:
# log("skipped system invisible window")
# return True
Expand Down Expand Up @@ -375,7 +379,8 @@ def power_broadcast_event(self, wParam, lParam):
log.info("WM_POWERBROADCAST: PBT_APMSUSPEND")
for source in self._server_sources.values():
source.may_notify(XPRA_IDLE_NOTIFICATION_ID, "Server Suspending",
"This Xpra server is going to suspend,\nthe connection is likely to be interrupted soon.", expire_timeout=10*1000, icon_name="shutdown")
"This Xpra server is going to suspend,\nthe connection is likely to be interrupted soon.",
expire_timeout=10*1000, icon_name="shutdown")
elif wParam==win32con.PBT_APMRESUMEAUTOMATIC:
log.info("WM_POWERBROADCAST: PBT_APMRESUMEAUTOMATIC")

Expand All @@ -397,7 +402,8 @@ def print_screen_info(self):

def make_tray_widget(self):
from xpra.platform.win32.win32_tray import Win32Tray
return Win32Tray(self, XPRA_APP_ID, self.tray_menu, "Xpra Shadow Server", "server-notconnected", None, self.tray_click_callback, None, self.tray_exit_callback)
return Win32Tray(self, XPRA_APP_ID, self.tray_menu, "Xpra Shadow Server", "server-notconnected",
None, self.tray_click_callback, None, self.tray_exit_callback)


def setup_capture(self):
Expand Down Expand Up @@ -439,8 +445,8 @@ def refresh(self):

def do_get_cursor_data(self):
ci = CURSORINFO()
ci.cbSize = ctypes.sizeof(CURSORINFO)
GetCursorInfo(ctypes.byref(ci))
ci.cbSize = sizeof(CURSORINFO)
GetCursorInfo(byref(ci))
#cursorlog("GetCursorInfo handle=%#x, last handle=%#x", ci.hCursor or 0, self.cursor_handle or 0)
if not (ci.flags & win32con.CURSOR_SHOWING):
#cursorlog("do_get_cursor_data() cursor not shown")
Expand All @@ -464,7 +470,7 @@ def do_get_cursor_data(self):

def get_pointer_position(self):
pos = POINT()
GetPhysicalCursorPos(ctypes.byref(pos))
GetPhysicalCursorPos(byref(pos))
return pos.x, pos.y

def do_process_mouse_common(self, proto, wid, pointer, *_args):
Expand Down
44 changes: 24 additions & 20 deletions src/xpra/server/shadow/root_window_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

import socket

from xpra.log import Logger
log = Logger("shadow")

from xpra.util import prettify_plug_name
from xpra.os_util import get_generic_os_name
from xpra.log import Logger

log = Logger("shadow")


class RootWindowModel(object):
Expand All @@ -19,7 +19,11 @@ def __init__(self, root_window, capture=None):
self.window = root_window
self.geometry = root_window.get_geometry()[:4]
self.capture = capture
self.property_names = ["title", "class-instance", "client-machine", "window-type", "size-hints", "icon", "shadow"]
self.property_names = [
"title", "class-instance",
"client-machine", "window-type",
"size-hints", "icon", "shadow",
]
self.dynamic_property_names = []
self.internal_property_names = ["content-type"]

Expand Down Expand Up @@ -102,27 +106,29 @@ def get_property(self, prop):
#otherwise fallback to default behaviour:
if prop=="title":
return prettify_plug_name(self.window.get_screen().get_display().get_name())
elif prop=="client-machine":
if prop=="client-machine":
return socket.gethostname()
elif prop=="window-type":
if prop=="window-type":
return ["NORMAL"]
elif prop=="fullscreen":
if prop=="fullscreen":
return False
elif prop=="shadow":
if prop=="shadow":
return True
elif prop=="scaling":
if prop=="scaling":
return None
elif prop=="opacity":
if prop=="opacity":
return None
elif prop=="size-hints":
if prop=="size-hints":
size = self.get_dimensions()
return {"maximum-size" : size,
"minimum-size" : size,
"base-size" : size}
elif prop=="class-instance":
return {
"maximum-size" : size,
"minimum-size" : size,
"base-size" : size,
}
if prop=="class-instance":
osn = get_generic_os_name()
return ("xpra-%s" % osn, "Xpra-%s" % osn.upper())
elif prop=="icon":
if prop=="icon":
try:
from xpra.platform.paths import get_icon
icon_name = get_generic_os_name()+".png"
Expand All @@ -132,11 +138,9 @@ def get_property(self, prop):
except:
log("failed to return window icon")
return None
elif prop=="content-type":
if prop=="content-type":
return "desktop"
else:
raise ValueError("invalid property: %s" % prop)
return None
raise ValueError("invalid property: %s" % prop)

def get(self, name, default_value=None):
try:
Expand Down

0 comments on commit b971cd2

Please sign in to comment.