def test(method_as_string): def run(obj): m = mocker.Mocker() ob2 = object() # part 1: replace method if method_as_string: args = (obj, "isEqualTo_") else: args = (obj.isEqualTo_,) iseq = m.method(*args) iseq(ob2) >> True with m: assert obj.isEqualTo_(ob2) assert not obj.isEqualTo_(ob2), "%r == %r" % (obj, ob2) # part 2: check if the original is called after test func = iseq.replaced.func try: class Error(Exception): pass def error(self, arg): assert self is obj, "%r != %r" % (self, obj) assert arg is ob2, repr(arg) raise Error("expected error") iseq.replaced.func = error assert_raises(Error, obj.isEqualTo_, ob2) finally: iseq.replaced.func = func a = NSObject.alloc().init() b = NSObject.alloc().init() run(a) run(b) # make sure first run did not disable future method replacements
def NSMOsetValue_ForKey_(self, name, value): try: if '__objc_python_subclass__' in self.__class__.__dict__: super(self.__class__, self).setValue_forKey_(value, name) else: self.setValue_forKey_(value, name) except KeyError, msg: NSObject.__setattr__(self, name, value)
def NSMOsetValue_ForKey_(self, name, value): try: first = _first_python(self.__class__) if first is not None: super(first, self).setValue_forKey_(value, name) else: self.setValue_forKey_(value, name) except KeyError: NSObject.__setattr__(self, name, value)
def NSMOsetValue_ForKey_(self, name, value): try: first = _first_python(self.__class__) if first is not None: super(first, self).setValue_forKey_(value, name) else: self.setValue_forKey_(value, name) except KeyError as msg: NSObject.__setattr__(self, name, value)
def __init__(self, path): bundle = NSBundle.mainBundle() info = bundle.localizedInfoDictionary() or bundle.infoDictionary() # Did you know you can override parts of infoDictionary (Info.plist, after loading) even though Apple says it's read-only? info['LSUIElement'] = '1' # Initialize our shared application instance NSApplication.sharedApplication() # Two possibilities here # Either the path is a directory and we really want the file inside it # or the path is just a real .nib file if os.path.isdir(path): # Ok, so they just saved it from Xcode, not their fault # let's fix the path path = os.path.join(path, 'keyedobjects.nib') with open(path, 'rb') as f: # get nib bytes d = buffer(f.read()) n_obj = NSNib.alloc().initWithNibData_bundle_(d, None) placeholder_obj = NSObject.alloc().init() result, n = n_obj.instantiateWithOwner_topLevelObjects_( placeholder_obj, None) self.hidden = True self.nib_contents = n self.win = [ x for x in self.nib_contents if x.className() == 'NSWindow' ][0] self.views = views_dict(self.nib_contents) self._attached = []
def main(): display_id = Quartz.CGMainDisplayID() session = AVF.AVCaptureSession.alloc().init() devices = AVF.AVCaptureDevice.defaultDeviceWithMediaType_( AVF.AVMediaTypeAudio) print(devices) screen_input = AVF.AVCaptureScreenInput.alloc().initWithDisplayID_( display_id) error = None audio, error = AVF.AVCaptureDeviceInput.deviceInputWithDevice_error_( devices, objc.nil) file_output = AVF.AVCaptureMovieFileOutput.alloc().init() session.addInput_(screen_input) session.addInput_(audio) session.addOutput_(file_output) session.startRunning() file_url = NSURL.fileURLWithPath_('fooste.mov') # Cheat and pass a dummy delegate object where normally we'd have a # AVCaptureFileOutputRecordingDelegate file_url = file_output.startRecordingToOutputFileURL_recordingDelegate_( file_url, NSObject.alloc().init()) time.sleep(30) session.stopRunning()
def test(method_as_string): def run(obj): m = mocker.Mocker() ob2 = object() # part 1: replace method if method_as_string: args = (obj, "isEqualTo_") else: args = (obj.isEqualTo_, ) iseq = m.method(*args) iseq(ob2) >> True with m: assert obj.isEqualTo_(ob2) assert not obj.isEqualTo_(ob2), "%r == %r" % (obj, ob2) # part 2: check if the original is called after test func = iseq.replaced.func try: class Error(Exception): pass def error(self, arg): assert self is obj, "%r != %r" % (self, obj) assert arg is ob2, repr(arg) raise Error("expected error") iseq.replaced.func = error assert_raises(Error, obj.isEqualTo_, ob2) finally: iseq.replaced.func = func a = NSObject.alloc().init() b = NSObject.alloc().init() run(a) run(b ) # make sure first run did not disable future method replacements
audio, error = AVF.AVCaptureDeviceInput.deviceInputWithDevice_error_(devices, objc.nil) file_output = AVF.AVCaptureMovieFileOutput.alloc().init() session.addInput_(screen_input) session.addInput_(audio) session.addOutput_(file_output) if now in str(df['starttime']): row = df.loc[df['starttime'] == now] link = str(row.iloc[0,1]) pwd = str(row.iloc[0,3]) if link.startswith('http'): if pd.isnull(df.loc[0, 'pass']): now = datetime.now() dt_file_name = now.strftime("ZoomRecording-%Y-%m-%d_%H-%M-%S.mov") session.startRunning() file_url = NSURL.fileURLWithPath_(dt_file_name) file_url = file_output.startRecordingToOutputFileURL_recordingDelegate_(file_url, NSObject.alloc().init()) webbrowser.open(link) print("1") time.sleep(10) time.sleep(60) else: now = datetime.now() dt_file_name = now.strftime("ZoomRecording-%Y-%m-%d_%H-%M-%S.mov") session.startRunning() file_url = NSURL.fileURLWithPath_(dt_file_name) file_url = file_output.startRecordingToOutputFileURL_recordingDelegate_(file_url, NSObject.alloc().init()) webbrowser.open(link) print("2") time.sleep(15) typewrite(pwd, interval=0.4) time.sleep(10)