[Ironpython-users] Unable to Update UI
Jawara Shelton
jawara.shelton at gmail.com
Sun Jan 1 22:11:02 CET 2012
Hello!
I'm new to FePy, and to the list as well. Got an issue I've been working at
for a while - and hoped someone wiser and more experienced could help with.
To start I'm using IronPython Studio (MS Visual Studio 2010), along with
WPF for the GUI. The problem I'm having is convincing the UI containing the
progress bars, and other messages to update during the process - including
closing after the process is completed.
The purpose of the object is to provide for File Sanitization. So if you
decide to test the code please be sure you don't delete any files you may
want to recover. Or better yet: Delete a copy.
TIA
- Damien
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
>>>>>[ BEGIN FileSanitization.py
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
import clr, datetime, os, random, sys, traceback, wpf
clr.AddReference('System.Windows.Forms')
from System.Windows import *
from System.Windows.Forms import MessageBox
from time import sleep, localtime, strftime
class Sanitizer(Window):
""" A File Sanitization class providing secure data removal.
Methods Available:
US Department of Defence
Gutmann
Pseudo-Random Number
RCMP TSSIT OPS11
Single Pass 0
Single Pass 1
"""
def __init__(self):
self.fileCount = 0
self.conDict = {}
wpf.LoadComponent(self, 'effacor_UIprogressBar.xaml')
mapControls(self.Content.Children, self.conDict, False)
self.ShowInTaskbar = False
def Sanitize(self, dGrid, method):
methDict={'DoD':self.sanViaDoD5220_22M, 'Gut':self.sanViaGutmann,
'PRN':self.pseudoRandomNumber,
'RCM':self.sanViaRCMP_TSSIT_OPS11,
'SP0':self.singlePass0, 'SP1':self.singlePass1
}
self.conDict['Task_Begun'] = 'Task Begun: %s' % (str(localtime()))
self.conDict['List_Progress'].Maximum = dGrid.Items.Count
self.ShowDialog()
# Sanitize the Data
for x in range(0, dGrid.Items.Count):
# /////
#self.conDict['File_Counter'].Content = "Processing File %s of
%s" % (str(x+1), str(dGrid.Items.Count))
# \\\\\
try:
methDict[method](dGrid.Items[x])
os.remove(dGrid.Items[x])
except Exception:
nbcLock = traceback.format_exc()
MessageBox.Show("there were errors:\n%s\n" % (nbcLock),
"Problem Occured During Sanitization")
self.Close()
def spOverwrite(self, fNym, oneZeroRandom):
""" Performs a single pass over the data.
- If oneZeroRandom is a 1 or 0, it writes that. Otherwise, it
randomizes
the output (I use "3" for that).
- By nature, function serves as the Single Pass 0, Single Pass
1, and PRNG
algorithms as well (use oneZeroRandom = 3 to use the PRNG
algorithm).
-----
fObj : File Pointer
fSiz : File Size
oneZeroRandom: Determines the type of pass to be performed.
0 = Overwrite file with zeros
1 = Overwrite file with ones
3 = Overwrite with random data (randomized data
actually written
for all values that are not 0 or 1)
"""
fObj = open(fNym, "rb+")
fSiz = os.path.getsize(fNym)
fObj.seek(0)
for x in range(0, fSiz):
if oneZeroRandom in (0,1):
fObj.write(chr(oneZeroRandom*255))
else:
fObj.write(chr(random.randrange(0,255)))
fObj.close()
def pseudoRandomNumber(self, fNym):
#
#self.conDict['File_Progress'].Maximum = 1
#
self.spOverwrite(fNym, 3)
#
#self.conDict['File_Progress'].Value = 1
#
def singlePass0(self, fNym):
#
#self.conDict['File_Progress'].Maximum = 1
#
self.spOverwrite(fNym, 0)
#
#self.conDict['File_Progress'].Value = 1
#
def singlePass1(self, fNym):
#
#self.conDict['File_Progress'].Maximum = 1
#
self.spOverwrite(fNym, 1)
#
#self.conDict['File_Progress'].Value = 1
#
def sanViaDoD5220_22M(self, fNym):
""" Performs Department of Defense spec data sanitization as
specified in
the National Industrial Security Program Operating Manual
(NISPOM DoD 5220.22-M).
-----
fObj : File Pointer
fSiz : File Size
dOdPat : An array storing the patterns for each sanitization
run.
"""
dOdPat = [0,1,3,0,1,0,3]
#
# self.conDict['File_Progress'].Maximum = 7
#
for x in range(0, 6):
#
#self.conDict['File_Progress'].Value = x+1
#
spOverwrite(fNym, dOdPat[x])
def sanViaRCMP_TSSIT_OPS11(self, fNym):
""" Performs RCMP TSSIT OPS-II data sanitization as originally
defined in Appendix Ops-II:
Media Sanitation of the Technical Security Standards for
Information Technology (TSSIT)
document, published by the Royal Canadian Mounted Police (RCMP).
-----
fObj : File Pointer
fSiz : File Size
rcmpPat : An array storing the patterns for each sanitization
run.
"""
rcmpPat = [1,0,1,0,1,0,3]
#
#self.conDict['File_Progress'].Maximum = 7
#
for x in range(0, 6):
#
#self.conDict['File_Progress'].Value = x+1
#
spOverwrite(fNym, rcmpPat[x])
def sanViaGutmann(self, fNym):
""" Performs data sanitization using the Gutmann Method.
Media Sanitation of the Technical Security Standards for
Information Technology (TSSIT)
document, published by the Royal Canadian Mounted Police (RCMP).
-----
fObj : File Pointer
fSiz : File Size
rcmpPat : An array storing the patterns for each sanitization
run.
"""
# gPat stores the pre-determined patterns used during the overwrite
process used
# in the gutmann method.
gPat = [[0x55], [0xAA], [0x92,0x49,0x24], [0x49,0x24,0x92],
[0x24,0x92,0x49], [0x00], [0x11], [0x22], [0x33]]
gPat[len(gPat):] = [[0x44], [0x55], [0x66], [0x77], [0x88], [0x99],
[0xAA], [0xBB], [0xCC], [0xDD], [0xEE]]
gPat[len(gPat):] = [[0xFF], [0x92,0x49,0x24], [0x49,0x24,0x92],
[0x24,0x92,0x49], [0x6D,0xB6,0xDB]]
gPat[len(gPat):] = [[0xB6,0xDB,0x6D], [0xDB,0x6D,0xB6]]
# Use the data containing the set of 27 pre-determined patterns and
determine pass order.
# The ORDER those patterns are written in is randomized.
x = random.randrange(0,26)
gPatOrder = []
while len(gPatOrder) < 26:
# It is necessary to check to insure that a pattern is not
selected twice.
# Hence the additional while clause.
while x in gPatOrder:
x = random.randrange(0,26)
gPatOrder[len(gPatOrder):] = [x]
fPass = 0
#
#self.conDict['File_Progress'].Maximum = 27
#
# Make the initial 4 passes writing over the data
# Each pass overwrites the data in the file with random data.
# This is the first step in the Gutmann process.
for x in range(0, 3):
self.spOverwrite(fNym, 3)
fPass = fPass + 1
#
#self.conDict['File_Progress'].Value = fPass
#
# Make the 27 passes to overwrite the data.
# Use the pre-determined, pseudo-random order as determined by
gPatOrder.
fObj = open(fNym, "rb+")
fSiz = os.path.getsize(fNym)
for x in gPatOrder:
fObj.seek(0)
for y in range(0, fSiz):
fObj.write(chr(gPat[x][y%len(gPat[x])]))
fPass = fPass + 1
#
#self.conDict['File_Progress'].Value = fPass
#
fObj.close()
# Make 4 passes writing over the data
# Each pass overwrites the data in the file with random data.
# This is the final step in the Gutmann process.
for x in range(0, 3):
self.spOverwrite(fNym, 3)
fPass = fPass + 1
#
#self.conDict['File_Progress'].Value = fPass
#
def mapControls(winObj, dict, items):
""" Maps the controls found in a WPF object (winObj) and places them
into
dict for easy reference later.
- The items parameter is used during the recursive pass.
-----
winObj : Object to be mapped.
dict : Dictionary in which mappings are stored.
items : (Boolean) Specifies whether or not the procedure for
iterating
through an items collection should be used.
x : Iterator
"""
if items == True:
for x in winObj.Items:
dict[x.Name] = x
if hasattr(x, "Items") and x.Items.Count > 0:
mapControls(x, dict, True)
else:
for x in winObj:
if "System.Windows.Controls." in str(x) and hasattr(x,"Name")
and x.Name.Length>0:
dict[x.Name] = x
if hasattr(x, "Items") and x.Items.Count > 0:
mapControls(x, dict, True)
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
>>>>>[ BEGIN effacor_UIprogressBar.xaml
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Task Progress" Height="180" Width="393"
IsManipulationEnabled="True" Topmost="False"
WindowStartupLocation="CenterScreen" WindowStyle="SingleBorderWindow"
ResizeMode="NoResize">
<Grid Height="136">
<ProgressBar Name="File_Progress" Height="10"
HorizontalAlignment="Left" Margin="12,86,0,0" VerticalAlignment="Top"
Width="348" />
<ProgressBar Name="List_Progress" Height="10"
HorizontalAlignment="Left" Margin="12,52,0,0" VerticalAlignment="Top"
Width="348" />
<Label Name="Current_File" Height="23" HorizontalAlignment="Left"
Margin="12,67,0,0" Content="Progress:" VerticalAlignment="Top"
FontFamily="Corbel" FontSize="12" Background="#00000000"
BorderBrush="#00000000" />
<Label Name="File_Counter" Height="23" HorizontalAlignment="Left"
Margin="12,33,0,0" Content="Processing File x of y ..."
VerticalAlignment="Top" FontFamily="Corbel" FontSize="12" IsEnabled="True"
Background="#00000000" BorderBrush="#00000000" />
<Label Name="Task_Begun" Height="23" HorizontalAlignment="Left"
Margin="180,0,0,0" Content="Task Begun:" VerticalAlignment="Top"
Width="180" FontFamily="Corbel" FontSize="12" Background="#00000000"
BorderBrush="#00000000" />
</Grid>
</Window>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20120101/afc8b441/attachment.html>
More information about the Ironpython-users
mailing list