1

I am currently trying to develop a simple instant messenger with a GUI based in Gtk+3. I am using PyCharm on OS X. I read this post, but I already have gtk+3 and pygobject3 installed (I attempted to [again] install them with Homebrew but I got the messages: "gtk+3 3.22.19 is already installed" and "pygobject3 3.24.1_1 is already installed"). My code thus far:

import threading
import re

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

import gobject
import socket
import time
import datetime

gobject.threads_init()

class MainWindow(Gtk.Window):

My specific concerns are that in PyCharm, require_version is highlighted, saying "Cannot find reference 'require_version' in __init__.py, repository is highlighted saying "Cannot find reference 'repository' in __init__.py, and Gtk is underlined saying "Unresolved refernce 'Gtk'. I am unsure as to why, however, there is no protest when I type Gtk.Window or Gtk.Entry() [snipped]. My final concern is that threads_init() is highlighted, again saying "Cannot find reference 'threads_init()' in __init__.py. Could someone offer some insight as to what is wrong? I have done a good amount of research, but I have found very little that fits my particular situation: Mac, python3, and the two modules already installed.

Secondary question: The guide I am using to write this code is written in python2, and I will be writing in python3, so does anyone know of a good source that would indicate the differences in Gtk between python2 and python3 (what is new, maybe) so I might be able to write the correct python3 version of the gtk code?

Ryan Flynn
  • 71
  • 1
  • 8
  • The `gi.repository` imports generally don't work with tools like PyCharm because their contents are generated dynamically by C code, not defined in Python source files. – ptomato Sep 02 '17 at 03:01
  • It actually works with pycharm these days you just need to right click and have it scan binary libraries or such. – TingPing Sep 03 '17 at 09:42
  • Also nothing about Gtk is different in Python 2 vs Python 3 (sadly). – TingPing Sep 03 '17 at 09:42
  • @TingPing Thank you for the answer to the secondary question! Could you elaborate on right-clicking to scan binary libraries? I attempted to do so, but did not find such an option in the menu box. I also regular-clicked on the highlighted portions: `gi.repository` produced an option "Generate stubs for binary module gi.repository.Gtk" upon clicking on the lightbulb that appeared, but selecting that option did not seem to change anything. Any suggestions? – Ryan Flynn Sep 03 '17 at 12:24
  • I don't have it currently installed but I know that option has been successful in the past for me. – TingPing Sep 03 '17 at 13:53

0 Answers0