Attach data element to tkinter Listbox element - python-3.x

I am using tkinter with python 3.2
I am making an audio tag editor, and need a way to display the audio files after the user imports them. I am using a Listbox to do this. For the string I am passing into the insert method, I am using the file name, but I need a way to store the full path. It needs to be associated with the list element it corresponds to, so that when the user selects the element, I can look at the file using the full path and display the current audio tags for editing.
Is there a way to make this kind of association, so that every list element points to a data structure of some sort (string containing the file path in this example)? I can trigger the logic to access it with a binding on the listbox itself, but I need to know how to associate the data structure with each list element.

to get more information on the methods of the listbox you can use this reference.
You can use a dict to associate the file names to their full paths:
files_to_show = {os.path.basename(name):name
for name in FULL_PATHS_SOURCE}
then on the listbox you can use the .curselection() to get the indices of the current selection then the .get() method to get the text for each entry:
(listbox.get(i) for i in listbox.curselection())
then to get the full path just look it up in the dict:
selected_full_paths = [files_to_show[listbox.get(i)]
for i in listbox.curselection()]
or more verbosely:
selected_full_paths = []
for selected_i in listbox.curselection():
selected_text = listbox.get(i)
full_path = files_to_show[selected_text]
selected_full_paths.append(full_path)

Related

How to find all elements with class name containing a specific string using HTML-requests library?

I am on this page on Tokyo Olympic Website
I would like to get all the elements that has class name beginning with a specific string. For instance I want to get all elements that begin with 'col-sm-'.
html.r.find('.col-sm-6') gives me all elements that have class name col-sm-6. However I would like to get all elements starting with class name col-sm-. In documentation they have asked to refer CSS selector at this link. As per the information on that page either:
r.html.find('[class~=col-sm-]') or
r.html.find('[class=col-sm-]') should do the job but they return an empty list.
Maybe that would work
*[class^='col-sm-']
Here is an image from chropath extension

Error creating a SharePoint list item due to lookup fields

I need to create an item in SP list. Unfortunately it does not work due to a Lookup field to another list.
Both lists exceed the list view threshold.
I tried more ways but got the same error.
Is there away to fix it?
attempt01
attempt02
Try using a SharePoint REST call instead. In my example below I'm updating an item, but you can create items too by simply using the PUT method.
The data to use is:
Site Address = Your full site URL.
Method = PUT to create new or PATCH to update existing.
Uri = The REST call portion of the URL, using the GUID ID of the list in question and the item ID of the specific item to be updated.
Headers = If-Match use *, Content-Type use application/json;odata-verbose, Accept use application/json;odata=verbose
Body = {"__metadata":{"type":"SP.Data.MyListListItem"},"MyField":"NewFieldValue","My2ndField":"New2ndFieldValue"}
NOTE: The double underscore before metadata.
NOTE: type is defined as "SP.Data. concatenated with the List Name, concatenated with ListItem"
NOTE: Multiple fields are updated in "name":"value","name":"value" pairs separated by commas.

ExtLib, iNotes List View: how can I access data selected in the view from the outside?

Using Firebug I found that the iNotes List View object has a function called "getSelectedData()" delivering something like an array of selected view entries (each one consisting of the item specific row data, like the "ext" element described here by Paul Withers). Thus, using one of List View's internal events (like "onContextMenu"), I can retrive selected data and put them somewhere else. Which is just great!
But, as I'm never content with what I have, now I'm looking for a way to address the List View's object from the outside (e.g. using a button) to access a selected data collection in a similar or even the same way. But no matter what I try, I can't seem to get to the proper object from outside of the List View itself. Using
dojo.byId("#{id:listView1}")
is giving me an object but without any of those specific methods that I need. Neither Google, nor openNtf or the ExtLib book itself has any info on that.
Any hint?
Greets,
Lothar
I guess I solved it. I've been close yesterday, but using dojo.byId instead of dijit.byId prevented it from working:
var grid = dijit.byId("#{id:listView1}");
var sel = grid.getSelectedData();
Result is a named array of row data where each row entry contains all the relevant view entry data for that row.
Works like a charm!
- Lothar

How to get only share point list columns that are displayed in the list properties?

I'm using Sharepoint 2010's web services interface to try to get the columns for a given list. I've got not problem with getting all of the columns using a GetList() call, but the issue is that I need to only get the columns that the user can see in the List Settings view of the Sharepoint UI.
The code that I'm currently using is as follows:
rootNode = serviceReference.GetList(List_id.ToString());
Element element = XElement.Parse(rootNode.OuterXml);
var fields = from e in element.Descendants()
where e.Name.LocalName == "Field" && e.Attribute("ID") != null &&
!(e.Attribute("Name").Value.StartsWith("_") && e.Attribute("SourceID").Value == "http://schemas.microsoft.com/sharepoint/v3")
select e;
Where serviceReference is an instance of the Sharepoint Lists Service and List_id is the GUID representing the list internally to Sharepoint.
This does filter out some of the columns that I don't want, but it doesn't get rid of everything.
Does anybody know what attributes I'm looking for to narrow it down just to the ones that the user can select to be added to a view? Or am I going about this entirely the wrong way?
Many thanks for any help.
The answer to this was that I was indeed looking in the wrong place for the information I needed. As user823959 pointed out, I needed to get the content type definition and use the fields in there rather than the list itself.
To do this was a two stage process, firstly we need to get the list of content types using the Lists.GetListContentTypes method (although this takes a content type id parameter, it doesn't actually seem to matter what we put here)
XmlNode rootNode = serviceReference.GetListContentTypes(List_id.ToString(), "0×01");
The CAML returned contains the definitions for each of the content types that are available in the list - with the first content type returned being the default one (in my case, the one I was after)
String contentType = rootNode.ChildNodes[0].Attributes["ID"].Value;
Once we've got the content type that we're after we can make a call to GetListContentType with the appropriate list content type id to get the full definition of the content type:
XmlNode contentTypeNode = serviceReference.GetListContentType(List_id.ToString(), contentType);
The CAML returned from this call will contain a list of field elements that correctly show the fields that are available in the SharePoint UI's view configuration. They can be selected in a LINQ query like this:
XElement contentTypesElement = XElement.Parse(contentTypeNode.OuterXml);
var fields = from e in contentTypesElement.Descendants()
where e.Name.LocalName == "Field"
select e;
At this point, we've got a list of Field XML elements that contain information about display names, static names, content types and a whole lot more. See Microsoft's documentation on the Lists.GetListContentType page for more information on the range of information returned about each field.
Many Thanks to user823959 for pointing me in the right direction.

how to render custom layout of the projection of known content items

I have defined my own projection by a query which returns a set of content items of known content type. I would like to take pick up certain content parts of these content items and display them in the list. Using shape tracing tool I have found the view template where to write my custom layout:
/Views/Parts.ProjectionPart.cshtml
but from the Model variable in the template I can not get the data I want because it is way too high above from the content parts data.
a good example of what I want: let's say I want to render product catalog as defined in this tutorial:
http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-part-5
but I want only to render a list which consists from items:
name of the owner who created the product
name of the product.
publish date of the product
and I need to render it at one place, i.e., not separately in their own part views.
Have you tried adding a layout in the projector module? There is a properties mode option that lets you select which fields/data to show. If the data you want is not there, you should be able to implement an IPropertyProvider. There are examples of this in the Projections module code.

Resources