This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__all__ = ( | |
####### Class Objects | |
#CoGetClassObject - Normal, not wrapped | |
'CoDllGetClassObject', #Get ClassObject from a DLL file | |
####### ClassFactory::CreateInstance Wrappers | |
'CoCreateInstanceFromFactory', #Create an object via IClassFactory::CreateInstance | |
'CoCreateInstanceFromFactoryLicenced', #Create a licenced object via IClassFactory2::CreateInstanceLic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pythoncom | |
import win32com.client | |
from uuid import UUID | |
from ctypes import OleDLL, WinDLL, c_long, c_ulong, byref, WINFUNCTYPE, POINTER, c_char_p, pointer | |
from ctypes.wintypes import HRESULT | |
IID_IClassFactory2 = "{B196B28F-BAB4-101A-B69C-00AA00341D07}" | |
def CoCreateInstanceLicenced(clsid_class, iid_interface=pythoncom.IID_IDispatch, key='', dwClsContext=pythoncom.CLSCTX_SERVER, pythoncom_iid_interface=pythoncom.IID_IDispatch, pythoncom_wrapdisp=True): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Example: | |
import django.db | |
from cStringIO import StringIO | |
def inspect_mdb(filename): | |
db_dict = {'ENGINE': 'access.pyodbc', 'OPTIONS': {'driver': 'access'}, 'NAME': filename} | |
with temp_db(db_dict, 'test') as using: | |
django.db.connections[using].cursor() #Connect immediately |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This class lets you add the 'other side' of a m2m to a django model. | |
#Why this is better than just using related_name: | |
# -Admin sees it as a real field, gives you the filter_horizontal widget if you ask | |
# | |
#Issues: | |
# -Probably breaks syncdb (table tries to be created twice) | |
# | |
#Non-issues: | |
# -Doesn't break south (custom introspection rule makes this field ignored) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def clipcopy(z): | |
#http://stackoverflow.com/questions/579687 | |
z = unicode(z) | |
try: | |
import win32clipboard | |
except ImportError: | |
from Tkinter import Tk | |
r = Tk() | |
r.withdraw() | |
r.clipboard_clear() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt4 import QtCore | |
from config import get_data_path | |
class SettingsWrapper(object): | |
"""Wrapper for QSettings using attribute access with conversion functions""" | |
_known_settings = { | |
#'setting': (conversionFuncRead, conversionFuncReadAttr, default), | |
} | |
def __init__(self, settings, subtree=None): | |
self._settings = settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
#Allow lookup by any kwargs in admin | |
#Reverts https://docs.djangoproject.com/en/1.2/releases/1.2.4/#restricted-filters-in-admin-interface | |
admin.ModelAdmin.lookup_allowed = lambda i, k, v: True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
import win32net | |
def getUsername(name_format=8): | |
#Only NameUserSamCompatable supported if not on a domain. | |
#'' is returned in that case. | |
#NameUserSamCompatable = 2 | |
#NameUserPrincipal = 8, | |
bufsz = ctypes.c_ulong() | |
ctypes.windll.secur32.GetUserNameExW(name_format, None, ctypes.byref(bufsz)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import ctypes | |
import traceback | |
import logging | |
log = logging.getLogger() | |
from QtBinding import QtCore, QtGui | |
def remove_window_context_help_button(qwindow): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import platform | |
#wnd is a HWND | |
def forceFocus(wnd): | |
if platform.system() != 'Windows': | |
return | |
SPI_GETFOREGROUNDLOCKTIMEOUT = 0x2000 | |
SPI_SETFOREGROUNDLOCKTIMEOUT = 0x2001 | |
SW_RESTORE = 9 |