def __init__(self, **kwargs): super().__init__(**kwargs) self.times = [] for i in range(len(self.default_times)): time_value = self.default_times[i] b = ui.Button( tint_color='black', #tint_color='white', background_color='white', #border_color='lightgrey', #border_width=1, corner_radius=10, flex='WH') if time_value == 'theme': b.image = ui.Image('iob:waterdrop_32') b.action = self.toggle_theme else: b.title = str(time_value) b.action = self.go_to_timer #b.objc_instance.setClipsToBounds_(False) bl = b.objc_instance.layer() bl.setMasksToBounds_(False) bl.setShadowOpacity_(1) bl.setShadowRadius_(1) bl.setShadowOffset_(objc_util.CGSize(2, 2)) bl.setShadowColor_(objc_black) b.font = (font, self.cell_font) #if i % 2 == 1: # b.background_color = 'darkgrey' self.times.append(b) self.add_subview(b) self.set_theme()
def apply(self, attr_str): self.attr_str = attr_str shadow = NSShadow.alloc().init() shadow.setShadowOffset_(objc_util.CGSize(*self.offset)) shadow.setShadowColor_(self.objc_color) shadow.setShadowBlurRadius_(self.blur) self.set('NSShadow', shadow)
def __init__(self, *args, **kwargs): super().__init__(self, *args, **kwargs) self._view = objc_util.ObjCClass("MKMapView").new() self._view.setFrame_( objc_util.CGRect(objc_util.CGPoint(0, 0), objc_util.CGSize(self.width, self.height))) self._view.setAutoresizingMask_(18) # W+H objc_util.ObjCInstance(self).addSubview_(self._view) self.animated = True
def bounds(self, coords): """get the upper left and lower right coordinates of the visible map area with latitude/longitude values.""" topleft, bottomright = coords[:2], coords[2:] min_x, min_y = topleft max_x, max_y = bottomright span = (max_x - min_x, max_y - min_y) center = (min_x + span[0] / 2, min_y + span[1] / 2) self._view.setRegion_animated_( _CoordinateRegion( objc_util.CGPoint(*center), objc_util.CGSize(*span), ), self.animated, restype=None, argtypes=[_CoordinateRegion, objc_util.c_bool])
# coding: utf-8 # https://github.com/jsbain/objc_hacks/blob/master/objcstuff.py import objc_util, ui v = ui.View() vv = objc_util.ObjCInstance(v._objc_ptr) wnd = objc_util.ObjCClass('UIWindow').alloc() r = objc_util.CGRect(objc_util.CGPoint(0, 0), objc_util.CGSize(100, 100)) wnd.initWithFrame_(r)
def get_text_width(view): size = view.objc_instance.sizeThatFits_(objc_util.CGSize(0, view.height)) return size.width
def get_text_height(view): size = view.objc_instance.sizeThatFits_(objc_util.CGSize(view.width, 0)) return size.height
def __init__(self, chosen_pic): self.MLModel = objc_util.ObjCClass('MLModel') self.VNCoreMLModel = objc_util.ObjCClass('VNCoreMLModel') self.VNCoreMLRequest = objc_util.ObjCClass('VNCoreMLRequest') self.VNImageRequestHandler = objc_util.ObjCClass('VNImageRequestHandler') result = self.classify_asset(chosen_pic) if result: resultString = str(result) resultWidth = int(resultString[resultString.find('width=') + 6:resultString.find(' ', resultString.find('width=') + 6)]) resultHeight = int(resultString[resultString.find('height=') + 7:resultString.find(' ', resultString.find('height=') + 7)]) CIImage = objc_util.ObjCClass('CIImage') pixelBuffer = result.pixelBuffer ci_img = CIImage.imageWithCVPixelBuffer_(pixelBuffer()) ctx = objc_util.ObjCClass('CIContext').context() cg_img = ctx.createCGImage_fromRect_(ci_img, objc_util.CGRect(objc_util.CGPoint(0, 0), objc_util.CGSize(resultWidth, resultHeight))) ui_img = objc_util.UIImage.imageWithCGImage_(cg_img) self.png_data = objc_util.uiimage_to_png(objc_util.ObjCInstance(ui_img))