-
abcabc
I will put it in a github repo with MIT license after two/three weeks ( Need to do some cleanup, add some more features, add few more
examples) -
abcabc
Did you try my code on mac or PC? (I have tested on PC ,(windows 10, kivy 1.9.1, python 3.6) it works fine.)
-
-
abcabc
I am sorry if I hurt your feelings. I thought that this code will help somebody like me who is familiar with pythonista but not with kivy. I just spent two to three hours to code this. I do not have any projects related to this and I am not associated with any company. I am a retired old man and my only intention is to help others. Once again I am sorry if I hurt your feelings.
-
abcabc
Nice. Here is a slightly different approach.
- Rather than using new set of API, pythonista API is used as standard. For example, "example1.py" (modified example of yours) runs directly in pythonista (currently it requires one line change from kivy code)
- In Kivy, you need an extra file "ui.py". All the code is in this file. It is just a wrapper on kivy objects.
- This code is not complete and a lot needs to be done.
import ui def closepage(sender): v.close() def function_1(sender): v['label1'].text = 'Oh! You clicked my button.' #uncomment or comment lines below based on platform #v = ui.MainView(frame=(0, 0, 600, 450)) # kivy v = ui.View(frame=(0, 0, 600, 450)) # pythonista v.add_subview(ui.Label(frame=(80, 10, 240, 20), name='label1', text='Hey I am just a simple label.')) v.add_subview(ui.Button(frame=(40, 40, 100, 40), title='Click me', action=function_1)) v.add_subview(ui.Button(frame=(460, 40, 100, 40), title='Close me', action=closepage)) v.add_subview(ui.TextField(frame=(40, 120, 300, 40), name='textfield1', text='I am a text field')) v.add_subview(ui.ImageView(frame=(460, 310, 100, 100), image=ui.Image('insidelogo.png'))) v.present('sheet')
from kivy.uix.floatlayout import FloatLayout from kivy.core.window import Window from kivy.base import runTouchApp from kivy.utils import platform as core_platform import sys from kivy.uix.label import Label as KivyLabel from kivy.uix.button import Button as KivyButton from kivy.uix.textinput import TextInput from kivy.uix.image import Image as KivyImage from kivy.graphics import Color from kivy.graphics import Rectangle class View(object): screen_size = (800, 600) xratio = screen_size[0] / 800.0 yratio = screen_size[1] / 600.0 def __init__(self, frame=(0,0,100,100), name=''): self.frame = frame self.name = name self.superview = None self.uniobject = None self.rootdict = {} class MainView(View): def __init__(self, frame=(0,0,100,100), name=''): super().__init__(frame=frame, name=name) self.root = FloatLayout() Window.size = View.screen_size self.root.canvas.add( Color(1.0, 1.0, 1.0)) self.root.canvas.add( Rectangle(pos = (self.frame[0] * View.xratio, self.frame[1]*View.yratio), size = (frame[2] * View.xratio, frame[3] * View.yratio))) def add_subview(self, v): v.superview = self if v.name: self.rootdict[v.name] = v.kivyobject self.root.add_widget(v.kivyobject) def __getitem__(self, key): return self.rootdict[key] def close(self): if core_platform == 'android': sys.exit() else: Window.close() def present(self, style): #todo: screen size, style runTouchApp(self.root) class Button(View): def __init__(self, frame=(0,0,100,100), title='', name='', font=('Helvetica', 20), action=None): super().__init__(frame=frame, name=name) self.kivyobject = (KivyButton(text=title, size_hint_y = None, size_hint_x = None, width = self.frame[2]* View.xratio, height = self.frame[3]* View.yratio, pos = (self.frame[0] * View.xratio, self.frame[1] * View.yratio), on_press = action)) class Label(View): def __init__(self, frame=(0,0,100,100), text='', alignment='', name='', font=('Helvetica', 20), text_color='blue'): super().__init__(frame=frame, name=name) label = KivyLabel(text=text, id=name, size_hint=(1.0, 1.9), halign="left", valign="bottom", pos = (self.frame[0] * View.xratio, self.frame[1] * View.yratio)) #label.bind(size=label.setter('text_size')) self.kivyobject = (label) class TextField(View): def __init__(self, frame=(0,0,100,100), text='', name='', font=('Helvetica', 20), alignment='', text_color='blue'): #action=None): super().__init__(frame=frame, name=name) self.kivyobject = (TextInput(text=text, size_hint_y = None, size_hint_x = None, height = self.frame[3]* View.yratio, width = self.frame[2]* View.xratio, multiline = True, pos = (self.frame[0] * View.xratio, self.frame[1] * View.yratio))) #on_press = action)) class ImageView(View): def __init__(self, frame=(0,0,100,100), name='', image=None): super().__init__(frame=frame, name=name) if image: image_source = image.source else: image_source = None self.kivyobject = ( KivyImage(source=image_source, allow_stretch = True, size = (self.frame[2]* View.xratio, self.frame[3]* View.yratio), pos = (self.frame[0] * View.xratio, self.frame[1] * View.yratio))) class Image(object): def __init__(self, source): self.source = source
Copy of the code in gist.
https://gist.github.com/balachandrana/4e9accfc894785682f230c54dc5da816#file-ui-py -
abcabc
Pythonista does not support modules like subprocess. Hence I think that you may not be able to run this on pythonista.
I am able to install it but it gives error while running (not able to start the interactive session).
-
abcabc
Look at this link. I have not tried it.
https://github.com/secdev/scapy/issues/401 -
abcabc
-
dropbox sync (look at few posts before) seems to work fine
https://forum.omz-software.com/topic/3951/sync-to-dropbox -
May be "Pythonista find and replace" does not support regular expressions
-
A simple appex script could be used to save files on pythonista
-
loading from working copy is another option
-
Look at this for some more editor options
https://forum.omz-software.com/topic/3543/share-in-work-side-bar-replacement
-
-
abcabc
I am able to reproduce the problem on my ipad ( Pythonista version 3.1.1 (311002) running Python 3.5.1 on iOS 10.1.1 on a 32-bit iPad3,4 with ascreen size of (1024 x 768) * 2) ). It looks like that my ipad is not able to handle large paths and i have done the following modifications to run it on my ipad. I have precomputed the shape nodes and have added a reduction factor. I am able to run with reduction factor 4 and above.
(I have also created a pretty printed version of pathLists file which can be edited on pythonista IDE
https://gist.github.com/balachandrana/de8c3a84ad59be90064108b148a8bd21 )Other possibility is implementing this in shaders and "2D vector graphics library" in shadertoy could help in this implementation.
https://www.shadertoy.com/view/lslXW8import scene from variableTools import glyphsListConstruct glyphs_list1 = glyphsListConstruct() reduction_factor = 4.0 x_factor = (10.24 / 2)*reduction_factor class MyScene(scene.Scene): def setup(self): self.glyphs_list = [scene.ShapeNode(i) for i in glyphs_list1[::int(reduction_factor)]] self.myPath = self.glyphs_list[0] self.myPath.anchor_point = 0, 0 self.myPath.position = (1024 - self.myPath.bbox.width * 1.75, 768 - self.myPath.bbox.height * 1.3) self.add_child(self.myPath) self.background_color = 'lightgrey' self.touch_moved = self.touch_began def touch_began(self, touch): r = int(touch.location.x / x_factor)%len(self.glyphs_list) #print(touch.location.x, r) self.myPath.remove_from_parent() self.myPath = self.glyphs_list[r] self.myPath.anchor_point = 0, 0 self.myPath.position = (1024 - self.myPath.bbox.width * 1.75, 768 - self.myPath.bbox.height * 1.3) self.add_child(self.myPath) scene.run(MyScene(), show_fps=True)
-
abcabc
-
A simple way to combine gifs would be to get the image lists of each gif, concatenate these image lists to form a single images list and then generate a new gif from this single list.
-
It seems to be a documentation error. The second one should be remove_assets. You could file an issue regarding this.
https://github.com/omz/Pythonista-Issues
-
-
abcabc
Even this works.
from scene import * import ui from objc_util import * glyphsDict = {} for i in range(96): font=ObjCClass('UIFont').systemFontOfSize_weight_(32+i,1) s='a' #'Hello world' p=ui.Path() p.line_width = 1 w=0 c.CTFontCreatePathForGlyph.restype = c_void_p c.CTFontCreatePathForGlyph.argtypes = [c_void_p, c_void_p, c_void_p] x = s.encode('ascii')[0] glyph= font._defaultGlyphForChar_(x) if not x==32: #space letter = ObjCInstance(c.CTFontCreatePathForGlyph(font, glyph, None)) letterBezier=UIBezierPath.bezierPathWithCGPath_(letter) #transform it so we shift and flip y letterBezier.applyTransform_(CGAffineTransform(1,0,0,-1,w,font.capHeight())) ObjCInstance(p).appendBezierPath_(letterBezier) w+=font.advancementForGlyph(glyph).width glyphsDict[i] = p #glyphsDict = {i:ui.Path.oval(0,0,10+i, 10+i) for i in range(200)} class MyScene (Scene): def setup(self): self.center = self.size/2 self.myPath = ShapeNode(glyphsDict[0], stroke_color='red', position=self.center, parent=self) self.background_color = 'grey' def touch_began(self, touch): x, y = touch.location x = x - self.center.x z = int(abs(x/5.0))%len(glyphsDict) self.myPath.path = glyphsDict[z] # Setting a new path to draw def touch_moved(self, touch): x, y = touch.location x = x - self.center.x z = int(abs(x/5.0))%len(glyphsDict) self.myPath.path = glyphsDict[z] # Setting a new path to draw run(MyScene(), show_fps=True)
-
abcabc
Simple shapes seem to work fine as you can see from the following code. As suggested by @JonB you can give us a sample glyphDict that fails.
from scene import * import ui glyphsDict = {i:ui.Path.oval(0,0,10+i, 10+i) for i in range(200)} class MyScene (Scene): def setup(self): self.center = self.size/2 self.myPath = ShapeNode(glyphsDict[0], fill_color='red', position=self.center, parent=self) self.background_color = 'grey' def touch_began(self, touch): x, y = touch.location x = x - self.center.x z = int(abs(x/5.0))%len(glyphsDict) self.myPath.path = glyphsDict[z] # Setting a new path to draw def touch_moved(self, touch): x, y = touch.location x = x - self.center.x z = int(abs(x/5.0))%len(glyphsDict) self.myPath.path = glyphsDict[z] # Setting a new path to draw run(MyScene(), show_fps=True)
-
abcabc
"Animated Gif.py" in "Examples/Misc" directory would combine images to gif. There does not seem to be a direct utility for combining images to video. As suggested by @dgelessus you may have to use workflow app for that.
-
abcabc
dialogs.py is pure python module (available in Standard Library(3.5)/site-packages). You can copy it (say as custom_dialogs.py) and modify it according to your need. In this case you may need to add a line like as follows after cell initialization :
cell.text_label.font = ('Helvetica', 25)
-
abcabc
Nice. The following two lines could be added after cubenode definition if someone wants to animate the cube. (Also need to include SCNAction in the list defined after load_framework)
rotate_action = SCNAction.repeatActionForever_(SCNAction.rotateByX_y_z_duration_(0, math.pi*2, math.pi*2, 10)) cube_node.runAction_(rotate_action)
-
abcabc
You may also look at this discussion.
https://forum.omz-software.com/topic/3728/having-trouble-writing-a-video-file-to-local-storage-ends-up-corrupted -
abcabc
Thanks Omz . I tried also the basic code from following tutorial using your template and it is working fine.
https://code.tutsplus.com/tutorials/an-introduction-to-scenekit-fundamentals--cms-23847from objc_util import * import ui import math load_framework('SceneKit') SCNView, SCNScene, SCNBox, SCNText, SCNNode, SCNLight, SCNCamera, SCNAction, UIFont = map(ObjCClass, ['SCNView', 'SCNScene', 'SCNBox', 'SCNText', 'SCNNode', 'SCNLight', 'SCNCamera', 'SCNAction', 'UIFont']) class SCNVector3 (Structure): _fields_ = [('x', c_float), ('y', c_float), ('z', c_float)] ''' https://code.tutsplus.com/tutorials/an-introduction-to-scenekit-fundamentals--cms-23847 ''' ''' override func viewDidLoad() { super.viewDidLoad() let sceneView = SCNView(frame: self.view.frame) self.view.addSubview(sceneView) let scene = SCNScene() sceneView.scene = scene let camera = SCNCamera() let cameraNode = SCNNode() cameraNode.camera = camera cameraNode.position = SCNVector3(x: 0.0, y: 0.0, z: 3.0) let light = SCNLight() light.type = SCNLightTypeOmni let lightNode = SCNNode() lightNode.light = light lightNode.position = SCNVector3(x: 1.5, y: 1.5, z: 1.5) let cubeGeometry = SCNBox(width: 1.0, height: 1.0, length: 1.0, chamferRadius: 0.0) let cubeNode = SCNNode(geometry: cubeGeometry) scene.rootNode.addChildNode(lightNode) scene.rootNode.addChildNode(cameraNode) scene.rootNode.addChildNode(cubeNode) } ''' @on_main_thread def demo(): main_view = ui.View() main_view_objc = ObjCInstance(main_view) scene_view = SCNView.alloc().initWithFrame_options_(((0, 0),(400, 400)), None).autorelease() scene_view.setAutoresizingMask_(18) scene_view.setAllowsCameraControl_(True) main_view_objc.addSubview_(scene_view) main_view.name = 'SceneKit Demo' scene = SCNScene.scene() scene_view.setScene_(scene) root_node = scene.rootNode() camera = SCNCamera.camera() camera_node = SCNNode.node() camera_node.setCamera(camera) camera_node.setPosition((0.0, 0.0, 3.0)) light = SCNLight.light() light.setType_('omni') light_node = SCNNode.node() light_node.setLight_(light) light_node.setPosition((1.5, 1.5, 1.5)) cube_geometry = SCNBox.boxWithWidth_height_length_chamferRadius_(1, 1, 1, 0) cube_node = SCNNode.nodeWithGeometry_(cube_geometry) root_node.addChildNode_(light_node) root_node.addChildNode_(camera_node) root_node.addChildNode_(cube_node) main_view.present() demo()
Full example here
https://gist.github.com/balachandrana/644840a223b636ecd84d14a595dad33b -
abcabc
"init " method is not called properly. Here is some sample code that illustrates use of ShapeNode. Note that this works with python 3 and for working with python 2.7 you need to call super differently (super(Ball, self))
import scene, ui class Coin(scene.SpriteNode): def __init__(self, **kwargs): super().__init__('emj:Snowflake', **kwargs) class Ball(scene.ShapeNode): def __init__(self, **kwargs): circle = ui.Path.oval (0, 0, 20, 20) super().__init__(circle, fill_color='red', stroke_color='clear', shadow=None, **kwargs) class Polygon(scene.ShapeNode): def __init__(self, **kwargs): path = ui.Path() path.line_width = 5 path.move_to(0, 0) path.line_to(200, 0) path.line_to(100, 100) path.close() super().__init__(path, **kwargs) class MyScene(scene.Scene): def setup(self): self.ball = Ball(position=(200, 100), parent=self) self.coin = Coin(position=(200, 200), parent=self) self.triangle1 = Polygon(fill_color='skyblue', stroke_color='green', position=(200, 400), parent=self) self.triangle2 = Polygon(fill_color='red', stroke_color='green', position=(200, 300), parent=self) scene.run(MyScene())
-
abcabc
Here is the code to place the players. Moved the draw part of the player code to board and call "set_needs_display" in touch function.
Also added code to find the coordinates of the players and to validate the positions.import ui from math import floor class Player(object): def __init__(self, i, j, color): self.i, self.j = i, j self.xpos, self.ypos = self.i*60+5, self.j*60+5 self.color = color self.piece = None class Board(ui.View): def __init__(self): self.height, self.width = 400, 400 self.background_color = 0.8, 0.7, 0.5 self.name = "Mill" self.toggle = True self.positions = [] self.players = [] self.valid_positions = set([(0,0), (3,0), (6,0), (1,1), (3,1), (5,1), (2,2), (3,2), (4,2), (0,3),(1,3),(2,3),(4,3),(5,3),(6,3), (2,4), (3,4), (4,4), (1,5), (3,5), (5,5), (0,6), (3,6), (6,6)]) self.occupied = set() def draw(self): ui.set_color('black') for i in range(3): rect = ui.Path.rect(i*60+20, i*60+20, (3-i)*120, (3-i)*120) rect.line_width = 10 rect.stroke() def strokeLine(fx, fy, tx, ty): line = ui.Path() line.move_to(fx, fy) line.line_to(tx, ty) line.line_width = 5 line.stroke() strokeLine(200, 20, 200, 140) strokeLine(200, 260, 200, 380) strokeLine(20, 200, 140, 200) strokeLine(260, 200, 380, 200) for p in self.players: ui.set_color(p.color) p.piece = ui.Path.oval(p.xpos, p.ypos, 30, 30) p.piece.fill() def touch_began(self, touch): x,y = touch.location i = (floor(x)//60) j = (floor(y)//60) if (i,j) in self.valid_positions and (i,j) not in self.occupied: self.occupied.add((i,j)) color = 'black' if self.toggle else 'gray' self.toggle = not self.toggle player = Player(i, j, color) self.players.append(player) self.set_needs_display() v = Board() v.present('sheet')
-
abcabc
Try the following in stash
git clone https://github.com/tommasoturchi/mysql-connector-pythonista.git