@pythonista21 , date has a day, month and year property you can access. So date.year, is an int.
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 Phuket2
-
RE: Use scene and ui in the same program
-
RE: Lan game communication?
@Drizzel , i just happened to watch this David Beasley YouTube Video today. If you haven't already watched I think you might find it intesting.
-
RE: Can Someone Turn This Script Into a ‘Node’ Tutorial, Please?
@ccc , its the / operator , need the // version in py3.x
for i, front_image in enumerate(self.front_images): x, y = i%5, i//5
-
RE: Stash Install
@Tiowang, thanks very much. That fixed it. 2 occurrences to replace in the source file.
-
RE: Stash Install
I am getting the same problem with installing other packages. I thought it might have something to do with the new python warehouse release and not using pip v10.x
I did selfupdate on stash to make sure it was the latest. Latest version is using pip v9 something.
I tried to upgrade pip in stash myself once and did something very wrong and had to reinstall stash. So i didn't try upgrading the pip myself this time. -
RE: Buttons not read from pyui
@Gadgettyke, looks like you just forgot to put your function name in action property of the button in the ui designer. ie button_action.
-
RE: tkinter on pythonista
Guys, tkinter can't be used in Pythonistia. Tkinter is for desktop ui's not mobile. Pythonistia comes with a ui module. You use this to make a GUI in Pythonistia. Its very good. There also is a ui designer. If you select 'UIFile' when creating a new file, once its created you will see you are in the UI Designer. You can also do in code, have a look at the UI module in the docs
-
RE: Need UI layout help
@nerdtron , no problems. I think for this example that flex would be the best and easiest. However, when I tried doing it, I had a brain freeze! Its been a long time since I have done it. Pls dont take that as it is hard to do. Once you have it in your head, normally its simple.
I am sure someone else here will chime in with the correct way to set the flex settings.The example I have put below is still a good a good way to know. Its using a custom view. One of the callbacks you get when you have a Custom View Class is layout. Its called by the ui automatically (if you have a method called layout) when you need to respond to changes in your views height or width. Its worth having a read through the docs about Custom Views.
They are easy to make and give you a lot more flexibility and some extra functionality.Anyway, I hope this also helps
import ui class MyClass(ui.View): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # create the field and button self.in_fld = ui.TextField() self.post_btn = ui.Button(title='Add Item', bg_color='orange', corner_radius=6, action=self.btn_action, ) # do some static adjustments to button and field properites # properties that we dont need to calculate in layout self.post_btn.size_to_fit() self.post_btn.width += 4 self.post_btn.y = 2 self.in_fld.x = 2 self.in_fld.y = 2 self.in_fld.height = self.post_btn.height self.add_subview(self.in_fld) self.add_subview(self.post_btn) def btn_action(self, sender): # just to show its working append '@' to the in_fld text self.in_fld.text += '@' def layout(self): ''' This method is called by the ui automatically when required, such as orientation change. ''' # only need to adjust the width of the fld and the x pos # of the btn for this case self.in_fld.width = self.width - self.post_btn.width - 6 self.post_btn.x = self.in_fld.frame.max_x + 2 if __name__ == '__main__': mc = MyClass() mc.present() ''' This would also work as expected if __name__ == '__main__': f=(0, 0, 320, 480) mc = MyClass(frame=f) mc.present('sheet') '''
-
RE: Need UI layout help
@nerdtron, I think the below gives you what you want. I didn't try and get your flex values correct. If you look in the ui.designer, this will help get the settings correct. But you still need to size and position your ui objects for flex to work. Hope it helps.
Also the + 2 and +4 etc in the code is for some margins between the view frame and the ui objects.import ui view = ui.View() view.name = 'test UI' view.background_color = 'black' r = ui.Button(title='Add Item', bg_color='orange', width=100, height=100, corner_radius=6) r.size_to_fit() # resizes the button, but a little tight r.width += 4 # add a few extra pixels # using get_window_size()[0], could use ui.get_screen_size()[0] # get_window_size should work on split screens also r.x = ui.get_window_size()[0] - r.width - 2 # returns a tuple (w,h) r.y = 2 #r.background_color = 'orange' #r.flex = 'BL' view.add_subview(r) s = ui.TextField(width=r.frame.min_x - 4, height=r.height) s.x = 2 s.y = 2 #s.flex = 'BR' view.add_subview(s) s.begin_editing() # This gets the text field ready for input. # You can comment this out, if you dont want # it to behave like this view.present('fullscreen')
-
RE: safari appex.get_web_page_info
This is only a stab in the dark. But often when I have had problems with something that works some of the time and not other times. The answer is normally relates to timing, ui/blocking etc.
So using the @ui.in_background decorator could help with the ui blocking, sometimes calling time.sleep(1) can help. As I say I am guessing, but I recognise the general pattern of sometimes this works other times it does not from the problems I have had. A ui blocking or timing issue. Hope it helps, I know others here could be more concise to the exact problem, maybe this is enough food for thought. -
RE: Bluetooth UI button send commands
@JonB , yeah i realise that. Like you, I was trying to filter how much to say while still being helpful. It's tricky :)
-
RE: Bluetooth UI button send commands
@smiddleton, one change you could make, to make things more explicit is to pass an action param to your BlunoBeetle class like below. It's not the whole story, but I think its a step in the right direction.
class BlunoBeetle (object): def __init__(self, action): ... self.b.action = action def my_action(sender): print(sender) mngr = BlunoBeetle(my_action)
-
RE: Speech to ear speaker?
@dwildbore , hi I used the example below from the Pythonista docs. I am using apple Airpods on iPad 12.5' 2nd gen. The sound worked fine for me. When the AirPods in, the speech came though them and after removal the sound come out of the speaker. I didn't have a wired pair of earphones handy to see if it worked differently or not.
import speech import time def finish_speaking(): # Block until speech synthesis has finished while speech.is_speaking(): time.sleep(0.1) # US English: speech.say('Hello World', 'en_US') finish_speaking() # Spanish: speech.say('Hola mundo', 'es_ES') finish_speaking() # German: speech.say('Hallo Welt', 'de_DE') finish_speaking()
-
RE: Display an animated GIF in an ImageView
@cvp , I just wanted to say another nice use of the update method. It's fairly easy for me to read your code and understand the logic flow. If you had to use threads and use decorators etc... all of a sudden its starts to look complex to someone like me. Also it appears that even very good Python programmers are not immune to different side effects when using threads and ui interaction. The update method just seems to work!
Just saying :) -
RE: Pyui button image options
@Sabarblatoe , no problems. There seems to be a few little quirks with this way that I dont remember from before. But I think its still really nice. But I think it will work as you expect. Once you have returned from the super() call, its the same as if you have created a Custom ui class by hand.
-
RE: Pyui button image options
In the example above, if you say want to set the action attr of a ui.Button in the ui Designer, you cant refer to self to access a method in your class. In the case of the example above, the class is named MyClass, so if you had a method in MyClass called hit, in the ui Designer in the action property of the btn you would enter MyClass.hit, not self.hit.
If your action is a func in the same source file you would do as normal, just enter the name of the func.I cant remember if it was always like this. It's possible that @omz made some changes to prevent injection attacks. I thought before that self.method worked. But maybe I am dreaming.
Regardless many things can be done with pyui files. It's worth searching the forum.
-
RE: Pyui button image options
@Sabarblatoe, not sure you are interested or not. Below is some code that reads a pyui/UIFile into a class and class behaves as if it is a Custom ui View. I think its handy for many reasons and it can make life a little easier (Maybe not in all cases). But in the demo below you can see you can code directly against the view rather than the pyui file being a subview of another view. This has been posted on the forum many times before.
Anyway, maybe its interesting to you.@omz do you have any plans to add this functionality directly into API? I know I have asked before. But I still believe this would be a great addition to the API. It would also then be documented, I think a lot of ppl would use this approach to loading UIFiles if it was documented and built in.
import ui class PYUILoader(ui.View): # this acts as a normal Custom ui.View class # the root view of the class is the pyui file read in # from @JonB def WrapInstance(obj): class Wrapper(obj.__class__): def __new__(cls): return obj return Wrapper def __init__(self, pyui_fn, *args, **kwargs): bindings = globals().copy() bindings[self.__class__.__name__] = self.WrapInstance() ui.load_view(pyui_fn, bindings) # call after so our kwargs modify attrs super().__init__(*args, **kwargs) class MyClass(PYUILoader): ''' This class acts the same as a ui Custom View would even though its been loaded in from a pyui file. *** NOTE *** You have to do 2 things for this to work correctly. 1. pass the file name of your .pyui file when creating the class 2. in the ui Designer, you need to set the 'Custom View Class' field in the Inspector to the name of this class's name. In this case 'MyClass' - Finding the 'Custom View Class' in the ui Designer Make sure you are at the root level, i.e not in a subview In the ui Designer, tap anywhere to make sure nothing is selected, Then you will see the 'Size Presets' in the Inspector. Directly below you will see the 'Custom View Class' field. ''' def __init__(self, pyui_fn, *args, **kwargs): super().__init__(pyui_fn, *args, **kwargs) self.update_interval = 1 def did_load(self): print('view loaded') def layout(self): print('in layout') def update(self): print('update fired') if __name__ == '__main__': f = (0, 0, 480, 600) v = MyClass('MyUIFile.pyui', frame=f) v.present(style='sheet')
-
RE: Scripter for Scene and other updates
@mikael, thanks for your reply. As regards to the error I am having, I am pretty sure somehow I have corrupted something. But at the moment my home internet is on and off like a yoyo :( Its cable issues in the streets. So its not so easy to do app downloads etc to reset. I will have to wait until they sort it out, again!
I like your example notice! But it really does illustrates something. How you intend your lib to be used. I know its going to seem stupid, but the name of the Lib does says it all. I didn't really get that somehow. I was looking at your lib more from a macro point of view rather than a micro POV.
I am not sure I have explained that clearly or not. But as I say, I will keep trying to get my head around it. In terms of doing animated views vrs PowerPoint slides concept. One could say they are they same or very similar(but they are not). I think the great thing is that your lib/module can support either direction. At least I think that... -
RE: Scripter for Scene and other updates
@mikael , ok no problems. I just misunderstood your post. I started having problems yesterday (I think after I updated to 11.2.5) about script not being defined. Strange, the trace back is below. I didn't have much time to found out the cause. The only thing i can think of is how I copied the Scripter code into Pythonista (I did a drag and drop copy from a clone of the repo in Working Copy). I am not really sure. Anyway, I am not really reporting it here as I need to try more things first.
Anyway, when I come across this issue, I was just going to make a view that used your wobble script to wobble a ui.Button at regular interval (to draw attention to it). I was just interested to see how this all would work out. I.e the containing view having and update method as well as calling the script on the container views update fire. I assume it would work.
As far as I can see there is no way for a script to re-animate given a duration/pause(maybe I am wrong) but I think its an interesting point, as some elements in a ui, you would like them to continue to animate forever, but with a pause between the animations so its not over the top. Even better the pause could have a ease function. Anyway, I am just talking giving my ideas. I dont expect anything from you, its your project.
I come from the dummies side of things, meaning the less I need to know about using a Lib the better. But I do understand that libs are also written with a certain expectation that the user of the Lib/module has a degree of understanding of some primitives core to the lib.Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/3533032E-E336-4C25-BBC4-112A6BF2AF75/Pythonista3/Documents/site-packages-3/scripter/scripter-demo.py", line 90, in <module>
@script
NameError: name 'script' is not defined