Skip to content

Instantly share code, notes, and snippets.

View leixingyu's full-sized avatar
👋
Let's Connect!

Xingyu Lei leixingyu

👋
Let's Connect!
View GitHub Profile
"""
Run the python script as adminstrator, which means anything evoked
from this script will have admin privilege
https://stackoverflow.com/questions/130763/request-uac-elevation-from-within-a-python-script/
"""
import ctypes
import sys
import socket
HEADER = 64
FORMAT = 'utf-8'
PORT = 5050
SERVER = '10.56.103.74'
ADDR = (SERVER, PORT)
import socket
import threading
# import pickle
# instead of sending strings, pickle serializes python object and
# unpickle de-serialize python object to put in use
# custom message protocol
# header message that represent how long the return message length is
HEADER = 64
import csv
import os
import signal
import subprocess
PROCESS = 'notepad.exe'
STATUS = 'running' # running or not responding
CMD = r'tasklist /fi "IMAGENAME eq {}" /fi "STATUS eq {}" /fo "csv"'.format(PROCESS, STATUS)
# output as csv format
import ctypes
EnumWindows = ctypes.windll.user32.EnumWindows
EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))
GetWindowText = ctypes.windll.user32.GetWindowTextW
GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
GetWindowProcessId = ctypes.windll.user32.GetWindowThreadProcessId
IsWindowVisible = ctypes.windll.user32.IsWindowVisible
winMapping = dict()
class TestUI(QtWidgets.QWidget):
def __init__(self, parent=None):
super(TestUI, self).__init__(parent)
# initialization object
layout = QtWidgets.QGridLayout()
pb = QtWidgets.QPushButton()
name = "SP_MessageBoxCritical"
icon = self.style().standardIcon(getattr(QtWidgets.QStyle, name))
class MyButton(QtWidgets.QPushButton):
def __init__(self, *args, **kwargs):
super(MyButton, self).__init__(*args, **kwargs)
def setPixmap(self, pixmap):
self.pixmap = pixmap
def sizeHint(self):
parent_size = QtWidgets.QPushButton.sizeHint(self)
return QtCore.QSize(parent_size.width() + self.pixmap.width(), max(parent_size.height(), self.pixmap.height()))
class MyButton(QtWidgets.QPushButton):
right_clicked = QtCore.Signal()
left_clicked = QtCore.Signal()
double_clicked = QtCore.Signal()
def __init__(self, *args, **kwargs):
super(MyButton, self).__init__(*args, **kwargs)
self.timer = QtCore.QTimer()
self.timer.setSingleShot(True)
class MainWidget(QtWidgets.QMainWindow):
def __init__(self, parent=None):
self.connectSignal()
def connectSignal(self):
self.someBtn.clicked.connect(self.openCustomWidget)
def openCustomWidget(self):
# initialize with a widget and a layout
self.customWidget = QtWidgets.QWidget()
class MainUI(QtWidgets.QMainWindow):
def __init__(self, parent=getMainWindow()):
super(MainUI, self).__init__(parent)
list = ['apple', 'banana', 'pear']
dialog = CustomDialog()
dialog.setNamespaceCBox(list)
# only when self.accept() is returned
# need close event to return self.close()