{"id":1189,"date":"2024-07-21T17:34:28","date_gmt":"2024-07-21T17:34:28","guid":{"rendered":"https:\/\/snersbots.co.uk\/?p=1189"},"modified":"2024-08-06T05:38:50","modified_gmt":"2024-08-06T05:38:50","slug":"photo-app-list-control","status":"publish","type":"post","link":"https:\/\/snersbots.co.uk\/index.php\/photo-app-list-control\/","title":{"rendered":"Photo App &#8211; List Control"},"content":{"rendered":"\n<p>Now we have a spreadsheet I need to be able to show the results on the screen. Still using wxPython, going to make use of the <a href=\"https:\/\/docs.wxpython.org\/wx.ListCtrl.html#\">list control<\/a>. It doesn&#8217;t look great on Windows, but it&#8217;s functional and seems to have a lot of flexibility.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create a ListCtrl<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Make the list control size=(-1, -1). This will make it take up the full size of the window, and will automatically resize. <\/li>\n\n\n\n<li>wx.LC_REPORT: Single or multi-column report view, with optional header.<\/li>\n\n\n\n<li>Add the titles to each column. Make them width=-1 as they need to be sized appropriate for the window.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code has-background\" style=\"background-color:#e9f1f7\"><code>\n        self.list_ctrl = wx.ListCtrl(panel, size=(-1,-1),\n                         style=wx.LC_REPORT\n                         |wx.BORDER_SUNKEN\n                         )\n        self.list_ctrl.InsertColumn(0, 'Name', width=-1)\n        self.list_ctrl.InsertColumn(1, 'File Path', width=-1)\n        self.list_ctrl.InsertColumn(2, 'Hash', width=-1)\n        <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Add the list to the sizer<\/h2>\n\n\n\n<p>This is what every example does. It works, so just taking it as is, without asking questions.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background\" style=\"background-color:#e9f1f7\"><code>     sizer.Add(self.list_ctrl, 0, wx.ALL|wx.EXPAND, 5)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Add the data to the control<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The data is in a pandas DataForm &#8211; see further down this blog for details on this.<\/li>\n\n\n\n<li>iterrows() is an iterator through the rows, gives the index, and the row object.<\/li>\n\n\n\n<li>First InsertItem to add a line &#8211; not sure what these two variables are here, line will always be 0, and index increments.<\/li>\n\n\n\n<li>In column 0, add the value of the &#8216;name&#8217; field. Ditto for &#8216;path&#8217; and &#8216;hash&#8217;.<\/li>\n\n\n\n<li>Increment the index &#8211; which will be the row number in the ListCtrl.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-background\" style=\"background-color:#e9f1f7\"><code>        line =  self.index'\n        for idx, row in photoList.iterrows():\n            self.list_ctrl.InsertItem(self.index, line)\n            self.list_ctrl.SetItem(self.index, 0, row&#91;'name'])\n            self.list_ctrl.SetItem(self.index, 1,  row&#91;'path'])\n            self.list_ctrl.SetItem(self.index, 2,  row&#91;'hash'])\n            self.index += 1\n        self.list_ctrl.SetColumnWidth(0, wx.LIST_AUTOSIZE)\n        self.list_ctrl.SetColumnWidth(1, wx.LIST_AUTOSIZE)\n        self.list_ctrl.SetColumnWidth(2, wx.LIST_AUTOSIZE)\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>After adding all the data, get the columns to resize themselves to fit the data.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Pandas DataFrame<\/h2>\n\n\n\n<p>I used test data for this snip. Here is how to read from csv using Pandas:<\/p>\n\n\n\n<pre class=\"wp-block-code has-background\" style=\"background-color:#e9f1f7\"><code>import pandas\n\nrawData = pandas.read_csv('TestOutput.csv')\nphotoList = pandas.DataFrame(rawData).sort_values(by='hash')\nphotoList = photoList&#91;photoList.duplicated('hash', keep=False)]\n<\/code><\/pre>\n\n\n\n<p>Use pip install to get your pandas. Don&#8217;t forget on mac to use pip3.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The trouble with pandas<\/h2>\n\n\n\n<p>On Windows I have installed pandas. But it is still flagging as not found.<\/p>\n\n\n\n<p>After much pip installing and pip uninstalling, somewhere I found a suggestion to use <code>py<\/code> instead of <code>python<\/code>.<\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#e9f1f7\"><code>py .\\showlist2.py<\/code> <\/p>\n\n\n\n<p>This works fine, but if I use the full name <code>python<\/code> it does not work. I&#8217;m pretty sure this has something to do with my path. But I&#8217;m not tinkering with that right now.<\/p>\n\n\n\n<p>In fact <a href=\"https:\/\/stackoverflow.com\/questions\/42907331\/how-to-install-pandas-from-pip-on-windows-cmd\">stack overflow<\/a> explains it properly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The trouble with wx.list_ctrl<\/h2>\n\n\n\n<p>It looks awful. Really I do not want to even put a screenshot here. It seems that it will look nice on Mac, but on Windows it just looks like a 1980s list.<\/p>\n\n\n\n<p>Looks like wxPython is not so great on looks on Windows. But <a href=\"https:\/\/stackoverflow.com\/questions\/47181247\/wxpython-python3-listctrl-header-with-bold-text-horizontal-rules\">stack overflow<\/a> has another suggestions for a wx widget, so I&#8217;ll try that.<\/p>\n\n\n\n<p>Need to try ultimate list control: <a href=\"https:\/\/wxpython.org\/Phoenix\/docs\/html\/wx.lib.agw.ultimatelistctrl.UltimateListCtrl.html\">https:\/\/wxpython.org\/Phoenix\/docs\/html\/wx.lib.agw.ultimatelistctrl.UltimateListCtrl.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now we have a spreadsheet I need to be able to show the results on the screen. Still using wxPython, going to make use of the list control. It doesn&#8217;t look great on Windows, but it&#8217;s functional and seems to have a lot of flexibility. Create a ListCtrl Add the list to the sizer This <a class=\"read-more\" href=\"https:\/\/snersbots.co.uk\/index.php\/photo-app-list-control\/\">The full story here&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":1197,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70,8],"tags":[69,71],"class_list":["post-1189","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-desktop-apps","category-software","tag-duplicate-photos","tag-python"],"_links":{"self":[{"href":"https:\/\/snersbots.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/1189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/snersbots.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/snersbots.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/snersbots.co.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/snersbots.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=1189"}],"version-history":[{"count":18,"href":"https:\/\/snersbots.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/1189\/revisions"}],"predecessor-version":[{"id":1212,"href":"https:\/\/snersbots.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/1189\/revisions\/1212"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/snersbots.co.uk\/index.php\/wp-json\/wp\/v2\/media\/1197"}],"wp:attachment":[{"href":"https:\/\/snersbots.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=1189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/snersbots.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=1189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/snersbots.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=1189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}