file copy program help

Hi all!

Im new to wxpython/python but need to write a little program for work. Ive gotten a little bit on the way but now im stuck :frowning:
The program im trying to develop is a simple file copying/verifier program. Im attaching an image of what im sort of aiming for
once its completed. Problems so far:
1: First file manager doesnt display image files in the file window, only second one do
2: All views are really small :slight_smile:
3: I would like to be able to print out the selected file name once clicked on
4: onSelect_top_Wind and onSelect_bot_Wind are very repetitive but cant seem to get them to work in
a more modular way.

These are my main problems for the moment, if anyone have a moment to help me out with at least the
2 first ones i would be very happy! :slight_smile:

On a side note, i wrote some programs earlier with pygtk and glade and found that pretty straight forward
since i found this tutorial:
http://www.learningpython.com/2007/02/17/pylan-a-gtd-todo-application-written-in-python-and-pygtk-part-one/
I havent found a single similar example for wxpython, but wxglade or similar would be so much more intuitive
to use if only there was some descent example tutorials to get me started.

Heres the code:

#!/usr/bin/python
#dragdrop.py
import os
import wx
import time

class pff_v2(wx.Frame):
def init(self, parent, id, title):
wx.Frame.init(self, parent, -1, title, size=(600, 600))

    vbox_top = wx.BoxSizer(wx.VERTICAL)
    panel = wx.Panel(self, -1)

    vbox = wx.BoxSizer(wx.VERTICAL)

    
    #panel 1
    self.panel_1 = wx.Panel(panel, -1)
    self.dir_Wind_1 = wx.GenericDirCtrl(self.panel_1, -1, dir='/home/', style=wx.DIRCTRL_DIR_ONLY)
    self.file_Wind_1 = myFilesDir(self.panel_1, -1)
    self.tree_1 = self.dir_Wind_1.GetTreeCtrl()
   
    grid1 = wx.GridSizer(1, 2)
    grid1.Add(self.dir_Wind_1)
    grid1.Add(self.file_Wind_1)
    self.panel_1.SetSizer(grid1)
    vbox.Add(self.panel_1, 0, wx.BOTTOM | wx.TOP, 9)
    #end panel 1

    #panel 2
    panel2 = wx.Panel(panel, -1)
    sizer2 = wx.GridSizer(2, 2, 2, 2)
   
    st1 = wx.StaticText(panel2, -1, 'Image seq')
    tc = wx.TextCtrl(panel2, -1)

    sizer2.Add(st1)
    sizer2.Add(tc)
    sizer2.Add(wx.Button(panel2, -1, 'Fcheck', size=(120, -1)))
   
    panel2.SetSizer(sizer2)
    vbox.Add(panel2, 0, wx.BOTTOM, 9)        #end panel 2

    #panel 3
    self.panel_3 = wx.Panel(panel, -1)
    self.dir_Wind_2 = wx.GenericDirCtrl(self.panel_3, -1, dir='/home/', style=wx.DIRCTRL_DIR_ONLY)
    self.file_Wind_2 = myFilesDir(self.panel_3, -1)
    self.tree_2 = self.dir_Wind_2.GetTreeCtrl()
    grid2 = wx.GridSizer(1, 2)
    grid2.Add(self.dir_Wind_2)
    grid2.Add(self.file_Wind_2)
    self.panel_3.SetSizer(grid2)
    vbox.Add(self.panel_3, 0, wx.BOTTOM | wx.TOP, 9)
    #end panel 3
  
    vbox_top.Add(vbox, 1, wx.LEFT, 5)
    panel.SetSizer(vbox_top)

   
    wx.EVT_TREE_SEL_CHANGED(self, self.tree_1.GetId(), self.onSelect_top_Wind)
    wx.EVT_TREE_SEL_CHANGED(self, self.tree_2.GetId(), self.onSelect_bot_Wind)
  
    self.onSelect_top_Wind(0)
    self.onSelect_bot_Wind(0)
    self.Centre()
def onSelect_top_Wind(self, event):
    files = os.listdir(self.dir_Wind_1.GetPath())
    self.file_Wind_1.ClearAll()
    for i in files:
        #print i
        (name, ext) = os.path.splitext(i)
        ex = ext[1:]
        if ex == 'jpg':
            if i[0] != '.':
                self.file_Wind_1.InsertStringItem(0, i)
        elif ex == 'tif':
            if i[0] != '.':
                self.file_Wind_1.InsertStringItem(0, i)
        elif ex == 'tga':
            if i[0] != '.':
                self.file_Wind_1.InsertStringItem(0, i)
        elif ex == 'iff':
            if i[0] != '.':
                self.file_Wind_1.InsertStringItem(0, i)
def onSelect_bot_Wind(self, event):
    files = os.listdir(self.dir_Wind_2.GetPath())
    self.file_Wind_2.ClearAll()
    for i in files:
        #print i
        (name, ext) = os.path.splitext(i)
        ex = ext[1:]
        if ex == 'jpg':
            if i[0] != '.':
                self.file_Wind_2.InsertStringItem(0, i)
        elif ex == 'tif':
            if i[0] != '.':
                self.file_Wind_2.InsertStringItem(0, i)
        elif ex == 'tga':
            if i[0] != '.':
                self.file_Wind_2.InsertStringItem(0, i)
        elif ex == 'iff':
            if i[0] != '.':
                self.file_Wind_2.InsertStringItem(0, i)

    def OnExit(self,e):
        self.Close(True)

class myFilesDir(wx.ListCtrl):
def init(self, parent, id):
‘’‘want to add column header later’’’
wx.ListCtrl.init(self, parent, id, style=wx.LC_LIST)

class pff_run(wx.App):
def OnInit(self):
frame = pff_v2(None, -1, “magnus test program”)
frame.Show(True)
self.SetTopWindow(frame)
return True

app = pff_run(0)
app.MainLoop()

layout_01.jpg

mo ol wrote:

Hi all!

Im new to wxpython/python but need to write a little program for work. Ive gotten a little bit on the way but now im stuck :frowning:
The program im trying to develop is a simple file copying/verifier program. Im attaching an image of what im sort of aiming for
once its completed. Problems so far:
1: First file manager doesnt display image files in the file window, only second one do

The GenericDirCtrl always uses the same ID for the TreeCtrl it uses internally, so if you want to catch the tree events yourself then you need to bind the handler directly to the tree widget, not self.

         self.tree_1.Bind(wx.EVT_TREE_SEL_CHANGED, self.onSelect_top_Wind)
         self.tree_2.Bind(wx.EVT_TREE_SEL_CHANGED, self.onSelect_bot_Wind)

See also: self.Bind vs. self.button.Bind - wxPyWiki

2: All views are really small :slight_smile:

See attached for changes in which sizers are used, and different flags and such for the sizer.Add() calls

3: I would like to be able to print out the selected file name once clicked on

You can do that by catching the selection events in the ListCtrls.

4: onSelect_top_Wind and onSelect_bot_Wind are very repetitive but cant seem to get them to work in
a more modular way.

Factor out the common code into a 3rd method, which each of the event methods will call and pass to it the values or objects that are diffent in each case.

These are my main problems for the moment, if anyone have a moment to help me out with at least the
2 first ones i would be very happy! :slight_smile:

On a side note, i wrote some programs earlier with pygtk and glade and found that pretty straight forward
since i found this tutorial:
http://www.learningpython.com/2007/02/17/pylan-a-gtd-todo-application-written-in-python-and-pygtk-part-one/
I havent found a single similar example for wxpython, but wxglade or similar would be so much more intuitive
to use if only there was some descent example tutorials to get me started.

There are lots of recipes and other examples in the wiki, and some tutorials too. There is also this page that started out in the wiki as the AnotherTutorial page, but has since moved here: wxPython tutorial - Python GUI programming in wxPython

dd.py (4.88 KB)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!