1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
|
"""
Copy Center
Description:
Python script to copy data between different datastores.
Author:
Sebastian Sauer <mail@dipe.org>
Copyright:
Dual-licensed under LGPL v2+higher and the BSD license.
"""
class CopyCenter:
class Plugin:
def __init__(self, plugin):
self.plugin = plugin
self.name = plugin.name
self.source = self.load("Source")
self.destination = self.load("Destination")
def load(self, plugintype):
instance = None
try:
if hasattr(self.plugin, plugintype):
return getattr(self.plugin, plugintype)(self.plugin)
except:
import traceback
print "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )
return None
def __init__(self, scriptpath):
self.scriptpath = scriptpath
self.homepath = self.getHomePath()
self.plugins = {}
import os
import sys
if not os.path.exists(scriptpath):
print "The Path %s does not exist" % scriptpath
else:
import re
regexp = re.compile('^CopyCenterPlugin(.*)\\.py$')
for f in os.listdir(scriptpath):
file = os.path.join(scriptpath, f)
if not os.path.isfile(file): continue
m = regexp.match(f)
if not m: continue
print "Plugin name=%s file=%s" % (m.group(1),file)
mylocals = {}
try:
execfile(file, globals(), mylocals)
if mylocals.has_key("CopyCenterPlugin"):
plugin = mylocals.get("CopyCenterPlugin")(self)
self.plugins[plugin.name] = self.Plugin(plugin)
except:
print "Failed to import file=%s" % file
import traceback
print "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )
def getHomePath(self):
""" Return the homedirectory. """
import os
try:
home = os.getenv("HOME")
if not home:
import pwd
user = os.getenv("USER") or os.getenv("LOGNAME")
if not user:
pwent = pwd.getpwuid(os.getuid())
else:
pwent = pwd.getpwnam(user)
home = pwent[6]
return home
except (KeyError, ImportError):
return os.curdir
class Copierer:
def __init__(self): pass
def appendProgressMessage(self,messagetext): pass
def writeSuccess(self,record,rowcount): pass
def writeFailed(self,record): pass
def runGuiApp(copycenter, name):
from TQt import qt
import sys
#--------------------------------------------------------------------
class ListViewDialog(qt.TQDialog):
def __init__(self, parent, caption):
qt.TQDialog.__init__(self, parent, "ProgressDialog", 1)
self.parent = parent
self.setCaption(caption)
layout = qt.TQVBoxLayout(self)
box = qt.TQVBox(self)
box.setMargin(2)
layout.addWidget(box)
self.listview = qt.TQListView(box)
self.listview.setAllColumnsShowFocus(True)
self.listview.header().setStretchEnabled(True,0)
btnbox = qt.TQHBox(box)
btnbox.setMargin(6)
btnbox.setSpacing(6)
self.okbtn = qt.TQPushButton(btnbox)
self.okbtn.setText("Ok")
#qt.TQObject.connect(okbtn, qt.SIGNAL("clicked()"), self.okClicked)
self.cancelbtn = qt.TQPushButton(btnbox)
self.cancelbtn.setText("Cancel")
qt.TQObject.connect(self.cancelbtn, qt.SIGNAL("clicked()"), self.close)
box.setMinimumSize(qt.TQSize(460,380))
def addItem(self,valuelist,afteritem = None):
if afteritem == None:
item = qt.TQListViewItem(self.listview)
else:
item = qt.TQListViewItem(self.listview,afteritem)
i = 0
for value in valuelist:
item.setText(i,value)
i += 1
return item
#--------------------------------------------------------------------
class CopyJobWidget(qt.TQVBox):
def __init__(self,dialog,parent):
self.dialog = dialog
qt.TQVBox.__init__(self,parent)
self.setSpacing(6)
typebox = qt.TQHBox(self)
typebox.setSpacing(6)
label = qt.TQLabel("Job File:",typebox)
self.jobfilecombobox = qt.TQComboBox(typebox)
typebox.setStretchFactor(self.jobfilecombobox,1)
self.jobfilecombobox.setEditable(True)
self.jobfilecombobox.insertItem("")
label.setBuddy(self.jobfilecombobox)
qt.TQObject.connect(self.jobfilecombobox, qt.SIGNAL("textChanged(const QString&)"), self.jobfilecomboboxChanged)
import os
import re
for f in os.listdir(self.dialog.copycenter.homepath):
file = os.path.join(self.dialog.copycenter.homepath,f)
if os.path.isfile(file) and re.search(".+\\.copycenterjob.xml$",f):
self.jobfilecombobox.insertItem(file)
loadbtn = qt.TQPushButton(typebox)
loadbtn.setText("Open...")
qt.TQObject.connect(loadbtn, qt.SIGNAL("clicked()"), self.openClicked)
savebtn = qt.TQPushButton(typebox)
savebtn.setText("Save...")
qt.TQObject.connect(savebtn, qt.SIGNAL("clicked()"), self.saveClicked)
self.listview = qt.TQListView(self)
self.listview.setAllColumnsShowFocus(True)
self.listview.setSorting(-1)
self.listview.setDefaultRenameAction(qt.TQListView.Reject)
self.listview.header().setClickEnabled(False)
self.listview.addColumn("Name")
self.listview.addColumn("Value")
qt.TQObject.connect(self.listview, qt.SIGNAL("doubleClicked(QListViewItem*, const QPoint&, int)"), self.doubleClicked)
#qt.TQObject.connect(self.listview, qt.SIGNAL("itemRenamed(QListViewItem*, int, const QString&)"), self.itemRenamed)
def doubleClicked(self, **args):
print "CopyJobWidget.doubleClicked"
item = self.listview.selectedItem()
if item and item.parent(): item.startRename(1)
def readOptions(self,domnode,plugininst):
print "CopyJobWidget.readOptions plugintype=\"%s\"" % plugininst.plugintype
for node in domnode.childNodes:
if node.nodeType == node.ELEMENT_NODE:
v = node.getAttribute("value")
plugininst.options[node.nodeName] = v
print "Option \"%s\" has value \"%s\" now." % (node.nodeName, v)
def jobfilecomboboxChanged(self, **args):
print "CopyJobWidget.jobfilecomboboxChanged"
import os
import xml.dom.minidom
filename = str(self.jobfilecombobox.currentText())
if not os.path.isfile(filename): return
domdoc = xml.dom.minidom.parse(filename)
try:
elements = domdoc.getElementsByTagName("CopyCenterJob")[0]
sourcenode = elements.getElementsByTagName("Source")[0]
destinationnode = elements.getElementsByTagName("Destination")[0]
except:
raise "The XML-file \"%s\" does not contain a valid copy-job." % filename
sourcepluginname = str(sourcenode.getAttribute('plugin'))
if not self.dialog.sourcedata.combobox.listBox().findItem(sourcepluginname,qt.TQt.ExactMatch):
raise "There exists no plugin with the name \"%s\"." % sourcepluginname
self.dialog.sourcedata.combobox.setCurrentText(sourcepluginname)
destinationpluginname = str(destinationnode.getAttribute('plugin'))
if not self.dialog.destinationdata.combobox.listBox().findItem(destinationpluginname,qt.TQt.ExactMatch):
raise "There exists no plugin with the name \"%s\"." % destinationpluginname
self.dialog.destinationdata.combobox.setCurrentText(destinationpluginname)
self.readOptions(sourcenode,self.dialog.getSourcePluginImpl())
self.readOptions(destinationnode,self.dialog.getDestinationPluginImpl())
self.maybeUpdate()
def openClicked(self):
text = str(self.jobfilecombobox.currentText())
if text == "": text = self.dialog.copycenter.homepath
filename = str(qt.TQFileDialog.getOpenFileName(text,"*.copycenterjob.xml;;*",self.dialog))
if filename != "": self.jobfilecombobox.setCurrentText(filename)
def escape(self,s):
return s.replace("&", "&").replace("'", "'").replace("<", "<").replace(">", ">").replace('"', """)
def writeOptions(self,writer,pluginname,plugininst):
print "CopyJobWidget.writeOptions"
writer.write("<%s plugin=\"%s\">\n" % (plugininst.plugintype, pluginname))
for optionname in plugininst.options:
value = self.escape( unicode(plugininst.options[optionname]).encode("utf-8") )
writer.write("\t<%s value=\"%s\" />\n" % (optionname,value))
writer.write("</%s>\n" % plugininst.plugintype)
def saveClicked(self):
text = str(self.jobfilecombobox.currentText())
if text == "":
import os
text = os.path.join(self.dialog.copycenter.homepath,"default.copycenterjob.xml")
filename = str(qt.TQFileDialog.getSaveFileName(text,"*.copycenterjob.xml;;*",self.dialog))
if str(filename) == "": return
f = open(filename, "w")
f.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
f.write("<CopyCenterJob>\n")
sourcepluginname = self.dialog.sourcedata.combobox.currentText()
self.writeOptions(f, sourcepluginname, self.dialog.getSourcePluginImpl())
destinationpluginname = self.dialog.destinationdata.combobox.currentText()
self.writeOptions(f, destinationpluginname, self.dialog.getDestinationPluginImpl())
f.write("</CopyCenterJob>\n")
f.close()
print "File \%s\" successfully written." % filename
def addItem(self, pluginimpl, afteritem = None, parentitem = None):
#print "CopyJobWidget.addItem"
class ListViewItem(qt.TQListViewItem):
def __init__(self, pluginimpl, listview, parentitem = None, afteritem = None):
self.pluginimpl = pluginimpl
if parentitem == None:
qt.TQListViewItem.__init__(self,listview)
self.setOpen(True)
else:
if afteritem == None:
qt.TQListViewItem.__init__(self,parentitem)
else:
qt.TQListViewItem.__init__(self,parentitem,afteritem)
self.setRenameEnabled(1,True)
def startRename(self, columnindex):
qt.TQListViewItem.startRename(self,columnindex)
#lineedit = self.listView().viewport().child("qt_renamebox")
#if lineedit:
# regexp = qt.TQRegExp("^[_A-Z]+[_A-Z0-9]*$", False)
# v = qt.TQRegExpValidator(regexp, self.listView());
# lineedit.setValidator(v)
def okRename(self, columnindex):
if columnindex == 1:
n = str(self.text(0))
if not self.pluginimpl.options.has_key(n):
raise "No such option \"%s\"" % n
qt.TQListViewItem.okRename(self,columnindex)
v = str(qt.TQListViewItem.text(self,1))
print "Option \"%s\" has value \"%s\" now." % (n,v)
self.pluginimpl.options[n] = v
def text(self, columnindex):
if columnindex == 1:
if qt.TQListViewItem.text(self,0).contains("password"):
return "*" * len(str(qt.TQListViewItem.text(self,1)))
return qt.TQListViewItem.text(self,columnindex)
return ListViewItem(pluginimpl, self.listview, parentitem, afteritem)
def updateItem(self,pluginname,pluginimpl):
#print "CopyJobWidget.updateItem"
if pluginimpl == None: return
#plugin = self.dialog.plugins[pluginname]
item = self.addItem(pluginimpl)
item.setText(0,"%s: %s" % (pluginimpl.plugintype, pluginname))
afteritem = None
for i in pluginimpl.options:
afteritem = self.addItem(pluginimpl, afteritem, item)
afteritem.setText(0,str(i))
afteritem.setText(1,str(pluginimpl.options[i]))
print "CopyJobWidget.updateItem Added item with name \"%s\" and value \"%s\"" % (str(i),str(pluginimpl.options[i]))
pass
def maybeUpdate(self):
print "CopyJobWidget.maybeUpdate"
self.listview.clear()
try:
self.updateItem(self.dialog.getDestinationPluginName(), self.dialog.getDestinationPluginImpl())
self.updateItem(self.dialog.getSourcePluginName(), self.dialog.getSourcePluginImpl())
except:
import traceback
print "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )
self.listview.clear()
#--------------------------------------------------------------------
class ProgressDialog(qt.TQDialog):
def __init__(self, dialog):
self.dialog = dialog
self.starttime = None
qt.TQDialog.__init__(self, dialog, "ProgressDialog", 1)
self.setCaption("Copying...")
layout = qt.TQVBoxLayout(self)
box = qt.TQVBox(self)
box.setSpacing(6)
box.setMargin(6)
layout.addWidget(box)
self.textbrowser = qt.TQTextBrowser(box)
self.textbrowser.setWordWrap(qt.TQTextEdit.WidgetWidth)
self.textbrowser.setTextFormat(qt.TQt.RichText)
statusbox = qt.TQFrame(box)
layout = qt.TQGridLayout(statusbox,4,2,0,2)
layout.addWidget(qt.TQLabel("Number of records done:",statusbox),0,0)
self.donecounter = 0
self.donelabel = qt.TQLabel("-",statusbox)
layout.addWidget(self.donelabel,0,1)
layout.addWidget(qt.TQLabel("Successfully copied records:",statusbox),1,0)
self.successcounter = 0
self.successlabel = qt.TQLabel("-",statusbox)
layout.addWidget(self.successlabel,1,1)
layout.addWidget(qt.TQLabel("Failed to copy records:",statusbox),2,0)
self.failedcounter = 0
self.failedlabel = qt.TQLabel("-",statusbox)
layout.addWidget(self.failedlabel,2,1)
layout.addWidget(qt.TQLabel("Elapsed time in seconds:",statusbox),3,0)
self.elapsedlabel = qt.TQLabel("-",statusbox)
layout.addWidget(self.elapsedlabel,3,1)
btnbox = qt.TQHBox(box)
btnbox.setSpacing(6)
self.donebtn = qt.TQPushButton(btnbox)
self.donebtn.setText("Done")
self.donebtn.setEnabled(False)
qt.TQObject.connect(self.donebtn,qt.SIGNAL("clicked()"),self.close)
self.cancelbtn = qt.TQPushButton(btnbox)
self.cancelbtn.setText("Cancel")
qt.TQObject.connect(self.cancelbtn,qt.SIGNAL("clicked()"),self.close)
box.setMinimumSize( qt.TQSize(500,380) )
def updateStates(self):
if self.starttime != None:
self.donelabel.setText(str(self.donecounter))
self.failedlabel.setText(str(self.failedcounter))
self.successlabel.setText(str(self.successcounter))
self.elapsedlabel.setText( str(self.starttime.elapsed() / 1000) )
self.donelabel.update()
self.failedlabel.update()
self.successlabel.update()
self.elapsedlabel.update()
def writeSuccess(self, record, rowcount):
self.donecounter += rowcount
self.successcounter += rowcount
qt.tqApp.processEvents()
def writeFailed(self, record):
self.donecounter += 1
self.failedcounter += 1
qt.tqApp.processEvents()
def startCopy(self):
try:
global Copierer
copierer = Copierer()
copierer.appendProgressMessage = self.textbrowser.append
copierer.writeSuccess = self.writeSuccess
copierer.writeFailed = self.writeFailed
self.starttime = qt.TQTime()
self.updatetimer = qt.TQTimer(self)
qt.TQObject.connect(self.updatetimer,qt.SIGNAL("timeout()"),self.updateStates)
# Initialize the source
sourcename = self.dialog.getSourcePluginName()
sourceimpl = self.dialog.getSourcePluginImpl()
self.textbrowser.append("Source: %s" % sourcename)
if sourceimpl == None:
raise "No such source."
try:
sourceimpl.init(copierer)
# Initialize the destination
destinationname = self.dialog.getDestinationPluginName()
destinationimpl = self.dialog.getDestinationPluginImpl()
self.textbrowser.append("<hr>Destination: %s" % destinationname)
if destinationimpl == None:
raise "No such destination."
try:
destinationimpl.init(copierer)
self.starttime.start()
self.updatetimer.start(500)
qt.tqApp.processEvents()
# Copy the records
self.textbrowser.append("<hr><i>Copy the records...</i>")
while True:
record = sourceimpl.read()
if record == None: break
destinationimpl.write(record)
self.updateStates()
finally:
destinationimpl.finish()
finally:
sourceimpl.finish()
self.setCaption("Copy done")
self.textbrowser.append("<hr><b>Copy done.</b>")
except:
self.setCaption("Copy failed")
self.textbrowser.append("<b>Error: %s</b>" % sys.exc_info()[0])
import traceback
print "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )
#self.progressbar.setEnabled(False)
self.donebtn.setEnabled(True)
self.cancelbtn.setEnabled(False)
self.updatetimer.stop()
self.starttime = None
def show(self):
qt.TQDialog.show(self)
qt.TQTimer.singleShot(10,self.startCopy)
qt.tqApp.processEvents()
def closeEvent(self, closeevent):
if not self.dialog.getSourcePluginImpl().isFinished():
if qt.TQMessageBox.warning(self,"Abort?","Abort the copy?",qt.TQMessageBox.Yes,qt.TQMessageBox.No) != qt.TQMessageBox.Yes:
closeevent.ignore()
return
self.dialog.getSourcePluginImpl().finish()
self.dialog.getDestinationPluginImpl().finish()
closeevent.accept()
#--------------------------------------------------------------------
class DataSelector(qt.TQVGroupBox):
def __init__(self, plugintype, title, caption, parent, dialog, items):
self.plugintype = plugintype
self.pluginimpl = None
self.dialog = dialog
self.mainbox = None
qt.TQVGroupBox.__init__(self,title,parent)
self.setInsideMargin(6)
self.setInsideSpacing(0)
typebox = qt.TQHBox(self)
label = qt.TQLabel(caption,typebox)
self.combobox = qt.TQComboBox(typebox)
for item in items:
self.combobox.insertItem(str(item))
label.setBuddy(self.combobox)
typebox.setStretchFactor(self.combobox,1)
self.scrollview = qt.TQScrollView(self)
try:
self.scrollview.setResizePolicy(qt.TQScrollView.AutoOne)
self.scrollview.setFrameStyle(qt.TQFrame.NoFrame);
self.scrollview.setResizePolicy(qt.TQScrollView.AutoOneFit);
self.scrollview.viewport().setPaletteBackgroundColor(self.paletteBackgroundColor())
except:
import traceback
print "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )
qt.TQObject.connect(self.combobox, qt.SIGNAL("activated(int)"), self.activated)
def updatePlugin(self):
print "DataSelector.updatePlugin"
self.pluginimpl = None
text = str(self.combobox.currentText())
plugin = self.dialog.copycenter.plugins[text]
self.pluginimpl = getattr(plugin, self.plugintype)
def removeMainBox(self):
if self.mainbox == None: return
try:
self.scrollview.removeChild(self.mainbox)
self.mainbox.destroy()
except:
pass
self.mainbox = None
def updateMainBox(self):
print "DataSelector.updateMainBox"
self.removeMainBox()
self.mainbox = qt.TQVBox( self.scrollview.viewport() )
self.mainbox.setSpacing(2)
if self.pluginimpl != None:
try:
self.pluginimpl.createWidget(self.dialog, self.mainbox)
except:
import traceback
print "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )
self.mainbox.setStretchFactor(qt.TQWidget(self.mainbox), 1)
self.mainbox.show()
self.scrollview.addChild(self.mainbox)
def activated(self, **args):
self.updatePlugin()
self.updateMainBox()
def maybeUpdate(self):
print "DataSelector.maybeUpdate"
self.removeMainBox()
qt.TQTimer.singleShot(50, self.activated)
def maybeDone(self):
print "DataSelector.maybeDone"
if self.pluginimpl.widget == None: return
for optionname in self.pluginimpl.options:
self.pluginimpl.options[optionname] = self.pluginimpl.widget.getOptionValue(optionname)
#--------------------------------------------------------------------
class Dialog(qt.TQDialog):
def __init__(self, copycenter, parent):
self.copycenter = copycenter
from TQt import qt
import os
import sys
self.ListViewDialog = ListViewDialog
qt.TQDialog.__init__(self, parent, "Dialog", 1, qt.TQt.WDestructiveClose)
self.setCaption("Copy Center")
layout = qt.TQVBoxLayout(self)
box = qt.TQVBox(self)
box.setMargin(6)
box.setSpacing(6)
layout.addWidget(box)
self.tab = qt.TQTabWidget(box)
self.tab.setMargin(6)
box.setStretchFactor(self.tab,1)
self.jobsbox = CopyJobWidget(self,self.tab)
self.tab.addTab(self.jobsbox,"Jobs")
self.splitter = qt.TQSplitter(self.tab)
sourceplugins = []
destinationplugins = []
for pluginname in self.copycenter.plugins:
if self.copycenter.plugins[pluginname].source != None:
sourceplugins.append(pluginname)
if self.copycenter.plugins[pluginname].destination != None:
destinationplugins.append(pluginname)
sourceplugins.sort()
destinationplugins.sort()
self.sourcedata = DataSelector(
"source", # id
"Read Data From", # title
"Source:", # caption
self.splitter, self, sourceplugins)
self.destinationdata = DataSelector(
"destination", # id
"Write Data to", # title
"Destination:", # caption
self.splitter, self, destinationplugins)
btnbox = qt.TQHBox(box)
btnbox.setSpacing(6)
okbtn = qt.TQPushButton(btnbox)
okbtn.setText("Start Copy")
okbtn.setDefault(True)
qt.TQObject.connect(okbtn,qt.SIGNAL("clicked()"),self.startCopy)
cancelbtn = qt.TQPushButton(btnbox)
cancelbtn.setText("Cancel")
qt.TQObject.connect(cancelbtn,qt.SIGNAL("clicked()"),self.close)
self.tab.addTab(self.splitter,"Copy")
self.tab.setCurrentPage(1)
self.helpbrowser = qt.TQTextBrowser(self.tab)
self.helpbrowser.setLinkUnderline(False)
self.helpbrowser.setUndoRedoEnabled(False)
self.tab.addTab(self.helpbrowser,"Help")
qt.TQObject.connect(self.tab,qt.SIGNAL("currentChanged(QWidget*)"),self.currentTabChanged)
box.setMinimumSize( qt.TQSize(760,500) )
defaultfile = os.path.join(self.copycenter.homepath,"default.copycenterjob.xml")
if os.path.isfile(defaultfile):
print "Reading default copy job file: %s" % defaultfile
self.jobsbox.jobfilecombobox.setCurrentText(defaultfile)
def getSourcePluginName(self):
return str(self.sourcedata.combobox.currentText())
def getSourcePluginImpl(self):
return self.copycenter.plugins[self.getSourcePluginName()].source
def getDestinationPluginName(self):
return str(self.destinationdata.combobox.currentText())
def getDestinationPluginImpl(self):
return self.copycenter.plugins[self.getDestinationPluginName()].destination
def currentTabChanged(self,widget):
if self.tab.currentPage() == self.jobsbox:
# The "Copy" page is done
self.sourcedata.maybeDone()
self.destinationdata.maybeDone()
# Update the "Jobs" page
self.jobsbox.maybeUpdate()
elif self.tab.currentPage() == self.splitter:
# Update the "Copy" page
self.sourcedata.maybeUpdate()
self.destinationdata.maybeUpdate()
elif self.tab.currentPage() == self.helpbrowser and self.helpbrowser.lines() <= 1:
# Update the "Help" page
import os
file = os.path.join(self.copycenter.scriptpath, "readme.html")
if not os.path.isfile(file): return
fh = open(file,'r')
self.helpbrowser.setText( fh.read() )
fh.close()
def startCopy(self):
dlg = ProgressDialog(self)
dlg.show()
#--------------------------------------------------------------------
if name == "__main__":
qtapp = qt.TQApplication(sys.argv)
else:
qtapp = qt.tqApp
dialog = Dialog(copycenter, qtapp.mainWidget())
dialog.exec_loop()
import os
if __name__ == "__main__":
scriptpath = os.getcwd()
else:
scriptpath = os.path.dirname(__name__)
copycenter = CopyCenter(scriptpath)
runGuiApp(copycenter, __name__)
|