Advertisement
LightningStalker

gresistor Xenial patch

Jan 3rd, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 14.40 KB | None | 0 0
  1. diff -Naur gresistor-0.0.2/gresistor gresistor-0.0.2p/gresistor
  2. --- gresistor-0.0.2/gresistor   2013-02-18 23:56:23.000000000 -0500
  3. +++ gresistor-0.0.2p/gresistor  2018-01-03 10:55:09.931425767 -0500
  4. @@ -14,15 +14,18 @@
  5.  
  6.  import pango
  7.  
  8. +import sys
  9. +sys.path.insert(0, '/usr/local/share/gresistor')
  10. +
  11.  from SimpleGladeApp import SimpleGladeApp
  12.  from SimpleGladeApp import bindtextdomain
  13.  
  14. +glade_dir = os.path.join('/usr', 'local', 'share', 'gresistor')
  15. +locale_dir = ""
  16. +
  17.  app_name = "gresistor"
  18.  app_version = "0.0.2"
  19.  
  20. -glade_dir = os.path.join('/usr', 'share', 'gresistor')
  21. -locale_dir = ""
  22. -
  23.  bindtextdomain(app_name, locale_dir)
  24.  
  25.  class Gresistor(SimpleGladeApp):
  26. diff -Naur gresistor-0.0.2/remove.sh gresistor-0.0.2p/remove.sh
  27. --- gresistor-0.0.2/remove.sh   1969-12-31 19:00:00.000000000 -0500
  28. +++ gresistor-0.0.2p/remove.sh  2018-01-03 11:06:06.759997400 -0500
  29. @@ -0,0 +1,7 @@
  30. +#!/bin/sh
  31. +rm /usr/local/bin/gresistor
  32. +rm /usr/local/share/gresistor/gresistor.glade
  33. +rm /usr/local/share/gresistor/SimpleGladeApp.py
  34. +rm /usr/local/lib/python2.7/dist-packages/gresistor-0.0.2.egg-info
  35. +rm /usr/local/share/applications/gresistor.desktop
  36. +rm /usr/local/share/icons/hicolor/48x48/apps/gresistor.png
  37. diff -Naur gresistor-0.0.2/setup.py gresistor-0.0.2p/setup.py
  38. --- gresistor-0.0.2/setup.py    2013-02-19 01:02:08.000000000 -0500
  39. +++ gresistor-0.0.2p/setup.py   2018-01-03 11:04:16.507230661 -0500
  40. @@ -9,7 +9,7 @@
  41.        url              = 'http://www.sf.net/',
  42.        license          = 'GPL',
  43.        scripts          =['gresistor'],
  44. -      data_files       = [('share/gresistor',['gresistor.glade']),('share/applications',
  45. +      data_files       = [('share/gresistor',['gresistor.glade','SimpleGladeApp.py']),('share/applications',
  46.                         ['gresistor.desktop']),('share/icons/hicolor/48x48/apps',
  47.                         ['gresistor.png'])],
  48.        long_description = 'This program is used to calculate the value of resistivity of a common, commercial resistor',
  49. diff -Naur gresistor-0.0.2/SimpleGladeApp.py gresistor-0.0.2p/SimpleGladeApp.py
  50. --- gresistor-0.0.2/SimpleGladeApp.py   1969-12-31 19:00:00.000000000 -0500
  51. +++ gresistor-0.0.2p/SimpleGladeApp.py  2018-01-03 10:55:09.931425767 -0500
  52. @@ -0,0 +1,341 @@
  53. +"""
  54. + SimpleGladeApp.py
  55. + Module that provides an object oriented abstraction to pygtk and libglade.
  56. + Copyright (C) 2004 Sandino Flores Moreno
  57. +"""
  58. +
  59. +# This library is free software; you can redistribute it and/or
  60. +# modify it under the terms of the GNU Lesser General Public
  61. +# License as published by the Free Software Foundation; either
  62. +# version 2.1 of the License, or (at your option) any later version.
  63. +#
  64. +# This library is distributed in the hope that it will be useful,
  65. +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  66. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  67. +# Lesser General Public License for more details.
  68. +#
  69. +# You should have received a copy of the GNU Lesser General Public
  70. +# License along with this library; if not, write to the Free Software
  71. +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  72. +# USA
  73. +
  74. +import os
  75. +import sys
  76. +import re
  77. +
  78. +import tokenize
  79. +import gtk
  80. +import gtk.glade
  81. +import weakref
  82. +import inspect
  83. +
  84. +__version__ = "1.0"
  85. +__author__ = 'Sandino "tigrux" Flores-Moreno'
  86. +
  87. +def bindtextdomain(app_name, locale_dir=None):
  88. +    """    
  89. +    Bind the domain represented by app_name to the locale directory locale_dir.
  90. +    It has the effect of loading translations, enabling applications for different
  91. +    languages.
  92. +
  93. +    app_name:
  94. +        a domain to look for translations, tipically the name of an application.
  95. +
  96. +    locale_dir:
  97. +        a directory with locales like locale_dir/lang_isocode/LC_MESSAGES/app_name.mo
  98. +        If omitted or None, then the current binding for app_name is used.
  99. +    """    
  100. +    try:
  101. +        import locale
  102. +        import gettext
  103. +        locale.setlocale(locale.LC_ALL, "")
  104. +        gtk.glade.bindtextdomain(app_name, locale_dir)
  105. +        gettext.install(app_name, locale_dir, unicode=1)
  106. +    except (IOError,locale.Error), e:
  107. +        print "Warning", app_name, e
  108. +        __builtins__.__dict__["_"] = lambda x : x
  109. +
  110. +
  111. +class SimpleGladeApp:
  112. +
  113. +    def __init__(self, path, root=None, domain=None, **kwargs):
  114. +        """
  115. +        Load a glade file specified by glade_filename, using root as
  116. +        root widget and domain as the domain for translations.
  117. +
  118. +        If it receives extra named arguments (argname=value), then they are used
  119. +        as attributes of the instance.
  120. +
  121. +        path:
  122. +            path to a glade filename.
  123. +            If glade_filename cannot be found, then it will be searched in the
  124. +            same directory of the program (sys.argv[0])
  125. +
  126. +        root:
  127. +            the name of the widget that is the root of the user interface,
  128. +            usually a window or dialog (a top level widget).
  129. +            If None or ommited, the full user interface is loaded.
  130. +
  131. +        domain:
  132. +            A domain to use for loading translations.
  133. +            If None or ommited, no translation is loaded.
  134. +
  135. +        **kwargs:
  136. +            a dictionary representing the named extra arguments.
  137. +            It is useful to set attributes of new instances, for example:
  138. +                glade_app = SimpleGladeApp("ui.glade", foo="some value", bar="another value")
  139. +            sets two attributes (foo and bar) to glade_app.
  140. +        """        
  141. +        if os.path.isfile(path):
  142. +            self.glade_path = path
  143. +        else:
  144. +            glade_dir = os.path.dirname( sys.argv[0] )
  145. +            self.glade_path = os.path.join(glade_dir, path)
  146. +        for key, value in kwargs.items():
  147. +            try:
  148. +                setattr(self, key, weakref.proxy(value) )
  149. +            except TypeError:
  150. +                setattr(self, key, value)
  151. +        self.glade = None
  152. +        self.install_custom_handler(self.custom_handler)
  153. +        self.glade = self.create_glade(self.glade_path, root, domain)
  154. +        if root:
  155. +            self.main_widget = self.get_widget(root)
  156. +        else:
  157. +            self.main_widget = None
  158. +        self.normalize_names()
  159. +        self.add_callbacks(self)
  160. +        self.new()
  161. +
  162. +    def __repr__(self):
  163. +        class_name = self.__class__.__name__
  164. +        if self.main_widget:
  165. +            root = gtk.Widget.get_name(self.main_widget)
  166. +            repr = '%s(path="%s", root="%s")' % (class_name, self.glade_path, root)
  167. +        else:
  168. +            repr = '%s(path="%s")' % (class_name, self.glade_path)
  169. +        return repr
  170. +
  171. +    def new(self):
  172. +        """
  173. +        Method called when the user interface is loaded and ready to be used.
  174. +        At this moment, the widgets are loaded and can be refered as self.widget_name
  175. +        """
  176. +        pass
  177. +
  178. +    def add_callbacks(self, callbacks_proxy):
  179. +        """
  180. +        It uses the methods of callbacks_proxy as callbacks.
  181. +        The callbacks are specified by using:
  182. +            Properties window -> Signals tab
  183. +            in glade-2 (or any other gui designer like gazpacho).
  184. +
  185. +        Methods of classes inheriting from SimpleGladeApp are used as
  186. +        callbacks automatically.
  187. +
  188. +        callbacks_proxy:
  189. +            an instance with methods as code of callbacks.
  190. +            It means it has methods like on_button1_clicked, on_entry1_activate, etc.
  191. +        """        
  192. +        self.glade.signal_autoconnect(callbacks_proxy)
  193. +
  194. +    def normalize_names(self):
  195. +        """
  196. +        It is internally used to normalize the name of the widgets.
  197. +        It means a widget named foo:vbox-dialog in glade
  198. +        is refered self.vbox_dialog in the code.
  199. +
  200. +        It also sets a data "prefixes" with the list of
  201. +        prefixes a widget has for each widget.
  202. +        """
  203. +        for widget in self.get_widgets():
  204. +            widget_name = gtk.Widget.get_name(widget)
  205. +            prefixes_name_l = widget_name.split(":")
  206. +            prefixes = prefixes_name_l[ : -1]
  207. +            widget_api_name = prefixes_name_l[-1]
  208. +            widget_api_name = "_".join( re.findall(tokenize.Name, widget_api_name) )
  209. +            gtk.Widget.set_name(widget, widget_api_name)
  210. +            if hasattr(self, widget_api_name):
  211. +                raise AttributeError("instance %s already has an attribute %s" % (self,widget_api_name))
  212. +            else:
  213. +                setattr(self, widget_api_name, widget)
  214. +                if prefixes:
  215. +                    gtk.Widget.set_data(widget, "prefixes", prefixes)
  216. +
  217. +    def add_prefix_actions(self, prefix_actions_proxy):
  218. +        """
  219. +        By using a gui designer (glade-2, gazpacho, etc)
  220. +        widgets can have a prefix in theirs names
  221. +        like foo:entry1 or foo:label3
  222. +        It means entry1 and label3 has a prefix action named foo.
  223. +
  224. +        Then, prefix_actions_proxy must have a method named prefix_foo which
  225. +        is called everytime a widget with prefix foo is found, using the found widget
  226. +        as argument.
  227. +
  228. +        prefix_actions_proxy:
  229. +            An instance with methods as prefix actions.
  230. +            It means it has methods like prefix_foo, prefix_bar, etc.
  231. +        """        
  232. +        prefix_s = "prefix_"
  233. +        prefix_pos = len(prefix_s)
  234. +
  235. +        is_method = lambda t : callable( t[1] )
  236. +        is_prefix_action = lambda t : t[0].startswith(prefix_s)
  237. +        drop_prefix = lambda (k,w): (k[prefix_pos:],w)
  238. +
  239. +        members_t = inspect.getmembers(prefix_actions_proxy)
  240. +        methods_t = filter(is_method, members_t)
  241. +        prefix_actions_t = filter(is_prefix_action, methods_t)
  242. +        prefix_actions_d = dict( map(drop_prefix, prefix_actions_t) )
  243. +
  244. +        for widget in self.get_widgets():
  245. +            prefixes = gtk.Widget.get_data(widget, "prefixes")
  246. +            if prefixes:
  247. +                for prefix in prefixes:
  248. +                    if prefix in prefix_actions_d:
  249. +                        prefix_action = prefix_actions_d[prefix]
  250. +                        prefix_action(widget)
  251. +
  252. +    def custom_handler(self,
  253. +            glade, function_name, widget_name,
  254. +            str1, str2, int1, int2):
  255. +        """
  256. +        Generic handler for creating custom widgets, internally used to
  257. +        enable custom widgets (custom widgets of glade).
  258. +
  259. +        The custom widgets have a creation function specified in design time.
  260. +        Those creation functions are always called with str1,str2,int1,int2 as
  261. +        arguments, that are values specified in design time.
  262. +
  263. +        Methods of classes inheriting from SimpleGladeApp are used as
  264. +        creation functions automatically.
  265. +
  266. +        If a custom widget has create_foo as creation function, then the
  267. +        method named create_foo is called with str1,str2,int1,int2 as arguments.
  268. +        """
  269. +        try:
  270. +            handler = getattr(self, function_name)
  271. +            return handler(str1, str2, int1, int2)
  272. +        except AttributeError:
  273. +            return None
  274. +
  275. +    def gtk_widget_show(self, widget, *args):
  276. +        """
  277. +        Predefined callback.
  278. +        The widget is showed.
  279. +        Equivalent to widget.show()
  280. +        """
  281. +        widget.show()
  282. +
  283. +    def gtk_widget_hide(self, widget, *args):
  284. +        """
  285. +        Predefined callback.
  286. +        The widget is hidden.
  287. +        Equivalent to widget.hide()
  288. +        """
  289. +        widget.hide()
  290. +
  291. +    def gtk_widget_grab_focus(self, widget, *args):
  292. +        """
  293. +        Predefined callback.
  294. +        The widget grabs the focus.
  295. +        Equivalent to widget.grab_focus()
  296. +        """
  297. +        widget.grab_focus()
  298. +
  299. +    def gtk_widget_destroy(self, widget, *args):
  300. +        """
  301. +        Predefined callback.
  302. +        The widget is destroyed.
  303. +        Equivalent to widget.destroy()
  304. +        """
  305. +        widget.destroy()
  306. +
  307. +    def gtk_window_activate_default(self, window, *args):
  308. +        """
  309. +        Predefined callback.
  310. +        The default widget of the window is activated.
  311. +        Equivalent to window.activate_default()
  312. +        """
  313. +        widget.activate_default()
  314. +
  315. +    def gtk_true(self, *args):
  316. +        """
  317. +        Predefined callback.
  318. +        Equivalent to return True in a callback.
  319. +        Useful for stopping propagation of signals.
  320. +        """
  321. +        return True
  322. +
  323. +    def gtk_false(self, *args):
  324. +        """
  325. +        Predefined callback.
  326. +        Equivalent to return False in a callback.
  327. +        """
  328. +        return False
  329. +
  330. +    def gtk_main_quit(self, *args):
  331. +        """
  332. +        Predefined callback.
  333. +        Equivalent to self.quit()
  334. +        """
  335. +        self.quit()
  336. +
  337. +    def main(self):
  338. +        """
  339. +        Starts the main loop of processing events.
  340. +        The default implementation calls gtk.main()
  341. +
  342. +        Useful for applications that needs a non gtk main loop.
  343. +        For example, applications based on gstreamer needs to override
  344. +        this method with gst.main()
  345. +
  346. +        Do not directly call this method in your programs.
  347. +        Use the method run() instead.
  348. +        """
  349. +        gtk.main()
  350. +
  351. +    def quit(self):
  352. +        """
  353. +        Quit processing events.
  354. +        The default implementation calls gtk.main_quit()
  355. +        
  356. +        Useful for applications that needs a non gtk main loop.
  357. +        For example, applications based on gstreamer needs to override
  358. +        this method with gst.main_quit()
  359. +        """
  360. +        gtk.main_quit()
  361. +
  362. +    def run(self):
  363. +        """
  364. +        Starts the main loop of processing events checking for Control-C.
  365. +
  366. +        The default implementation checks wheter a Control-C is pressed,
  367. +        then calls on_keyboard_interrupt().
  368. +
  369. +        Use this method for starting programs.
  370. +        """
  371. +        try:
  372. +            self.main()
  373. +        except KeyboardInterrupt:
  374. +            self.on_keyboard_interrupt()
  375. +
  376. +    def on_keyboard_interrupt(self):
  377. +        """
  378. +        This method is called by the default implementation of run()
  379. +        after a program is finished by pressing Control-C.
  380. +        """
  381. +        pass
  382. +
  383. +    def install_custom_handler(self, custom_handler):
  384. +        gtk.glade.set_custom_handler(custom_handler)
  385. +
  386. +    def create_glade(self, glade_path, root, domain):
  387. +        return gtk.glade.XML(self.glade_path, root, domain)
  388. +
  389. +    def get_widget(self, widget_name):
  390. +        return self.glade.get_widget(widget_name)
  391. +
  392. +    def get_widgets(self):
  393. +        return self.glade.get_widget_prefix("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement