Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

GTK2 #2

Merged
merged 2 commits into from Oct 5, 2012
Jump to file or symbol
Failed to load files and symbols.
+285 −196
Split
View
@@ -17,7 +17,7 @@
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
LIBFILES="mintstick.py find_devices.py raw_write.py"
-DATAFILES="mintstick.xml"
+DATAFILES="mintstick.glade"
if [ "$1" = "uninstall" ]; then
View
@@ -8,7 +8,9 @@
import re
import gettext
from gettext import gettext as _
-from gi.repository import GObject, Gio, Polkit, Gtk
+import gtk
+import gtk.glade
+import gobject
class MintStick:
def __init__(self):
@@ -17,27 +19,26 @@ def __init__(self):
gettext.bindtextdomain(APP, DIR)
gettext.textdomain(APP)
- #Gtk.glade.bindtextdomain(APP, DIR)
- #Gtk.glade.textdomain(APP)
+ gtk.glade.bindtextdomain(APP, DIR)
+ gtk.glade.textdomain(APP)
- # get glade tree
- self.gladefile = "/usr/share/mintstick/mintstick.xml"
- self.wTree = Gtk.Builder()
- self.wTree.add_from_file(self.gladefile)
+ # get glade tree
+ self.gladefile = "/usr/share/mintstick/mintstick.glade"
+ self.wTree = gtk.glade.XML(self.gladefile)
# make sure we have a target device
self.get_devices()
# get globally needed widgets
- self.window = self.wTree.get_object("main_dialog")
- self.devicelist = self.wTree.get_object("device_combobox")
- self.logview = self.wTree.get_object("detail_text")
+ self.window = self.wTree.get_widget("main_dialog")
+ self.devicelist = self.wTree.get_widget("device_combobox")
+ self.logview = self.wTree.get_widget("detail_text")
self.log = self.logview.get_buffer()
self.ddpid = 0
# set default file filter to *.img
- self.chooser = self.wTree.get_object("filechooserbutton")
- filt = Gtk.FileFilter()
+ self.chooser = self.wTree.get_widget("filechooserbutton")
+ filt = gtk.FileFilter()
filt.add_pattern("*.img")
filt.add_pattern("*.iso")
self.chooser.set_filter(filt)
@@ -52,36 +53,36 @@ def __init__(self):
"on_detail_expander_activate" : self.expander_control,
"on_device_combobox_changed" : self.device_selected,
"on_write_button_clicked" : self.do_write}
- self.wTree.connect_signals(dict)
+ self.wTree.signal_autoconnect(dict)
self.window.show_all()
def get_devices(self):
list = Popen(["/usr/lib/mintstick/find_devices.py"], stdout=PIPE).communicate()[0]
if not len(list):
- dialog = self.wTree.get_object("nodev_dialog")
+ dialog = self.wTree.get_widget("nodev_dialog")
dialog.run()
exit(0)
- self.combo = self.wTree.get_object("device_combobox")
+ self.combo = self.wTree.get_widget("device_combobox")
list = list.strip().split('\n')
for item in list:
name,path = item.split(',')
self.combo.append_text(name+' ('+path.lstrip()+')')
def device_selected(self, widget):
- write_button = self.wTree.get_object("write_button")
+ write_button = self.wTree.get_widget("write_button")
write_button.set_sensitive(True)
self.dev = self.combo.get_active_text()
def do_write(self, widget):
- write_button = self.wTree.get_object("write_button")
+ write_button = self.wTree.get_widget("write_button")
write_button.set_sensitive(False)
- combo = self.wTree.get_object("device_combobox")
+ combo = self.wTree.get_widget("device_combobox")
combo.set_sensitive(False)
self.chooser.set_sensitive(False)
source = self.chooser.get_filename()
target = self.dev.split('(')[1].rstrip(')')
- dialog = self.wTree.get_object("confirm_dialog")
+ dialog = self.wTree.get_widget("confirm_dialog")
self.logger(_('Image: ')+source)
self.logger(_('Target Device: ')+self.dev)
if os.geteuid() > 0:
@@ -92,8 +93,8 @@ def do_write(self, widget):
if resp:
self.do_umount(target)
dialog.hide()
- while Gtk.events_pending():
- Gtk.main_iteration()
+ while gtk.events_pending():
+ gtk.main_iteration(True)
self.raw_write(source, target)
else:
self.close('dummy')
@@ -107,8 +108,8 @@ def do_umount(self, target):
self.logger(_('Unmounting all partitions of ')+target+':')
for mount in mounts:
self.logger(_('Trying to unmount ')+mount[0]+'...')
- while Gtk.events_pending():
- Gtk.main_iteration()
+ while gtk.events_pending():
+ gtk.main_iteration(True)
try:
retcode = call('umount '+mount[0], shell=True)
if retcode < 0:
@@ -133,42 +134,42 @@ def get_mounted(self, target):
self.emergency()
def raw_write(self, source, target):
- progress = self.wTree.get_object("progressbar")
- progress.set_sensitive(True)
- progress.set_text(_('Writing ')+source.split('/')[-1]+_(' to ')+self.dev)
- self.logger(_('Starting copy from ')+source+' to '+target)
- while Gtk.events_pending():
- Gtk.main_iteration()
- total_size = float(os.path.getsize(source))
- # Add launcher string, only when not root
- launcher = ''
- size=''
- if os.geteuid() > 0:
+ progress = self.wTree.get_widget("progressbar")
+ progress.set_sensitive(True)
+ progress.set_text(_('Writing ')+source.split('/')[-1]+_(' to ')+self.dev)
+ self.logger(_('Starting copy from ')+source+' to '+target)
+ while gtk.events_pending():
+ gtk.main_iteration(True)
+ total_size = float(os.path.getsize(source))
+ # Add launcher string, only when not root
+ launcher = ''
+ size=''
+ if os.geteuid() > 0:
launcher='pkexec'
output = Popen([launcher,'/usr/bin/python', '/usr/lib/mintstick/raw_write.py','-s',source,'-t',target], shell=False, stdout=PIPE)
- else:
+ else:
output = Popen(['/usr/bin/python', '/usr/lib/mintstick/raw_write.py','-s',source,'-t',target], shell=False, stdout=PIPE)
- while output.stdout.readline():
- size = output.stdout.readline().strip()
- try:
- size = float(size)
- flag = True
- except ValueError:
- flag = False
- while Gtk.events_pending():
- Gtk.main_iteration()
- if flag:
- progress.set_fraction(size)
- if size == 1.0:
- self.logger(_('Image ')+source.split('/')[-1]+_(' successfully written to')+target)
- self.success()
- else:
- self.logger(_('The process ended with an error !'))
- self.emergency()
- return False
+ while output.stdout.readline():
+ size = output.stdout.readline().strip()
+ try:
+ size = float(size)
+ flag = True
+ except ValueError:
+ flag = False
+ while gtk.events_pending():
+ gtk.main_iteration(True)
+ if flag:
+ progress.set_fraction(size)
+ if size == 1.0:
+ self.logger(_('Image ')+source.split('/')[-1]+_(' successfully written to')+target)
+ self.success()
+ else:
+ self.logger(_('The process ended with an error !'))
+ self.emergency()
+ return False
def success(self):
- dialog = self.wTree.get_object("success_dialog")
+ dialog = self.wTree.get_widget("success_dialog")
self.final_unsensitive()
resp = dialog.run()
if resp:
@@ -177,8 +178,8 @@ def success(self):
def emergency(self):
self.final_unsensitive()
- dialog = self.wTree.get_object("emergency_dialog")
- expander = self.wTree.get_object("detail_expander")
+ dialog = self.wTree.get_widget("emergency_dialog")
+ expander = self.wTree.get_widget("detail_expander")
expander.set_expanded(True)
mark = self.log.create_mark("end", self.log.get_end_iter(), False)
self.logview.scroll_to_mark(mark, 0.05, True, 0.0, 1.0)
@@ -189,9 +190,9 @@ def emergency(self):
def final_unsensitive(self):
self.chooser.set_sensitive(False)
self.devicelist.set_sensitive(False)
- write_button = self.wTree.get_object("write_button")
+ write_button = self.wTree.get_widget("write_button")
write_button.set_sensitive(False)
- progress = self.wTree.get_object("progressbar")
+ progress = self.wTree.get_widget("progressbar")
progress.set_sensitive(False)
def close(self, widget):
@@ -200,9 +201,9 @@ def close(self, widget):
try:
os.killpg(os.getpgid(self.ddpid), signal.SIGKILL)
except:
- Gtk.main_quit()
+ gtk.main_quit()
else:
- Gtk.main_quit()
+ gtk.main_quit()
def write_logfile(self):
start = self.log.get_start_iter()
@@ -213,8 +214,8 @@ def logger(self, text):
self.log.insert_at_cursor(text+"\n")
def activate_devicelist(self, widget):
- label = self.wTree.get_object("to_label")
- expander = self.wTree.get_object("detail_expander")
+ label = self.wTree.get_widget("to_label")
+ expander = self.wTree.get_widget("detail_expander")
self.devicelist.set_sensitive(True)
expander.set_sensitive(True)
label.set_sensitive(True)
@@ -224,8 +225,8 @@ def expander_control(self, widget):
# this is darn ugly but still better than the UI behavior of
# the unexpanded expander which doesnt reset the window size
if widget.get_expanded():
- GObject.timeout_add(130, lambda: self.window.reshow_with_initial_size())
+ gobject.timeout_add(130, lambda: self.window.reshow_with_initial_size())
if __name__ == "__main__":
app = MintStick()
- Gtk.main()
+ gtk.main()
View
@@ -24,6 +24,10 @@ def raw_write(source, target):
#os.fsync(output.fileno())
input.close()
output.close()
+ if size == total_size:
+ print "1.0"
+ else:
+ print "failed"
def main():
# parse command line options
@@ -1,4 +1,3 @@
-
[Desktop Entry]
Version=1.0
Type=Application
@@ -7,6 +6,6 @@ Icon=system-run
Exec=mintstick
Name=MintStick
Comment=Make a bootable USB stick
-Categories=System
+Categories=System;
OnlyShowIn=KDE;
Name[en_IE]=mintstick-kde.desktop
@@ -6,5 +6,5 @@ Icon=gtk-execute
Exec=mintstick
Name=MintStick
Comment=Make a bootable USB stick
-Categories=GNOME;GTK;Utility
+Categories=GNOME;GTK;Utility;
NotShowIn=KDE;
Oops, something went wrong.