Python ui 模块,ImageView() 实例源码

我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用ui.ImageView()

项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
def unimage(self, params):
        self.unimages.append([])
        if self.kivy:
            from kivy.uix.image import Image
            self.unimages[len(self.unimages) - 1] = Image( source= params[4],
                allow_stretch = True, size_hint = (None, None),
                size=(params[2] * self.xratio, params[3] * self.yratio),
                pos=(params[0] * self.xratio, params[1] * self.yratio))

            self.root.add_widget(self.unimages[len(self.unimages) - 1])

        else:
            import ui
            self.unimages[len(self.unimages) - 1] = (ui.ImageView
            (name = 'Image', frame = (params[0] * self.xratio, \
            (600 - params[1] - params[3]) * self.yratio, \
            params[2] * self.xratio, params[3] * self.yratio)))

            self.root.add_subview (self.unimages[len(self.unimages) - 1])
            self.unimages[len(self.unimages) - 1].image = \
                ui.Image.named(params[4])
项目:caves    作者:mikaelho    | 项目源码 | 文件源码
def __init__(self, control, *args, **kwargs):
    super().__init__(*args, **kwargs)
    self.control = control
    self.multiplier = 1.0
    #self.iv = ui.ImageView(args, **kwargs)
    #self.filename = ''
    self.bg_filename = None # Default is caves.jpg
    #self.add_subview(self.iv)
    self.alpha = 0.9
    self.digging = True
    self.flood_filling = False
    self.touch_start = None
    self.target_size = (self.width, self.height)
    self.dragging_waypoint = False
    self.last_img = None
    self.waypoints = []
    self.history_capacity = 10
    self.fill()
项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
def unimage(self, params):
        self.unimages.append([])
        if self.kivy:
            from kivy.uix.image import Image
            self.unimages[len(self.unimages) - 1] = Image( source= params[4],
                allow_stretch = True, size_hint = (None, None),
                size=(params[2] * self.xratio, params[3] * self.yratio),
                pos=(params[0] * self.xratio, params[1] * self.yratio))

            self.root.add_widget(self.unimages[len(self.unimages) - 1])

        else:
            import ui
            self.unimages[len(self.unimages) - 1] = (ui.ImageView
            (name = 'Image', frame = (params[0] * self.xratio, \
            (600 - params[1] - params[3]) * self.yratio, \
            params[2] * self.xratio, params[3] * self.yratio)))

            self.root.add_subview (self.unimages[len(self.unimages) - 1])
            self.unimages[len(self.unimages) - 1].image = \
                ui.Image.named(params[4])
项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
def unimage(self, params):
        self.unimages.append([])
        if self.kivy:
            from kivy.uix.image import Image
            self.unimages[len(self.unimages) - 1] = Image( source= params[4],
                allow_stretch = True, size_hint = (None, None),
                size=(params[2] * self.xratio, params[3] * self.yratio),
                pos=(params[0] * self.xratio, params[1] * self.yratio))

            self.root.add_widget(self.unimages[len(self.unimages) - 1])

        else:
            import ui
            self.unimages[len(self.unimages) - 1] = (ui.ImageView
            (name = 'Image', frame = (params[0] * self.xratio, \
            (600 - params[1] - params[3]) * self.yratio, \
            params[2] * self.xratio, params[3] * self.yratio)))

            self.root.add_subview (self.unimages[len(self.unimages) - 1])
            self.unimages[len(self.unimages) - 1].image = \
                ui.Image.named(params[4])
项目:ui2    作者:controversial    | 项目源码 | 文件源码
def demo_ChainedTransition():
    v1 = ui.View(frame=(0, 0, 500, 500), background_color="pink")
    v1.add_subview(ui.Button(frame=(100, 100, 300, 20)))
    v1.subviews[0].title = "Hello! I'm a button"
    v1.add_subview(ui.Slider(frame=(100, 300, 100, 20)))
    v2 = ui.View(background_color="lightblue")
    v2.add_subview(ui.ImageView(frame=(100, 100, 300, 300)))
    v2.subviews[0].image = ui.Image.named('test:Peppers')
    v3 = ui.View(background_color="lightgreen")
    v3.add_subview(ui.Switch(frame=(100, 100, 20, 10)))
    v3.subviews[0].value = True

    t1 = ui2.Transition(v1, v2, ui2.TRANSITION_CURL_UP, 1.5)
    t2 = ui2.Transition(v2, v3, ui2.TRANSITION_FLIP_FROM_LEFT, 1)
    t3 = ui2.Transition(v3, v1, ui2.TRANSITION_CROSS_DISSOLVE, 1)

    v1.present("sheet", hide_title_bar=True)

    ui2.delay(ui2.ChainedTransition(t1, t2, t3).play, 1)
项目:ui2    作者:controversial    | 项目源码 | 文件源码
def demo_BlurView():
    a = ui.View(frame=(0, 0, 500, 500))
    a.add_subview(ui.ImageView(frame=(0, 0, 500, 500)))
    a.subviews[0].image = ui.Image.named('test:Peppers')
    a.add_subview(ui2.BlurView())
    a.subviews[1].frame = (100, 100, 100, 100)
    a.present('sheet', hide_title_bar=True)

    toggle = ui2.Animation(a.subviews[1].toggle_brightness, 0.5)
    def movea():
        a.subviews[1].x = 300
    def moveb():
        a.subviews[1].y = 300
    def movec():
        a.subviews[1].x = 100
    def moved():
        a.subviews[1].y = 100
    movea = ui2.Animation(movea, 1)
    moveb = ui2.Animation(moveb, 1)
    movec = ui2.Animation(movec, 1)
    moved = ui2.Animation(moved, 1)
    ui2.ChainedAnimation(movea, moveb, movec, moved, toggle,
                         movea, moveb, movec, moved).play()
项目:Pythonista-C64-Painter    作者:superrune    | 项目源码 | 文件源码
def create_zoom_frame(self):
        zoomWidth = self.width / self.zoomLevels[self.zoomCurrent]
        zoomHeight = self.height / self.zoomLevels[self.zoomCurrent]
        # create an movable image showing the zoom area
        with ui.ImageContext(320,200) as ctx:
            ui.set_color('black')
            line_inside = ui.Path.rect(2,2,316,196)
            line_inside.line_width = 4
            line_inside.stroke()
            ui.set_color('white')
            line_outside = ui.Path.rect(0,0,320,200)
            line_outside.line_width = 4
            line_outside.stroke()
            zoomSquare = ctx.get_image()
        zoom_frame = ui.ImageView(hidden=True)
        zoom_frame.bounds = (0,0,zoomWidth,zoomHeight)
        zoom_frame.center = (self.width/2, self.height/2)
        zoom_frame.image = zoomSquare
        self.add_subview(zoom_frame)
        return zoom_frame
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
      PinchView.__init__(self,*args,**kwargs)
      # prevent resize from causing redraw until we r ready
      self.ready=threading.Lock()
      #self.ready.acquire()

      self.img_view = ui.ImageView(frame=self.bounds,flex='WH')
      self.add_subview(self.img_view)
      self.b = io.BytesIO()

      #store base xlim and ylim, only update when drag ends
      self.xlim=plt.xlim()
      self.ylim=plt.ylim()
      self.centroid=tuple(self.center) # zoom center

      # fast and slow dpi.. 
      self.high_dpi=72.0
      self.low_dpi=16
      # set output image size to match view size.  this probably should be modified to use actual device dpi and size.  fonts and line width are based on pts, not pixels
      plt.gcf().set_size_inches(self.width/self.high_dpi,self.height/self.high_dpi)
      #update plot, ensuring update really happens
      self.update_plt(dpi=self.high_dpi, waitForLock=True)

      ObjCInstance(self).becomeFirstResponder()
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
      PinchView.__init__(self,*args,**kwargs)
      # prevent resize from causing redraw until we r ready
      self.ready=threading.Lock()
      #self.ready.acquire()

      self.img_view = ui.ImageView(frame=self.bounds,flex='WH')
      self.add_subview(self.img_view)
      self.b = io.BytesIO()

      #store base xlim and ylim, only update when drag ends
      self.xlim=plt.xlim()
      self.ylim=plt.ylim()
      self.centroid=tuple(self.center) # zoom center

      # fast and slow dpi.. 
      self.high_dpi=72.0
      self.low_dpi=16
      # set output image size to match view size.  this probably should be modified to use actual device dpi and size.  fonts and line width are based on pts, not pixels
      plt.gcf().set_size_inches(self.width/self.high_dpi,self.height/self.high_dpi)
      #update plot, ensuring update really happens
      self.update_plt(dpi=self.high_dpi, waitForLock=True)

      ObjCInstance(self).becomeFirstResponder()
项目:caves    作者:mikaelho    | 项目源码 | 文件源码
def load_actual(self, burn_waypoints_in=False):
    # Clear old waypoints
    for wp in self.edit_view.waypoints:
      self.edit_view.remove_subview(wp)
    self.edit_view.waypoints = []

    # Load image
    img_filename = self.filename
    iv = ui.ImageView(frame=self.bg.bounds)
    iv.image = ui.Image(img_filename)
    self.edit_view.img = snapshot(iv)
    self.multiplier = self.edit_view.img.size[1]/self.edit_view.height

    # Load settings
    json_filename = img_filename[:-3]+'json'
    if os.path.exists(json_filename):
      with open(json_filename) as fp:
        settings = json.load(fp)
      if isinstance(settings, dict):
        locations = settings['waypoint_locations']
        self.bg.image = ui.Image.named(settings['bg_filename'])
        self.edit_view.bg_filename = settings['bg_filename']
      else:
        locations = settings
        self.bg.image = ui.Image.named('backgrounds/caves.jpg')
        self.edit_view.bg_filename = None
      for loc in locations:
        wp = self.edit_view.add_waypoint()
        wp.center = loc

    if burn_waypoints_in:
      with ui.ImageContext(self.edit_view.width, self.edit_view.height) as ctx:
        self.edit_view.img.draw()
        ui.set_blend_mode(ui.BLEND_CLEAR)
        ui.set_color('black')
        for wp in self.edit_view.waypoints:
          (x,y) = wp.center
          path = ui.Path.oval(x-15, y-15, 30, 30)
          path.fill()
        self.edit_view.img = ctx.get_image()
项目:caves    作者:mikaelho    | 项目源码 | 文件源码
def fill(self):
    self.history = []
    self.future = []
    with ui.ImageContext(self.width, self.height) as ctx:
      ui.set_color('black')
      ui.fill_rect(0, 0, self.width, self.height)
#      iv = ui.ImageView(frame=self.bounds)
#      iv.image = ui.Image('playfields/origami.png')
#
#      img = snapshot(iv)
#      blend_mode = ui.B
#      ui.set_blend_mode(blend_mode)
      #iv.image.draw()
#      img.draw()
      self.img = ctx.get_image()
项目:PyDoc    作者:shaun-h    | 项目源码 | 文件源码
def tableView_cellForRowAtIndexPath_(sel,cmd,tableView,indexPath):
    ip = ObjCInstance(indexPath)
    ds = ObjCInstance(sel)
    data = ds.data[ip.row()]
    tv = ObjCInstance(sel)
    cell = ui.TableViewCell('subtitle')
    cell.text_label.text = data['name']
    cell.detail_text_label.text = data['docsetname']
    cell.image_view.image = data['icon']
    cell.border_color = Theme_manager.currentTheme.borderColour
    cell.background_color = Theme_manager.currentTheme.backgroundColour
    cell.bg_color = Theme_manager.currentTheme.backgroundColour
    cell.tint_color = Theme_manager.currentTheme.tintColour
    cell.text_label.text_color = Theme_manager.currentTheme.textColour
    cell.detail_text_label.text_color = Theme_manager.currentTheme.subTextColour
    selectedBackgroundView = ui.View()
    selectedBackgroundView.background_color = Theme_manager.currentTheme.cellSelectionColour
    if not Theme_manager.currentTheme.showCellSelection:
        selectedBackgroundView.alpha = 0
    cell.selected_background_view = selectedBackgroundView
    iv = ui.ImageView()
    cell.content_view.add_subview(iv)
    iv.image = data['type'].icon
    iv.width = 15
    iv.height = 15
    iv.x = cell.content_view.width - (iv.width * 2)
    iv.y = (cell.content_view.height) / 2 - (iv.height)
    iv.flex = 'L'
    return ObjCInstance(cell).ptr
项目:Pythonista-C64-Painter    作者:superrune    | 项目源码 | 文件源码
def init_draw_image(self):
        image_view = ui.ImageView(frame=self.bounds)
        image_view.image = self.init_pixel_grid()
        self.add_subview(image_view)
        return image_view
项目:Pythonista-C64-Painter    作者:superrune    | 项目源码 | 文件源码
def create_image_view(self):
        image_view = ui.ImageView(frame=self.bounds)
        image_view.image = self.create_new_image()
        self.add_subview(image_view)
        return image_view
项目:Pythonista-C64-Painter    作者:superrune    | 项目源码 | 文件源码
def preview_big_window(self, sender):
        if self.pixel_editor.has_image():
            v = ui.ImageView(frame=(100,100,320,200))

            # CRT Emulation
            ui_im = self.pixel_editor.get_image()
            # insert CRT emulation here, convert to ui_to_pil
            v.image = ui_im

            v.width, v.height = v.image.size
            v.present('popover', popover_location=(100, 100), hide_title_bar=True)
        else:
            self.show_error()
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def tableview_cell_for_row(self, tv, section, row):
        cell = ui.TableViewCell()
        entry = self.flat_entries[row]
        level = entry.level - 1
        image_view = ui.ImageView(frame=(44 + 20*level, 5, 34, 34))
        label_x = 44+34+8+20*level
        label_w = cell.content_view.bounds.w - label_x - 8
        if entry.subtitle:
            label_frame = (label_x, 0, label_w, 26)
            sub_label = ui.Label(frame=(label_x, 26, label_w, 14))
            sub_label.font = ('<System>', 12)
            sub_label.text = entry.subtitle
            sub_label.text_color = '#999'
            cell.content_view.add_subview(sub_label)
        else:
            label_frame = (label_x, 0, label_w, 44)
        label = ui.Label(frame=label_frame)
        if entry.subtitle:
            label.font = ('<System>', 15)
        else:
            label.font = ('<System>', 18)
        label.text = entry.title
        label.flex = 'W'
        cell.content_view.add_subview(label)
        if entry.leaf and not entry.enabled:
            label.text_color = '#999'
        cell.content_view.add_subview(image_view)
        if not entry.leaf:
            has_children = entry.expanded
            btn = ui.Button(image=ui.Image.named('CollapseFolder' if has_children else 'ExpandFolder'))
            btn.frame = (20*level, 0, 44, 44)
            btn.action = self.expand_dir_action
            cell.content_view.add_subview(btn)
        if entry.icon_name:
            image_view.image = ui.Image.named(entry.icon_name)
        else:
            image_view.image = None
        cell.selectable = entry.enabled
        return cell
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def make_image_view(self, image_name=''):  # fullscreen background photo
        image_view = ui.ImageView(frame=self.bounds)
        image_view.image = ui.Image.from_data(photos.get_image(raw_data=True))
        return image_view
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self, N_onscreen=700,*args, **kwargs):
      ui.View.__init__(self,*args,**kwargs)
      # ready lock is used to protect calls to matplotlib
      self.ready=threading.Lock()
      #set up zoomable sliders
      self.hslider=ZoomSlider(frame=(self.width*0.08,0,self.width*0.84,self.height*0.08),vert=0,flex='wt')
      self.vslider=ZoomSlider(frame=(0,self.height*0.08,self.width*0.08,self.height*0.84),vert=1,flex='hr')
      self.add_subview(self.hslider)
      self.add_subview(self.vslider)
      self.hslider.barvalue=0.125
      self.hslider.barwidth=0.25
      self.vslider.barvalue=0.5
      self.vslider.barwidth=1.0
      self.hslider.action=self.did_slide
      self.vslider.action=self.did_slide
      #matplotlib image output
      self.img_view = ui.ImageView(frame=[self.width*0.08,self.height*0.08,self.width*0.84,self.height*0.84],flex='WH',bg_color=(1,1,1))
      self.add_subview(self.img_view)
      # image buffer
      self.b = io.BytesIO()

      #store base xlim and ylim, only update when drag ends
      self.xlim=plt.xlim()
      self.ylim=plt.ylim()
      self.N_onscreen=N_onscreen # number of points onscreen

      # fast and slow dpi..  set low_dpi to lower number for snappier response
      self.high_dpi=92
      self.low_dpi=16.
      self.device_dpi=72
      # set output image size to match view size.  this probably should be modified to use actual device dpi and size.  fonts and line width are based on pts, not pixels
      plt.gcf().set_size_inches(self.img_view.width/self.device_dpi,self.img_view.height/self.device_dpi)
      #update plot, ensuring update really happens
      #self.update_plt(dpi=self.high_dpi, waitForLock=True)

      #ObjCInstance(self).becomeFirstResponder()
项目:caves    作者:mikaelho    | 项目源码 | 文件源码
def flood_fill_start_marker(self, starting_point, base_color):
    marker_color = pil_color('#ffc688')
    #marker_color = pil_color(base_color)
    marker_color = tuple([min(marker_color[i], 255) for i in range(3)])
    start_area_view = ui.ImageView(frame=self.bounds)
    start_area_view.touch_enabled = False
    with io.BytesIO(snapshot(start_area_view).to_png()) as fp:
      pil = pilImage.open(fp).resize((int(self.width), int(self.height)))
      canvas = pil.load()
      starting_point = inttuple(starting_point)
      canvas[starting_point] = marker_color + (125,)
      edge = [starting_point]
      sp_vector = Vector(starting_point)
      while edge:
        newedge = []
        for (x, y) in edge:
          for candidate in ((x+1, y), (x-1, y), (x, y+1), (x, y-1)):
            distance = sp_vector.distance_to(candidate)
            if distance <= 15 and self.playfield[candidate][3] == 0 and canvas[candidate][3] == 0:
              ceil_dist = math.ceil(distance)
              if ceil_dist == 15:
                color = pil_color((1,1,1,0.9))
              elif ceil_dist == 14:
                color = pil_color((0.5,0.5,0.5,0.9))
              elif ceil_dist == 13:
                color = pil_color((0,0,0,0.9))
              elif ceil_dist == 12:
                color = pil_color((0.5,0.5,0.5,0.9))
              else:
                color = pil_color((1,1,1,0.01))
              canvas[candidate] = color
              #canvas[candidate] = marker_color + (125,) #(int(10+230/15*distance), )
              newedge.append(candidate)
        edge = newedge

    with io.BytesIO() as fp:
      pil.save(fp, 'PNG')
      start_area_view.image = ui.Image.from_data(fp.getvalue())

    self.add_subview(start_area_view)

    return canvas


#class TimedVectorPlayingLayer(PlayingLayer):
项目:caves    作者:mikaelho    | 项目源码 | 文件源码
def __init__(self, control, spec, *args, **kwargs):
    super().__init__(*args, **kwargs)

    self.control = control
    img_view = ui.ImageView(frame=self.bounds)

    img_view.image = ui.Image.named("playfields/caves of soukka.png")
    self.add_subview(img_view)

    self.menu = ui.View(frame=(
      30, self.height/2.1, self.width - 60, self.height/2 - 30
    ), corner_radius=10)
    #self.menu.background_color=(0,0,0,0.7)
    self.add_subview(self.menu)

    (_,_,w,h) = self.menu.frame
    def pick_map(sender):
      self.control.load_map(next_func=self.control.set_map_for_play)
    self.map_btn = ui.Button(title='Pick map', tint_color='white', background_color=self.menu_color, corner_radius=5, action=pick_map)
    self.menu.add_subview(self.map_btn)
    self.map_btn.frame = (0.05*w, 0.05*h, 0.55*w, 50)

    (title, action) = spec[2]
    self.menu_button(title, action, 50, (0.7*w, 0.05*h+25))
    (title, action) = spec[1]
    self.menu_button(title, action, 50, (0.9*w, 0.05*h+25))

    self.icons = {}
    self.small_icons = {}
    for i in range(len(self.control.icon_names)):
      icon =   ui.Image.named(self.control.icon_names[i]).with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
      small_icon = ui.Image.named(self.control.small_icon_names[i]).with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
      name = 'player'+str(i)
      self.icons[name] = icon
      self.small_icons[name] = small_icon
      btn = self.menu_color_button(
        name, self.control.colors[i], icon,
        (0.05*w + i*51, 0.25*h))
      if i > 0:
        self.toggle(btn)

    (title, action) = spec[0]
    self.menu_button(title, action, 50, (0.9*w, 0.25*h+25))

    #btn = self.create_button
    #self.set_menu('main', spec)
项目:blackmamba    作者:zrzka    | 项目源码 | 文件源码
def tableview_cell_for_row(self, tv, section, row):
        if section == self._folder_section:
            item = self.items[row]
            node = item['node']
        else:
            item = self._files[row]
            node = None

        cell = ui.TableViewCell()

        cvb = cell.content_view.bounds

        x = 15 + cvb.x + item['level'] * 15

        if node and node.children_exists:
            image_view = ui.ImageView()
            image_view.frame = (x, 10, 24, 24)
            image_view.image = ui.Image.named(
                'iob:arrow_down_b_24' if node.path in self._expanded_node_paths else 'iob:arrow_right_b_24'
            )
            cell.content_view.add_subview(image_view)

        x += 24 + 8

        image_view = ui.ImageView()
        image_view.frame = (x, 10, 24, 24)
        image_view.image = ui.Image.named('iob:folder_24' if node else 'iob:document_24')
        cell.content_view.add_subview(image_view)

        x += 24 + 8

        title_label = ui.Label(flex='W')
        title_label.text = item['title']
        title_label.size_to_fit()
        title_label.frame = (
            x, cvb.y + (cvb.height - title_label.height) / 2.0,
            cvb.width - (x - cvb.x) - 8, title_label.height
        )
        cell.content_view.add_subview(title_label)

        separator = ui.View(flex='W')
        separator.background_color = (0, 0, 0, 0.05)
        x = title_label.frame.x - 12 - 8
        separator.frame = (
            x, cvb.y + cvb.height - 1,
            cvb.width - (x - cvb.x), 1
        )
        cell.content_view.add_subview(separator)

        cell_objc = ObjCInstance(cell)
        cell_objc.setSelectionStyle(0)

        return cell