How can I update what is displayed in TextInput widget? python kivy - python-3.x

I have a TextInput widget that is suppose to display text within a .log file.
The python script looks like
logginfo = ObjectProperty()
with open('logtest.log', 'r') as file:
loginfo = file.read()
The kivy file looks like
TextInput:
id: logginfo
text: root.loginfo
The problem is, the log file is only read once and that is what is displayed.
How can I update loginfo whenever the .log file changes? In other words, how can I get a live feed of the logtest.log file?

You will have to produce a method/function that will check for changes and load the file to update the textbox for you. There is no "automagic" way to do it.
I don't work with kivy directly, but most GUI frameworks seem to come with some sort of timer, or timeout object. Kivy doesn't seem to be any different in this case. A quick search revealed that Kivy has a "Clock" object. I found some docs here.
Most of the time these work on a timeout, so you define the Clock, tell it what function to run, whether it should repeat or not, and how frequently to time out. Each time the Clock times out, the function will be called. You can code the function to do whatever you like, in this case, check the file for changes.
I'd suggest making a hash of the file (something simple like md5) and storing the hash in a variable. Then, each time the clock times out, it can simply compare the files hash, to the hash you stored in ram, and if it's changed, you know you need to update the text box with the new contents of the file. If it doesn't you don't need to re-access the file for another timeout interval.
If you have specific questions on problems you encounter trying to work through the project please make new questions with specific issues, again showing your code at that point.

Related

Import headshots via CSV

I have a sequence set up in my premiere project. It's a simple slide in from right (whilst fading in) of a headshot. Under the headshot is the name of the person (that follows the slide and fade in animation of the headshot) and I have to create a main sequence of 40 of these (each headshot sequence lasts around 3 seconds). That means manually placing the headshots (that are all the same size) and typing in the persons name for each one.
I am wondering if there is a way to automate this via a script in premiere pro that will read from a csv file the location of the headshot image and the name of the person and create it automatically for me?
I have tried looking around for such information but haven't had much success.
You can easily acheive this using Dataclay's Templater for Adobe After Effects. Even better than a CSV, you can use a cloud based Google Sheet and connect directly to that asset so you never have to deal with a file again.

select and copy files + directory [duplicate]

I am using Tkinter for building a GUI for a python script. I need a button which opens up a dialog box which allows me to select both files and directories.
Till now, I've come across
tkFileDialog.askdirectory(parent=root, title=dirtext1)
which allows just to select directories in the dialog box
and,
tkFileDialog.askopenfilename(parent=root, title=filetext)
which allows me to just select files. As of now, I access these dialog boxes using separate buttons, each of which calls one of these functions.
Is there anyway to select either a file or a folder using a single dialog box?
I don't think so. There is no built-in class to do it easily
Investigation
If you look at the tkFileDialog module's source code, both the Open and the Directory classes inherit from _Dialog, located in tkCommonDialog.
Good so far; these classes are simple and only extend two methods. _fixresult is a hook that filters based on your options (promising), and _fixoptions adds the right tcl parameters (like initial directory).
But when we get to the Dialog class (parent of _Dialog), we see that it calls a tcl command by a given name. The names built-in are "tk_getOpenFile" and "tk_chooseDirectory". We don't have a lot of python-level freedom of the command after this. If we go to see what other tcl scripts are avaliable, we are disappointed.
Looks like your options are
ttk::getOpenFile
ttk::getSaveFile
ttk::chooseDirectory
ttk::getAppendFile
Conclusion
Rats! Luckily, it should be quite easy for you to make your own dialog using listboxes, entry fields, button, (and other tk-builtins), and the os module.
Simple Alternative
From your comments, it looks like a viable simple work-around might be to use
directory = os.path.dirname(os.path.realpath(tkFileDialog.askopenfilename()))
They'll have to select a file, but the "Open" button will "return a path", in the sense that the path is computed from the file location
But I really want it!
If for some reason you really want this behaviour but don't want to remake the widget, you can call tcl scripts directly. It may be possible to copy the code from getOpenFile and provide more loose arguments that allow for selecting a more generic object. This isn't my speciality and seems like a really bad idea, but here is how you call tcl directly and here is where you can learn more about the underlying commands.
I've had a similar issue.
In the end, I used askopenfilenames() (plural) and split the path from the files. Then with a radiobutton, ask the user to choose if they want to process all the files in the directory, or just those they selected.
filetypes = [('All files', '*.*'), ('CSV files', '*.csv'),]
data_list = askopenfilenames(title='Select folder', filetypes=filetypes)
data_dir = data_list[0].rsplit('/', 1)[0]
I mention it because askopenfilenames() doesn't get suggested much, but is closer to selecting a folder, as can ctrl+A all files.

p:remotecommand to upload files

I would like to upload file programatically to my jsf application. The user should select a directory on his system, and a js script should loop on any file in dir and send each one to the listener serverside
I cannot use FileUpload, because it cannot select a whole dir with thousands of file, so I was thinking to use jquery and send the file to a remotecommand, but I have no clue to how send the file itself (normally I pass just string)
so I was thinking to use jquery and send the file to a remotecommand, but I have no clue to how send the file itself
Don't go there. It is a bad attempt to a workaround for a bad design choice. You'd most likely run into similar problems and what about the user selecting a lot of files for second time if it fails halfway? It might become slow, might run into browser limits (search for uploading multiple files in plain html)...
If you still want to do it via a webbrowser (which according to one of your other questions you do not want to), maybe try something like https://webdeltasync.github.io/ (disclaimer: I did not use it myself, and there might be similar ones (https://www.google.com/search?q=browser+based+rsync), it is just a hint in which direction to find a real solution)

How to log in and auto fill values into a 'drupal form' from an 'excel file'?

So, there is this website where I have to log in and insert values in the add content->person roles and I have to take values from an excel file. I tried entering the values in the database directly but got nowhere. The database is too randomly generated.
I want to know- how to go by this problem? I think python would be the best way but I am more comfortable with java. The images bellow will help understand the situation better-
The log in from:
The form to be filled:
Try using feeds module:
https://www.drupal.org/project/feeds
Install it on you site first of course. Or look for some similar import module. Maybe this one:
https://www.drupal.org/project/datasources
If nothing succeeds then try making import script on your own. You have to parse document (would be much easier to open it from excel and export as CSV if possible http://php.net/manual/en/function.fgetcsv.php) and have some loop to write content into Drupal system. Use Drupal's functions for that, do not directly write to database. It's not hard as it looks like:
https://www.drupal.org/node/1388922

Create a Pop-Up menu to call a custom exporter (Blender 2.6 API)?

am trying to create a friendlier menu to export models using a file format I created, using the python scripts in Blender 2.63.
Have been checking the API documentation for Blender, also the template examples and haven't figured out how to actually call the Exporter I created, which works ok.
Let me describe a bit more the problem; to export I have to go to File->Export->select the desire format->give a name->Press Export button. I want to automate this process through a menu (like the one provived in the templates, ui_menu); just load/run the script and select Export, the rest should be handled by the script it self. Lets suppose the blend file is MyCoolModel.blend, it will assume the exported file will be placed in the same location, taking the name MyCoolMode appending the correct extension.
By having the Custom menu, which is in one file. Don't know how to call the proccess of the exporter giving the described parameters, don't even know if that's possible.
On the other hand, it might be easier to move the code of the exporter to another module, the Custom Menu, add a button and call a function executing what was described, I just one to get feedback if someone already coded this, and re-use the export module.
In the end I would want to preserve the original export module, in case the artist needs to change the default name of the exporting process, or simply 'cause he wants to do it manually.... Having both versions, trying to re-use the Export would be the best if that's possible, no duplication of code really ;).
I am looking to do something similar, they only thing that I have found that is close enough is the following Scripts/Cookbook/Interface:popup. Of course is still far away from anything close to the export menu, but hopefully it can be extended a lot more.

Resources