当前位置: 首页>>代码示例>>Python>>正文


Python Color.connect方法代码示例

本文整理汇总了Python中color.Color.connect方法的典型用法代码示例。如果您正苦于以下问题:Python Color.connect方法的具体用法?Python Color.connect怎么用?Python Color.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在color.Color的用法示例。


在下文中一共展示了Color.connect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: save

# 需要导入模块: from color import Color [as 别名]
# 或者: from color.Color import connect [as 别名]

#.........这里部分代码省略.........
                ("File", None, "_File"),
                ("Action", None, "_Action"),
                ("Help", None, "_Help"),
            ]
        )

        uimanager.insert_action_group(actiongroup)
        uimanager.add_ui_from_string(
            """
    <ui>
      <menubar name="ElicitMain">
        <menu action="File">
          <menuitem action="Save"/>
          <menuitem action="Quit"/>
        </menu>
        <menu action="Action">
          <menuitem action="Magnify"/>
          <menuitem action="Select Color"/>
        </menu>
        <menu action="Help">
          <menuitem action="About"/>
        </menu>
      </menubar>
    </ui>
    """
        )
        menubar = uimanager.get_widget("/ElicitMain")
        return menubar

    def build_gui(self):
        self.win = gtk.Window()
        self.win.set_title("Elicit")
        self.win.set_icon_name("rephorm-elicit")
        self.win.connect("destroy", self.quit, None)

        main_vbox = gtk.VBox(False, 2)

        menubar = self.build_menu()
        w_vbox = gtk.VBox()
        w_vbox.pack_start(menubar, False)
        w_vbox.pack_end(main_vbox, True)
        # main_vbox.pack_start(menubar, False)
        main_vbox.set_border_width(7)
        self.win.add(w_vbox)

        frame_mag = gtk.Frame()
        frame_mag.set_shadow_type(gtk.SHADOW_NONE)

        frame_mag_inner = gtk.Frame()
        frame_mag_inner.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        self.mag = Magnifier()
        frame_mag_inner.add(self.mag)
        mag_vbox = gtk.VBox()
        mag_vbox.pack_start(frame_mag_inner)
        frame_mag.add(mag_vbox)
        self.mag.connect("zoom-changed", self.mag_zoom_changed)
        self.mag.connect("grid-toggled", self.mag_grid_toggled)
        self.mag.connect("measure-changed", self.mag_measure_changed)
        self.mag.connect("location-changed", self.mag_location_changed)

        hbox = gtk.HBox(False, 0)

        self.mag_label = gtk.Label()
        hbox.pack_start(self.mag_label, False)

        icon_path = os.path.join(os.path.dirname(__file__), "data", "icons")
开发者ID:molok,项目名称:elicit-gtk,代码行数:70,代码来源:elicit.py

示例2: ColorPicker

# 需要导入模块: from color import Color [as 别名]
# 或者: from color.Color import connect [as 别名]
class ColorPicker(gtk.Widget):
  """
  A widget to select colors from the screen

  This displays the currently selected color and handles grabbing a color
  from anywhere on screen.

  It also allows dragging and dropping of colors from and onto the widget.

  Signals:
    'save-color' - save the current color
  """
  data_path = os.path.join(os.path.dirname(__file__), 'data')
  icon_path = os.path.join(data_path, 'icons')

  __gsignals__ = {
      'save-color': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ())
  }

  def __init__(self):
    """ Initialize color picker """
    super(ColorPicker, self).__init__()
    self.pick_rate = 60
    self.color = Color()
    self.mag = None
    self.picking = 0
    self.pick_timeout = None
    self.save_on_release = False

  def set_magnifier(self, mag):
    """
    Set the magnifier widget
    This is needed so that we can pick colors directly from the magnified
    image when possible
    """
    self.mag = mag

  def set_color(self, color):
    """
    Set the color object to store selected colors in

    This color object is updated when a new color is selected or dropped
    on the widget.

    To explicitly change the selected color, do not use this function, but
    instead call set_rgb() or set_hsv() on the current color object.
    """
    self.color = color
    self.color.connect('changed', self.color_changed)

  def color_changed(self, color):
    """ Callback for color changes """
    if not self.flags() & gtk.REALIZED: return

    r,g,b = self.color.rgb16()
    col = self.gc.get_colormap().alloc_color(r, g, b, False, False)
    self.gc.set_foreground(col)
    self.queue_draw()

  def pick_immediate(self, x, y, magnifier):
    """
    Select the color at the specified pixel

    The coordinates are relative to the screen.
    """

    if self.flags() & gtk.REALIZED == False: return

    if magnifier:
      r,g,b = self.mag.raw_pixbuf.get_pixels_array()[y,x]
    else:
      # grab raw screen data
      self.raw_pixbuf.get_from_drawable(
          gdk.get_default_root_window(),
          gdk.colormap_get_system(),
          x, y,
          0, 0,
          self.raw_width, self.raw_height)

      #pull out rgb value
      #XXX first time this is called generates a warning and doesn't work.
      #    all subsequent times are fine. why?
      r,g,b = self.raw_pixbuf.get_pixels_array()[0,0]

    self.color.set_rgb(r,g,b)

  def cb_pick_timeout(self):
    """ Callback for pick timeout """
    # repeat time until we've realized the widget
    if self.flags() & gtk.REALIZED == False:
      return True

    # widget is realized, so grab data and end timer
    self.pick_immediate(self.pick_x, self.pick_y, self.pick_mag)
    self.pick_timeout = None
    return False

  def cb_drag_set_color(self, color, x, y):
    """ Drag set color callback """
    self.color.set_rgb(*color.rgb())
#.........这里部分代码省略.........
开发者ID:rephorm,项目名称:elicit-gtk,代码行数:103,代码来源:colorpicker.py

示例3: save

# 需要导入模块: from color import Color [as 别名]
# 或者: from color.Color import connect [as 别名]

#.........这里部分代码省略.........
      ('About', gtk.STOCK_ABOUT, '_About', None, 'About Elicit', self.action_about),
      ('Magnify', gtk.STOCK_ABOUT, '_Magnify', '<Ctrl>z', 'Start Magnifying', self.action_magnify),
      ('Select Color', gtk.STOCK_ABOUT, 'Select _Color', '<Ctrl>d', 'Start Selecting Color', self.action_pick_color),
      ('File', None, '_File'),
      ('Action', None, '_Action'),
      ('Help', None, '_Help')
      ])

    uimanager.insert_action_group(actiongroup)
    uimanager.add_ui_from_string("""
    <ui>
      <menubar name="ElicitMain">
        <menu action="File">
          <menuitem action="Save"/>
          <menuitem action="Quit"/>
        </menu>
        <menu action="Action">
          <menuitem action="Magnify"/>
          <menuitem action="Select Color"/>
        </menu>
        <menu action="Help">
          <menuitem action="About"/>
        </menu>
      </menubar>
    </ui>
    """)
    menubar = uimanager.get_widget("/ElicitMain")
    return menubar

  def build_gui(self):
    self.win = gtk.Window()
    self.win.set_title("Elicit")
    self.win.set_icon_name('rephorm-elicit')
    self.win.connect('destroy', self.quit, None)

    vbox = gtk.VBox(False, 2)
    self.win.add(vbox)

    menubar = self.build_menu()
    vbox.pack_start(menubar, False)

    # notebook with magnifier, etc
    hbox = gtk.HBox(False, 0)
    vbox.pack_start(hbox, True, True)
    notebook = gtk.Notebook()
    self.notebook = notebook
    hbox.pack_start(notebook, True, True, padding=HPAD)

    # magnifier tab
    mag_vbox = gtk.VBox(False, 2)
    mag_tab_icon = gtk.Image()
    mag_tab_icon.set_from_file(os.path.join(self.icon_path, "magnify-16.png"))
    notebook.append_page(mag_vbox, mag_tab_icon)

    # the magnifier
    hbox = gtk.HBox(False, 0)
    mag_vbox.pack_start(hbox, True, True)

    frame = gtk.Frame()
    frame.set_shadow_type(gtk.SHADOW_IN)
    hbox.pack_start(frame, True, True, padding=HPAD)

    self.mag = Magnifier()
    frame.add(self.mag)
    self.mag.connect('zoom-changed', self.mag_zoom_changed)
    self.mag.connect('grid-toggled', self.mag_grid_toggled)
开发者ID:rephorm,项目名称:elicit-gtk,代码行数:70,代码来源:elicit.py


注:本文中的color.Color.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。