@enceladus thanks, I knew I'd seen that somewhere before!
Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Posts made by m_doyle04
-
RE: Colour/tint built-in Images
-
Colour/tint built-in Images
Hi All,
I'm 99.99% sure I've read something about changing the colour/tint of Pythonista's in-built images somewhere in this forum but I've spent a long time searching and can't find it. Hopefully this post will appear more easily in searches in the future with some appropriate tags for the benefit of others.
I thought changing the colour of the in-built images would be as simple as accessing the "tint" or "tin_color" attributes of the Image object but it isn't. It's actually a real pain in the proverbial. For those interested you can do so by using the ImageContext as follows:
import ui with ui.ImageContext(100, 100) as ctx: ui.set_color('red') img = ui.Image('iob:arrow_down_a_256').with_rendering_mode(ui.RENDERING_MODE_TEMPLATE).draw(0,0,100,100) img = ctx.get_image() img.show()
-
Where is the _ui module and can i view it?
Hi All,
When we import the (pure python) ui module there is another module it depends on/imports - the _ui module...Is there anywhere I can view the source code for this?
Cheers
-
PNG to SpriteNode texture?
Hi All,
I've had a good look through this forum and as much documentation as I could take but I can't find a way to convert photos/images on my phone in PNG and JPEG format to a 'texture' for a SpriteNode in a Scene.
Anyone know how to do this? I can import as a 'ui.Image' but that doesn't work for SpriteNodes...
-
RE: ui.Switch and Scene
Thanks @mikael that's greatly appreciated. Problem solved!
-
RE: ui.Switch and Scene
Ah yes, I was missing the parentheses as I was playing around with it a bit. After correcting to MyScene2.clear_game() I get the error:
TypeError: clear_game() missing 1 required positional argument: 'self'
And when I run clear_game(self) I get the error:
ui.Switch object has no attribute "shape_list"
Obviously I was to be calling the shape_list attribute from the MyScene/MyScene2 object but am having trouble doing so.
-
ui.Switch and Scene
Hi All,
Would love some help on this one! I've got the bare bones of a game I'm building here but I've hit a stumbling block.
What I have is a ui.View with a ui.Switch attached at the top to control flicking between two scenes embedded scenes ("MyScene" and "MyScene2"). I can get the switch to flick between the two scenes but what I can't do is get the "clear_game" function to run within each Scene. Essentially what I want is either; A) ability to run the "clear_game" function from within each scene when the ui.Switch value changes or, B) ability to completely restart each scene when the ui.Switch value is changed.
Code is below. I'm not sure if this is troublesome because I'm trying to call a function within a Scene from a different module i.e. ui.Switch? Or am I just having a 'mare, so to speak?
from scene import * from ui import * import canvas X,Y = ui.get_screen_size() W,H = (X-40)/3,(X-40)/3 Left = 20 Mid = int(Left+W) Right = int(Mid+W) Base = 150 Centre = int(Base+H) Top = int(Centre+H) Locations = [(Left,Top),(Mid,Top),(Right,Top),(Left,Centre),(Mid,Centre),(Right,Centre),(Left,Base),(Mid,Base),(Right,Base)] def Switch_Flicked(self): if switch.value==True: V.remove_subview(SV) V.add_subview(SV2) MyScene2.clear_game else: V.remove_subview(SV2) V.add_subview(SV) MyScene.clear_game class MyView(ui.View): def __init__(self, *args, **kwargs): ui.View.__init__(self, *args, **kwargs) class Squares(ShapeNode): def __init__(self, *args, **kwargs): ShapeNode.__init__(self, path=ui.Path.rect(0,0,W,H), stroke_color='#000000', anchor_point=(0,0), fill_color='#ffffff', **kwargs) class MyScene(Scene): def setup(self): self.background_color = '#4dc870' self.shape_list = [] for location in Locations: self.square = Squares(parent=self, position=location) self.square.line_width = 2 self.shape_list.append(self.square) def touch_began(self, touch): for shape in self.shape_list: if 0 < touch.location[0]-shape.position[0] < W and 0 < touch.location[1]-shape.position[1] < H: shape.color = '#065fa2' def clear_game(self): for shape in self.shape_list: shape.color = '#ffffff' class MyScene2(Scene): def setup(self): self.background_color = '#c84d93' self.shape_list = [] for location in Locations: self.square = Squares(parent=self, position=location) self.square.line_width = 2 self.shape_list.append(self.square) def touch_began(self, touch): for shape in self.shape_list: if 0 < touch.location[0]-shape.position[0] < W and 0 < touch.location[1]-shape.position[1] < H: shape.color = '#e5cc35' def clear_game(self): for shape in self.shape_list: shape.color = '#ffffff' switch = ui.Switch(action=Switch_Flicked, x=0, y=0) V = MyView(background_color='#ffffff') V.add_subview(switch) SV = SceneView(frame=(0,50,X,Y-100)) SV2 = SceneView(frame=(0,50,X,Y-100)) SV.scene = MyScene() SV2.scene = MyScene2() V.add_subview(SV) V.present()
-
RE: Ui.button / inheritance issue
@Phuket2 You're a legend. Thank you very much! I've still got a long way to go with my learning but it's great to get help when you hit a stumbling block.
-
Ui.button / inheritance issue
Hi Guys,
I'm new to Python/Pythonista and reading through different material but I'm struggling to find examples of how to get a ui.button to change attributes of a different class object.
I have a basic example of a widget that has an Image View that should present/change a different image when the ui.button is pressed.
The error I get is "ui.button object has no attribute "view"". Obviously it's "ImView" that has the attribute "view" but I just can't seem to work out how to access the "ImView" object via the button action.
I'm sure there may be numerous issues with my beginner code but any general help would be greatly appreciated.
import appex, ui import random Image_One = ui.Image.named('Image_One.PNG') Image_Two = ui.Image.named('Image_Two.JPG') PIC_LIST = [Image_One,Image_Two] class MyView(ui.View): def __init__(self): self.hue = 0 self.background_color = 'white' self.add_subview(ImView().view) self.add_subview(MyHandler().sender) class ImView(object): def __init__(self): self.view = ui.ImageView() self.view.frame = (150,0,170,110) self.view.background_color = 'white' self.view.border_color = 'black' self.view.border_width = 1 self.view.image = None def add_pic(self): self.view.image = PIC_LIST[random.randint(0,1)] class MyHandler(object): def __init__(self): self.sender = ui.Button(frame=(0,0,150,110), title='Hit Me', action=ImView.add_pic) appex.set_widget_view(MyView())```