Beispiel #1
0
    def __init__(self, config=None):
        """Constructor.

        Reads the GUI definition from the GtkBuilder file and creates the GUI,
        registers event handlers and starts periodic tasks to update dynamic
        GUI elements.

        """
        self.config = config

        # read UI definition from GtkBuilder XML file
        ui_file = expanduser(self.config.get('ui_file', UI_FILENAME))

        if not exists(ui_file) and exists(join(ui_dir, ui_file)):
            ui_file = join(ui_dir, ui_file)

        self.ui = gtk.Builder()
        log.debug("Loading UI definition from '%s'.", ui_file)
        self.ui.add_from_file(ui_file)
        self.window = self.ui.get_object('mainwin')
        self.window.connect("destroy", self.quit)

        self.statusbar = self.ui.get_object('statusbar')
        self.aboutdialog = self.ui.get_object('aboutdialog')
        self.aboutdialog.set_name(__app_name__)
        self.aboutdialog.set_version(__version__)
        self.aboutdialog.set_comments(
            self.aboutdialog.get_comments().replace(
                "2.x", "3.x").replace("PyGTK", "Python GObject"))

        # parse Gtk+ RC file
        rc_file = expanduser(self.config.get('rc_file', GTKRC_FILENAME))

        if not exists(rc_file) and exists(join(ui_dir, rc_file)):
            rc_file = join(ui_dir, rc_file)

        gtk.rc_parse(rc_file)

        self.init_treeview()

        # attach signal handlers
        self.ui.connect_signals(self)

        # set up periodic tasks
        glib.timeout_add(1000, self.set_time)
        self.set_time()

        self.window.set_title(__app_name__)
        self.window.show_all()
Beispiel #2
0
    def __init__(self, feature='', module=''):
        GuiBuilder.__init__(self, file_name='mainwindow.ui')

        self.window_size_setting = GSetting('com.ubuntu-tweak.tweak.window-size')
        width, height = self.window_size_setting.get_value()
        if width >= 800 and height >= 480:
            self.mainwindow.set_default_size(width, height)

        Gtk.rc_parse(os.path.join(DATA_DIR, 'theme/ubuntu-tweak.rc'))

        tweaks_page = FeaturePage('tweaks')
        admins_page = FeaturePage('admins')
        clip_page = ClipPage()
#        apps_page = AppsPage()
        janitor_page = JanitorPage()
        self.preferences_dialog = PreferencesDialog(self.mainwindow)

        self.rencently_used_settings = GSetting('com.ubuntu-tweak.tweak.rencently-used')

        self.feature_dict['overview'] = self.notebook.append_page(clip_page, Gtk.Label())
#        self.feature_dict['apps'] = self.notebook.append_page(apps_page, Gtk.Label())
        self.feature_dict['tweaks'] = self.notebook.append_page(tweaks_page, Gtk.Label())
        self.feature_dict['admins'] = self.notebook.append_page(admins_page, Gtk.Label())
        self.feature_dict['janitor'] = self.notebook.append_page(janitor_page, Gtk.Label())
        self.feature_dict['wait'] = self.notebook.append_page(self._crete_wait_page(),
                                                           Gtk.Label())

        # Always show welcome page at first
        self.mainwindow.connect('realize', self._initialize_ui_states)
        tweaks_page.connect('module_selected', self.on_module_selected)
        admins_page.connect('module_selected', self.on_module_selected)
        clip_page.connect('load_module', lambda widget, name: self.load_module(name))
        clip_page.connect('load_feature', lambda widget, name: self.select_target_feature(name))
        self.mainwindow.show()
        self.link_button.hide()

        if module:
            self.load_module(module)
        elif feature:
            self.select_target_feature(feature)
Beispiel #3
0
from gi.repository import Gio  # for inquiring mime types information
from gi.repository import GObject  # for using custom signals

##from gi.repository import cairo        # Raises the error : 'gi.repository.cairo' object has no attribute 'ImageSurface'
import cairo

from PyPDF2_G.pdf import PdfFileWriter, PdfFileReader

from pdfshuffler_iconview3 import CellRendererImage

GObject.type_register(CellRendererImage)


import time

Gtk.rc_parse("./gtkrc")


class PdfShuffler:
    prefs = {
        "window width": min(700, Gdk.Screen.get_default().get_width() / 2),
        "window height": min(600, Gdk.Screen.get_default().get_height() - 50),
        "window x": 0,
        "window y": 0,
        "initial thumbnail size": 300,
        "initial zoom level": -14,
    }

    MODEL_ROW_INTERN = 1001
    MODEL_ROW_EXTERN = 1002
    TEXT_URI_LIST = 1003
Beispiel #4
0
def main():
    """ creates a HAL component.
        parsees a glade XML file with Gtk.builder or libglade
        calls gladevcp.makepins with the specified XML file
        to create pins and register callbacks.
        main window must be called "window1"
    """
    global gladevcp_debug
    (progdir, progname) = os.path.split(sys.argv[0])

    usage = "usage: %prog [options] myfile.ui"
    parser = OptionParser(usage=usage)
    parser.disable_interspersed_args()
    parser.add_options(options)

    (opts, args) = parser.parse_args()
    if not args:
        parser.print_help()
        sys.exit(1)

    gladevcp_debug = debug = opts.debug
    xmlname = args[0]

    #if there was no component name specified use the xml file name
    if opts.component is None:
        opts.component = os.path.splitext(os.path.basename(xmlname))[0]

    #try loading as a libglade project
    try:
        builder = Gtk.Builder()
        builder.add_from_file(xmlname)
    except:
        try:
            # try loading as a Gtk.builder project
            dbg("**** GLADE VCP INFO:    Not a builder project, trying to load as a lib glade project")
            builder = Gtk.glade.XML(xmlname)
            builder = GladeBuilder(builder)

        except Exception as e:
            print("**** GLADE VCP ERROR:    With xml file: %s : %s" % (xmlname,e), file=sys.stderr)
            sys.exit(0)

    window = builder.get_object("window1")

    window.set_title(opts.component)

    try:
        halcomp = hal.component(opts.component)
    except:
        print("*** GLADE VCP ERROR:    Asking for a HAL component using a name that already exists.", file=sys.stderr)
        sys.exit(0)

    panel = gladevcp.makepins.GladePanel( halcomp, xmlname, builder, None)

    # at this point, any glade HL widgets and their pins are set up.
    handlers, mod, obj = load_handlers(opts.usermod,halcomp,builder,opts.useropts)

    # so widgets can call handler functions - give them refeence to the handler object
    panel.set_handler(obj)

    builder.connect_signals(handlers)

    # This option puts the gladevcp panel into a plug and pushed the plug's
    # X window id number to standard output - so it can be reparented exterally
    # it also forwards events to qtvcp
    if opts.push_XID:
        if not opts.debug:
            # supress warnings when x window closes
            warnings.filterwarnings("ignore")
        # block X errors since Gdk error handling silently exits the
        # program without even the atexit handler given a chance
        Gdk.error_trap_push()

        forward = os.environ.get('QTVCP_FORWARD_EVENTS_TO', None)
        if forward:
            xembed.keyboard_forward(window, forward)

    # This option reparents gladevcp in a given X window id.
    # it also forwards keyboard events from gladevcp to AXIS
    if opts.parent:
        if not opts.debug:
            # supress warnings when x window closes
            warnings.filterwarnings("ignore")
        # block X errors since Gdk error handling silently exits the
        # program without even the atexit handler given a chance
        Gdk.error_trap_push()

        window = xembed.reparent(window, opts.parent)

        forward = os.environ.get('AXIS_FORWARD_EVENTS_TO', None)
        if forward:
            xembed.keyboard_forward(window, forward)

    window.connect("destroy", on_window_destroy)
    window.show()

    # for window resize and or position options
    if "+" in opts.geometry:
        try:
            j =  opts.geometry.partition("+")
            pos = j[2].partition("+")
            window.move( int(pos[0]), int(pos[2]) )
        except:
            print("**** GLADE VCP ERROR:    With window position data", file=sys.stderr)
            parser.print_usage()
            sys.exit(1)
    if "x" in opts.geometry:
        try:
            if "+" in opts.geometry:
                j =  opts.geometry.partition("+")
                t = j[0].partition("x")
            else:
                t = window_geometry.partition("x")
            window.resize( int(t[0]), int(t[2]) )
        except:
            print("**** GLADE VCP ERROR:    With window resize data", file=sys.stderr)
            parser.print_usage()
            sys.exit(1)

    if opts.gtk_rc:
        dbg( "**** GLADE VCP INFO: %s reading gtkrc file '%s'" %(opts.component,opts.gtk_rc))
        Gtk.rc_add_default_file(opts.gtk_rc)
        Gtk.rc_parse(opts.gtk_rc)

    if opts.theme:
        dbg("**** GLADE VCP INFO:    Switching %s to '%s' theme" %(opts.component,opts.theme))
        settings = Gtk.Settings.get_default()
        settings.set_string_property("gtk-theme-name", opts.theme, "")

    # This needs to be done after geometry moves so on dual screens the window maxumizes to the actual used screen size.
    if opts.maximum:
        window.window.maximize()
    if opts.always_above_flag:
        window.set_keep_above(True)
    if opts.halfile:
        if opts.halfile[-4:] == ".tcl":
            cmd = ["haltcl", opts.halfile]
        else:
            cmd = ["halcmd", "-f", opts.halfile]
        res = subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr)
        if res:
            print("'%s' exited with %d" %(' '.join(cmd), res), file=sys.stderr)
            sys.exit(res)

    # User components are set up so report that we are ready
    halcomp.ready()
    GSTAT.forced_update()

    # push the XWindow id number to standard out
    if opts.push_XID or opts.parent:
        w_id = window.get_property('window').get_xid()
        print(w_id, file=sys.stdout)
        sys.stdout.flush()

    if signal_func in handlers:
        dbg("Register callback '%s' for SIGINT and SIGTERM" %(signal_func))
        signal.signal(signal.SIGTERM, handlers[signal_func])
        signal.signal(signal.SIGINT,  handlers[signal_func])

    try:
        Gtk.main()
    except KeyboardInterrupt:
        sys.exit(0)
    finally:
        halcomp.exit()

    if opts.parent or opts.push_XID:
        Gdk.flush()
        error = Gdk.error_trap_pop()
        if error and opts.debug:
            print("**** GLADE VCP ERROR:    X Protocol Error: %s" % str(error), file=sys.stderr)
    def __init__(self):
        Gtk.Box.__init__(self, orientation = Gtk.Orientation.VERTICAL, spacing = 6)
        LOG.debug('Starting')
        
        css = Gtk.CssProvider()
        print css.load_from_data("""
        GtkButton:active {
    background-color: #0274d9;
}

/* Theme buttons with the mouse pointer on it,
   both are equivalent */
GtkButton:hover,
GtkButton:prelight {
    background-color: #3085a9;
}

/* Theme insensitive widgets, both are equivalent */
:insensitive,
*:insensitive {
    background-color: #320a91;
}

/* Theme selection colors in entries */
GtkEntry:selected {
    background-color: #56f9a0;
}

/* Theme focused labels */
GtkLabel:focused {
    background-color: #b4940f;
}
GtkLabel:hover, GtkLabel:active, GtkLabel:selected {
    background-color: #b4940f;
}
        """)
        
        self.background = self.DEFAULT_BACKGROUND
        
        data = 'http://webpub.esi.uclm.es/actualidad/noticias.rss' 
        news_reader = NewsReader(data)
        news_reader.render()
        
        self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(self.background))
        
        
        Gdk.Cursor.new(Gdk.CursorType.HAND2)
        
        self.set_border_width(0)

        self.allocation = Gdk.Rectangle()
        
        title_label = Gtk.Label()
        title_label.set_justify(Gtk.Justification.CENTER)

        title_label.set_halign(Gtk.Align.END)
        title_label.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(self.background))

        bg='black'
        fg =  'blue'
        text = '<b>'  + news_reader.title + '</b>'

        self.pack_start(title_label, True, True, False)
        
        feed_label = Gtk.Label(news_reader.title)
        feed_label.set_justify(Gtk.Justification.LEFT) 
        feed_label.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(self.background))
        
        try:
            self.icon = GdkPixbuf.Pixbuf.new_from_file(join('img', self.RSS_ICON))
        except:
            self.icon = GdkPixbuf.Pixbuf.new_from_file(join(file_path, 'img', self.RSS_ICON))
            
        self.icon = self.icon.scale_simple(32, 32, GdkPixbuf.InterpType.BILINEAR)
        
        self.rss_icon = Gtk.Image()
        self.rss_icon.set_from_pixbuf(self.icon)

        self.hbox = Gtk.Box(orientation = Gtk.Orientation.HORIZONTAL, spacing = 0)
        self.hbox.pack_start(self.rss_icon, expand = False, fill = False, padding = 0)
        self.hbox.pack_start(feed_label, expand = False, fill = False, padding = 0)
        
        self.pack_start(self.hbox, expand = False, fill = False, padding = 0)
        
        content = news_reader.entries_result
        content = self.clean_html(content)
        
        feed_content = Gtk.Label(content)
        feed_content.set_size_request(100, 300)
        feed_content.set_width_chars(80) # This is the real with size
        feed_content.set_line_wrap(True)
        feed_content.set_justify(Gtk.Justification.LEFT) 
        feed_content.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(self.background))
        
        Gtk.rc_parse(join(file_path, 'themes', 'default.txt'))
        #Gtk.rc_parse_string("""style "default" {font_name = "sans 7"}""")
        Gtk.rc_reparse_all()

        style = feed_content.get_style()
        
        context = feed_content.get_style_context()
        context.add_class("backforward-left-button")

        self.pack_start(feed_content, expand = False, fill = False, padding = 0)