Ejemplo n.º 1
0
 def set_theme(self, tname=None):
     if tname is None:
         return
     screen = self.dialog.get_screen()
     settings = gtk.settings_get_for_screen(screen)
     settings.set_string_property('gtk-theme-name', tname, "")
     theme = settings.get_property('gtk-theme-name')
Ejemplo n.º 2
0
 def button_press_event(self, widget, event):
     x = event.x
     # flipy so y=0 is bottom of canvas
     y = self.allocation.height - event.y
     dblclick = (event.type == gdk._2BUTTON_PRESS)
     if not dblclick:
         # GTK is the only backend that generates a DOWN-UP-DOWN-DBLCLICK-UP  event
         # sequence for a double click.  All other backends have a DOWN-UP-DBLCLICK-UP
         # sequence.  In order to provide consistency to matplotlib users, we will
         # eat the extra DOWN event in the case that we detect it is part of a double
         # click.
         # first, get the double click time in milliseconds.
         current_time = event.get_time()
         last_time = self.last_downclick.get(event.button, 0)
         dblclick_time = gtk.settings_get_for_screen(
             gdk.screen_get_default()).get_property('gtk-double-click-time')
         delta_time = current_time - last_time
         if delta_time < dblclick_time:
             del self.last_downclick[
                 event.button]  # we do not want to eat more than one event.
             return False  # eat.
         self.last_downclick[event.button] = current_time
     FigureCanvasBase.button_press_event(self,
                                         x,
                                         y,
                                         event.button,
                                         dblclick=dblclick,
                                         guiEvent=event)
     return False  # finish event propagation?
Ejemplo n.º 3
0
    def on_size_allocate(self, widget, allocation):
        """
            Takes care of resizing the icon if necessary
        """
        screen = widget.get_screen()
        settings = gtk.settings_get_for_screen(screen)
        icon_sizes = (
            gtk.ICON_SIZE_MENU,  # 1
            gtk.ICON_SIZE_SMALL_TOOLBAR,  # 2
            gtk.ICON_SIZE_LARGE_TOOLBAR,  # 3
            gtk.ICON_SIZE_BUTTON,  # 4
            gtk.ICON_SIZE_DND,  # 5
            gtk.ICON_SIZE_DIALOG  # 6
        )
        # Retrieve pixel dimensions of stock icon sizes
        sizes = [(gtk.icon_size_lookup_for_settings(settings, i)[0], i)
                 for i in icon_sizes]
        # Only look at sizes lower than the current dimensions
        sizes = [(s, i) for s, i in sizes if s <= allocation.width]
        # Get the closest fit
        target_size = max(sizes)[1]

        # Avoid setting the same size over and over again
        if self.image.props.icon_size is not target_size.real:
            glib.idle_add(self.image.set_from_icon_name,
                          self.image.props.icon_name, target_size)
Ejemplo n.º 4
0
 def set_theme(self,tname=None):
     if tname is None:
         return
     screen   = self.dialog.get_screen()
     settings = gtk.settings_get_for_screen(screen)
     settings.set_string_property('gtk-theme-name',tname,"")
     theme    = settings.get_property('gtk-theme-name')
Ejemplo n.º 5
0
Archivo: roio.py Proyecto: ov1d1u/roio
    def __init__(self, *args, **kwargs):
        super(RoioGUI, self).__init__()
        gtk.rc_reset_styles(
            gtk.settings_get_for_screen(self.mainWindow.get_screen()))

        # initial values
        self.is_maximized = bool(
            self.mainWindow.get_state() == gtk.gdk.WINDOW_STATE_MAXIMIZED)
        self.account_data = {}

        # customize the UI
        pixbuf = gtk.gdk.pixbuf_new_from_file('ui/top_bar.png')
        (pixmap, mask) = pixbuf.render_pixmap_and_mask(255)
        style = self.topbox.get_style().copy()
        style.bg_pixmap[gtk.STATE_NORMAL] = pixmap
        self.topbox.set_style(style)

        self.windowBox.modify_bg(gtk.STATE_NORMAL,
                                 gtk.gdk.color_parse("white"))
        self.bodyBox.modify_bg(gtk.STATE_NORMAL,
                               gtk.gdk.color_parse("#222222"))
        self.bottomBox.modify_bg(gtk.STATE_NORMAL,
                                 gtk.gdk.color_parse("#191919"))

        # init network handler
        self.net = ROIONetwork()

        # we're ready to go
        self.show_first_content()
Ejemplo n.º 6
0
    def on_size_allocate(self, widget, allocation):
        """
            Takes care of resizing the icon if necessary
        """
        screen = widget.get_screen()
        settings = gtk.settings_get_for_screen(screen)
        icon_sizes = (
            gtk.ICON_SIZE_MENU, # 1
            gtk.ICON_SIZE_SMALL_TOOLBAR, # 2
            gtk.ICON_SIZE_LARGE_TOOLBAR, # 3
            gtk.ICON_SIZE_BUTTON, # 4
            gtk.ICON_SIZE_DND, # 5
            gtk.ICON_SIZE_DIALOG # 6
        )
        # Retrieve pixel dimensions of stock icon sizes
        sizes = [(gtk.icon_size_lookup_for_settings(settings, i)[0], i)
                 for i in icon_sizes]
        # Only look at sizes lower than the current dimensions
        sizes = [(s, i) for s, i in sizes if s <= allocation.width]
        # Get the closest fit
        target_size = max(sizes)[1]

        # Avoid setting the same size over and over again
        if self.image.props.icon_size is not target_size.real:
            glib.idle_add(self.image.set_from_icon_name,
                self.image.props.icon_name, target_size)
Ejemplo n.º 7
0
def on_header_motion_notify(item, event):
    if not header_button_down:
        return

    distance = max(abs(event.x - header_button_down_x), abs(event.x - header_button_down_x))
    double_click_distance = gtk.settings_get_for_screen(window.get_screen()).props.gtk_double_click_distance
    if distance > double_click_distance:
        begin_move()
Ejemplo n.º 8
0
 def button_press_event(self, widget, event):
     x = event.x
     # flipy so y=0 is bottom of canvas
     y = self.allocation.height - event.y
     dblclick = (event.type == gdk._2BUTTON_PRESS)
     if not dblclick:
         # GTK is the only backend that generates a DOWN-UP-DOWN-DBLCLICK-UP  event
         # sequence for a double click.  All other backends have a DOWN-UP-DBLCLICK-UP
         # sequence.  In order to provide consistency to matplotlib users, we will
         # eat the extra DOWN event in the case that we detect it is part of a double
         # click.
         # first, get the double click time in milliseconds.
         current_time  = event.get_time()
         last_time     = self.last_downclick.get(event.button,0)
         dblclick_time = gtk.settings_get_for_screen(gdk.screen_get_default()).get_property('gtk-double-click-time')
         delta_time    = current_time-last_time
         if delta_time < dblclick_time:
             del self.last_downclick[event.button] # we do not want to eat more than one event.
             return False                          # eat.
         self.last_downclick[event.button] = current_time
     FigureCanvasBase.button_press_event(self, x, y, event.button, dblclick=dblclick, guiEvent=event)
     return False  # finish event propagation?
Ejemplo n.º 9
0
    def __init__(self):
        self.entry = None
        self.timeout = 0
        self.is_a11y_theme = False
        self.search_timeout = 300
        self.menu = None

        gtk.HBox.__gobject_init__(self)
        self.set_spacing(HIG.PAD_NORMAL)
        self.set_border_width(HIG.PAD_NORMAL)

        settings = gtk.settings_get_for_screen(self.get_screen())
        theme = settings.get_property("gtk-theme-name")
        self.is_a11y_theme = theme == "HighContrast" or theme == "LowContrast"

        label = gtk.Label()
        label.set_text_with_mnemonic(_("_Filter:"))
        label.set_justify(gtk.JUSTIFY_RIGHT)
        self.pack_start(label, False, True, 0)

        self.entry = gtk.Entry()
        if gtk.__dict__.has_key("ENTRY_ICON_PRIMARY"):
            # We have primary/secondary icon support.
            self.entry.set_icon_from_stock(gtk.ENTRY_ICON_PRIMARY, gtk.STOCK_FIND)
            self.entry.set_icon_from_stock(gtk.ENTRY_ICON_SECONDARY, gtk.STOCK_CLEAR)

            self.entry.set_icon_sensitive(gtk.ENTRY_ICON_SECONDARY, False)
            self.entry.set_icon_activatable(gtk.ENTRY_ICON_SECONDARY, False)
            self.entry.connect("icon-press", self.on_icon_press)

        label.set_mnemonic_widget(self.entry)

        self.pack_start(self.entry, True, True, 0)

        self.entry.connect("changed", self.on_changed)
        self.entry.connect("focus_out_event", self.on_focus_out_event)
        self.entry.connect("activate", self.on_activate)
Ejemplo n.º 10
0
Archivo: roio.py Proyecto: ov1d1u/roio
    def __init__(self, *args, **kwargs):
    	super(RoioGUI, self).__init__()
        gtk.rc_reset_styles(gtk.settings_get_for_screen(self.mainWindow.get_screen()))

    	# initial values
    	self.is_maximized = bool(self.mainWindow.get_state() == gtk.gdk.WINDOW_STATE_MAXIMIZED)
        self.account_data = {}

    	# customize the UI
    	pixbuf = gtk.gdk.pixbuf_new_from_file('ui/top_bar.png')
    	(pixmap, mask) = pixbuf.render_pixmap_and_mask(255)
    	style = self.topbox.get_style().copy()
    	style.bg_pixmap[gtk.STATE_NORMAL] = pixmap
    	self.topbox.set_style(style)

    	self.windowBox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("white"))
    	self.bodyBox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#222222"))
    	self.bottomBox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#191919"))

        # init network handler
        self.net = ROIONetwork()

        # we're ready to go
        self.show_first_content()
Ejemplo n.º 11
0
        try:
            self.last_file = self.halg._current_file
        except AttributeError:
            self.last_file = None
        self.last_file_mtime = None

        self.parent = parent
        if self.parent is None:
            # topwindow (standalone) application
            # print "TOP:",gtk_theme_name
            screen   = self.topwindow.get_screen()
        else:
            # print "REPARENT:",gtk_theme_name
            screen   = self.halg.get_screen()

        settings = gtk.settings_get_for_screen(screen)
        systname = settings.get_property("gtk-theme-name")
        if (   (gtk_theme_name is None)
            or (gtk_theme_name == "")
            or (gtk_theme_name == "Follow System Theme")):
            gtk_theme_name = systname
        settings.set_string_property('gtk-theme-name',gtk_theme_name,"")

        self.topwindow.connect('destroy',self._topwindowquit)
        self.topwindow.show_all()
        self.running = True

        if self.last_file is not None:
            self.topwindow.set_title(g_progname
                      + ': ' + os.path.basename(self.last_file))
            self.last_file_mtime = datetime.datetime.fromtimestamp(
Ejemplo n.º 12
0
    def __init__(
            self,
            glade_file=None  #None: use default ui
        ,
            parent=None,
            width=None,
            height=None,
            alive=True,
            gtk_theme_name="Follow System Theme"):

        self.alive = alive
        linuxcnc_running = False
        if ini_check():
            linuxcnc_running = True

        if (glade_file == None):
            glade_file = os.path.join(g_ui_dir, 'gremlin_view.ui')

        bldr = gtk.Builder()
        try:
            bldr.add_from_file(glade_file)
        except glib.GError as detail:
            print('\nGremlinView:%s\n' % detail)
            raise glib.GError(detail)  # re-raise

        # required objects:
        self.topwindow = bldr.get_object('gremlin_view_window')
        self.gbox = bldr.get_object('gremlin_view_box')
        self.halg = bldr.get_object('gremlin_view_hal_gremlin')

        #self.halg.show_lathe_radius = 1 # for test, hal_gremlin default is Dia

        if not linuxcnc_running:
            # blanks display area:
            self.halg.set_has_window(False)

        # radiobuttons for selecting view: (expect at least one)
        select_view_letters = ['p', 'x', 'y', 'z', 'z2']
        found_view = None
        for vletter in select_view_letters:
            try:
                obj = bldr.get_object('select_' + vletter + '_view')
            except:
                continue
            if obj is not None:
                setattr(self, vletter + '_view', obj)
                if found_view is None:
                    found_view = obj
                    self.my_view = vletter
                    obj.set_group(None)
                    obj.set_active(True)
                else:
                    obj.set_group(found_view)
        if found_view is None:
            print('%s:Expected to find "select_*_view"' % __file__)

        check_button_objects = [
            'enable_dro', 'show_machine_speed', 'show_distance_to_go',
            'show_limits', 'show_extents', 'show_tool', 'show_metric'
        ]
        for objname in check_button_objects:
            obj = bldr.get_object(objname)
            if obj is not None:
                setattr(self, 'objname', obj)
                obj.set_active(True)
            else:
                if g_verbose:
                    print('%s: Optional object omitted <%s>' %
                          (__file__, objname))

        # show_metric: use ini file
#FIXME  show_metric,lunits s/b mandatory?
        try:
            objname = 'show_metric'
            self.show_metric = bldr.get_object('show_metric')
            lunits = self.halg.inifile.find('TRAJ', 'LINEAR_UNITS')
        except AttributeError:
            if g_verbose:
                print('%s: Problem for <%s>' % (__file__, objname))

        if linuxcnc_running:
            if lunits == 'inch':
                self.halg.metric_units = False
            elif lunits == 'mm':
                self.halg.metric_units = True
            else:
                raise AttributeError('%s: unknown [TRAJ]LINEAR_UNITS] <%s>' %
                                     (__file__, lunits))

        if self.halg.get_show_metric():
            self.show_metric.set_active(True)
        else:
            self.show_metric.set_active(False)

        if alive:
            bldr.connect_signals(self)
            # todo: to remove other signals on halg:
            # bldr.disconnect(integer_handle_id)
            # bldr.disconnect_by_func('func_name')
            # bldr.handler_disconnect()

        minwidth = 300  # smallest size
        minheight = 300  # smallest size

        if (width is None):
            width = minwidth
        else:
            width = int(width)

        if (height is None):
            height = minheight
        else:
            height = int(height)

        if width < minwidth:
            width = minwidth
        if height < minheight:
            height = minheight

        # err from gremlin if omit this
        self.halg.width = width
        self.halg.height = height
        self.halg.set_size_request(width, height)

        # self.x,self.y used in conjunction with pan buttons
        # but using mouse may change internal values in gremlin
        # resulting in unexpected movement if both mouse and
        # pan buttons are used
        self.x = 0
        self.y = 0

        #  prevent flashing topwindow
        self.topwindow.iconify()
        self.topwindow.show_all()
        self.topwindow.hide()

        self.preview_file(None)
        if linuxcnc_running:
            try:
                self.preview_file(None)
            except linuxcnc.error as detail:
                print('linuxcnc.error')
                print('        detail=', detail)

        try:
            self.last_file = self.halg._current_file
        except AttributeError:
            self.last_file = None
        self.last_file_mtime = None

        self.parent = parent
        if self.parent is None:
            # topwindow (standalone) application
            # print "TOP:",gtk_theme_name
            screen = self.topwindow.get_screen()
        else:
            # print "REPARENT:",gtk_theme_name
            screen = self.halg.get_screen()

        settings = gtk.settings_get_for_screen(screen)
        systname = settings.get_property("gtk-theme-name")
        if ((gtk_theme_name is None) or (gtk_theme_name == "")
                or (gtk_theme_name == "Follow System Theme")):
            gtk_theme_name = systname
        settings.set_string_property('gtk-theme-name', gtk_theme_name, "")

        self.topwindow.connect('destroy', self._topwindowquit)
        self.topwindow.show_all()
        self.running = True

        if self.last_file is not None:
            self.topwindow.set_title(g_progname + ': ' +
                                     os.path.basename(self.last_file))
            self.last_file_mtime = datetime.datetime.fromtimestamp(
                os.path.getmtime(self.last_file))

        self.ct = 0
        if self.parent is None: self.topwindow.deiconify()
        self._periodic('BEGIN')
        gobject.timeout_add_seconds(g_periodic_secs, self._periodic,
                                    'Continue')