-
Notifications
You must be signed in to change notification settings - Fork 0
/
jadfactory
executable file
·263 lines (203 loc) · 11.8 KB
/
jadfactory
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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import gtk, pygtk, os, sys, shutil, string, gettext, locale, webbrowser
from gettext import gettext as _
# setup translation support
APP = "jadfactory"
DIR = "/usr/share/locale"
gettext.bindtextdomain(APP, DIR)
gettext.textdomain(APP)
_ = gettext.gettext
class JADbuilder:
def run(self, widget):
jar = ".jar"
file = self.textbox.get_text()
#Frist check
if file[-4:] != jar:
fristmsg = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, _("""The file:\n%s\n is not a ".jar" file""") % file)
fristmsg.run()
fristmsg.destroy()
else:
#Safety check 1
if os.path.exists(file) == False:
msg0 = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, _("""The file:\n%s not exist\nMake sure to print the correct path name\nOr use "select a file" button""") % file)
msg0.run()
msg0.destroy()
elif os.path.exists(file) == True:
jad = file[0:-4]+".jad"
if os.path.exists(jad) == True:
print "True"
msg7 = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, _("File:\n%s\n Is already exists\n") % jad)
msg7.run()
msg7.destroy()
elif os.path.exists(jad) == False:
FILE = os.path.basename('%s' % self.textbox.get_text())
size = os.path.getsize('%s' % self.textbox.get_text())
os.system("jadunzip %s" % file)
O = open(jad, 'a')
print >> O, "MIDlet-Jar-URL: %s" % FILE
print >> O, "MIDlet-Info-URL: http://jadfactory.blogspot.com/"
print >> O, "MIDlet-Jar-Size: %s" % size
O.close()
msg2 = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, _("File : %s\nhas created") % jad)
msg2.run()
msg2.destroy()
def fileChooser(self, wiget):
fs = gtk.FileChooserDialog(_("Select a file"), None,
gtk.FILE_CHOOSER_ACTION_OPEN,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
fs.set_default_response(gtk.RESPONSE_OK)
filter = gtk.FileFilter()
filter.set_name(_("JAD file"))
filter.add_pattern("*.jar")
filter.add_pattern("*.JAR")
fs.add_filter(filter)
response = fs.run()
if response == gtk.RESPONSE_OK:
print "Selected filepath: %s" % fs.get_filename()
FILE = os.path.basename('%s' % fs.get_filename())
size = os.path.getsize('%s' % fs.get_filename())
self.textbox.set_text(fs.get_filename())
#Safety check1
filename = fs.get_filename()
jad = filename[0:-4]+".jad"
if os.path.exists(jad) == True:
print "True"
msg = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, _("File:\n%s\n Is already exists\n") % jad)
msg.run()
msg.destroy()
else:
os.system("jadunzip %s" % filename)
O = open(jad, 'a')
print >> O, "MIDlet-Jar-URL: %s" % FILE
print >> O, "MIDlet-Info-URL: http://jadfactory.blogspot.com/"
print >> O, "MIDlet-Jar-Size: %s" % size
O.close()
msg1 = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, _("File : %s\nhas created") % jad)
msg1.run()
msg1.destroy()
elif response == gtk.RESPONSE_CANCEL:
print "You don't select any file!"
error = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, _("You don't select any file!"))
error.run()
error.destroy()
fs.destroy()
def about_win(self, widget):
about = gtk.AboutDialog()
about.set_icon(gtk.gdk.pixbuf_new_from_file("/usr/share/pixmaps/jadfactory64.png"))
about.set_logo(gtk.gdk.pixbuf_new_from_file("/usr/share/pixmaps/jadfactory/jadfactory180.png"))
about.set_program_name(_("JADfactory"))
about.set_version(_("v1.1"))
about.set_comments(_("This is a simple Application\nto make jad files for *.jar"))
about.set_copyright(_("Copyright © 2011 Karim Oulad Chalha"))
about.set_license(_("GPLv3\nSee http://www.gnu.org/copyleft/gpl.html"))
about.set_website(_("http://jadfactory.blogspot.com/"))
about.set_translator_credits(_("translator-credits"))
about.run()
about.destroy()
def destroy(self, widget):
gtk.main_quit()
def delete(self, widget):
return False
def whatjad(self, widget):
webbrowser.open("http://en.wikipedia.org/wiki/JAD_(file_format)")
def translation(self, widget):
webbrowser.open("https://www.transifex.net/projects/p/jadfactory/")
def report(self, widget):
webbrowser.open("http://github.com/karim88/JADfactory/issues")
def __init__(self):
self.win = gtk.Window(gtk.WINDOW_TOPLEVEL) #Main window
self.win.set_icon(gtk.gdk.pixbuf_new_from_file("/usr/share/pixmaps/jadfactory64.png"))
self.win.set_title(_("JADfactory"))
self.label = gtk.Label(_("""Welcome in JADfactory v1.1"""))
self.label1 = gtk.Label(_("""\nNOTE :The name of file\nshould not contient a space like:\n"name file.jar"\nmake sure to rename it like:\n"namefile.jar" or "name_file.jar" , "name-file.jar" ,....\n"""))
self.win.set_position(gtk.WIN_POS_CENTER)
self.win.set_default_size(350, 200)
self.menu = gtk.MenuBar() #Menubar
self.file = gtk.MenuItem(_("File"))
self.help = gtk.MenuItem(_("Help"))
self.file_sub = gtk.Menu() #Sub menu of file
self.chooser = gtk.MenuItem(_("Select a file"))
self.quit = gtk.MenuItem(_("Quit"))
self.file_sub.append(self.chooser)
self.file_sub.append(self.quit)
self.help_sub = gtk.Menu() #Sub menu of help
self.what = gtk.MenuItem(_("What is JAD file?"))
self.trans = gtk.MenuItem(_("Translate this application"))
self.bug = gtk.MenuItem(_("Report a bug"))
self.apropos = gtk.MenuItem(_("About"))
self.help_sub.append(self.what)
self.help_sub.append(self.trans)
self.help_sub.append(self.bug)
self.help_sub.append(self.apropos)
self.file.set_submenu(self.file_sub)
self.help.set_submenu(self.help_sub)
self.menu.append(self.file)
self.menu.append(self.help)
self.chooser.connect("activate", self.fileChooser)
self.quit.connect("activate", self.destroy)
self.what.connect("activate", self.whatjad)
self.trans.connect("activate",self.translation)
self.bug.connect("activate", self.report)
self.apropos.connect("activate", self.about_win)
self.image = gtk.Image() #Image
self.image.set_from_file("/usr/share/pixmaps/jadfactory/jadfactory.png")
self.image.set_tooltip_text(_("JADfactory"))
self.hs = gtk.HSeparator() #Horizontal separator
self.hs1 = gtk.HSeparator() #// // // //1
self.hs2 = gtk.HSeparator() #// // // //2
self.info = gtk.InfoBar() #Info Bar
self.content = self.info.get_content_area()
self.content.add(self.label1)
self.expander = gtk.Expander("Important") #Expander
self.expander.set_tooltip_text("Important Information")
self.expander.add(self.info)
self.rb = gtk.Button(_("run")) #Run button
self.rb.connect("clicked", self.run)
self.rb.set_tooltip_text(_("Run to make *.jad file"))
self.textbox = gtk.Entry() #Entry
self.textbox.set_text(_("Type path here"))
self.textbox.connect("activate", self.run)
self.filebutton = gtk.Button(_("Select a file")) #Filechooser button
self.filebutton.connect("clicked", self.fileChooser)
self.filebutton.set_tooltip_text(_("Select a *.jar file"))
self.b0 = gtk.Button(_("About")) #About button
self.b0.connect("clicked", self.about_win)
self.b0.set_tooltip_text(_("About"))
self.b1 = gtk.Button(_("Quit")) #Quit button
self.b1.connect("clicked", self.destroy)
self.b1.set_tooltip_text(_("Quit"))
self.box6 = gtk.HBox() #Box6
self.box6.pack_start(self.textbox)
self.box6.pack_start(self.rb, False)
self.box5 = gtk.HBox() #Box5
self.box4 = gtk.HBox() #Box4
self.box4.pack_start(self.filebutton, False, False)
self.box4.add(self.box5)
self.box1 = gtk.VBox() #Box1
self.box1.pack_start(self.menu, False)
self.box1.pack_start(self.label, False)
self.box1.add(self.hs1)
self.box1.pack_start(self.expander, False, False)
self.box1.add(self.hs2)
self.box1.pack_start(self.box6)
self.box1.add(self.box4)
self.box3 = gtk.HBox() #Box3
self.box2 = gtk.HBox() #Box2
self.box2.pack_start(self.b0, False)
self.box2.add(self.box3)
self.box2.pack_start(self.b1, False)
self.box0 = gtk.VBox() #Box0
self.box0.pack_start(self.box1)
self.box0.add(self.hs)
self.box0.pack_start(self.box2, False)
self.win.add(self.box0)
self.win.show_all()
self.win.connect("destroy", self.destroy)
def main(self):
gtk.main()
if __name__ == "__main__":
base = JADbuilder()
base.main()