def __init__(self, tableView, filterData, *args, **kwargs): ui.View.__init__(self, *args, **kwargs) frame = CGRect(CGPoint(0, 0), CGSize(self.width, self.height)) self.tv = tableView self.tableView = ObjCInstance(self.tv) flex_width, flex_height = (1 << 1), (1 << 4) self.tableView.setAutoresizingMask_(flex_width | flex_height) sd = createSearchDelegateClass() self.searchDelegate = sd.alloc().init().autorelease() self.searchDelegate.filt = filterData searchBar = UISearchBar.alloc().init() searchBar.setPlaceholder_(ns('Search')) searchBar.setDelegate_(self.searchDelegate) #searchBar.setShowsBookmarkButton_(ns(True)) searchBar.setShowsCancelButton_(ns(True)) #searchBar.setShowsSearchResultsButton_(ns(True)) #searchBar.setScopeButtonTitles_(ns(['test1','hi'])) #searchBar.setShowsScopeBar(ns(True)) self.tableView.setTableHeaderView_(searchBar) searchBar.sizeToFit() self_objc = ObjCInstance(self) self_objc.addSubview_(self.tableView) self.tableView.release()
class View(ui.View): def __init__(self): self.instance = ObjCInstance(self) self.setup_objc() self.setup_ui() @on_main_thread def setup_objc(self): self.vc = ViewController() self.instance.addSubview_(self.vc.scn_view) def setup_ui(self): self.close_btn = self.create_btn('iob:ios7_close_32') self.close_btn.action = (lambda sender: self.close()) self.add_subview(self.close_btn) def create_btn(self, icon): btn_icon = ui.Image.named(icon) return ui.Button(image=btn_icon) def layout(self): _x, _y, _w, _h = self.frame _bx, _by, btn_w, btn_h = self.close_btn.frame self.close_btn.x = (_w * .92) - (btn_w / 2) self.close_btn.y = (_h * .08) - (btn_h / 2) def will_close(self): self.vc.view_will_disappear()
class MainView(ui.View): def __init__(self, *args, **kwargs): # todo: おまじないになっとる super().__init__(self, *args, **kwargs) self.bg_color = 'red' self.selfIns = ObjCInstance(self) initFrame = CGRect(CGPoint(0, 0), CGSize(self.width, self.height)) # fullViewSize flex_w, flex_h = (1 << 1), (1 << 4) uiTextView = ObjCClass('UITextView').alloc() self.uiTV = uiTextView self.uiTV.initWithFrame_(initFrame) self.uiTV.setAutoresizingMask_(flex_w | flex_h) self.uiTV.returnKeyType = 10 self.selfIns.addSubview_(self.uiTV)
class PlayerView(ui.View): '''A player view with controls''' def __init__(self, player=None, pause=True, autoplay=False): self._pause_on_dismiss = pause self._objc = ObjCInstance(self) self._playerViewController = AVPlayerViewController.new() self._objc.addSubview_(self._playerViewController.view()) self.player = player self._autoplay = autoplay @property def player(self): return self._playerItem @player.setter def player(self, player): if type(player) == Player: self._playerViewController.setPlayer_(player._objc) self._playerItem = player self.controller = PlayerController( self._playerViewController.playerController()) elif type(player) == type(None): self._playerViewController.setPlayer_(player) self._playerItem = None elif type(player) == ObjCInstance: self._playerItem = Player(player.currentItem()) self._playerViewController.setPlayer_(self._playerItem) self.controller = PlayerController( self._playerViewController.playerController()) else: raise TypeError("player is not able to be set") @player.deleter def player(self): self._playerViewController.setPlayer_(None) def will_close(self): if self._pause_on_dismiss: self.player.pause() def did_load(self): if self._autoplay: self.player.play() def layout(self): pass
class PlayerView (ui.View): '''A player view with controls''' def __init__(self, player = None, pause= True, autoplay = False, pip = False): self._pause_on_dismiss = pause self._objc = ObjCInstance(self) self._playerViewController = AVPlayerViewController.new() self._objc.addSubview_(self._playerViewController.view()) self.player = player self._autoplay = autoplay self._playerViewController.setAllowsPictureInPicturePlayback_(pip) @property def player(self): return self._playerItem @player.setter def player(self, player): if type(player) == Player: self._playerViewController.setPlayer_(player._objc) self._playerItem = player self.controller = PlayerController(self._playerViewController.playerController()) elif type(player) == type(None): self._playerViewController.setPlayer_(player) self._playerItem = None elif type(player) == ObjCInstance: self._playerItem = Player(player.currentItem()) self._playerViewController.setPlayer_(self._playerItem) self.controller = PlayerController(self._playerViewController.playerController()) else: raise TypeError("player is not able to be set") @player.deleter def player(self): self._playerViewController.setPlayer_(None) def will_close(self): if self._pause_on_dismiss: self.player.pause() def did_load(self): if self._autoplay: self.player.play() def layout(self): pass @property def pipSupported(self): self._playerViewController.allowsPictureInPicturePlayback() @pipSupported.setter def pipSupported(self, value): self._playerViewController.setAllowsPictureInPicturePlayback_(value) @property def showsPlaybackControls(self): return self._playerViewController.showsPlaybackControls() @showsPlaybackControls.setter def showsPlaybackControls(self, state): self._playerViewController.setShowsPlaybackControls_(state)
def __init__(self, tableView, filterData, selectCallBack, theme_manager, soofflineSelectCallBack, *args, **kwargs): ui.View.__init__(self, *args, **kwargs) self.width, self.height = ui.get_screen_size() frame = CGRect(CGPoint(0, 0), CGSize(self.width, self.height)) theme_manager_g = theme_manager self.theme_manager = theme_manager bkg_view = ui.View() bkg_view.background_color = self.theme_manager.currentTheme.backgroundColour self.tv = tableView self.tv.width = self.width self.tv.height = self.height self.tableView = ObjCInstance(self.tv) self.tableView.setBackgroundView(bkg_view) flex_width, flex_height = (1<<1), (1<<4) self.tableView.setAutoresizingMask_(flex_width|flex_height) self.selectCallBack = selectCallBack self.soofflineSelectCallBack = soofflineSelectCallBack v = UITableViewController.alloc().init().autorelease() tvd = createTableViewDelegateClass(theme_manager) self.tb_ds = tvd.alloc().init().autorelease() v.tableView().setDataSource_(self.tb_ds) v.tableView().setDelegate_(self.tb_ds) v.tableView().dataSource().data = [] v.tableView().dataSource().selectCallBack = self.performSelectCallBack self.searchController = UISearchController.alloc().initWithSearchResultsController_(v) self.searchController.resultController = v self.searchController.firstRun = True sd = createSearchDelegateClass() self.searchDelegate = sd.alloc().init().autorelease() self.searchDelegate.filter = filterData self.searchDelegate.resultController = v self.tableView.extendedLayoutIncludesOpaqueBars = True self.searchController.searchResultsUpdater = self.searchDelegate self.searchController.dimsBackgroundDuringPresentation = True self.searchController.hidesNavigationBarDuringPresentation = True self.searchController.searchBar().delegate = self.searchDelegate self.searchController.searchBar().setPlaceholder_(ns('Search')) self.tableView.tableHeaderView =self.searchController.searchBar(); self.searchController.searchBar().sizeToFit(); tColour = tuple(int(self.theme_manager.currentTheme.searchTintColour.lstrip('#')[i:i+2], 16) for i in (0, 2 ,4)) bTColour = tuple(int(self.theme_manager.currentTheme.searchBackgroundColour.lstrip('#')[i:i+2], 16) for i in (0, 2 ,4)) tColour = (tColour[0]/255, tColour[1]/255, tColour[2]/255) bTColour = (bTColour[0]/255, bTColour[1]/255, bTColour[2]/255) searchTintColour = UIColor.colorWithRed_green_blue_alpha_(tColour[0], tColour[1], tColour[2], 1) self.searchController.searchBar().tintColor = searchTintColour searchBackgroundTintColour = UIColor.colorWithRed_green_blue_alpha_(bTColour[0], bTColour[1], bTColour[2], 1) self.searchController.searchBar().tintColor = searchTintColour self.searchController.searchBar().barTintColor = searchBackgroundTintColour # self.tb_ds.textColour = searchTColour self.tv.border_color = self.theme_manager.currentTheme.borderColour self.tv.background_color = self.theme_manager.currentTheme.backgroundColour self.tv.bg_color = self.theme_manager.currentTheme.backgroundColour self.tv.tint_color = self.theme_manager.currentTheme.tintColour self.tv.separator_color = self.theme_manager.currentTheme.separatorColour bk_view = ui.View() bk_view.background_color = self.theme_manager.currentTheme.backgroundColour v.tableView().setBackgroundView(bk_view) self_objc = ObjCInstance(self) self_objc.addSubview_(self.tableView) self.tableView.release()
class View(ui.View): def __init__(self): self.bg_color = 'maroon' self.instance = ObjCInstance(self) self.viewDidLoad() self.setup_ui() @on_main_thread def viewDidLoad(self): ship_URL = nsurl('./assets/ship.scn') bkSky_URL = NSData.dataWithContentsOfURL_( nsurl('./assets/Background_sky.png')) tex_bks = UIImage.alloc().initWithData_(bkSky_URL) # --- Scene scene = SCNScene.sceneWithURL_options_(ship_URL, None) ship_node = scene.rootNode().objectInChildNodesAtIndex_(0) scene.background().contents = tex_bks scene.lightingEnvironment().contents = tex_bks scene.lightingEnvironment().intensity = 1.0 ship_material = SCNMaterial.material() ship_material.diffuse().contents = UIColor.purpleColor() ship_material.lightingModelName = 'SCNLightingModelPhysicallyBased' ship_geometry = ship_node.childNodes().objectAtIndex_(0).geometry() ship_geometry.material = ship_material ball_color = UIColor.colorWithRed_green_blue_alpha_(0.0, 0.5, 0.8, 0.5) ball_geometry = SCNSphere.sphereWithRadius_(0.5) ball_geometry.geodesic = True ball_geometry.segmentCount = 5 ball_geometry.material( ).lightingModelName = 'SCNLightingModelPhysicallyBased' ball_geometry.firstMaterial().diffuse().contents = ball_color ball_node = SCNNode.nodeWithGeometry_(ball_geometry) ball_node.position = (0.0, 6.0, 1.0) ball_node.eulerAngles = (1, 0, 0) scene.rootNode().addChildNode_(ball_node) # --- Light omni_object = SCNLight.light() omni_object.type = 'omni' omni_object.intensity = 250 omni_object.castsShadow = True omni_node = SCNNode.node() omni_node.light = omni_object omni_node.position = (0, 10.0, 0) scene.rootNode().addChildNode_(omni_node) # --- Camera camera_object = SCNCamera.camera() camera_object.wantsHDR = True camera_object.bloomBlurRadius = 18.0 camera_object.bloomIntensity = 1.0 camera_object.bloomThreshold = 1.0 camera_object.colorFringeIntensity = 4.0 camera_object.colorFringeStrength = 4.0 camera_object.motionBlurIntensity = 6 camera_object.xFov = 35.0 camera_object.yFov = 35.0 camera_node = SCNNode.node() camera_node.camera = camera_object camera_node.position = (0.0, 0.0, 25.0) scene.rootNode().addChildNode_(camera_node) # --- View frame = CGRect((0, 0), (100, 100)) flex_w, flex_h = (1 << 1), (1 << 4) scn_view = SCNView.alloc() scn_view.initWithFrame_options_(frame, None) scn_view.autorelease() scn_view.autoresizingMask = (flex_w | flex_h) scn_view.allowsCameraControl = True scn_view.showsStatistics = True ''' OptionNone = 0 ShowPhysicsShapes = (1 << 0) ShowBoundingBoxes = (1 << 1) ShowLightInfluences = (1 << 2) ShowLightExtents = (1 << 3) ShowPhysicsFields = (1 << 4) ShowWireframe = (1 << 5) RenderAsWireframe = (1 << 6) ShowSkeletons = (1 << 7) ShowCreases = (1 << 8) ShowConstraints = (1 << 9) ShowCameras = (1 << 10) ''' scn_view.debugOptions = (1 << 1) | (1 << 3) | (1 << 5) | (1 << 10) scn_view.scene = scene self.instance.addSubview_(scn_view) def setup_ui(self): self.close_btn = self.create_btn('iob:ios7_close_32') self.close_btn.action = (lambda sender: self.close()) self.add_subview(self.close_btn) def create_btn(self, icon): btn_icon = ui.Image.named(icon) return ui.Button(image=btn_icon) def layout(self): _x, _y, _w, _h = self.frame _bx, _by, btn_w, btn_h = self.close_btn.frame self.close_btn.x = (_w * .92) - (btn_w / 2) self.close_btn.y = (_h * .08) - (btn_h / 2)