def addImageFile(self, path): path = os.path.normpath(path) if os.path.dirname(path) != self.storage_folder: # scale and copy the image to our photo dir try: image = NSImage.alloc().initWithContentsOfFile_(path) except: NSRunAlertPanel( NSLocalizedString("Camera Capture Error", "Window title"), NSLocalizedString("%s is not a valid image", "Label") % path, NSLocalizedString("OK", "Button title"), None, None) return size = image.size() if size.width > 128 or size.height > 128: image.setScalesWhenResized_(True) image.setSize_(NSMakeSize(128, 128 * size.height / size.width)) finalpath = self.storage_folder + "/" + os.path.basename(path) prefix, ext = os.path.splitext(finalpath) i = 0 while os.path.exists(finalpath): finalpath = prefix + str(i) + ext image.TIFFRepresentation().writeToFile_atomically_( finalpath, False) self.refreshLibrary()
def awakeFromNib(self): smileys = SmileyManager().get_smiley_list() menu = self.smileyButton.menu() while menu.numberOfItems() > 0: menu.removeItemAtIndex_(0) bigText = NSAttributedString.alloc().initWithString_attributes_( " ", NSDictionary.dictionaryWithObject_forKey_( NSFont.systemFontOfSize_(16), NSFontAttributeName)) for text, file in smileys: image = NSImage.alloc().initWithContentsOfFile_(file) if not image: print("cant load %s" % file) continue image.setScalesWhenResized_(True) image.setSize_(NSMakeSize(16, 16)) atext = bigText.mutableCopy() atext.appendAttributedString_( NSAttributedString.alloc().initWithString_(text)) item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( text, "insertSmiley:", "") menu.addItem_(item) item.setTarget_(self) item.setAttributedTitle_(atext) item.setRepresentedObject_( NSAttributedString.alloc().initWithString_(text)) item.setImage_(image)
def render_pidf(self): if not self.contact: return has_locations = False status_label = '' if self.contact.presence_state['devices']: has_locations = any(device['location'] for device in list(self.contact.presence_state['devices'].values()) if device['location'] is not None) count = len(self.contact.presence_state['devices']) if count == 1: status_label = NSLocalizedString("One device available", "Label") elif count > 1: status_label = NSLocalizedString("%d devices available" % count, "Label") splitViewFrame = self.splitView.frame() mapViewFrame = self.mapViewSplitView.frame() pidfViewFrame = self.pidfView.frame() if has_locations: if mapViewFrame.size.height == 0: mapViewFrame.size.height = SPLITTER_HEIGHT self.mapViewSplitView.setFrame_(mapViewFrame) pidfViewFrame.size.height -= SPLITTER_HEIGHT self.pidfView.setFrame_(pidfViewFrame) self.mapView.setContact(self.contact) nr_countries = len(self.mapView.selectedCountries) if nr_countries == 1: status_label += NSLocalizedString(" in one country", "Label") elif nr_countries > 1: status_label += NSLocalizedString(" in %d countries" % nr_countries, "Label") else: mapViewFrame.size.height = 0 self.mapViewSplitView.setFrame_(mapViewFrame) pidfViewFrame.size.height = splitViewFrame.size.height self.pidfView.setFrame_(pidfViewFrame) self.statusLabel.setStringValue_(status_label) text = '' for pidf in self.contact.pidfs: text += self.build_pidf_text(pidf) + '\n\n' if self.contact.presence_state['pending_authorizations']: text += "Pending authorizations:\n" pending_authorizations = self.contact.presence_state['pending_authorizations'] for key in list(pending_authorizations.keys()): text += " Subscription to %s from account %s\n" % (sip_prefix_pattern.sub('', key), pending_authorizations[key]) self.presenceText.textStorage().deleteCharactersInRange_(NSMakeRange(0, self.presenceText.textStorage().length())) astring = NSAttributedString.alloc().initWithString_(text) self.presenceText.textStorage().appendAttributedString_(astring) image = presence_status_for_contact(self.contact) if image: icon = NSImage.imageNamed_(image) icon.setScalesWhenResized_(True) icon.setSize_(NSMakeSize(12,12)) self.presence_icon.setImage_(icon)
def show(self, item): if not self.items: #self.statusItem = NSStatusBar.systemStatusBar().statusItemWithLength_(30) self.statusItem = Null self.menu = NSMenu.alloc().init() image = NSImage.imageNamed_("display").copy() image.setSize_(NSMakeSize(24, 24)) self.statusItem.setImage_(image) self.statusItem.setMenu_(self.menu) self.items.append(item) mitem = self.menu.addItemWithTitle_action_keyEquivalent_( NSLocalizedString("%s - Waiting", "Menu item") % item.sessionController.titleLong, "activateItem:", "") mitem.setTag_(item.sessionController.identifier) mitem.setTarget_(self)
def _NH_CameraSnapshotDidSucceed(self, notification): self.photoView.setHidden_(False) self.captureView.setHidden_(True) self.previewButton.setHidden_(False) self.countdownCheckbox.setHidden_(True) self.mirrorButton.setHidden_(True) self.captureButton.setHidden_(True) self.useButton.setEnabled_(True) self.captured_image = notification.data.image image = notification.data.image image.setScalesWhenResized_(True) h = self.photoView.frame().size.height w = h * self.captured_image.size().width / self.captured_image.size( ).height image.setSize_(NSMakeSize(w, h)) self.photoView.setImage_(image)
def initWithSwitcher_item_(self, switcher, item): self = NSView.initWithFrame_(self, NSMakeRect(0, 2, 100, 18)) if self: self.closeIcon.setSize_(NSMakeSize(12, 12)) self.closeButton = NSButton.alloc().initWithFrame_( NSMakeRect(3, 5, 12, 14)) self.closeButton.setImagePosition_(NSImageOnly) self.closeButton.setButtonType_(NSMomentaryChangeButton) self.closeButton.cell().setBezelStyle_(NSSmallSquareBezelStyle) self.closeButton.setBordered_(False) self.closeButton.setImage_(self.closeIcon) self.closeButton.setAutoresizingMask_(NSViewMaxXMargin | NSViewMaxYMargin) self.closeButton.setHidden_(True) self.addSubview_(self.closeButton) self.switcher = switcher self.item = item return self
def updateIcon(self, icon): image = NSImage.alloc().initWithSize_(NSMakeSize(48, 48)) image.lockFocus() size = icon.size() icon.drawAtPoint_fromRect_operation_fraction_( NSMakePoint((48 - size.width) / 2, (48 - size.height) / 2), NSMakeRect(0, 0, size.width, size.height), NSCompositeSourceOver, 1) # overlay file transfer direction icon if type(self.transfer) == OutgoingPushFileTransferHandler or ( self.oldTransferInfo and self.oldTransferInfo.direction == "outgoing"): icon = NSImage.imageNamed_("outgoing_file") else: icon = NSImage.imageNamed_("incoming_file") icon.drawAtPoint_fromRect_operation_fraction_( NSMakePoint(2, 4), NSMakeRect(0, 0, size.width, size.height), NSCompositeSourceOver, 1) image.unlockFocus() self.icon.setImage_(image)
def drawRect_(self, rect): r = self.bounds() r.size.width -= 0.5 r.size.height += 4 if self.draggedOut: NSColor.colorWithDeviceWhite_alpha_(0.4, 1.0).set() path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_( r, 5, 5) path.fill() else: if self == self.switcher.activeItem(): NSColor.controlColor().set() else: NSColor.colorWithDeviceWhite_alpha_(0.6, 1.0).set() path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_( r, 5, 5) path.fill() NSColor.colorWithDeviceRed_green_blue_alpha_(0.3, 0.3, 0.3, 1.0).set() path.stroke() if self.badgeLabel and not self.mouseInside and not self.busyIndicator and not self.composing: # draw the number in redbadge indicator gradient = NSGradient.alloc().initWithStartingColor_endingColor_( NSColor.colorWithDeviceRed_green_blue_alpha_(0.9, 0.2, 0.2, 1), NSColor.colorWithDeviceRed_green_blue_alpha_(1.0, 0.2, 0.2, 1)) size = self.badgeLabel.size() size.width += 4 if size.width < 12: size.width = 12 bez = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_( NSMakeRect(3, 5, size.width, 12), 6, 6) gradient.drawInBezierPath_angle_(bez, 90 + 45) self.badgeLabel.drawInRect_(NSMakeRect(3, 5, size.width, 12)) if not self.mouseInside and not self.busyIndicator and self.composing: rect = NSZeroRect.copy() rect.size = self.composeIcon.size() self.composeIcon.drawAtPoint_fromRect_operation_fraction_( NSMakePoint(1, 3), rect, NSCompositeSourceOver, 1) if not self.busyIndicator and self.screen_sharing_active: rect = NSZeroRect.copy() rect.size = self.screenIcon.size() self.screenIcon.drawAtPoint_fromRect_operation_fraction_( NSMakePoint(17, 3), rect, NSCompositeSourceOver, 1) if not self.draggedOut: shadow = NSShadow.alloc().init() shadow.setShadowOffset_(NSMakeSize(0, -1)) if self == self.switcher.activeItem(): shadow.setShadowColor_(NSColor.whiteColor()) else: shadow.setShadowColor_( NSColor.colorWithDeviceWhite_alpha_(0.7, 1.0)) para = NSParagraphStyle.defaultParagraphStyle().mutableCopy() para.setLineBreakMode_(NSLineBreakByTruncatingTail) para.setAlignment_(NSCenterTextAlignment) attribs = NSDictionary.dictionaryWithObjectsAndKeys_( NSFont.systemFontOfSize_(11), NSFontAttributeName, shadow, NSShadowAttributeName, para, NSParagraphStyleAttributeName) rect = self.bounds() rect.origin.y -= 3 rect.origin.x += 20 rect.origin.x = rect.origin.x + 12 if self.screen_sharing_active else rect.origin.x rect.size.width -= 46 rect.size.width = rect.size.width - 12 if self.screen_sharing_active else rect.size.width self.label.drawInRect_withAttributes_(rect, attribs)
def cellSize(self): if self.conference_file is None: return objc.super(ConferenceFileCell, self).cellSize() return NSMakeSize(100, 30)
def cellSize(self): if self.contact is None: return objc.super(ContactCell, self).cellSize() return NSMakeSize(100, 30)